From d9af85f4582becda697482edce03959ddd15ca17 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 18 Jun 2023 12:23:47 +0200 Subject: [PATCH] impr: Split offset column into Start and End column in pattern data view --- plugins/builtin/romfs/lang/de_DE.json | 3 +- plugins/builtin/romfs/lang/en_US.json | 3 +- plugins/builtin/romfs/lang/es_ES.json | 1 - plugins/builtin/romfs/lang/it_IT.json | 1 - plugins/builtin/romfs/lang/ja_JP.json | 1 - plugins/builtin/romfs/lang/ko_KR.json | 1 - plugins/builtin/romfs/lang/pt_BR.json | 1 - plugins/builtin/romfs/lang/zh_CN.json | 1 - plugins/builtin/romfs/lang/zh_TW.json | 1 - plugins/builtin/source/ui/pattern_drawer.cpp | 59 ++++++++++++++------ 10 files changed, 45 insertions(+), 27 deletions(-) diff --git a/plugins/builtin/romfs/lang/de_DE.json b/plugins/builtin/romfs/lang/de_DE.json index fe14a8569..757f03da3 100644 --- a/plugins/builtin/romfs/lang/de_DE.json +++ b/plugins/builtin/romfs/lang/de_DE.json @@ -365,10 +365,11 @@ "hex.builtin.nodes.visualizer.layered_dist.header": "Schichtverteilung", "hex.builtin.pattern_drawer.color": "Farbe", "hex.builtin.pattern_drawer.double_click": "Doppelklicken um mehr Einträge zu sehen", + "hex.builtin.pattern_drawer.end": "Ende", "hex.builtin.pattern_drawer.favorites": "", "hex.builtin.pattern_drawer.local": "", - "hex.builtin.pattern_drawer.offset": "Offset", "hex.builtin.pattern_drawer.size": "Grösse", + "hex.builtin.pattern_drawer.start": "Start", "hex.builtin.pattern_drawer.tree_style.auto_expanded": "Automatisch geöffneter Baum", "hex.builtin.pattern_drawer.tree_style.flattened": "Flach", "hex.builtin.pattern_drawer.tree_style.tree": "Baum", diff --git a/plugins/builtin/romfs/lang/en_US.json b/plugins/builtin/romfs/lang/en_US.json index c54d05edf..282cf781c 100644 --- a/plugins/builtin/romfs/lang/en_US.json +++ b/plugins/builtin/romfs/lang/en_US.json @@ -366,11 +366,12 @@ "hex.builtin.nodes.visualizer.layered_dist.header": "Layered Distribution", "hex.builtin.pattern_drawer.color": "Color", "hex.builtin.pattern_drawer.double_click": "Double-click to see more items", + "hex.builtin.pattern_drawer.end": "End", "hex.builtin.pattern_drawer.export": "Export Patterns as...", "hex.builtin.pattern_drawer.favorites": "Favorites", "hex.builtin.pattern_drawer.local": "Local", - "hex.builtin.pattern_drawer.offset": "Offset", "hex.builtin.pattern_drawer.size": "Size", + "hex.builtin.pattern_drawer.start": "Start", "hex.builtin.pattern_drawer.tree_style.tree": "Tree", "hex.builtin.pattern_drawer.tree_style.auto_expanded": "Auto Expanded Tree", "hex.builtin.pattern_drawer.tree_style.flattened": "Flattened", diff --git a/plugins/builtin/romfs/lang/es_ES.json b/plugins/builtin/romfs/lang/es_ES.json index e72d94c51..39712ab28 100644 --- a/plugins/builtin/romfs/lang/es_ES.json +++ b/plugins/builtin/romfs/lang/es_ES.json @@ -367,7 +367,6 @@ "hex.builtin.pattern_drawer.double_click": "Haga doble clic para ver más elementos", "hex.builtin.pattern_drawer.favorites": "", "hex.builtin.pattern_drawer.local": "", - "hex.builtin.pattern_drawer.offset": "Offset", "hex.builtin.pattern_drawer.size": "Tamaño", "hex.builtin.pattern_drawer.tree_style.auto_expanded": "Árbol Automáticamente Expandido", "hex.builtin.pattern_drawer.tree_style.flattened": "Allanado", diff --git a/plugins/builtin/romfs/lang/it_IT.json b/plugins/builtin/romfs/lang/it_IT.json index c6244536b..ea6ab2a43 100644 --- a/plugins/builtin/romfs/lang/it_IT.json +++ b/plugins/builtin/romfs/lang/it_IT.json @@ -367,7 +367,6 @@ "hex.builtin.pattern_drawer.double_click": "", "hex.builtin.pattern_drawer.favorites": "", "hex.builtin.pattern_drawer.local": "", - "hex.builtin.pattern_drawer.offset": "", "hex.builtin.pattern_drawer.size": "", "hex.builtin.pattern_drawer.tree_style.auto_expanded": "", "hex.builtin.pattern_drawer.tree_style.flattened": "", diff --git a/plugins/builtin/romfs/lang/ja_JP.json b/plugins/builtin/romfs/lang/ja_JP.json index 23fa8b50d..38d00161c 100644 --- a/plugins/builtin/romfs/lang/ja_JP.json +++ b/plugins/builtin/romfs/lang/ja_JP.json @@ -367,7 +367,6 @@ "hex.builtin.pattern_drawer.double_click": "", "hex.builtin.pattern_drawer.favorites": "", "hex.builtin.pattern_drawer.local": "", - "hex.builtin.pattern_drawer.offset": "オフセット", "hex.builtin.pattern_drawer.size": "サイズ", "hex.builtin.pattern_drawer.tree_style.auto_expanded": "", "hex.builtin.pattern_drawer.tree_style.flattened": "", diff --git a/plugins/builtin/romfs/lang/ko_KR.json b/plugins/builtin/romfs/lang/ko_KR.json index 016c48534..a67d8fb05 100644 --- a/plugins/builtin/romfs/lang/ko_KR.json +++ b/plugins/builtin/romfs/lang/ko_KR.json @@ -367,7 +367,6 @@ "hex.builtin.pattern_drawer.double_click": "", "hex.builtin.pattern_drawer.favorites": "", "hex.builtin.pattern_drawer.local": "", - "hex.builtin.pattern_drawer.offset": "오프셋", "hex.builtin.pattern_drawer.size": "크기", "hex.builtin.pattern_drawer.tree_style.auto_expanded": "", "hex.builtin.pattern_drawer.tree_style.flattened": "", diff --git a/plugins/builtin/romfs/lang/pt_BR.json b/plugins/builtin/romfs/lang/pt_BR.json index 210bae43e..e12ea15f4 100644 --- a/plugins/builtin/romfs/lang/pt_BR.json +++ b/plugins/builtin/romfs/lang/pt_BR.json @@ -367,7 +367,6 @@ "hex.builtin.pattern_drawer.double_click": "", "hex.builtin.pattern_drawer.favorites": "", "hex.builtin.pattern_drawer.local": "", - "hex.builtin.pattern_drawer.offset": "Offset", "hex.builtin.pattern_drawer.size": "Tamanho", "hex.builtin.pattern_drawer.tree_style.auto_expanded": "", "hex.builtin.pattern_drawer.tree_style.flattened": "", diff --git a/plugins/builtin/romfs/lang/zh_CN.json b/plugins/builtin/romfs/lang/zh_CN.json index 9807e2d07..3fc45983b 100644 --- a/plugins/builtin/romfs/lang/zh_CN.json +++ b/plugins/builtin/romfs/lang/zh_CN.json @@ -367,7 +367,6 @@ "hex.builtin.pattern_drawer.double_click": "双击查看更多", "hex.builtin.pattern_drawer.favorites": "", "hex.builtin.pattern_drawer.local": "", - "hex.builtin.pattern_drawer.offset": "偏移", "hex.builtin.pattern_drawer.size": "大小", "hex.builtin.pattern_drawer.tree_style.auto_expanded": "自动展开树", "hex.builtin.pattern_drawer.tree_style.flattened": "扁平化", diff --git a/plugins/builtin/romfs/lang/zh_TW.json b/plugins/builtin/romfs/lang/zh_TW.json index 10217c69e..2861e5f2e 100644 --- a/plugins/builtin/romfs/lang/zh_TW.json +++ b/plugins/builtin/romfs/lang/zh_TW.json @@ -367,7 +367,6 @@ "hex.builtin.pattern_drawer.double_click": "Double-click to see more items", "hex.builtin.pattern_drawer.favorites": "", "hex.builtin.pattern_drawer.local": "", - "hex.builtin.pattern_drawer.offset": "位移", "hex.builtin.pattern_drawer.size": "大小", "hex.builtin.pattern_drawer.tree_style.auto_expanded": "", "hex.builtin.pattern_drawer.tree_style.flattened": "", diff --git a/plugins/builtin/source/ui/pattern_drawer.cpp b/plugins/builtin/source/ui/pattern_drawer.cpp index 0e6f6e481..3f6e013c8 100644 --- a/plugins/builtin/source/ui/pattern_drawer.cpp +++ b/plugins/builtin/source/ui/pattern_drawer.cpp @@ -91,25 +91,43 @@ namespace hex::plugin::builtin::ui { } inline void drawOffsetColumnForBitfieldMember(const pl::ptrn::PatternBitfieldMember &pattern) { - auto bitOffset = pattern.getBitOffsetForDisplay(); - if (pattern.getBitSize() <= 1) - ImGui::TextFormatted("bit {0}", bitOffset); - else - ImGui::TextFormatted("bits {0} - {1}", bitOffset, bitOffset + pattern.getBitSize() - 1); + if (pattern.isPatternLocal()) { + ImGui::TextFormatted("[{}]", "hex.builtin.pattern_drawer.local"_lang); + ImGui::TableNextColumn(); + ImGui::TextFormatted("[{}]", "hex.builtin.pattern_drawer.local"_lang); + ImGui::TableNextColumn(); + } else { + ImGui::TextFormatted("0x{0:08X}, bit {1}", pattern.getOffset(), pattern.getBitOffsetForDisplay()); + ImGui::TableNextColumn(); + ImGui::TextFormatted("0x{0:08X}, bit {1}", pattern.getOffset() + pattern.getSize(), pattern.getBitOffsetForDisplay() + pattern.getBitSize() - (pattern.getSize() == 0 ? 0 : 1)); + ImGui::TableNextColumn(); + } } void drawOffsetColumn(const pl::ptrn::Pattern& pattern) { - if (pattern.isPatternLocal()) { - ImGui::TextFormatted("[{}]", "hex.builtin.pattern_drawer.local"_lang); - } else { - if (auto *bitfieldMember = dynamic_cast(&pattern); bitfieldMember != nullptr && bitfieldMember->getParentBitfield() != nullptr) - drawOffsetColumnForBitfieldMember(*bitfieldMember); - else if (pattern.getSize() > 0) { - ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", pattern.getOffset(), pattern.getOffset() + pattern.getSize() - (pattern.getSize() == 0 ? 0 : 1)); + if (auto *bitfieldMember = dynamic_cast(&pattern); bitfieldMember != nullptr && bitfieldMember->getParentBitfield() != nullptr) + drawOffsetColumnForBitfieldMember(*bitfieldMember); + else { + if (pattern.isPatternLocal()) { + ImGui::TextFormatted("[{}]", "hex.builtin.pattern_drawer.local"_lang); + } else { + if (pattern.getSize() > 0) { + ImGui::TextFormatted("0x{0:08X}", pattern.getOffset()); + } } - } - ImGui::TableNextColumn(); + ImGui::TableNextColumn(); + + if (pattern.isPatternLocal()) { + ImGui::TextFormatted("[{}]", "hex.builtin.pattern_drawer.local"_lang); + } else { + if (pattern.getSize() > 0) { + ImGui::TextFormatted("0x{0:08X}", pattern.getOffset() + pattern.getSize() - (pattern.getSize() == 0 ? 0 : 1)); + } + } + + ImGui::TableNextColumn(); + } } inline void drawSizeColumnForBitfieldMember(const pl::ptrn::PatternBitfieldMember &pattern) { @@ -358,7 +376,6 @@ namespace hex::plugin::builtin::ui { ImGui::TableNextColumn(); drawColorColumn(pattern); drawOffsetColumnForBitfieldMember(pattern); - ImGui::TableNextColumn(); drawSizeColumnForBitfieldMember(pattern); ImGui::TableNextColumn(); ImGui::TextFormattedColored(ImColor(0xFF9BC64D), "bits"); @@ -901,11 +918,16 @@ namespace hex::plugin::builtin::ui { return left->getDisplayName() < right->getDisplayName(); else return left->getDisplayName() > right->getDisplayName(); - } else if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("offset")) { + } else if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("start")) { if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Ascending) return left->getOffsetForSorting() < right->getOffsetForSorting(); else return left->getOffsetForSorting() > right->getOffsetForSorting(); + } else if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("end")) { + if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Ascending) + return left->getOffsetForSorting() + left->getSize() < right->getOffsetForSorting() + right->getSize(); + else + return left->getOffsetForSorting() + left->getSize() > right->getOffsetForSorting() + right->getSize(); } else if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("size")) { if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Ascending) return left->getSizeForSorting() < right->getSizeForSorting(); @@ -932,12 +954,13 @@ namespace hex::plugin::builtin::ui { } static bool beginPatternTable(const std::vector> &patterns, std::vector &sortedPatterns, float height) { - if (ImGui::BeginTable("##Patterntable", 7, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY, ImVec2(0, height))) { + if (ImGui::BeginTable("##Patterntable", 8, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY, ImVec2(0, height))) { ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableSetupColumn("##favorite", ImGuiTableColumnFlags_NoSort | ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_NoReorder | ImGuiTableColumnFlags_NoHide | ImGuiTableColumnFlags_IndentDisable, ImGui::GetTextLineHeight(), ImGui::GetID("favorite")); ImGui::TableSetupColumn("hex.builtin.pattern_drawer.var_name"_lang, ImGuiTableColumnFlags_PreferSortAscending | ImGuiTableColumnFlags_NoHide | ImGuiTableColumnFlags_IndentEnable, 0, ImGui::GetID("name")); ImGui::TableSetupColumn("hex.builtin.pattern_drawer.color"_lang, ImGuiTableColumnFlags_PreferSortAscending, 0, ImGui::GetID("color")); - ImGui::TableSetupColumn("hex.builtin.pattern_drawer.offset"_lang, ImGuiTableColumnFlags_PreferSortAscending | ImGuiTableColumnFlags_DefaultSort, 0, ImGui::GetID("offset")); + ImGui::TableSetupColumn("hex.builtin.pattern_drawer.start"_lang, ImGuiTableColumnFlags_PreferSortAscending | ImGuiTableColumnFlags_DefaultSort, 0, ImGui::GetID("start")); + ImGui::TableSetupColumn("hex.builtin.pattern_drawer.end"_lang, ImGuiTableColumnFlags_PreferSortAscending | ImGuiTableColumnFlags_DefaultSort, 0, ImGui::GetID("end")); ImGui::TableSetupColumn("hex.builtin.pattern_drawer.size"_lang, ImGuiTableColumnFlags_PreferSortAscending, 0, ImGui::GetID("size")); ImGui::TableSetupColumn("hex.builtin.pattern_drawer.type"_lang, ImGuiTableColumnFlags_PreferSortAscending, 0, ImGui::GetID("type")); ImGui::TableSetupColumn("hex.builtin.pattern_drawer.value"_lang, ImGuiTableColumnFlags_PreferSortAscending, 0, ImGui::GetID("value"));