mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-01 21:17:44 -05:00
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>
This commit is contained in:
43
plugins/builtin/source/content/pl_visualizers/hex_viewer.cpp
Normal file
43
plugins/builtin/source/content/pl_visualizers/hex_viewer.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user