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

ui: Fix highlighting of separator column in hex editor

Fixes #776
This commit is contained in:
WerWolv 2022-10-10 17:26:05 +02:00
parent 6975d7e2cd
commit daca49658e
2 changed files with 29 additions and 24 deletions

View File

@ -114,6 +114,7 @@ namespace hex::plugin::builtin {
void drawFooter(const ImVec2 &size);
void handleSelection(u64 address, u32 bytesPerCell, const u8 *data, bool cellHovered);
std::optional<color_t> applySelectionColor(u64 byteAddress, std::optional<color_t> color);
private:
u16 m_bytesPerRow = 16;

View File

@ -522,6 +522,27 @@ namespace hex::plugin::builtin {
return std::nullopt;
}
std::optional<color_t> ViewHexEditor::applySelectionColor(u64 byteAddress, std::optional<color_t> color) {
if (!color.has_value())
return std::nullopt;
if (this->isSelectionValid()) {
auto selection = this->getSelection();
if (byteAddress >= selection.getStartAddress() && byteAddress <= selection.getEndAddress()) {
if (color.has_value())
color = (ImAlphaBlendColors(color.value(), this->m_selectionColor)) & 0x00FFFFFF;
else
color = this->m_selectionColor;
}
}
if (color.has_value())
color = (*color & 0x00FFFFFF) | (this->m_selectionColor & 0xFF000000);
return color;
}
struct CustomEncodingData {
std::string displayValue;
size_t advance;
@ -811,25 +832,7 @@ namespace hex::plugin::builtin {
// Query cell colors
if (x < std::ceil(float(validBytes) / bytesPerCell)) {
const auto foregroundColor = queryForegroundColor(byteAddress, &bytes[x * cellBytes], cellBytes);
const auto backgroundColor = [&]{
auto color = queryBackgroundColor(byteAddress, &bytes[x * cellBytes], cellBytes);
if (this->isSelectionValid()) {
auto selection = this->getSelection();
if (byteAddress >= selection.getStartAddress() && byteAddress <= selection.getEndAddress()) {
if (color.has_value())
color = (ImAlphaBlendColors(color.value(), this->m_selectionColor)) & 0x00FFFFFF;
else
color = this->m_selectionColor;
}
}
if (color.has_value())
color = (*color & 0x00FFFFFF) | (this->m_selectionColor & 0xFF000000);
return color;
}();
const auto backgroundColor = queryBackgroundColor(byteAddress, &bytes[x * cellBytes], cellBytes);
cellColors.emplace_back(
foregroundColor,
@ -862,8 +865,9 @@ namespace hex::plugin::builtin {
auto [foregroundColor, backgroundColor] = cellColors[x];
if (isColumnSeparatorColumn(x + 1, columnCount)) {
if (this->isSelectionValid() && this->getSelection().getEndAddress() != x + y * columnCount)
cellSize.x += SeparatorColumWidth + 1;
auto separatorAddress = x + y * columnCount;
if ((this->isSelectionValid() && this->getSelection().overlaps({ separatorAddress, 1 }) && this->getSelection().getEndAddress() != separatorAddress) || cellColors[x] == cellColors[x + 1])
cellSize.x += SeparatorColumWidth + 1;
}
if (y == u64(clipper.DisplayStart))
@ -874,7 +878,7 @@ namespace hex::plugin::builtin {
auto drawList = ImGui::GetWindowDrawList();
// Draw background color
drawList->AddRectFilled(cellStartPos, cellStartPos + cellSize, backgroundColor.value());
drawList->AddRectFilled(cellStartPos, cellStartPos + cellSize, applySelectionColor(byteAddress, backgroundColor).value());
// Draw frame around mouse selection
this->drawSelectionFrame(x, y, byteAddress, bytesPerCell, cellStartPos, cellSize);
@ -936,7 +940,7 @@ namespace hex::plugin::builtin {
auto drawList = ImGui::GetWindowDrawList();
// Draw background color
drawList->AddRectFilled(cellStartPos, cellStartPos + cellSize, backgroundColor.value());
drawList->AddRectFilled(cellStartPos, cellStartPos + cellSize, applySelectionColor(byteAddress, backgroundColor).value());
this->drawSelectionFrame(x, y, byteAddress, 1, cellStartPos, cellSize);
}
@ -994,7 +998,7 @@ namespace hex::plugin::builtin {
auto drawList = ImGui::GetWindowDrawList();
// Draw background color
drawList->AddRectFilled(cellStartPos, cellStartPos + cellSize, backgroundColor.value());
drawList->AddRectFilled(cellStartPos, cellStartPos + cellSize, applySelectionColor(address, backgroundColor).value());
this->drawSelectionFrame(x, y, address, 1, cellStartPos, cellSize);
}