From b7438f6ab82f62a13a76467f411270c65d0781d7 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 23 Nov 2020 15:22:26 +0100 Subject: [PATCH] Massively improved look and feel of pattern data, string and disassembly tables --- include/lang/pattern_data.hpp | 41 ++++++++++++++---- include/views/view_disassembler.hpp | 3 +- source/views/view_disassembler.cpp | 64 ++++++++++++++--------------- source/views/view_pattern_data.cpp | 7 +--- source/views/view_strings.cpp | 7 +--- 5 files changed, 72 insertions(+), 50 deletions(-) diff --git a/include/lang/pattern_data.hpp b/include/lang/pattern_data.hpp index 2dece4fa5..8b49d57b7 100644 --- a/include/lang/pattern_data.hpp +++ b/include/lang/pattern_data.hpp @@ -144,7 +144,7 @@ namespace hex::lang { ImGui::TableNextColumn(); ImGui::Text("0x%04lx", this->getSize()); ImGui::TableNextColumn(); - ImGui::Text("%s", this->getTypeName().c_str()); + ImGui::TextColored(ImColor(0xFF9BC64D), "%s", this->getTypeName().c_str()); ImGui::TableNextColumn(); ImGui::Text("%s", value.c_str()); } @@ -198,7 +198,7 @@ namespace hex::lang { ImGui::TableNextColumn(); ImGui::Text("0x%04lx", this->getSize()); ImGui::TableNextColumn(); - ImGui::Text("%s", this->getTypeName().c_str()); + ImGui::TextColored(ImColor(0xFF9BC64D), "%s", this->getTypeName().c_str()); ImGui::TableNextColumn(); ImGui::Text("*(0x%0*llx)", this->getSize() * 2, data); @@ -357,7 +357,15 @@ namespace hex::lang { ImGui::TableNextColumn(); ImGui::Text("0x%04lx", this->getSize()); ImGui::TableNextColumn(); - ImGui::Text("%s", this->getTypeName().c_str()); + ImGui::TextColored(ImColor(0xFF9BC64D), "%s", this->m_entries[0]->getTypeName().c_str()); + ImGui::SameLine(0, 0); + + ImGui::TextUnformatted("["); + ImGui::SameLine(0, 0); + ImGui::TextColored(ImColor(0xFF00FF00), "%llu", this->m_entries.size()); + ImGui::SameLine(0, 0); + ImGui::TextUnformatted("]"); + ImGui::TableNextColumn(); ImGui::Text("%s", "{ ... }"); @@ -402,7 +410,7 @@ namespace hex::lang { ImGui::TableNextColumn(); ImGui::Text("0x%04lx", this->getSize()); ImGui::TableNextColumn(); - ImGui::Text("%s", this->getTypeName().c_str()); + ImGui::TextColored(ImColor(0xFFD69C56), "struct"); ImGui::SameLine(); ImGui::Text("%s", this->m_structName.c_str()); ImGui::TableNextColumn(); ImGui::Text("%s", "{ ... }"); @@ -461,7 +469,8 @@ namespace hex::lang { ImGui::TableNextColumn(); ImGui::Text("0x%04lx", this->getSize()); ImGui::TableNextColumn(); - ImGui::Text("%s", this->getTypeName().c_str()); + ImGui::TextColored(ImColor(0xFFD69C56), "union"); ImGui::SameLine(); ImGui::Text("%s", this->m_unionName.c_str()); + ImGui::TableNextColumn(); ImGui::Text("%s", "{ ... }"); @@ -528,7 +537,25 @@ namespace hex::lang { if (!foundValue) valueString += "???"; - this->createDefaultEntry(hex::format("%s (0x%0*lx)", valueString.c_str(), this->getSize() * 2, value)); + ImGui::TableNextRow(); + ImGui::TreeNodeEx(this->getName().c_str(), ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_SpanFullWidth); + ImGui::TableNextColumn(); + ImGui::ColorButton("color", ImColor(this->getColor()), ImGuiColorEditFlags_NoTooltip); + ImGui::TableNextColumn(); + if (ImGui::Selectable(("##PatternDataLine"s + std::to_string(this->getOffset())).c_str(), false, ImGuiSelectableFlags_SpanAllColumns)) { + Region selectRegion = { this->getOffset(), this->getSize() }; + View::postEvent(Events::SelectionChangeRequest, &selectRegion); + } + ImGui::SameLine(); + ImGui::Text("%s", this->getName().c_str()); + ImGui::TableNextColumn(); + ImGui::Text("0x%08lx : 0x%08lx", this->getOffset(), this->getOffset() + this->getSize() - 1); + ImGui::TableNextColumn(); + ImGui::Text("0x%04lx", this->getSize()); + ImGui::TableNextColumn(); + ImGui::TextColored(ImColor(0xFFD69C56), "enum"); ImGui::SameLine(); ImGui::Text("%s", this->m_enumName.c_str()); + ImGui::TableNextColumn(); + ImGui::Text("%s", hex::format("%s (0x%0*lx)", valueString.c_str(), this->getSize() * 2, value).c_str()); } std::string getTypeName() override { @@ -560,7 +587,7 @@ namespace hex::lang { ImGui::TableNextColumn(); ImGui::Text("0x%04lx", this->getSize()); ImGui::TableNextColumn(); - ImGui::Text("%s", this->getTypeName().c_str()); + ImGui::TextColored(ImColor(0xFFD69C56), "bitfield"); ImGui::SameLine(); ImGui::Text("%s", this->m_bitfieldName.c_str()); ImGui::TableNextColumn(); ImGui::Text("{ %llx }", value); diff --git a/include/views/view_disassembler.hpp b/include/views/view_disassembler.hpp index ee5eecfc6..a8b271475 100644 --- a/include/views/view_disassembler.hpp +++ b/include/views/view_disassembler.hpp @@ -17,7 +17,8 @@ namespace hex { u64 offset; size_t size; std::string bytes; - std::string opcodeString; + std::string mnemonic; + std::string operators; }; class ViewDisassembler : public View { diff --git a/source/views/view_disassembler.cpp b/source/views/view_disassembler.cpp index f4e66c33b..de5af6a47 100644 --- a/source/views/view_disassembler.cpp +++ b/source/views/view_disassembler.cpp @@ -60,7 +60,8 @@ namespace hex { disassembly.address = instructions[instr].address; disassembly.offset = this->m_codeOffset + address + usedBytes; disassembly.size = instructions[instr].size; - disassembly.opcodeString = instructions[instr].mnemonic + " "s + instructions[instr].op_str; + disassembly.mnemonic = instructions[instr].mnemonic; + disassembly.operators = instructions[instr].op_str; for (u8 i = 0; i < instructions[instr].size; i++) disassembly.bytes += hex::format("%02X ", instructions[instr].bytes[i]); @@ -234,43 +235,42 @@ namespace hex { ImGui::Separator(); ImGui::NewLine(); - if (ImGui::BeginChild("##scrolling")) { - if (ImGui::BeginTable("##disassembly", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg | ImGuiTableFlags_Reorderable)) { - ImGui::TableSetupColumn("Address"); - ImGui::TableSetupColumn("Offset"); - ImGui::TableSetupColumn("Bytes"); - ImGui::TableSetupColumn("Disassembly"); + if (ImGui::BeginTable("##disassembly", 4, ImGuiTableFlags_ScrollY | ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg | ImGuiTableFlags_Reorderable)) { + ImGui::TableSetupScrollFreeze(0, 1); + ImGui::TableSetupColumn("Address"); + ImGui::TableSetupColumn("Offset"); + ImGui::TableSetupColumn("Bytes"); + ImGui::TableSetupColumn("Disassembly"); - ImGuiListClipper clipper; - clipper.Begin(this->m_disassembly.size()); + ImGuiListClipper clipper; + clipper.Begin(this->m_disassembly.size()); - ImGui::TableHeadersRow(); - while (clipper.Step()) { - for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - if (ImGui::Selectable(("##DisassemblyLine"s + std::to_string(i)).c_str(), false, ImGuiSelectableFlags_SpanAllColumns)) { - Region selectRegion = { this->m_disassembly[i].offset, this->m_disassembly[i].size }; - View::postEvent(Events::SelectionChangeRequest, &selectRegion); - } - ImGui::SameLine(); - ImGui::Text("0x%llx", this->m_disassembly[i].address); - ImGui::TableNextColumn(); - ImGui::Text("0x%llx", this->m_disassembly[i].offset); - ImGui::TableNextColumn(); - ImGui::TextUnformatted(this->m_disassembly[i].bytes.c_str()); - ImGui::TableNextColumn(); - ImGui::TextUnformatted(this->m_disassembly[i].opcodeString.c_str()); + ImGui::TableHeadersRow(); + while (clipper.Step()) { + for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + if (ImGui::Selectable(("##DisassemblyLine"s + std::to_string(i)).c_str(), false, ImGuiSelectableFlags_SpanAllColumns)) { + Region selectRegion = { this->m_disassembly[i].offset, this->m_disassembly[i].size }; + View::postEvent(Events::SelectionChangeRequest, &selectRegion); } + ImGui::SameLine(); + ImGui::Text("0x%llx", this->m_disassembly[i].address); + ImGui::TableNextColumn(); + ImGui::Text("0x%llx", this->m_disassembly[i].offset); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(this->m_disassembly[i].bytes.c_str()); + ImGui::TableNextColumn(); + ImGui::TextColored(ImColor(0xFFD69C56), "%s", this->m_disassembly[i].mnemonic.c_str()); + ImGui::SameLine(); + ImGui::TextUnformatted(this->m_disassembly[i].operators.c_str()); } - - clipper.End(); - - ImGui::EndTable(); } - } - ImGui::EndChild(); + clipper.End(); + + ImGui::EndTable(); + } } } ImGui::End(); diff --git a/source/views/view_pattern_data.cpp b/source/views/view_pattern_data.cpp index b982a12c5..8cc30729a 100644 --- a/source/views/view_pattern_data.cpp +++ b/source/views/view_pattern_data.cpp @@ -18,7 +18,8 @@ namespace hex { } static bool beginPatternDataTable(prv::Provider* &provider, const std::vector &patterns, std::vector &sortedPatterns) { - if (ImGui::BeginTable("##patterndatatable", 6, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody)) { + if (ImGui::BeginTable("##patterndatatable", 6, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_ScrollY)) { + ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableSetupColumn("Color", 0, -1, ImGui::GetID("color")); ImGui::TableSetupColumn("Name", 0, -1, ImGui::GetID("name")); ImGui::TableSetupColumn("Offset", 0, -1, ImGui::GetID("offset")); @@ -52,8 +53,6 @@ namespace hex { return; if (ImGui::Begin("Pattern Data", &this->m_windowOpen)) { - ImGui::BeginChild("##scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav); - if (this->m_dataProvider != nullptr && this->m_dataProvider->isReadable()) { if (beginPatternDataTable(this->m_dataProvider, this->m_patternData, this->m_sortedPatternData)) { @@ -69,8 +68,6 @@ namespace hex { } } - - ImGui::EndChild(); } ImGui::End(); } diff --git a/source/views/view_strings.cpp b/source/views/view_strings.cpp index 6cef1d103..ee475d126 100644 --- a/source/views/view_strings.cpp +++ b/source/views/view_strings.cpp @@ -73,11 +73,10 @@ namespace hex { ImGui::Separator(); ImGui::NewLine(); - ImGui::BeginChild("##scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav); - if (ImGui::BeginTable("##strings", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable | - ImGuiTableFlags_Reorderable | ImGuiTableFlags_RowBg)) { + ImGuiTableFlags_Reorderable | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY)) { + ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableSetupColumn("Offset", 0, -1, ImGui::GetID("offset")); ImGui::TableSetupColumn("Size", 0, -1, ImGui::GetID("size")); ImGui::TableSetupColumn("String", 0, -1, ImGui::GetID("string")); @@ -141,8 +140,6 @@ namespace hex { ImGui::EndTable(); } - - ImGui::EndChild(); } } ImGui::End();