Skip to content

Commit 538f71e

Browse files
committed
Closes #7
1 parent 53046ac commit 538f71e

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

frontend/config.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ void Config::save_memory_editor(std::string sessionid, MemEditor *editor)
278278
memconfig->optShowHexII = editor->_memoryEditor.OptShowHexII;
279279
memconfig->optShowOptions = editor->_memoryEditor.OptShowOptions;
280280
memconfig->optUpperCaseHex = editor->_memoryEditor.OptUpperCaseHex;
281+
memconfig->optHighlightChanges = editor->_memoryEditor.OptHighlightChanges;
281282
memconfig->selected_bank = editor->_memBank;
282283
}
283284
else
@@ -293,6 +294,7 @@ void Config::save_memory_editor(std::string sessionid, MemEditor *editor)
293294
store.optShowHexII = editor->_memoryEditor.OptShowHexII;
294295
store.optShowOptions = editor->_memoryEditor.OptShowOptions;
295296
store.optUpperCaseHex = editor->_memoryEditor.OptUpperCaseHex;
297+
store.optHighlightChanges = editor->_memoryEditor.OptHighlightChanges;
296298
store.selected_bank = editor->_memBank;
297299
found->mem_editors.push_back(store);
298300
}
@@ -342,6 +344,7 @@ void Config::load_memory_editor(std::string sessionid, MemEditor *editor)
342344
editor->_memoryEditor.OptShowHexII = memconfig->optShowHexII;
343345
editor->_memoryEditor.OptShowOptions = memconfig->optShowOptions;
344346
editor->_memoryEditor.OptUpperCaseHex = memconfig->optUpperCaseHex;
347+
editor->_memoryEditor.OptHighlightChanges = memconfig->optHighlightChanges;
345348
editor->_memBank = (LynxMemBank)memconfig->selected_bank;
346349
}
347350

frontend/include/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct SessionMemEditorConfigStore
7676
bool optShowAscii;
7777
bool optGreyOutZeroes;
7878
bool optUpperCaseHex;
79+
bool optHighlightChanges;
7980
int optMidColsCount;
8081
int optAddrDigitsCount;
8182
float optFooterExtraHeight;
@@ -93,6 +94,7 @@ struct SessionMemEditorConfigStore
9394
archive(CEREAL_NVP(optUpperCaseHex));
9495
archive(CEREAL_NVP(optMidColsCount));
9596
archive(CEREAL_NVP(optAddrDigitsCount));
97+
archive(CEREAL_NVP(optHighlightChanges));
9698
archive(CEREAL_NVP(optFooterExtraHeight));
9799
archive(CEREAL_NVP(selected_bank));
98100
}

frontend/include/imgui_memory_editor.h

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)