diff --git a/lib/libimhex/source/api/theme_manager.cpp b/lib/libimhex/source/api/theme_manager.cpp index 7851cb855..6f45f3f82 100644 --- a/lib/libimhex/source/api/theme_manager.cpp +++ b/lib/libimhex/source/api/theme_manager.cpp @@ -16,9 +16,22 @@ namespace hex { AutoReset> s_styleHandlers; AutoReset s_imageTheme; AutoReset s_currTheme; - AutoReset> s_accentColor; + AutoReset> s_accentColor; + ImColor s_accentBaseColor; std::recursive_mutex s_themeMutex; + + std::tuple getHSV(const ImColor &color) { + float h, s, v; + ImGui::ColorConvertRGBtoHSV(color.Value.x, color.Value.y, color.Value.z, h, s, v); + return { h, s, v }; + } + + ImColor getRGB(float h, float s, float v) { + float r, g, b; + ImGui::ColorConvertHSVtoRGB(h, s, v, r, g, b); + return ImColor(r, g, b); + } } @@ -142,6 +155,10 @@ namespace hex { } } + if (theme.contains("base_color")) { + s_accentBaseColor = parseColorString(theme["base_color"].get()).value_or(ImColor(1.0F, 1.0F, 1.0F)); + } + if (theme.contains("colors") && !s_themeHandlers->empty()) { for (const auto&[type, content] : theme["colors"].items()) { if (!s_themeHandlers->contains(type)) { @@ -170,12 +187,15 @@ namespace hex { } if (accentableColor && s_accentColor->has_value()) { - float h, s, v; - ImGui::ColorConvertRGBtoHSV(color->Value.x, color->Value.y, color->Value.z, h, s, v); + const auto [baseH, baseS, baseV] = getHSV(s_accentBaseColor); + const auto [accentH, accentS, accentV] = getHSV(s_accentColor->value()); + auto [colorH, colorS, colorV] = getHSV(color.value()); - h = s_accentColor->value(); + colorH = std::max(colorH - baseH, 0.0F) + accentH; + colorS = std::max(colorS - baseS, 0.0F) + accentS; + colorV = std::max(colorV - baseV, 0.0F) + accentV; - ImGui::ColorConvertHSVtoRGB(h, s, v, color->Value.x, color->Value.y, color->Value.z); + color = getRGB(colorH, colorS, colorV); } (*s_themeHandlers)[type].setFunction((*s_themeHandlers)[type].colorMap.at(key), color.value()); @@ -254,10 +274,7 @@ namespace hex { } void ThemeManager::setAccentColor(const ImColor &color) { - float h, s, v; - ImGui::ColorConvertRGBtoHSV(color.Value.x, color.Value.y, color.Value.z, h, s, v); - - s_accentColor = h; + s_accentColor = color; reapplyCurrentTheme(); } diff --git a/plugins/builtin/romfs/themes/classic.json b/plugins/builtin/romfs/themes/classic.json index 8c365c00c..801a08200 100644 --- a/plugins/builtin/romfs/themes/classic.json +++ b/plugins/builtin/romfs/themes/classic.json @@ -1,5 +1,6 @@ { "base": "Classic", + "base_color": "#59669B9E", "colors": { "imgui": { "border": "#7F7F7F7F", diff --git a/plugins/builtin/romfs/themes/dark.json b/plugins/builtin/romfs/themes/dark.json index 4db34e6b2..6aa2a4ea8 100644 --- a/plugins/builtin/romfs/themes/dark.json +++ b/plugins/builtin/romfs/themes/dark.json @@ -1,5 +1,6 @@ { "base": "Dark", + "base_color": "#4296F966", "colors": { "imgui": { "border": "#6D6D7F7F", diff --git a/plugins/builtin/romfs/themes/light.json b/plugins/builtin/romfs/themes/light.json index 77783b840..2be5b53b2 100644 --- a/plugins/builtin/romfs/themes/light.json +++ b/plugins/builtin/romfs/themes/light.json @@ -1,5 +1,6 @@ { "base": "Light", + "base_color": "#4296F966", "colors": { "imgui": { "border": "#0000004C",