2020-11-10 20:31:04 +00:00
|
|
|
#include "views/view_pattern_data.hpp"
|
|
|
|
|
2020-11-11 09:47:02 +00:00
|
|
|
#include "providers/provider.hpp"
|
2020-11-19 10:36:52 +00:00
|
|
|
#include "lang/pattern_data.hpp"
|
2020-11-11 09:47:02 +00:00
|
|
|
|
2020-11-10 20:31:04 +00:00
|
|
|
namespace hex {
|
|
|
|
|
2020-11-19 10:36:52 +00:00
|
|
|
ViewPatternData::ViewPatternData(prv::Provider* &dataProvider, std::vector<lang::PatternData*> &patternData)
|
2020-11-14 13:42:21 +00:00
|
|
|
: View(), m_dataProvider(dataProvider), m_patternData(patternData) {
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2020-11-14 23:46:18 +00:00
|
|
|
this->subscribeEvent(Events::PatternChanged, [this](auto data) {
|
|
|
|
this->m_sortedPatternData.clear();
|
|
|
|
});
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ViewPatternData::~ViewPatternData() {
|
2020-11-14 23:46:18 +00:00
|
|
|
this->unsubscribeEvent(Events::PatternChanged);
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-19 20:19:03 +00:00
|
|
|
static bool beginPatternDataTable(prv::Provider* &provider, const std::vector<lang::PatternData*> &patterns, std::vector<lang::PatternData*> &sortedPatterns) {
|
|
|
|
if (ImGui::BeginTable("##patterndatatable", 6, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_RowBg)) {
|
|
|
|
ImGui::TableSetupColumn("Color", 0, -1, ImGui::GetID("color"));
|
|
|
|
ImGui::TableSetupColumn("Name", 0, -1, ImGui::GetID("name"));
|
2020-11-19 23:16:50 +00:00
|
|
|
ImGui::TableSetupColumn("Offset", 0, -1, ImGui::GetID("offset"));
|
2020-11-19 20:19:03 +00:00
|
|
|
ImGui::TableSetupColumn("Size", 0, -1, ImGui::GetID("size"));
|
|
|
|
ImGui::TableSetupColumn("Type", 0, -1, ImGui::GetID("type"));
|
|
|
|
ImGui::TableSetupColumn("Value", 0, -1, ImGui::GetID("value"));
|
|
|
|
|
|
|
|
auto sortSpecs = ImGui::TableGetSortSpecs();
|
|
|
|
|
|
|
|
if (sortSpecs->SpecsDirty || sortedPatterns.empty()) {
|
|
|
|
sortedPatterns = patterns;
|
|
|
|
|
|
|
|
std::sort(sortedPatterns.begin(), sortedPatterns.end(), [&sortSpecs, &provider](lang::PatternData* left, lang::PatternData* right) -> bool {
|
|
|
|
return lang::PatternData::sortPatternDataTable(sortSpecs, provider, left, right);
|
|
|
|
});
|
|
|
|
|
|
|
|
for (auto &pattern : sortedPatterns)
|
|
|
|
pattern->sort(sortSpecs, provider);
|
|
|
|
|
|
|
|
sortSpecs->SpecsDirty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-10 20:31:04 +00:00
|
|
|
void ViewPatternData::createView() {
|
|
|
|
if (!this->m_windowOpen)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ImGui::Begin("Pattern Data", &this->m_windowOpen)) {
|
|
|
|
ImGui::BeginChild("##scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav);
|
|
|
|
|
2020-11-12 22:57:43 +00:00
|
|
|
if (this->m_dataProvider != nullptr && this->m_dataProvider->isReadable()) {
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2020-11-19 20:19:03 +00:00
|
|
|
if (beginPatternDataTable(this->m_dataProvider, this->m_patternData, this->m_sortedPatternData)) {
|
2020-11-19 20:59:27 +00:00
|
|
|
if (this->m_sortedPatternData.size() > 0) {
|
|
|
|
ImGui::TableHeadersRow();
|
|
|
|
|
|
|
|
u32 rowCount = 0;
|
|
|
|
for (auto &patternData : this->m_sortedPatternData) {
|
|
|
|
patternData->createEntry(this->m_dataProvider);
|
|
|
|
ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0,
|
|
|
|
((rowCount % 2) == 0) ? 0xFF101010 : 0xFF303030);
|
|
|
|
rowCount++;
|
|
|
|
}
|
|
|
|
|
2020-11-14 23:46:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
2020-11-11 08:18:35 +00:00
|
|
|
}
|
2020-11-14 23:46:18 +00:00
|
|
|
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
}
|
2020-11-11 09:47:02 +00:00
|
|
|
ImGui::End();
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewPatternData::createMenu() {
|
2020-11-11 08:22:55 +00:00
|
|
|
if (ImGui::BeginMenu("View")) {
|
2020-11-10 20:31:04 +00:00
|
|
|
ImGui::MenuItem("Data View", "", &this->m_windowOpen);
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|