diff --git a/plugins/builtin/include/ui/hex_editor.hpp b/plugins/builtin/include/ui/hex_editor.hpp index 02850d657..08341a845 100644 --- a/plugins/builtin/include/ui/hex_editor.hpp +++ b/plugins/builtin/include/ui/hex_editor.hpp @@ -26,7 +26,7 @@ namespace hex::plugin::builtin::ui { enum class CellType { None, Hex, ASCII }; void drawCell(u64 address, const u8 *data, size_t size, bool hovered, CellType cellType); - void drawSelectionFrame(u32 x, u32 y, u64 byteAddress, u16 bytesPerCell, const ImVec2 &cellPos, const ImVec2 &cellSize) const; + void drawSelectionFrame(u32 x, u32 y, Region selection, u64 byteAddress, u16 bytesPerCell, const ImVec2 &cellPos, const ImVec2 &cellSize, const ImColor &backgroundColor) const; void drawEditor(const ImVec2 &size); void drawFooter(const ImVec2 &size); void drawTooltip(u64 address, const u8 *data, size_t size) const; diff --git a/plugins/builtin/source/ui/hex_editor.cpp b/plugins/builtin/source/ui/hex_editor.cpp index 023173953..32d6f3d73 100644 --- a/plugins/builtin/source/ui/hex_editor.cpp +++ b/plugins/builtin/source/ui/hex_editor.cpp @@ -262,10 +262,9 @@ namespace hex::plugin::builtin::ui { } } - void HexEditor::drawSelectionFrame(u32 x, u32 y, u64 byteAddress, u16 bytesPerCell, const ImVec2 &cellPos, const ImVec2 &cellSize) const { + void HexEditor::drawSelectionFrame(u32 x, u32 y, Region selection, u64 byteAddress, u16 bytesPerCell, const ImVec2 &cellPos, const ImVec2 &cellSize, const ImColor &backgroundColor) const { if (!this->isSelectionValid()) return; - const auto selection = getSelection(); if (!Region { byteAddress, 1 }.isWithin(selection)) return; @@ -273,6 +272,9 @@ namespace hex::plugin::builtin::ui { auto drawList = ImGui::GetWindowDrawList(); + // Draw background color + drawList->AddRectFilled(cellPos, cellPos + cellSize, backgroundColor); + // Draw vertical line at the left of first byte and the start of the line if (x == 0 || byteAddress == selection.getStartAddress()) drawList->AddLine(cellPos, cellPos + ImVec2(0, cellSize.y), ImColor(SelectionFrameColor), 1_scaled); @@ -304,6 +306,8 @@ namespace hex::plugin::builtin::ui { return; } + const auto selection = getSelection(); + ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(0.5, 0)); if (ImGui::BeginTable("##hex", byteColumnCount, ImGuiTableFlags_ScrollY | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoKeepColumnsVisible, size)) { View::discardNavigationRequests(); @@ -449,13 +453,8 @@ namespace hex::plugin::builtin::ui { // Draw highlights and selection if (backgroundColor.has_value()) { - auto drawList = ImGui::GetWindowDrawList(); - - // Draw background color - drawList->AddRectFilled(cellStartPos, cellStartPos + cellSize, backgroundColor.value()); - // Draw frame around mouse selection - this->drawSelectionFrame(x, y, byteAddress, bytesPerCell, cellStartPos, cellSize); + this->drawSelectionFrame(x, y, selection, byteAddress, bytesPerCell, cellStartPos, cellSize, backgroundColor.value()); } const bool cellHovered = ImGui::IsMouseHoveringRect(cellStartPos, cellStartPos + cellSize, false); @@ -513,12 +512,7 @@ namespace hex::plugin::builtin::ui { // Draw highlights and selection if (backgroundColor.has_value()) { - auto drawList = ImGui::GetWindowDrawList(); - - // Draw background color - drawList->AddRectFilled(cellStartPos, cellStartPos + cellSize, backgroundColor.value()); - - this->drawSelectionFrame(x, y, byteAddress, 1, cellStartPos, cellSize); + this->drawSelectionFrame(x, y, selection, byteAddress, 1, cellStartPos, cellSize, backgroundColor.value()); } ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (this->m_characterCellPadding * 1_scaled) / 2); @@ -587,12 +581,7 @@ namespace hex::plugin::builtin::ui { // Draw highlights and selection if (backgroundColor.has_value()) { - auto drawList = ImGui::GetWindowDrawList(); - - // Draw background color - drawList->AddRectFilled(cellStartPos, cellStartPos + cellSize, backgroundColor.value()); - - this->drawSelectionFrame(x, y, address, 1, cellStartPos, cellSize); + this->drawSelectionFrame(x, y, selection, address, 1, cellStartPos, cellSize, backgroundColor.value()); } auto startPos = ImGui::GetCursorPos();