diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index e52ea57143..889d072ac1 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -14,6 +14,7 @@ add_executable(launcher src/options/parser.cpp src/main.cpp src/ui/frame.cpp + src/ui/color.cpp src/client/configuration.cpp src/client/cache.cpp src/client/ui.cpp diff --git a/launcher/src/ui/color.cpp b/launcher/src/ui/color.cpp new file mode 100644 index 0000000000..f277afd9ed --- /dev/null +++ b/launcher/src/ui/color.cpp @@ -0,0 +1,35 @@ +#include "frame.h" + +// Clamp Function +static float clamp(const float value, const float min = 0.0f, const float max = 1.0f) { + return std::max(min, std::min(value, max)); +} + +// Calculate Perceived Brightness Of Color +// See: https://en.wikipedia.org/w/index.php?title=Relative_luminance&useskin=vector +static float compute_luma(const ImVec4 &color) { + return (0.2126f * color.x) + (0.7152f * color.y) + (0.0722f * color.z); +} + +// Apply Luma To RGB +static ImVec4 apply_luma_to_color(const float target_luma, const ImVec4 &color) { + const float current_luma = compute_luma(color); + const float luma_ratio = (current_luma != 0) ? target_luma / current_luma : 0; + ImVec4 out = color; + for (float *x : {&out.x, &out.y, &out.z}) { + *x = clamp(*x * luma_ratio); + } + return out; +} + +// Blend Color +static ImVec4 blend_color(const ImVec4 &top, const ImVec4 &bottom) { + const float luma = compute_luma(bottom); + ImVec4 out = apply_luma_to_color(luma, top); + out.w = bottom.w; + return out; +} +ImVec4 Frame::blend_with_primary(const ImVec4 &color) { + static constexpr ImVec4 primary_color = {1.0f, (69.0f / 255.0f), 0.0f, 1.0f}; + return blend_color(primary_color, color); +} \ No newline at end of file diff --git a/launcher/src/ui/frame.cpp b/launcher/src/ui/frame.cpp index 469074ed61..8fa4397f1c 100644 --- a/launcher/src/ui/frame.cpp +++ b/launcher/src/ui/frame.cpp @@ -86,4 +86,39 @@ void Frame::setup_style(const float scale) { style.WindowBorderSize = 0; ImGui::StyleColorsDark(&style); style.ScaleAllSizes(scale); + // Colors + static int target_colors[] = { + ImGuiCol_FrameBg, + ImGuiCol_FrameBgHovered, + ImGuiCol_FrameBgActive, + ImGuiCol_TitleBgActive, + ImGuiCol_CheckMark, + ImGuiCol_SliderGrab, + ImGuiCol_SliderGrabActive, + ImGuiCol_Button, + ImGuiCol_ButtonHovered, + ImGuiCol_ButtonActive, + ImGuiCol_Header, + ImGuiCol_HeaderHovered, + ImGuiCol_HeaderActive, + ImGuiCol_Separator, + ImGuiCol_SeparatorHovered, + ImGuiCol_SeparatorActive, + ImGuiCol_ResizeGrip, + ImGuiCol_ResizeGripHovered, + ImGuiCol_ResizeGripActive, + ImGuiCol_TabHovered, + ImGuiCol_Tab, + ImGuiCol_TabSelected, + ImGuiCol_TabSelectedOverline, + ImGuiCol_TabDimmed, + ImGuiCol_TabDimmedSelected, + ImGuiCol_TextLink, + ImGuiCol_TextSelectedBg, + ImGuiCol_NavCursor + }; + for (const int target_color : target_colors) { + ImVec4 &color = style.Colors[target_color]; + color = blend_with_primary(color); + } } diff --git a/launcher/src/ui/frame.h b/launcher/src/ui/frame.h index 0a60420c2b..a2dbcfa1bb 100644 --- a/launcher/src/ui/frame.h +++ b/launcher/src/ui/frame.h @@ -19,4 +19,5 @@ private: // Internal float get_scale(); void setup_style(float scale); + static ImVec4 blend_with_primary(const ImVec4 &color); }; \ No newline at end of file