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

ux: Add slider to entropy plot

This commit is contained in:
WerWolv 2021-04-12 22:20:05 +02:00
parent 959988a670
commit 1e6b493b41
3 changed files with 13 additions and 4 deletions

View File

@ -717,7 +717,6 @@ struct MemoryEditor
ImGui::EndChild();
DataEditingAddr = DataPreviewAddr = HighlightMin;
DataPreviewAddrEnd = HighlightMax;
DataEditingTakeFocus = true;
}
GotoAddr = (size_t)-1;
}

View File

@ -26,6 +26,8 @@ namespace hex {
float m_highestBlockEntropy = 0;
std::vector<float> m_blockEntropy;
double m_entropyHandlePosition;
std::array<ImU64, 256> m_valueCounts = { 0 };
bool m_analyzing = false;

View File

@ -30,10 +30,15 @@ namespace hex {
this->m_fileDescription = "";
this->m_analyzedRegion = { 0, 0 };
});
EventManager::subscribe<EventRegionSelected>(this, [this](Region region) {
this->m_entropyHandlePosition = region.address / this->m_blockSize;
});
}
ViewInformation::~ViewInformation() {
EventManager::unsubscribe<EventDataChanged>(this);
EventManager::unsubscribe<EventRegionSelected>(this);
}
static float calculateEntropy(std::array<ImU64, 256> &valueCounts, size_t numBytes) {
@ -196,7 +201,9 @@ namespace hex {
return result;
}();
ImPlot::PlotBars<ImU64>("##bytes", x.data(), this->m_valueCounts.data(), x.size(), 0.67);
ImPlot::EndPlot();
}
@ -208,8 +215,9 @@ namespace hex {
if (ImPlot::BeginPlot("##entropy", "Address", "Entropy", ImVec2(-1,0), ImPlotFlags_CanvasOnly, ImPlotAxisFlags_Lock | ImPlotAxisFlags_NoTickLabels, ImPlotAxisFlags_Lock)) {
ImPlot::PlotLine("##entropy_line", this->m_blockEntropy.data(), this->m_blockEntropy.size());
if (ImGui::IsItemClicked())
EventManager::post<RequestSelectionChange>( Region{ u64(ImPlot::GetPlotMousePos().x) * this->m_blockSize, 1 });
if (ImPlot::DragLineX("Position", &this->m_entropyHandlePosition, false)) {
EventManager::post<RequestSelectionChange>( Region{ u64(this->m_entropyHandlePosition * this->m_blockSize), 1 });
}
ImPlot::EndPlot();
}
@ -218,7 +226,7 @@ namespace hex {
ImGui::NewLine();
ImGui::LabelText("hex.view.information.block_size"_lang, "hex.view.information.block_size.desc"_lang, this->m_blockEntropy.size(), this->m_blockSize);
ImGui::LabelText("hex.view.information.block_size"_lang, "%s", hex::format("hex.view.information.block_size.desc"_lang, this->m_blockEntropy.size(), this->m_blockSize).c_str());
ImGui::LabelText("hex.view.information.file_entropy"_lang, "%.8f", this->m_averageEntropy);
ImGui::LabelText("hex.view.information.highest_entropy"_lang, "%.8f", this->m_highestBlockEntropy);