Skip to content

Commit

Permalink
Add ascii highlight to selection in memory editor
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jun 10, 2024
1 parent 47af433 commit 129c8de
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
19 changes: 18 additions & 1 deletion platforms/desktop-shared/imgui/memory_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,16 @@ void MemEditor::Draw(uint8_t* mem_data, int mem_size, int base_display_addr)
{
ImGui::TableNextColumn();

int byte_address = address + x;
ImVec2 cell_start_pos = ImGui::GetCursorScreenPos() - ImGui::GetStyle().CellPadding;
ImVec2 cell_size = (character_size * ImVec2(1, 1)) + (ImVec2(2, 2) * ImGui::GetStyle().CellPadding) + ImVec2(1 + byte_cell_padding, 0);

DrawSelectionAsciiBackground(x, byte_address, cell_start_pos, cell_size);

ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (character_cell_padding * 1) / 2);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
ImGui::PushItemWidth(character_size.x);

int byte_address = address + x;
unsigned char c = mem_data[byte_address];

bool gray_out = m_gray_out_zeros && (c < 32 || c >= 128);
Expand Down Expand Up @@ -305,6 +310,18 @@ void MemEditor::DrawSelectionBackground(int x, int address, ImVec2 cell_pos, ImV
drawList->AddRectFilled(cell_pos, cell_pos + cell_size, ImColor(background_color));
}

void MemEditor::DrawSelectionAsciiBackground(int x, int address, ImVec2 cell_pos, ImVec2 cell_size)
{
ImDrawList* drawList = ImGui::GetWindowDrawList();
ImVec4 background_color = dark_cyan;
int start = m_selection_start <= m_selection_end ? m_selection_start : m_selection_end;
int end = m_selection_end >= m_selection_start ? m_selection_end : m_selection_start;

if (address < start || address > end)
return;
drawList->AddRectFilled(cell_pos, cell_pos + cell_size, ImColor(background_color));
}

void MemEditor::DrawSelectionFrame(int x, int y, int address, ImVec2 cell_pos, ImVec2 cell_size)
{
ImDrawList* drawList = ImGui::GetWindowDrawList();
Expand Down
1 change: 1 addition & 0 deletions platforms/desktop-shared/imgui/memory_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class MemEditor
private:
bool IsColumnSeparator(int current_column, int column_count);
void DrawSelectionBackground(int x, int address, ImVec2 cellPos, ImVec2 cellSize);
void DrawSelectionAsciiBackground(int x, int address, ImVec2 cellPos, ImVec2 cellSize);
void DrawSelectionFrame(int x, int y, int address, ImVec2 cellPos, ImVec2 cellSize);
void HandleSelection(int address, int row);
void JumpToAddress(int address);
Expand Down

0 comments on commit 129c8de

Please sign in to comment.