From 6e1b451a9c6092c3ca1bb8b8ae9b117c98ed7a27 Mon Sep 17 00:00:00 2001 From: Zachary Hall Date: Sun, 4 Jun 2023 03:39:28 -0700 Subject: [PATCH] Prepare for moving hue preference code to themes --- main.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/main.cpp b/main.cpp index 1ea89f4..d05bae4 100644 --- a/main.cpp +++ b/main.cpp @@ -29,6 +29,9 @@ using namespace std::numbers; static float accent_color = 280.0; float GetHue(ImVec4 rgba){ float r = rgba.x, g = rgba.y, b = rgba.z; + if (r == g && g == b) { + return -1.0; + } float hue; if ((r >= g) && (g >= b)) { hue = 60.0 * (g-b)/(r-b); @@ -47,11 +50,15 @@ float GetHue(ImVec4 rgba){ } return hue; } -void change_accent_color(ImGuiCol color, float hue) { - ImGuiStyle& style = ImGui::GetStyle(); - ImVec4 in = style.Colors[color]; +void change_accent_color(ImVec4 &color, float hue) { + //ImGuiStyle& style = ImGui::GetStyle(); + //ImVec4 in = style.Colors[color]; + ImVec4 in = color; float Target = hue; float Current = GetHue(in); + if (Current < 0.0f) { + return; + } float H = 360-Target+Current; // TODO: Figure out why these magic numbers are necessary. //printf("Cur: %f, Target: %f, Diff: %f", Current, Target, H); float U = cos(H*pi/180.0); @@ -67,7 +74,7 @@ void change_accent_color(ImGuiCol color, float hue) { + (.587-.588*U-1.05*W)*in.y + (.114+.886*U-.203*W)*in.z; //printf(", Actual: %f\n", GetHue(out)); - style.Colors[color] = out; + color = out; } void UpdateStyle(bool dark) { @@ -75,7 +82,7 @@ void UpdateStyle(bool dark) { ImGui::StyleColorsDark(); } else { ImGui::StyleColorsLight(); - } + }/* ImGuiCol colors[] = { ImGuiCol_FrameBgHovered, ImGuiCol_FrameBgActive, @@ -106,15 +113,15 @@ void UpdateStyle(bool dark) { ImGuiCol_FrameBg, ImGuiCol_TitleBgActive, ImGuiCol_ResizeGrip, - }; - for (auto color : colors) { + };*/ + for (auto& color : ImGui::GetStyle().Colors) { change_accent_color(color, accent_color); - } + }/* if (dark) { for (auto color : colors_dark) { change_accent_color(color, accent_color); } - } + }*/ } // Main code int main(int, char**)