This commit is contained in:
TheBrokenRail 2024-11-21 03:16:11 -05:00
parent 4a91937b0a
commit 00f90afc2a
4 changed files with 72 additions and 0 deletions

View File

@ -14,6 +14,7 @@ add_executable(launcher
src/options/parser.cpp src/options/parser.cpp
src/main.cpp src/main.cpp
src/ui/frame.cpp src/ui/frame.cpp
src/ui/color.cpp
src/client/configuration.cpp src/client/configuration.cpp
src/client/cache.cpp src/client/cache.cpp
src/client/ui.cpp src/client/ui.cpp

35
launcher/src/ui/color.cpp Normal file
View File

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

View File

@ -86,4 +86,39 @@ void Frame::setup_style(const float scale) {
style.WindowBorderSize = 0; style.WindowBorderSize = 0;
ImGui::StyleColorsDark(&style); ImGui::StyleColorsDark(&style);
style.ScaleAllSizes(scale); 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);
}
} }

View File

@ -19,4 +19,5 @@ private:
// Internal // Internal
float get_scale(); float get_scale();
void setup_style(float scale); void setup_style(float scale);
static ImVec4 blend_with_primary(const ImVec4 &color);
}; };