2020-11-10 21:31:04 +01:00
|
|
|
#include "views/view_pattern_data.hpp"
|
|
|
|
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <hex/providers/provider.hpp>
|
|
|
|
#include <hex/lang/pattern_data.hpp>
|
2020-11-11 10:47:02 +01:00
|
|
|
|
2020-11-10 21:31:04 +01:00
|
|
|
namespace hex {
|
|
|
|
|
2020-12-27 15:39:06 +01:00
|
|
|
ViewPatternData::ViewPatternData(std::vector<lang::PatternData*> &patternData)
|
|
|
|
: View("Pattern Data"), m_patternData(patternData) {
|
2020-11-10 21:31:04 +01:00
|
|
|
|
2020-11-15 00:46:18 +01:00
|
|
|
this->subscribeEvent(Events::PatternChanged, [this](auto data) {
|
|
|
|
this->m_sortedPatternData.clear();
|
|
|
|
});
|
2020-11-10 21:31:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ViewPatternData::~ViewPatternData() {
|
2020-11-15 00:46:18 +01:00
|
|
|
this->unsubscribeEvent(Events::PatternChanged);
|
2020-11-10 21:31:04 +01:00
|
|
|
}
|
|
|
|
|
2020-11-19 21:19:03 +01:00
|
|
|
static bool beginPatternDataTable(prv::Provider* &provider, const std::vector<lang::PatternData*> &patterns, std::vector<lang::PatternData*> &sortedPatterns) {
|
2020-11-23 22:14:11 +01:00
|
|
|
if (ImGui::BeginTable("##patterndatatable", 6, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY)) {
|
2020-11-23 15:22:26 +01:00
|
|
|
ImGui::TableSetupScrollFreeze(0, 1);
|
2020-11-19 21:19:03 +01:00
|
|
|
ImGui::TableSetupColumn("Name", 0, -1, ImGui::GetID("name"));
|
2020-11-23 22:14:11 +01:00
|
|
|
ImGui::TableSetupColumn("Color", 0, -1, ImGui::GetID("color"));
|
2020-11-20 00:16:50 +01:00
|
|
|
ImGui::TableSetupColumn("Offset", 0, -1, ImGui::GetID("offset"));
|
2020-11-19 21:19:03 +01: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-12-22 18:10:01 +01:00
|
|
|
void ViewPatternData::drawContent() {
|
2020-11-23 23:57:19 +01:00
|
|
|
if (ImGui::Begin("Pattern Data", &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
2021-01-12 23:28:41 +01:00
|
|
|
auto provider = SharedData::currentProvider;
|
2020-12-27 15:39:06 +01:00
|
|
|
if (provider != nullptr && provider->isReadable()) {
|
2020-11-10 21:31:04 +01:00
|
|
|
|
2020-12-27 15:39:06 +01:00
|
|
|
if (beginPatternDataTable(provider, this->m_patternData, this->m_sortedPatternData)) {
|
2021-01-11 09:53:20 +01:00
|
|
|
ImGui::TableHeadersRow();
|
2020-11-19 21:59:27 +01:00
|
|
|
if (this->m_sortedPatternData.size() > 0) {
|
|
|
|
|
2020-11-22 20:41:54 +01:00
|
|
|
for (auto &patternData : this->m_sortedPatternData)
|
2020-12-27 15:39:06 +01:00
|
|
|
patternData->createEntry(provider);
|
2020-11-19 21:59:27 +01:00
|
|
|
|
2020-11-15 00:46:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
2020-11-11 09:18:35 +01:00
|
|
|
}
|
2020-11-15 00:46:18 +01:00
|
|
|
|
2020-11-10 21:31:04 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-11 10:47:02 +01:00
|
|
|
ImGui::End();
|
2020-11-10 21:31:04 +01:00
|
|
|
}
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
void ViewPatternData::drawMenu() {
|
2020-11-23 23:57:19 +01:00
|
|
|
|
2020-11-10 21:31:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|