1
0
mirror of synced 2024-12-03 11:47:20 +01:00
ImHex/plugins/builtin/source/content/pl_visualizers/hex_viewer.cpp
Nik f9a9ed4846
impr: Vastly improved 3D Visualizer (#1456)
Based entirely on @paxcut's amazing PR #1443

---------

Co-authored-by: paxcut <paxcut@outlook.com>
Co-authored-by: paxcut <53811119+paxcut@users.noreply.github.com>
2023-12-05 10:49:51 +01:00

43 lines
1.3 KiB
C++

#include <hex/helpers/utils.hpp>
#include <content/pl_visualizers/visualizer_helpers.hpp>
#include <imgui.h>
#include <hex/ui/imgui_imhex_extensions.h>
#include <ui/hex_editor.hpp>
#include <content/providers/memory_file_provider.hpp>
namespace hex::plugin::builtin {
void drawHexVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span<const pl::core::Token::Literal> arguments) {
static ui::HexEditor editor;
static std::unique_ptr<MemoryFileProvider> dataProvider;
if (shouldReset) {
auto pattern = arguments[0].toPattern();
std::vector<u8> data;
dataProvider = std::make_unique<MemoryFileProvider>();
try {
data = pattern->getBytes();
} catch (const std::exception &) {
dataProvider->resize(0);
throw;
}
dataProvider->resize(data.size());
dataProvider->writeRaw(0x00, data.data(), data.size());
dataProvider->setReadOnly(true);
editor.setProvider(dataProvider.get());
}
if (ImGui::BeginChild("##editor", scaled(ImVec2(600, 400)), false, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
editor.draw();
ImGui::EndChild();
}
}
}