@@ -75,15 +75,16 @@ struct MemoryEditor
7575 };
7676
7777 // Settings
78- bool Open ; // = true // set to false when DrawWindow() was closed. ignore if not using DrawWindow().
79- bool ReadOnly ; // = false // disable any editing.
80- int Cols ; // = 16 // number of columns to display.
81- bool OptShowOptions ; // = true // display options button/context menu. when disabled, options will be locked unless you provide your own UI for them.
82- bool OptShowDataPreview ; // = false // display a footer previewing the decimal/binary/hex/float representation of the currently selected bytes.
83- bool OptShowHexII ; // = false // display values in HexII representation instead of regular hexadecimal: hide null/zero bytes, ascii values as ".X".
84- bool OptShowAscii ; // = true // display ASCII representation on the right side.
85- bool OptGreyOutZeroes ; // = true // display null/zero bytes using the TextDisabled color.
86- bool OptUpperCaseHex ; // = true // display hexadecimal values as "FF" instead of "ff".
78+ bool Open ; // = true // set to false when DrawWindow() was closed. ignore if not using DrawWindow().
79+ bool ReadOnly ; // = false // disable any editing.
80+ int Cols ; // = 16 // number of columns to display.
81+ bool OptShowOptions ; // = true // display options button/context menu. when disabled, options will be locked unless you provide your own UI for them.
82+ bool OptShowDataPreview ; // = false // display a footer previewing the decimal/binary/hex/float representation of the currently selected bytes.
83+ bool OptShowHexII ; // = false // display values in HexII representation instead of regular hexadecimal: hide null/zero bytes, ascii values as ".X".
84+ bool OptShowAscii ; // = true // display ASCII representation on the right side.
85+ bool OptGreyOutZeroes ; // = true // display null/zero bytes using the TextDisabled color.
86+ bool OptUpperCaseHex ; // = true // display hexadecimal values as "FF" instead of "ff".
87+ bool OptHighlightChanges ;
8788 int OptMidColsCount ; // = 8 // set to 0 to disable extra spacing between every mid-cols.
8889 int OptAddrDigitsCount ; // = 0 // number of addr digits to display (default calculated based on maximum displayed addr).
8990 float OptFooterExtraHeight ; // = 0 // space to reserve at the bottom of the widget to add custom widgets
@@ -104,6 +105,8 @@ struct MemoryEditor
104105 size_t HighlightMin , HighlightMax ;
105106 int PreviewEndianess ;
106107 ImGuiDataType PreviewDataType ;
108+ ImU8 PreviousStates [0xFFFF + 1 ]{};
109+ ImU8 HighlightDecay [0xFFFF + 1 ]{};
107110
108111 MemoryEditor ()
109112 {
@@ -117,6 +120,7 @@ struct MemoryEditor
117120 OptShowAscii = true;
118121 OptGreyOutZeroes = true;
119122 OptUpperCaseHex = true;
123+ OptHighlightChanges = true;
120124 OptMidColsCount = 8 ;
121125 OptAddrDigitsCount = 0 ;
122126 OptFooterExtraHeight = 0.0f ;
@@ -324,8 +328,8 @@ struct MemoryEditor
324328 if (DataEditingTakeFocus )
325329 {
326330 ImGui ::SetKeyboardFocusHere (0 );
327- snprintf (AddrInputBuf ,sizeof (AddrInputBuf ), format_data , s .AddrDigitsCount , base_display_addr + addr );
328- snprintf (DataInputBuf ,sizeof (DataInputBuf ), format_byte , ReadFn ? ReadFn (mem_data , addr , HandlersContext ) : mem_data [addr ]);
331+ snprintf (AddrInputBuf , sizeof (AddrInputBuf ), format_data , s .AddrDigitsCount , base_display_addr + addr );
332+ snprintf (DataInputBuf , sizeof (DataInputBuf ), format_byte , ReadFn ? ReadFn (mem_data , addr , HandlersContext ) : mem_data [addr ]);
329333 }
330334 struct UserData
331335 {
@@ -384,6 +388,30 @@ struct MemoryEditor
384388 // NB: The trailing space is not visible but ensure there's no gap that the mouse cannot click on.
385389 ImU8 b = ReadFn ? ReadFn (mem_data , addr , HandlersContext ) : mem_data [addr ];
386390
391+ if (OptHighlightChanges )
392+ {
393+ if (PreviousStates [addr ] != b )
394+ {
395+ HighlightDecay [addr ] = 60 ;
396+ }
397+
398+ PreviousStates [addr ] = b ;
399+
400+ if (HighlightDecay [addr ])
401+ {
402+ ImVec2 pos = ImGui ::GetCursorScreenPos ();
403+ float highlight_width = s .GlyphWidth * 2 ;
404+ if (n + 1 == Cols )
405+ {
406+ highlight_width = s .HexCellWidth ;
407+ if (OptMidColsCount > 0 && n > 0 && (n + 1 ) < Cols && ((n + 1 ) % OptMidColsCount ) == 0 )
408+ highlight_width += s .SpacingBetweenMidCols ;
409+ }
410+ draw_list -> AddRectFilled (pos , ImVec2 (pos .x + highlight_width , pos .y + s .LineHeight ), IM_COL32 (255 , 0 , 255 , HighlightDecay [addr ] * 4 ));
411+ -- HighlightDecay [addr ];
412+ }
413+ }
414+
387415 if (OptShowHexII )
388416 {
389417 if ((b >= 32 && b < 128 ))
@@ -494,6 +522,7 @@ struct MemoryEditor
494522 }
495523 ImGui ::Checkbox ("Grey out zeroes" , & OptGreyOutZeroes );
496524 ImGui ::Checkbox ("Uppercase Hex" , & OptUpperCaseHex );
525+ ImGui ::Checkbox ("Highlight changes" , & OptHighlightChanges );
497526
498527 ImGui ::EndPopup ();
499528 }
0 commit comments