1
0
mirror of synced 2024-11-28 09:30:51 +01:00

fix: Flickering of selection frame in hex editor view when scrolling

This commit is contained in:
WerWolv 2023-12-17 18:26:36 +01:00
parent c3d99e29dc
commit a315ecb831
2 changed files with 10 additions and 21 deletions

View File

@ -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;

View File

@ -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();