1
0
mirror of synced 2025-02-17 18:59:21 +01:00

feat: Added support for transparent and blurry window styles

This commit is contained in:
WerWolv 2023-05-22 12:00:35 +02:00
parent 6b28828174
commit f81276f7e3
10 changed files with 96 additions and 10 deletions

View File

@ -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);
/**

View File

@ -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<ImHexCustomData *>(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<decltype(args)>(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<decltype(args)>(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<decltype(args)>(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<decltype(args)>(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<decltype(args)>(args)...);
auto availableSpace = ImGui::GetContentRegionAvail();
auto textSize = ImGui::CalcTextSize(text.c_str(), nullptr, false, availableSpace.x * 0.75F);

View File

@ -1,5 +1,6 @@
#include <hex/api/theme_manager.hpp>
#include <hex/api/imhex_api.hpp>
#include <hex/api/event.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/helpers/utils.hpp>
@ -182,6 +183,8 @@ namespace hex {
}
s_currTheme = name;
EventManager::post<EventThemeChanged>();
}
const std::string &ThemeManager::getThemeImagePostfix() {

View File

@ -353,6 +353,24 @@ namespace ImGui {
return c;
}
float GetCustomStyleFloat(ImGuiCustomStyle idx) {
auto &customData = *static_cast<ImHexCustomData *>(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<ImHexCustomData *>(GImGui->IO.UserData)->Colors;

View File

@ -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<EventThemeChanged>([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() {

View File

@ -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;

View File

@ -310,6 +310,9 @@
10.0,
10.0
]
},
"imhex": {
"window-blur": 0.0
}
}
}

View File

@ -310,6 +310,9 @@
10.0,
10.0
]
},
"imhex": {
"window-blur": 0.0
}
}
}

View File

@ -310,6 +310,9 @@
10.0,
10.0
]
},
"imhex": {
"window-blur": 0.0
}
}
}

View File

@ -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);
}
});
}