2023-01-20 21:16:28 +01:00
|
|
|
#include <hex/api/content_registry.hpp>
|
|
|
|
#include <hex/api/localization.hpp>
|
2023-05-14 21:50:58 +02:00
|
|
|
#include <hex/api/task.hpp>
|
2023-01-20 21:16:28 +01:00
|
|
|
|
|
|
|
#include <hex/helpers/disassembler.hpp>
|
|
|
|
#include <hex/helpers/utils.hpp>
|
|
|
|
#include <hex/helpers/opengl.hpp>
|
2023-07-04 09:40:05 +02:00
|
|
|
#include <hex/helpers/http_requests.hpp>
|
2023-01-20 21:16:28 +01:00
|
|
|
|
|
|
|
#include <imgui.h>
|
|
|
|
#include <implot.h>
|
2023-10-04 12:00:32 +02:00
|
|
|
|
|
|
|
#if defined(OS_WEB)
|
|
|
|
#define GLFW_INCLUDE_ES3
|
|
|
|
#include <GLES3/gl3.h>
|
|
|
|
#else
|
|
|
|
#include <imgui_impl_opengl3_loader.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
|
2023-01-20 21:16:28 +01:00
|
|
|
#include <hex/ui/imgui_imhex_extensions.h>
|
2023-01-24 23:27:35 +01:00
|
|
|
#include <fonts/codicons_font.h>
|
2023-01-20 21:16:28 +01:00
|
|
|
|
|
|
|
#include <pl/patterns/pattern.hpp>
|
2023-01-23 16:25:23 +01:00
|
|
|
#include <pl/patterns/pattern_padding.hpp>
|
2023-01-20 21:16:28 +01:00
|
|
|
|
2023-01-24 23:27:35 +01:00
|
|
|
#include <miniaudio.h>
|
|
|
|
|
2023-01-21 13:00:02 +01:00
|
|
|
#include <romfs/romfs.hpp>
|
|
|
|
|
2023-01-20 21:16:28 +01:00
|
|
|
#include <numeric>
|
2023-07-05 19:54:18 +02:00
|
|
|
#include <numbers>
|
2023-01-20 21:16:28 +01:00
|
|
|
|
2023-03-10 16:06:18 +01:00
|
|
|
#include <content/helpers/diagrams.hpp>
|
2023-06-02 10:47:18 +02:00
|
|
|
#include <ui/hex_editor.hpp>
|
|
|
|
|
|
|
|
#include <content/providers/memory_file_provider.hpp>
|
2023-03-10 16:06:18 +01:00
|
|
|
|
2023-01-20 21:16:28 +01:00
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2023-01-25 10:16:46 +01:00
|
|
|
template<typename T>
|
|
|
|
std::vector<T> patternToArray(pl::ptrn::Pattern *pattern){
|
2023-02-07 14:18:59 +01:00
|
|
|
const auto bytes = pattern->getBytes();
|
|
|
|
|
2023-01-25 10:16:46 +01:00
|
|
|
std::vector<T> result;
|
2023-02-07 14:18:59 +01:00
|
|
|
result.resize(bytes.size() / sizeof(T));
|
|
|
|
for (size_t i = 0; i < result.size(); i++)
|
|
|
|
std::memcpy(&result[i], &bytes[i * sizeof(T)], sizeof(T));
|
2023-01-25 10:16:46 +01:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2023-04-18 10:06:47 +02:00
|
|
|
void drawLinePlotVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span<const pl::core::Token::Literal> arguments) {
|
2023-01-25 10:16:46 +01:00
|
|
|
static std::vector<float> values;
|
|
|
|
auto dataPattern = arguments[0].toPattern();
|
|
|
|
|
|
|
|
if (ImPlot::BeginPlot("##plot", ImVec2(400, 250), ImPlotFlags_NoChild | ImPlotFlags_CanvasOnly)) {
|
2023-06-06 08:20:58 +02:00
|
|
|
ImPlot::SetupAxes("X", "Y", ImPlotAxisFlags_AutoFit, ImPlotAxisFlags_AutoFit);
|
2023-01-25 10:16:46 +01:00
|
|
|
|
|
|
|
if (shouldReset) {
|
|
|
|
values.clear();
|
2023-06-11 00:08:34 +02:00
|
|
|
values = sampleData(patternToArray<float>(dataPattern.get()), ImPlot::GetPlotSize().x * 4);
|
2023-01-25 10:16:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ImPlot::PlotLine("##line", values.data(), values.size());
|
|
|
|
|
|
|
|
ImPlot::EndPlot();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-18 10:06:47 +02:00
|
|
|
void drawScatterPlotVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span<const pl::core::Token::Literal> arguments) {
|
2023-01-25 10:16:46 +01:00
|
|
|
static std::vector<float> xValues, yValues;
|
|
|
|
|
|
|
|
auto xPattern = arguments[0].toPattern();
|
|
|
|
auto yPattern = arguments[1].toPattern();
|
|
|
|
|
2023-01-20 21:16:28 +01:00
|
|
|
if (ImPlot::BeginPlot("##plot", ImVec2(400, 250), ImPlotFlags_NoChild | ImPlotFlags_CanvasOnly)) {
|
2023-06-06 08:20:58 +02:00
|
|
|
ImPlot::SetupAxes("X", "Y", ImPlotAxisFlags_AutoFit, ImPlotAxisFlags_AutoFit);
|
2023-01-20 21:16:28 +01:00
|
|
|
|
2023-01-25 10:16:46 +01:00
|
|
|
if (shouldReset) {
|
|
|
|
xValues.clear(); yValues.clear();
|
2023-06-11 00:08:34 +02:00
|
|
|
xValues = sampleData(patternToArray<float>(xPattern.get()), ImPlot::GetPlotSize().x * 4);
|
|
|
|
yValues = sampleData(patternToArray<float>(yPattern.get()), ImPlot::GetPlotSize().x * 4);
|
2023-01-25 10:16:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ImPlot::PlotScatter("##scatter", xValues.data(), yValues.data(), xValues.size());
|
2023-01-20 21:16:28 +01:00
|
|
|
|
|
|
|
ImPlot::EndPlot();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-18 10:06:47 +02:00
|
|
|
void drawImageVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span<const pl::core::Token::Literal> arguments) {
|
2023-01-20 21:16:28 +01:00
|
|
|
static ImGui::Texture texture;
|
2023-07-03 21:24:36 +02:00
|
|
|
static float scale = 1.0F;
|
2023-07-04 22:17:51 +02:00
|
|
|
|
2023-01-20 21:16:28 +01:00
|
|
|
if (shouldReset) {
|
2023-02-07 14:18:59 +01:00
|
|
|
auto pattern = arguments[0].toPattern();
|
2023-01-27 10:45:07 +01:00
|
|
|
|
2023-02-07 14:18:59 +01:00
|
|
|
auto data = pattern->getBytes();
|
2023-01-20 21:16:28 +01:00
|
|
|
texture = ImGui::Texture(data.data(), data.size());
|
2023-07-03 21:24:36 +02:00
|
|
|
scale = 200_scaled / texture.getSize().x;
|
2023-01-20 21:16:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (texture.isValid())
|
2023-07-03 21:24:36 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2023-01-20 21:16:28 +01:00
|
|
|
}
|
|
|
|
|
2023-04-18 10:06:47 +02:00
|
|
|
void drawBitmapVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span<const pl::core::Token::Literal> arguments) {
|
2023-01-20 21:16:28 +01:00
|
|
|
static ImGui::Texture texture;
|
2023-07-04 22:17:51 +02:00
|
|
|
static float scale = 1.0F;
|
|
|
|
|
2023-01-20 21:16:28 +01:00
|
|
|
if (shouldReset) {
|
2023-02-07 14:18:59 +01:00
|
|
|
auto pattern = arguments[0].toPattern();
|
|
|
|
auto width = arguments[1].toUnsigned();
|
|
|
|
auto height = arguments[2].toUnsigned();
|
2023-01-20 21:16:28 +01:00
|
|
|
|
2023-02-07 14:18:59 +01:00
|
|
|
auto data = pattern->getBytes();
|
2023-01-20 21:16:28 +01:00
|
|
|
texture = ImGui::Texture(data.data(), data.size(), width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (texture.isValid())
|
2023-07-04 22:17:51 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2023-01-20 21:16:28 +01:00
|
|
|
}
|
|
|
|
|
2023-04-18 10:06:47 +02:00
|
|
|
void drawDisassemblyVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span<const pl::core::Token::Literal> arguments) {
|
2023-01-20 21:16:28 +01:00
|
|
|
struct Disassembly {
|
|
|
|
u64 address;
|
|
|
|
std::vector<u8> bytes;
|
|
|
|
std::string instruction;
|
|
|
|
};
|
|
|
|
|
|
|
|
static std::vector<Disassembly> disassembly;
|
|
|
|
if (shouldReset) {
|
2023-02-07 14:18:59 +01:00
|
|
|
auto pattern = arguments[0].toPattern();
|
|
|
|
auto baseAddress = arguments[1].toUnsigned();
|
|
|
|
auto architecture = arguments[2].toUnsigned();
|
|
|
|
auto mode = arguments[3].toUnsigned();
|
2023-01-20 21:16:28 +01:00
|
|
|
|
|
|
|
disassembly.clear();
|
|
|
|
|
|
|
|
csh capstone;
|
|
|
|
if (cs_open(static_cast<cs_arch>(architecture), static_cast<cs_mode>(mode), &capstone) == CS_ERR_OK) {
|
|
|
|
cs_option(capstone, CS_OPT_SKIPDATA, CS_OPT_ON);
|
|
|
|
|
2023-02-07 14:18:59 +01:00
|
|
|
auto data = pattern->getBytes();
|
2023-01-20 21:16:28 +01:00
|
|
|
cs_insn *instructions = nullptr;
|
|
|
|
|
|
|
|
size_t instructionCount = cs_disasm(capstone, data.data(), data.size(), baseAddress, 0, &instructions);
|
|
|
|
for (size_t i = 0; i < instructionCount; i++) {
|
|
|
|
disassembly.push_back({ instructions[i].address, { instructions[i].bytes, instructions[i].bytes + instructions[i].size }, hex::format("{} {}", instructions[i].mnemonic, instructions[i].op_str) });
|
|
|
|
}
|
|
|
|
cs_free(instructions, instructionCount);
|
|
|
|
cs_close(&capstone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui::BeginTable("##disassembly", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_ScrollY, scaled(ImVec2(0, 300)))) {
|
|
|
|
ImGui::TableSetupScrollFreeze(0, 1);
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.common.address"_lang);
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.common.bytes"_lang);
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.common.instruction"_lang);
|
|
|
|
ImGui::TableHeadersRow();
|
|
|
|
|
|
|
|
for (auto &entry : disassembly) {
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::TextFormatted("0x{0:08X}", entry.address);
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
std::string bytes;
|
|
|
|
for (auto byte : entry.bytes)
|
|
|
|
bytes += hex::format("{0:02X} ", byte);
|
|
|
|
ImGui::TextUnformatted(bytes.c_str());
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::TextUnformatted(entry.instruction.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-18 10:06:47 +02:00
|
|
|
void draw3DVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span<const pl::core::Token::Literal> arguments) {
|
2023-02-07 14:18:59 +01:00
|
|
|
auto verticesPattern = arguments[0].toPattern();
|
|
|
|
auto indicesPattern = arguments[1].toPattern();
|
2023-01-22 16:17:10 +01:00
|
|
|
|
2023-01-20 21:16:28 +01:00
|
|
|
static ImGui::Texture texture;
|
2023-02-16 23:24:24 +01:00
|
|
|
|
2023-01-23 16:25:23 +01:00
|
|
|
static gl::Vector<float, 3> translation;
|
2023-02-16 23:24:24 +01:00
|
|
|
static gl::Vector<float, 3> rotation = { { 1.0F, -1.0F, 0.0F } };
|
|
|
|
static float scaling = 0.1F;
|
|
|
|
|
2023-01-21 13:00:02 +01:00
|
|
|
static std::vector<float> vertices, normals;
|
2023-01-22 16:17:10 +01:00
|
|
|
static std::vector<u32> indices;
|
2023-02-16 23:24:24 +01:00
|
|
|
|
2023-01-21 13:00:02 +01:00
|
|
|
static gl::Shader shader;
|
|
|
|
static gl::VertexArray vertexArray;
|
|
|
|
static gl::Buffer<float> vertexBuffer, normalBuffer;
|
2023-01-22 16:17:10 +01:00
|
|
|
static gl::Buffer<u32> indexBuffer;
|
2023-01-21 13:00:02 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
auto dragDelta = ImGui::GetMouseDragDelta(ImGuiMouseButton_Middle);
|
|
|
|
rotation[0] += -dragDelta.y * 0.0075F;
|
|
|
|
rotation[1] += -dragDelta.x * 0.0075F;
|
|
|
|
ImGui::ResetMouseDragDelta(ImGuiMouseButton_Middle);
|
|
|
|
|
2023-01-23 16:25:23 +01:00
|
|
|
dragDelta = ImGui::GetMouseDragDelta(ImGuiMouseButton_Right);
|
|
|
|
translation[0] += -dragDelta.x * 0.1F;
|
|
|
|
translation[1] += -dragDelta.y * 0.1F;
|
|
|
|
ImGui::ResetMouseDragDelta(ImGuiMouseButton_Right);
|
|
|
|
|
2023-01-21 13:00:02 +01:00
|
|
|
auto scrollDelta = ImGui::GetIO().MouseWheel;
|
|
|
|
scaling += scrollDelta * 0.01F;
|
|
|
|
|
|
|
|
if (scaling < 0.01F)
|
|
|
|
scaling = 0.01F;
|
|
|
|
}
|
2023-01-20 21:16:28 +01:00
|
|
|
|
2023-01-21 13:00:02 +01:00
|
|
|
if (shouldReset) {
|
2023-06-11 00:08:34 +02:00
|
|
|
vertices = patternToArray<float>(verticesPattern.get());
|
|
|
|
indices = patternToArray<u32>(indicesPattern.get());
|
2023-01-20 21:16:28 +01:00
|
|
|
|
2023-01-21 13:00:02 +01:00
|
|
|
normals.clear();
|
2023-01-20 23:32:51 +01:00
|
|
|
normals.resize(vertices.size());
|
2023-05-26 09:01:16 +02:00
|
|
|
|
|
|
|
for (u32 i = 0; i < normals.size(); i += 9) {
|
|
|
|
|
|
|
|
auto v1 = gl::Vector<float, 3>({ vertices[i] , vertices[i + 1], vertices[i + 2] });
|
|
|
|
auto v2 = gl::Vector<float, 3>({ vertices[i + 3], vertices[i + 4], vertices[i + 5] });
|
|
|
|
auto v3 = gl::Vector<float, 3>({ vertices[i + 6], vertices[i + 7], vertices[i + 8] });
|
2023-01-20 23:32:51 +01:00
|
|
|
|
|
|
|
auto normal = ((v2 - v1).cross(v3 - v1)).normalize();
|
2023-05-26 09:01:16 +02:00
|
|
|
normals[i] = normal[0];
|
|
|
|
normals[i + 1] = normal[1];
|
|
|
|
normals[i + 2] = normal[2];
|
|
|
|
normals[i + 3] = normal[0];
|
|
|
|
normals[i + 4] = normal[1];
|
|
|
|
normals[i + 5] = normal[2];
|
|
|
|
normals[i + 6] = normal[0];
|
|
|
|
normals[i + 7] = normal[1];
|
|
|
|
normals[i + 8] = normal[2];
|
2023-01-20 23:32:51 +01:00
|
|
|
}
|
2023-01-20 21:16:28 +01:00
|
|
|
|
2023-01-21 13:00:02 +01:00
|
|
|
shader = gl::Shader(romfs::get("shaders/default/vertex.glsl").string(), romfs::get("shaders/default/fragment.glsl").string());
|
2023-01-20 23:32:51 +01:00
|
|
|
|
2023-01-21 13:00:02 +01:00
|
|
|
vertexArray = gl::VertexArray();
|
2023-01-23 16:25:23 +01:00
|
|
|
|
|
|
|
vertexBuffer = {};
|
|
|
|
normalBuffer = {};
|
|
|
|
indexBuffer = {};
|
|
|
|
|
2023-01-21 13:00:02 +01:00
|
|
|
vertexArray.bind();
|
2023-01-20 23:32:51 +01:00
|
|
|
|
2023-01-23 16:25:23 +01:00
|
|
|
vertexBuffer = gl::Buffer<float>(gl::BufferType::Vertex, vertices);
|
2023-01-21 13:00:02 +01:00
|
|
|
normalBuffer = gl::Buffer<float>(gl::BufferType::Vertex, normals);
|
2023-01-23 16:25:23 +01:00
|
|
|
indexBuffer = gl::Buffer<u32>(gl::BufferType::Index, indices);
|
2023-01-20 21:16:28 +01:00
|
|
|
|
2023-01-21 13:00:02 +01:00
|
|
|
vertexArray.addBuffer(0, vertexBuffer);
|
|
|
|
vertexArray.addBuffer(1, normalBuffer);
|
2023-01-20 21:16:28 +01:00
|
|
|
|
2023-01-22 16:17:10 +01:00
|
|
|
if (!indices.empty())
|
|
|
|
vertexArray.addBuffer(2, indexBuffer);
|
|
|
|
|
2023-01-21 13:00:02 +01:00
|
|
|
vertexBuffer.unbind();
|
2023-01-23 16:25:23 +01:00
|
|
|
normalBuffer.unbind();
|
|
|
|
indexBuffer.unbind();
|
2023-01-21 13:00:02 +01:00
|
|
|
vertexArray.unbind();
|
|
|
|
}
|
2023-01-20 21:16:28 +01:00
|
|
|
|
2023-01-21 13:00:02 +01:00
|
|
|
{
|
|
|
|
gl::FrameBuffer frameBuffer;
|
2023-01-20 21:16:28 +01:00
|
|
|
|
2023-02-16 23:24:24 +01:00
|
|
|
gl::Texture renderTexture(400_scaled, 400_scaled);
|
2023-01-21 13:00:02 +01:00
|
|
|
frameBuffer.attachTexture(renderTexture);
|
2023-01-20 21:16:28 +01:00
|
|
|
|
2023-01-21 13:00:02 +01:00
|
|
|
frameBuffer.bind();
|
2023-01-20 21:16:28 +01:00
|
|
|
|
2023-01-21 13:00:02 +01:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
2023-01-23 16:25:23 +01:00
|
|
|
glEnable(GL_DEPTH_CLAMP);
|
2023-01-20 21:16:28 +01:00
|
|
|
|
2023-01-21 13:00:02 +01:00
|
|
|
shader.bind();
|
|
|
|
shader.setUniform("scale", scaling);
|
|
|
|
shader.setUniform("rotation", rotation);
|
2023-01-23 16:25:23 +01:00
|
|
|
shader.setUniform("translation", translation);
|
2023-01-20 23:32:51 +01:00
|
|
|
|
2023-01-21 13:00:02 +01:00
|
|
|
vertexArray.bind();
|
2023-01-20 21:16:28 +01:00
|
|
|
|
2023-01-21 13:00:02 +01:00
|
|
|
glViewport(0, 0, renderTexture.getWidth(), renderTexture.getHeight());
|
|
|
|
glClearColor(0.00F, 0.00F, 0.00F, 0.00f);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2023-01-23 16:25:23 +01:00
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
glFrustum(-1.0F, 1.0F, -1.0F, 1.0F, 0.0000001F, 10000000.0F);
|
2023-01-22 16:17:10 +01:00
|
|
|
|
|
|
|
if (indices.empty())
|
|
|
|
vertexBuffer.draw();
|
|
|
|
else
|
|
|
|
indexBuffer.draw();
|
2023-01-20 21:16:28 +01:00
|
|
|
|
2023-01-21 13:00:02 +01:00
|
|
|
vertexArray.unbind();
|
|
|
|
shader.unbind();
|
|
|
|
frameBuffer.unbind();
|
2023-01-20 21:16:28 +01:00
|
|
|
|
2023-01-21 13:00:02 +01:00
|
|
|
texture = ImGui::Texture(renderTexture.release(), renderTexture.getWidth(), renderTexture.getHeight());
|
2023-01-20 21:16:28 +01:00
|
|
|
}
|
|
|
|
|
2023-02-16 23:24:24 +01:00
|
|
|
auto textureSize = texture.getSize();
|
|
|
|
|
|
|
|
if (ImGui::BeginTable("##3DVisualizer", 2, ImGuiTableFlags_SizingFixedFit)) {
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
|
|
|
|
if (ImGui::BeginChild("##image", textureSize, true, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
|
|
|
|
ImGui::Image(texture, textureSize, ImVec2(0, 1), ImVec2(1, 0));
|
|
|
|
}
|
|
|
|
ImGui::EndChild();
|
|
|
|
ImGui::PopStyleVar();
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::TextUnformatted("hex.builtin.pl_visualizer.3d.rotation"_lang);
|
|
|
|
ImGui::VSliderFloat("##X", ImVec2(18_scaled, textureSize.y), &rotation.data()[0], 0, std::numbers::pi * 2, "", ImGuiSliderFlags_AlwaysClamp);
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::VSliderFloat("##Y", ImVec2(18_scaled, textureSize.y), &rotation.data()[1], 0, std::numbers::pi * 2, "", ImGuiSliderFlags_AlwaysClamp);
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::VSliderFloat("##Z", ImVec2(18_scaled, textureSize.y), &rotation.data()[2], 0, std::numbers::pi * 2, "", ImGuiSliderFlags_AlwaysClamp);
|
|
|
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
ImGui::TextUnformatted("hex.builtin.pl_visualizer.3d.scale"_lang);
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x);
|
|
|
|
ImGui::SliderFloat("##Scale", &scaling, 0.0001F, 0.2F, "");
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
|
|
|
for (u8 i = 0; i < 3; i++) {
|
|
|
|
while (rotation.data()[i] > std::numbers::pi * 2)
|
|
|
|
rotation.data()[i] -= std::numbers::pi * 2;
|
|
|
|
while (rotation.data()[i] < 0)
|
|
|
|
rotation.data()[i] += std::numbers::pi * 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
if (ImGui::Button("hex.builtin.common.reset"_lang, ImVec2(ImGui::GetContentRegionAvail().x, 0))) {
|
|
|
|
translation = gl::Vector<float, 3>({ 0.0F, 0.0F, 0.0F });
|
|
|
|
rotation = gl::Vector<float, 3>({ 0.0F, 0.0F, 0.0F });
|
|
|
|
scaling = 0.1F;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-20 21:16:28 +01:00
|
|
|
}
|
|
|
|
|
2023-04-18 10:06:47 +02:00
|
|
|
void drawSoundVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span<const pl::core::Token::Literal> arguments) {
|
2023-02-07 14:18:59 +01:00
|
|
|
auto wavePattern = arguments[0].toPattern();
|
|
|
|
auto channels = arguments[1].toUnsigned();
|
|
|
|
auto sampleRate = arguments[2].toUnsigned();
|
2023-01-24 23:27:35 +01:00
|
|
|
|
2023-01-25 10:16:46 +01:00
|
|
|
static std::vector<i16> waveData, sampledData;
|
2023-01-24 23:27:35 +01:00
|
|
|
static ma_device audioDevice;
|
|
|
|
static ma_device_config deviceConfig;
|
|
|
|
static bool shouldStop = false;
|
|
|
|
static u64 index = 0;
|
|
|
|
static TaskHolder resetTask;
|
|
|
|
|
2023-07-26 22:13:39 +02:00
|
|
|
if (sampleRate == 0)
|
|
|
|
throw std::logic_error(hex::format("Invalid sample rate: {}", sampleRate));
|
|
|
|
else if (channels == 0)
|
|
|
|
throw std::logic_error(hex::format("Invalid channel count: {}", channels));
|
|
|
|
|
2023-01-24 23:27:35 +01:00
|
|
|
if (shouldReset) {
|
|
|
|
waveData.clear();
|
|
|
|
|
|
|
|
resetTask = TaskManager::createTask("Visualizing...", TaskManager::NoProgress, [=](Task &) {
|
|
|
|
ma_device_stop(&audioDevice);
|
2023-06-11 00:08:34 +02:00
|
|
|
waveData = patternToArray<i16>(wavePattern.get());
|
2023-01-25 10:16:46 +01:00
|
|
|
sampledData = sampleData(waveData, 300_scaled * 4);
|
2023-01-24 23:27:35 +01:00
|
|
|
index = 0;
|
|
|
|
|
|
|
|
deviceConfig = ma_device_config_init(ma_device_type_playback);
|
|
|
|
deviceConfig.playback.format = ma_format_s16;
|
|
|
|
deviceConfig.playback.channels = channels;
|
|
|
|
deviceConfig.sampleRate = sampleRate;
|
|
|
|
deviceConfig.pUserData = &waveData;
|
|
|
|
deviceConfig.dataCallback = [](ma_device *device, void *pOutput, const void *, ma_uint32 frameCount) {
|
|
|
|
if (index >= waveData.size()) {
|
|
|
|
index = 0;
|
|
|
|
shouldStop = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ma_copy_pcm_frames(pOutput, waveData.data() + index, frameCount, device->playback.format, device->playback.channels);
|
|
|
|
index += frameCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
ma_device_init(nullptr, &deviceConfig, &audioDevice);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::BeginDisabled(resetTask.isRunning());
|
|
|
|
|
|
|
|
ImPlot::PushStyleVar(ImPlotStyleVar_PlotPadding, ImVec2(0, 0));
|
|
|
|
if (ImPlot::BeginPlot("##amplitude_plot", scaled(ImVec2(300, 80)), ImPlotFlags_NoChild | ImPlotFlags_CanvasOnly | ImPlotFlags_NoFrame | ImPlotFlags_NoInputs)) {
|
|
|
|
ImPlot::SetupAxes("##time", "##amplitude", ImPlotAxisFlags_NoDecorations | ImPlotAxisFlags_NoMenus, ImPlotAxisFlags_NoDecorations | ImPlotAxisFlags_NoMenus);
|
|
|
|
ImPlot::SetupAxesLimits(0, waveData.size(), std::numeric_limits<i16>::min(), std::numeric_limits<i16>::max(), ImGuiCond_Always);
|
|
|
|
|
|
|
|
double dragPos = index;
|
|
|
|
if (ImPlot::DragLineX(1, &dragPos, ImGui::GetStyleColorVec4(ImGuiCol_Text))) {
|
|
|
|
if (dragPos < 0) dragPos = 0;
|
|
|
|
if (dragPos >= waveData.size()) dragPos = waveData.size() - 1;
|
|
|
|
|
|
|
|
index = dragPos;
|
|
|
|
}
|
|
|
|
|
2023-01-25 10:16:46 +01:00
|
|
|
ImPlot::PlotLine("##audio", sampledData.data(), sampledData.size());
|
2023-01-24 23:27:35 +01:00
|
|
|
|
|
|
|
ImPlot::EndPlot();
|
|
|
|
}
|
|
|
|
ImPlot::PopStyleVar();
|
|
|
|
|
|
|
|
{
|
|
|
|
const u64 min = 0, max = waveData.size();
|
|
|
|
ImGui::PushItemWidth(300_scaled);
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
|
|
|
|
ImGui::SliderScalar("##index", ImGuiDataType_U64, &index, &min, &max, "");
|
|
|
|
ImGui::PopStyleVar();
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldStop) {
|
|
|
|
shouldStop = false;
|
|
|
|
ma_device_stop(&audioDevice);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool playing = ma_device_is_started(&audioDevice);
|
|
|
|
|
|
|
|
if (ImGui::IconButton(playing ? ICON_VS_DEBUG_PAUSE : ICON_VS_PLAY, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarGreen))) {
|
|
|
|
if (playing)
|
|
|
|
ma_device_stop(&audioDevice);
|
|
|
|
else
|
|
|
|
ma_device_start(&audioDevice);
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
if (ImGui::IconButton(ICON_VS_DEBUG_STOP, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarRed))) {
|
|
|
|
index = 0;
|
|
|
|
ma_device_stop(&audioDevice);
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndDisabled();
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
if (resetTask.isRunning())
|
2023-01-25 10:16:46 +01:00
|
|
|
ImGui::TextSpinner("");
|
2023-01-24 23:27:35 +01:00
|
|
|
else
|
2023-01-24 23:57:29 +01:00
|
|
|
ImGui::TextFormatted("{:02d}:{:02d} / {:02d}:{:02d}",
|
|
|
|
(index / sampleRate) / 60, (index / sampleRate) % 60,
|
|
|
|
(waveData.size() / sampleRate) / 60, (waveData.size() / sampleRate) % 60);
|
2023-01-24 23:27:35 +01:00
|
|
|
}
|
|
|
|
|
2023-04-18 10:06:47 +02:00
|
|
|
void drawChunkBasedEntropyVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span<const pl::core::Token::Literal> arguments) {
|
2023-10-04 12:00:32 +02:00
|
|
|
// Variable used to store the result to avoid having to recalculate the result at each frame
|
2023-06-02 10:47:18 +02:00
|
|
|
static DiagramChunkBasedEntropyAnalysis analyzer;
|
2023-03-10 16:06:18 +01:00
|
|
|
|
2023-10-04 12:00:32 +02:00
|
|
|
// Compute data
|
2023-03-10 16:06:18 +01:00
|
|
|
if (shouldReset) {
|
|
|
|
auto pattern = arguments[0].toPattern();
|
|
|
|
auto chunkSize = arguments[1].toUnsigned();
|
2023-06-02 10:47:18 +02:00
|
|
|
analyzer.process(pattern->getBytes(), chunkSize);
|
2023-03-10 16:06:18 +01:00
|
|
|
}
|
2023-06-02 10:47:18 +02:00
|
|
|
|
2023-10-04 12:00:32 +02:00
|
|
|
// Show results
|
2023-06-02 10:47:18 +02:00
|
|
|
analyzer.draw(ImVec2(400, 250), ImPlotFlags_NoChild | ImPlotFlags_CanvasOnly);
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2023-06-21 09:29:40 +02:00
|
|
|
std::vector<u8> data;
|
2023-06-02 10:47:18 +02:00
|
|
|
|
|
|
|
dataProvider = std::make_unique<MemoryFileProvider>();
|
2023-06-21 09:29:40 +02:00
|
|
|
try {
|
|
|
|
data = pattern->getBytes();
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
dataProvider->resize(0);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2023-06-02 10:47:18 +02:00
|
|
|
dataProvider->resize(data.size());
|
|
|
|
dataProvider->writeRaw(0x00, data.data(), data.size());
|
|
|
|
dataProvider->setReadOnly(true);
|
|
|
|
|
|
|
|
editor.setProvider(dataProvider.get());
|
|
|
|
}
|
|
|
|
|
2023-06-02 11:03:44 +02:00
|
|
|
if (ImGui::BeginChild("##editor", scaled(ImVec2(600, 400)), false, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
|
2023-06-02 10:47:18 +02:00
|
|
|
editor.draw();
|
|
|
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
}
|
2023-03-10 16:06:18 +01:00
|
|
|
}
|
|
|
|
|
2023-07-04 09:40:05 +02:00
|
|
|
void drawCoordinateVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span<const pl::core::Token::Literal> arguments) {
|
|
|
|
static ImVec2 coordinate;
|
|
|
|
static double latitude, longitude;
|
|
|
|
static std::string address;
|
|
|
|
static std::mutex addressMutex;
|
|
|
|
static TaskHolder addressTask;
|
|
|
|
|
2023-08-26 23:43:35 +02:00
|
|
|
static auto mapTexture = ImGui::Texture(romfs::get("assets/common/map.jpg").span());
|
2023-07-04 09:40:05 +02:00
|
|
|
static ImVec2 mapSize = scaled(ImVec2(500, 500 / mapTexture.getAspectRatio()));
|
|
|
|
|
|
|
|
if (shouldReset) {
|
|
|
|
std::scoped_lock lock(addressMutex);
|
|
|
|
|
|
|
|
address.clear();
|
|
|
|
latitude = arguments[0].toFloatingPoint();
|
|
|
|
longitude = arguments[1].toFloatingPoint();
|
|
|
|
|
|
|
|
// Convert latitude and longitude to X/Y coordinates on the image
|
|
|
|
coordinate.x = float((longitude + 180) / 360 * mapSize.x);
|
|
|
|
coordinate.y = float((-latitude + 90) / 180 * mapSize.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto startPos = ImGui::GetWindowPos() + ImGui::GetCursorPos();
|
|
|
|
|
|
|
|
// Draw background image
|
|
|
|
ImGui::Image(mapTexture, mapSize);
|
|
|
|
|
|
|
|
// Draw Longitude / Latitude text below image
|
2023-07-06 10:08:47 +02:00
|
|
|
ImGui::PushTextWrapPos(startPos.x + mapSize.x);
|
|
|
|
ImGui::TextFormattedWrapped("{}: {:.0f}° {:.0f}' {:.4f}\" {} | {}: {:.0f}° {:.0f}' {:.4f}\" {}",
|
2023-07-04 09:40:05 +02:00
|
|
|
"hex.builtin.pl_visualizer.coordinates.latitude"_lang,
|
|
|
|
std::floor(std::abs(latitude)),
|
|
|
|
std::floor(std::abs(latitude - std::floor(latitude)) * 60),
|
|
|
|
(std::abs(latitude - std::floor(latitude)) * 60 - std::floor(std::abs(latitude - std::floor(latitude)) * 60)) * 60,
|
|
|
|
latitude >= 0 ? "N" : "S",
|
|
|
|
"hex.builtin.pl_visualizer.coordinates.longitude"_lang,
|
|
|
|
std::floor(std::abs(longitude)),
|
|
|
|
std::floor(std::abs(longitude - std::floor(longitude)) * 60),
|
|
|
|
(std::abs(longitude - std::floor(longitude)) * 60 - std::floor(std::abs(longitude - std::floor(longitude)) * 60)) * 60,
|
|
|
|
longitude >= 0 ? "E" : "W"
|
|
|
|
);
|
2023-07-06 10:08:47 +02:00
|
|
|
ImGui::PopTextWrapPos();
|
2023-07-04 09:40:05 +02:00
|
|
|
|
|
|
|
if (addressTask.isRunning()) {
|
|
|
|
ImGui::TextSpinner("hex.builtin.pl_visualizer.coordinates.querying"_lang);
|
|
|
|
} else if (address.empty()) {
|
|
|
|
if (ImGui::DimmedButton("hex.builtin.pl_visualizer.coordinates.query"_lang)) {
|
|
|
|
addressTask = TaskManager::createBackgroundTask("hex.builtin.pl_visualizer.coordinates.querying"_lang, [lat = latitude, lon = longitude](auto &) {
|
|
|
|
constexpr static auto ApiURL = "https://geocode.maps.co/reverse?lat={}&lon={}&format=jsonv2";
|
|
|
|
|
|
|
|
HttpRequest request("GET", hex::format(ApiURL, lat, lon));
|
|
|
|
auto response = request.execute().get();
|
|
|
|
|
|
|
|
if (!response.isSuccess())
|
|
|
|
return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
auto json = nlohmann::json::parse(response.getData());
|
|
|
|
auto jsonAddr = json["address"];
|
|
|
|
|
|
|
|
std::scoped_lock lock(addressMutex);
|
|
|
|
if (jsonAddr.contains("village")) {
|
|
|
|
address = hex::format("{} {}, {} {}",
|
|
|
|
jsonAddr["village"].get<std::string>(),
|
|
|
|
jsonAddr["county"].get<std::string>(),
|
|
|
|
jsonAddr["state"].get<std::string>(),
|
|
|
|
jsonAddr["country"].get<std::string>());
|
|
|
|
} else if (jsonAddr.contains("city")) {
|
|
|
|
address = hex::format("{}, {} {}, {} {}",
|
|
|
|
jsonAddr["road"].get<std::string>(),
|
|
|
|
jsonAddr["quarter"].get<std::string>(),
|
|
|
|
jsonAddr["city"].get<std::string>(),
|
|
|
|
jsonAddr["state"].get<std::string>(),
|
|
|
|
jsonAddr["country"].get<std::string>());
|
|
|
|
}
|
|
|
|
} catch (std::exception &e) {
|
|
|
|
address = std::string("hex.builtin.pl_visualizer.coordinates.querying_no_address"_lang);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ImGui::PushTextWrapPos(startPos.x + mapSize.x);
|
|
|
|
ImGui::TextFormattedWrapped("{}", address);
|
|
|
|
ImGui::PopTextWrapPos();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw crosshair pointing to the coordinates
|
|
|
|
{
|
|
|
|
constexpr static u32 CrossHairColor = 0xFF00D0D0;
|
|
|
|
constexpr static u32 BorderColor = 0xFF000000;
|
|
|
|
|
|
|
|
auto drawList = ImGui::GetWindowDrawList();
|
|
|
|
drawList->AddLine(startPos + ImVec2(coordinate.x, 0), startPos + ImVec2(coordinate.x, mapSize.y), CrossHairColor, 2_scaled);
|
|
|
|
drawList->AddLine(startPos + ImVec2(0, coordinate.y), startPos + ImVec2(mapSize.x, coordinate.y), CrossHairColor, 2_scaled);
|
|
|
|
drawList->AddCircleFilled(startPos + coordinate, 5, CrossHairColor);
|
|
|
|
drawList->AddCircle(startPos + coordinate, 5, BorderColor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 19:54:18 +02:00
|
|
|
void drawTimestampVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool, std::span<const pl::core::Token::Literal> arguments) {
|
|
|
|
time_t timestamp = arguments[0].toUnsigned();
|
|
|
|
auto tm = fmt::gmtime(timestamp);
|
|
|
|
auto date = std::chrono::year_month_day(std::chrono::year(tm.tm_year + 1900), std::chrono::month(tm.tm_mon + 1), std::chrono::day(tm.tm_mday));
|
|
|
|
|
|
|
|
auto lastMonthDay = std::chrono::year_month_day_last(date.year(), date.month() / std::chrono::last);
|
|
|
|
auto firstWeekDay = std::chrono::weekday(std::chrono::year_month_day(date.year(), date.month(), std::chrono::day(1)));
|
|
|
|
|
2023-07-06 10:08:47 +02:00
|
|
|
const auto scale = 1_scaled * (ImHexApi::System::getFontSize() / ImHexApi::System::DefaultFontSize);
|
2023-07-05 19:54:18 +02:00
|
|
|
|
|
|
|
// Draw calendar
|
|
|
|
if (ImGui::BeginTable("##month_table", 2)) {
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
// Draw centered month name and year
|
2023-07-06 10:08:47 +02:00
|
|
|
ImGui::TextFormattedCenteredHorizontal("{:%B %Y}", tm);
|
2023-07-05 19:54:18 +02:00
|
|
|
|
2023-07-06 10:08:47 +02:00
|
|
|
if (ImGui::BeginTable("##days_table", 7, ImGuiTableFlags_Borders | ImGuiTableFlags_NoHostExtendX, ImVec2(160, 120) * scale)) {
|
2023-07-05 19:54:18 +02:00
|
|
|
constexpr static auto ColumnFlags = ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_NoReorder | ImGuiTableColumnFlags_NoHide;
|
|
|
|
ImGui::TableSetupColumn("M", ColumnFlags);
|
|
|
|
ImGui::TableSetupColumn("T", ColumnFlags);
|
|
|
|
ImGui::TableSetupColumn("W", ColumnFlags);
|
|
|
|
ImGui::TableSetupColumn("T", ColumnFlags);
|
|
|
|
ImGui::TableSetupColumn("F", ColumnFlags);
|
|
|
|
ImGui::TableSetupColumn("S", ColumnFlags);
|
|
|
|
ImGui::TableSetupColumn("S", ColumnFlags);
|
|
|
|
|
|
|
|
ImGui::TableHeadersRow();
|
|
|
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
|
|
|
// Skip days before the first day of the month
|
|
|
|
for (u8 i = 0; i < firstWeekDay.c_encoding() - 1; ++i)
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
// Draw days
|
|
|
|
for (u8 i = 1; i <= u32(lastMonthDay.day()); ++i) {
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::TextFormatted("{:02}", i);
|
|
|
|
|
|
|
|
if (std::chrono::day(i) == date.day())
|
|
|
|
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, ImGui::GetCustomColorU32(ImGuiCustomCol_ToolbarRed));
|
|
|
|
|
|
|
|
if (std::chrono::weekday(std::chrono::year_month_day(date.year(), date.month(), std::chrono::day(i))) == std::chrono::Sunday)
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
// Draw analog clock
|
2023-07-06 10:08:47 +02:00
|
|
|
const auto size = ImVec2(120, 120) * scale;
|
|
|
|
if (ImGui::BeginChild("##clock", size + ImVec2(0, ImGui::GetTextLineHeightWithSpacing()))) {
|
|
|
|
// Draw centered digital hour, minute and seconds
|
|
|
|
ImGui::TextFormattedCenteredHorizontal("{:%H:%M:%S}", tm);
|
2023-07-05 19:54:18 +02:00
|
|
|
auto drawList = ImGui::GetWindowDrawList();
|
2023-07-06 10:08:47 +02:00
|
|
|
const auto center = ImGui::GetWindowPos() + ImVec2(0, ImGui::GetTextLineHeightWithSpacing()) + size / 2;
|
2023-07-05 19:54:18 +02:00
|
|
|
|
|
|
|
// Draw clock face
|
|
|
|
drawList->AddCircle(center, size.x / 2, ImGui::GetColorU32(ImGuiCol_TextDisabled), 0);
|
|
|
|
|
|
|
|
auto sectionPos = [](float i) {
|
|
|
|
return ImVec2(std::sin(-i * 30.0F * std::numbers::pi / 180.0F + std::numbers::pi / 2), std::cos(-i * 30.0F * std::numbers::pi / 180.0F + std::numbers::pi / 2));
|
|
|
|
};
|
|
|
|
|
|
|
|
// Draw clock sections and numbers
|
|
|
|
for (u8 i = 0; i < 12; ++i) {
|
|
|
|
auto text = hex::format("{}", (((i + 2) % 12) + 1));
|
|
|
|
drawList->AddLine(center + sectionPos(i) * size / 2.2, center + sectionPos(i) * size / 2, ImGui::GetColorU32(ImGuiCol_TextDisabled), 1_scaled);
|
|
|
|
drawList->AddText(center + sectionPos(i) * size / 3 - ImGui::CalcTextSize(text.c_str()) / 2, ImGui::GetColorU32(ImGuiCol_Text), text.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw hour hand
|
|
|
|
drawList->AddLine(center, center + sectionPos((tm.tm_hour + 9) % 12 + float(tm.tm_min) / 60.0) * size / 3.5, ImGui::GetColorU32(ImGuiCol_TextDisabled), 3_scaled);
|
|
|
|
|
|
|
|
// Draw minute hand
|
|
|
|
drawList->AddLine(center, center + sectionPos((float(tm.tm_min) / 5.0F) - 3) * size / 2.5, ImGui::GetColorU32(ImGuiCol_TextDisabled), 3_scaled);
|
|
|
|
|
|
|
|
// Draw second hand
|
|
|
|
drawList->AddLine(center, center + sectionPos((float(tm.tm_sec) / 5.0F) - 3) * size / 2.5, ImGui::GetCustomColorU32(ImGuiCustomCol_ToolbarRed), 2_scaled);
|
|
|
|
}
|
|
|
|
ImGui::EndChild();
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-20 21:16:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void registerPatternLanguageVisualizers() {
|
2023-10-31 10:56:20 +01:00
|
|
|
using ParamCount = pl::api::FunctionParameterCount;
|
|
|
|
|
|
|
|
ContentRegistry::PatternLanguage::addVisualizer("line_plot", drawLinePlotVisualizer, ParamCount::exactly(1));
|
|
|
|
ContentRegistry::PatternLanguage::addVisualizer("scatter_plot", drawScatterPlotVisualizer, ParamCount::exactly(2));
|
|
|
|
ContentRegistry::PatternLanguage::addVisualizer("image", drawImageVisualizer, ParamCount::exactly(1));
|
|
|
|
ContentRegistry::PatternLanguage::addVisualizer("bitmap", drawBitmapVisualizer, ParamCount::exactly(3));
|
|
|
|
ContentRegistry::PatternLanguage::addVisualizer("disassembler", drawDisassemblyVisualizer, ParamCount::exactly(4));
|
|
|
|
ContentRegistry::PatternLanguage::addVisualizer("3d", draw3DVisualizer, ParamCount::exactly(2));
|
|
|
|
ContentRegistry::PatternLanguage::addVisualizer("sound", drawSoundVisualizer, ParamCount::exactly(3));
|
|
|
|
ContentRegistry::PatternLanguage::addVisualizer("chunk_entropy", drawChunkBasedEntropyVisualizer, ParamCount::exactly(2));
|
|
|
|
ContentRegistry::PatternLanguage::addVisualizer("hex_viewer", drawHexVisualizer, ParamCount::exactly(1));
|
|
|
|
ContentRegistry::PatternLanguage::addVisualizer("coordinates", drawCoordinateVisualizer, ParamCount::exactly(2));
|
|
|
|
ContentRegistry::PatternLanguage::addVisualizer("timestamp", drawTimestampVisualizer, ParamCount::exactly(1));
|
2023-01-20 21:16:28 +01:00
|
|
|
}
|
|
|
|
|
2023-03-10 16:06:18 +01:00
|
|
|
}
|