diff --git a/lib/libimhex/include/hex/api/event.hpp b/lib/libimhex/include/hex/api/event.hpp index cca425e02..2e137d5b5 100644 --- a/lib/libimhex/include/hex/api/event.hpp +++ b/lib/libimhex/include/hex/api/event.hpp @@ -162,6 +162,7 @@ namespace hex { EVENT_DEF(EventRegionSelected, ImHexApi::HexEditor::ProviderRegion); EVENT_DEF(EventSettingsChanged); EVENT_DEF(EventAbnormalTermination, int); + EVENT_DEF(EventThemeChanged); EVENT_DEF(EventOSThemeChanged); /** diff --git a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h index 2e09a920d..c4b2d22c1 100644 --- a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h +++ b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h @@ -33,6 +33,12 @@ enum ImGuiCustomCol { ImGuiCustomCol_COUNT }; +enum ImGuiCustomStyle { + ImGuiCustomStyle_WindowBlur, + + ImGuiCustomStyle_COUNT +}; + namespace ImGui { class Texture { @@ -106,34 +112,47 @@ namespace ImGui { struct ImHexCustomData { ImVec4 Colors[ImGuiCustomCol_COUNT]; + + struct Styles { + float WindowBlur = 0.0F; + } styles; }; ImU32 GetCustomColorU32(ImGuiCustomCol idx, float alpha_mul = 1.0F); ImVec4 GetCustomColorVec4(ImGuiCustomCol idx, float alpha_mul = 1.0F); + inline ImHexCustomData::Styles& GetCustomStyle() { + auto &customData = *static_cast(GImGui->IO.UserData); + + return customData.styles; + } + + float GetCustomStyleFloat(ImGuiCustomStyle idx); + ImVec2 GetCustomStyleVec2(ImGuiCustomStyle idx); + void StyleCustomColorsDark(); void StyleCustomColorsLight(); void StyleCustomColorsClassic(); void SmallProgressBar(float fraction, float yOffset = 0.0F); - void TextFormatted(const std::string &fmt, auto &&...args) { + inline void TextFormatted(const std::string &fmt, auto &&...args) { ImGui::TextUnformatted(hex::format(fmt, std::forward(args)...).c_str()); } - void TextFormattedColored(ImColor color, const std::string &fmt, auto &&...args) { + inline void TextFormattedColored(ImColor color, const std::string &fmt, auto &&...args) { ImGui::TextColored(color, "%s", hex::format(fmt, std::forward(args)...).c_str()); } - void TextFormattedDisabled(const std::string &fmt, auto &&...args) { + inline void TextFormattedDisabled(const std::string &fmt, auto &&...args) { ImGui::TextDisabled("%s", hex::format(fmt, std::forward(args)...).c_str()); } - void TextFormattedWrapped(const std::string &fmt, auto &&...args) { + inline void TextFormattedWrapped(const std::string &fmt, auto &&...args) { ImGui::TextWrapped("%s", hex::format(fmt, std::forward(args)...).c_str()); } - void TextFormattedCentered(const std::string &fmt, auto &&...args) { + inline void TextFormattedCentered(const std::string &fmt, auto &&...args) { auto text = hex::format(fmt, std::forward(args)...); auto availableSpace = ImGui::GetContentRegionAvail(); auto textSize = ImGui::CalcTextSize(text.c_str(), nullptr, false, availableSpace.x * 0.75F); diff --git a/lib/libimhex/source/api/theme_manager.cpp b/lib/libimhex/source/api/theme_manager.cpp index d5e55a6fc..4a360d3e5 100644 --- a/lib/libimhex/source/api/theme_manager.cpp +++ b/lib/libimhex/source/api/theme_manager.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -182,6 +183,8 @@ namespace hex { } s_currTheme = name; + + EventManager::post(); } const std::string &ThemeManager::getThemeImagePostfix() { diff --git a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp index 6a287d3a2..de40d3423 100644 --- a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp +++ b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp @@ -353,6 +353,24 @@ namespace ImGui { return c; } + float GetCustomStyleFloat(ImGuiCustomStyle idx) { + auto &customData = *static_cast(GImGui->IO.UserData); + + switch (idx) { + case ImGuiCustomStyle_WindowBlur: + return customData.styles.WindowBlur; + default: + return 0.0f; + } + } + + ImVec2 GetCustomStyleVec2(ImGuiCustomStyle idx) { + switch (idx) { + default: + return { }; + } + } + void StyleCustomColorsDark() { auto &colors = static_cast(GImGui->IO.UserData)->Colors; diff --git a/main/source/window/win_window.cpp b/main/source/window/win_window.cpp index 0dcfa5ee6..00225c470 100644 --- a/main/source/window/win_window.cpp +++ b/main/source/window/win_window.cpp @@ -333,6 +333,36 @@ namespace hex { } }); } + + struct ACCENTPOLICY { + int na; + int nf; + int nc; + int nA; + }; + struct WINCOMPATTRDATA { + int na; + PVOID pd; + ULONG ul; + }; + + EventManager::subscribe([this]{ + auto hwnd = glfwGetWin32Window(this->m_window); + + const HINSTANCE user32Dll = LoadLibraryA("user32.dll"); + if (user32Dll != nullptr) { + using SetWindowCompositionAttributeFunc = BOOL(WINAPI*)(HWND, WINCOMPATTRDATA*); + + const auto SetWindowCompositionAttribute = (SetWindowCompositionAttributeFunc)(void*)GetProcAddress(user32Dll, "SetWindowCompositionAttribute"); + if (SetWindowCompositionAttribute != nullptr) { + ACCENTPOLICY policy = { 3, 0, 0, 0 }; + WINCOMPATTRDATA data = { ImGui::GetCustomStyle().WindowBlur > 0.0F ? 19 : 0, &policy, sizeof(ACCENTPOLICY) }; + SetWindowCompositionAttribute(hwnd, &data); + } + FreeLibrary(user32Dll); + } + }); + } void Window::beginNativeWindowFrame() { diff --git a/main/source/window/window.cpp b/main/source/window/window.cpp index 2a214d500..f000cce61 100644 --- a/main/source/window/window.cpp +++ b/main/source/window/window.cpp @@ -692,7 +692,7 @@ namespace hex { int displayWidth, displayHeight; glfwGetFramebufferSize(this->m_window, &displayWidth, &displayHeight); glViewport(0, 0, displayWidth, displayHeight); - glClearColor(0.00F, 0.00F, 0.00F, 1.00f); + glClearColor(0.00F, 0.00F, 0.00F, 0.00F); glClear(GL_COLOR_BUFFER_BIT); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); @@ -735,6 +735,7 @@ namespace hex { glfwWindowHint(GLFW_DECORATED, ImHexApi::System::isBorderlessWindowModeEnabled() ? GL_FALSE : GL_TRUE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); + glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // Create window @@ -905,10 +906,6 @@ namespace hex { ImGuiIO &io = ImGui::GetIO(); ImGuiStyle &style = ImGui::GetStyle(); - // Configure window alpha and rounding to make them not stand out when detached - style.Alpha = 1.0F; - style.WindowRounding = 0.0F; - ImNodes::GetStyle().Flags = ImNodesStyleFlags_NodeOutline | ImNodesStyleFlags_GridLines; io.ConfigFlags |= ImGuiConfigFlags_DockingEnable | ImGuiConfigFlags_NavEnableKeyboard; diff --git a/plugins/builtin/romfs/themes/classic.json b/plugins/builtin/romfs/themes/classic.json index f352bc129..f582de7b6 100644 --- a/plugins/builtin/romfs/themes/classic.json +++ b/plugins/builtin/romfs/themes/classic.json @@ -310,6 +310,9 @@ 10.0, 10.0 ] + }, + "imhex": { + "window-blur": 0.0 } } } \ No newline at end of file diff --git a/plugins/builtin/romfs/themes/dark.json b/plugins/builtin/romfs/themes/dark.json index 2d10dc7d3..0c7ba18c7 100644 --- a/plugins/builtin/romfs/themes/dark.json +++ b/plugins/builtin/romfs/themes/dark.json @@ -310,6 +310,9 @@ 10.0, 10.0 ] + }, + "imhex": { + "window-blur": 0.0 } } } \ No newline at end of file diff --git a/plugins/builtin/romfs/themes/light.json b/plugins/builtin/romfs/themes/light.json index 9112e1fa4..46960347a 100644 --- a/plugins/builtin/romfs/themes/light.json +++ b/plugins/builtin/romfs/themes/light.json @@ -310,6 +310,9 @@ 10.0, 10.0 ] + }, + "imhex": { + "window-blur": 0.0 } } } \ No newline at end of file diff --git a/plugins/builtin/source/content/themes.cpp b/plugins/builtin/source/content/themes.cpp index d3cecae85..55d361487 100644 --- a/plugins/builtin/source/content/themes.cpp +++ b/plugins/builtin/source/content/themes.cpp @@ -326,6 +326,15 @@ namespace hex::plugin::builtin { ThemeManager::addStyleHandler("imnodes", ImNodesStyleMap); } + + { + auto &style = ImGui::GetCustomStyle(); + const static ThemeManager::StyleMap ImHexStyleMap = { + { "window-blur", { &style.WindowBlur, 0.0F, 1.0F, true } }, + }; + + ThemeManager::addStyleHandler("imhex", ImHexStyleMap); + } }); }