2023-12-05 10:49:51 +01:00
|
|
|
#include <hex/helpers/utils.hpp>
|
|
|
|
|
2023-12-23 21:09:41 +01:00
|
|
|
#include <content/visualizer_helpers.hpp>
|
2023-12-05 10:49:51 +01:00
|
|
|
|
|
|
|
#include <imgui.h>
|
|
|
|
|
|
|
|
#include <hex/ui/imgui_imhex_extensions.h>
|
|
|
|
|
2023-12-23 21:09:41 +01:00
|
|
|
namespace hex::plugin::visualizers {
|
2023-12-05 10:49:51 +01:00
|
|
|
|
|
|
|
void drawImageVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span<const pl::core::Token::Literal> arguments) {
|
|
|
|
static ImGuiExt::Texture texture;
|
|
|
|
static float scale = 1.0F;
|
|
|
|
|
|
|
|
if (shouldReset) {
|
|
|
|
auto pattern = arguments[0].toPattern();
|
|
|
|
|
|
|
|
auto data = pattern->getBytes();
|
2024-05-01 20:36:10 +02:00
|
|
|
texture = ImGuiExt::Texture::fromImage(data.data(), data.size(), ImGuiExt::Texture::Filter::Nearest);
|
2023-12-05 10:49:51 +01:00
|
|
|
scale = 200_scaled / texture.getSize().x;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (texture.isValid())
|
|
|
|
ImGui::Image(texture, texture.getSize() * scale);
|
|
|
|
|
|
|
|
if (ImGui::IsWindowHovered()) {
|
|
|
|
auto scrollDelta = ImGui::GetIO().MouseWheel;
|
|
|
|
if (scrollDelta != 0.0F) {
|
|
|
|
scale += scrollDelta * 0.1F;
|
|
|
|
scale = std::clamp(scale, 0.1F, 10.0F);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawBitmapVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span<const pl::core::Token::Literal> arguments) {
|
|
|
|
static ImGuiExt::Texture texture;
|
|
|
|
static float scale = 1.0F;
|
|
|
|
|
|
|
|
if (shouldReset) {
|
|
|
|
auto pattern = arguments[0].toPattern();
|
|
|
|
auto width = arguments[1].toUnsigned();
|
|
|
|
auto height = arguments[2].toUnsigned();
|
|
|
|
|
|
|
|
auto data = pattern->getBytes();
|
2024-05-01 20:36:10 +02:00
|
|
|
texture = ImGuiExt::Texture::fromBitmap(data.data(), data.size(), width, height, ImGuiExt::Texture::Filter::Nearest);
|
2023-12-05 10:49:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (texture.isValid())
|
|
|
|
ImGui::Image(texture, texture.getSize() * scale);
|
|
|
|
|
|
|
|
if (ImGui::IsWindowHovered()) {
|
|
|
|
auto scrollDelta = ImGui::GetIO().MouseWheel;
|
|
|
|
if (scrollDelta != 0.0F) {
|
|
|
|
scale += scrollDelta * 0.1F;
|
|
|
|
scale = std::clamp(scale, 0.1F, 10.0F);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|