From bbfb0556a66576cc17414aeb347405a88a51d178 Mon Sep 17 00:00:00 2001 From: averne Date: Sun, 15 Nov 2020 15:48:30 +0100 Subject: [PATCH 1/2] Only statically link on Windows --- .gitignore | 2 ++ CMakeLists.txt | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 784576e03..73ff7ed9c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,7 @@ cmake-build-debug/ cmake-build-release/ build-linux/ +build/ *.mgc +imgui.ini diff --git a/CMakeLists.txt b/CMakeLists.txt index 98d512f6a..7dd13c61c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,11 @@ pkg_search_module(GLFW REQUIRED glfw3) find_package(OpenGL REQUIRED) include_directories(include ${GLFW_INCLUDE_DIRS} libs/ImGui/include libs/glad/include) -SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -DIMGUI_IMPL_OPENGL_LOADER_GLAD -static-libstdc++ -static-libgcc -static") +SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -DIMGUI_IMPL_OPENGL_LOADER_GLAD") + +if (WIN32) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc -static") +endif (WIN32) add_executable(ImHex source/main.cpp From ec294228aee0d29813fc3b7ec8d0249122142709 Mon Sep 17 00:00:00 2001 From: averne Date: Sun, 15 Nov 2020 15:49:21 +0100 Subject: [PATCH 2/2] Simple configuration parsing for size scaling --- include/window.hpp | 3 +++ source/window.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/include/window.hpp b/include/window.hpp index 28c545851..1e9d0f22c 100644 --- a/include/window.hpp +++ b/include/window.hpp @@ -24,6 +24,9 @@ namespace hex { return static_cast(this->m_views.back()); } + public: + float m_globalScale = 1.0f, m_fontScale = 1.0f; + private: void frameBegin(); void frameEnd(); diff --git a/source/window.cpp b/source/window.cpp index e0ac5f4de..b51ba23f2 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -3,6 +3,7 @@ #include #include "imgui.h" +#include "imgui_internal.h" #include "imgui_impl_glfw.h" #include "imgui_impl_opengl3.h" @@ -11,6 +12,44 @@ namespace hex { + namespace { + + void *ImHexSettingsHandler_ReadOpenFn(ImGuiContext *ctx, ImGuiSettingsHandler *, const char *) { + return ctx; // Unused, but the return value has to be non-null + } + + void ImHexSettingsHandler_ReadLine(ImGuiContext*, ImGuiSettingsHandler *handler, void *, const char* line) { + auto *window = reinterpret_cast(handler->UserData); + + float scale; + if (sscanf(line, "Scale=%f", &scale) == 1) { window->m_globalScale = scale; } + else if (sscanf(line, "FontScale=%f", &scale) == 1) { window->m_fontScale = scale; } + } + + void ImHexSettingsHandler_ApplyAll(ImGuiContext *ctx, ImGuiSettingsHandler *handler) { + auto *window = reinterpret_cast(handler->UserData); + auto &style = ImGui::GetStyle(); + auto &io = ImGui::GetIO(); + + if (window->m_globalScale != 0.0f) + style.ScaleAllSizes(window->m_globalScale); + if (window->m_fontScale != 0.0f) + io.FontGlobalScale = window->m_fontScale; + } + + void ImHexSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler *handler, ImGuiTextBuffer *buf) { + auto *window = reinterpret_cast(handler->UserData); + + buf->reserve(buf->size() + 0x20); // Ballpark reserve + + buf->appendf("[%s][General]\n", handler->TypeName); + buf->appendf("Scale=%.1f\n", window->m_globalScale); + buf->appendf("FontScale=%.1f\n", window->m_fontScale); + buf->append("\n"); + } + + } + Window::Window() { this->initGLFW(); this->initImGui(); @@ -141,10 +180,21 @@ namespace hex { void Window::initImGui() { IMGUI_CHECKVERSION(); - ImGui::CreateContext(); - ImGuiIO& io = ImGui::GetIO(); (void)io; + auto *ctx = ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; + // Install custom settings handler + ImGuiSettingsHandler handler; + handler.TypeName = "ImHex"; + handler.TypeHash = ImHashStr("ImHex"); + handler.ReadOpenFn = ImHexSettingsHandler_ReadOpenFn; + handler.ReadLineFn = ImHexSettingsHandler_ReadLine; + handler.ApplyAllFn = ImHexSettingsHandler_ApplyAll; + handler.WriteAllFn = ImHexSettingsHandler_WriteAll; + handler.UserData = this; + ctx->SettingsHandlers.push_back(handler); + ImGui::StyleColorsDark(); ImGui_ImplGlfw_InitForOpenGL(this->m_window, true);