Prepare for moving hue preference code to themes

This commit is contained in:
Zachary Hall 2023-06-04 03:39:28 -07:00
parent f2c794d362
commit 6e1b451a9c

View file

@ -29,6 +29,9 @@ using namespace std::numbers;
static float accent_color = 280.0; static float accent_color = 280.0;
float GetHue(ImVec4 rgba){ float GetHue(ImVec4 rgba){
float r = rgba.x, g = rgba.y, b = rgba.z; float r = rgba.x, g = rgba.y, b = rgba.z;
if (r == g && g == b) {
return -1.0;
}
float hue; float hue;
if ((r >= g) && (g >= b)) { if ((r >= g) && (g >= b)) {
hue = 60.0 * (g-b)/(r-b); hue = 60.0 * (g-b)/(r-b);
@ -47,11 +50,15 @@ float GetHue(ImVec4 rgba){
} }
return hue; return hue;
} }
void change_accent_color(ImGuiCol color, float hue) { void change_accent_color(ImVec4 &color, float hue) {
ImGuiStyle& style = ImGui::GetStyle(); //ImGuiStyle& style = ImGui::GetStyle();
ImVec4 in = style.Colors[color]; //ImVec4 in = style.Colors[color];
ImVec4 in = color;
float Target = hue; float Target = hue;
float Current = GetHue(in); float Current = GetHue(in);
if (Current < 0.0f) {
return;
}
float H = 360-Target+Current; // TODO: Figure out why these magic numbers are necessary. float H = 360-Target+Current; // TODO: Figure out why these magic numbers are necessary.
//printf("Cur: %f, Target: %f, Diff: %f", Current, Target, H); //printf("Cur: %f, Target: %f, Diff: %f", Current, Target, H);
float U = cos(H*pi/180.0); 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 + (.587-.588*U-1.05*W)*in.y
+ (.114+.886*U-.203*W)*in.z; + (.114+.886*U-.203*W)*in.z;
//printf(", Actual: %f\n", GetHue(out)); //printf(", Actual: %f\n", GetHue(out));
style.Colors[color] = out; color = out;
} }
void UpdateStyle(bool dark) { void UpdateStyle(bool dark) {
@ -75,7 +82,7 @@ void UpdateStyle(bool dark) {
ImGui::StyleColorsDark(); ImGui::StyleColorsDark();
} else { } else {
ImGui::StyleColorsLight(); ImGui::StyleColorsLight();
} }/*
ImGuiCol colors[] = { ImGuiCol colors[] = {
ImGuiCol_FrameBgHovered, ImGuiCol_FrameBgHovered,
ImGuiCol_FrameBgActive, ImGuiCol_FrameBgActive,
@ -106,15 +113,15 @@ void UpdateStyle(bool dark) {
ImGuiCol_FrameBg, ImGuiCol_FrameBg,
ImGuiCol_TitleBgActive, ImGuiCol_TitleBgActive,
ImGuiCol_ResizeGrip, ImGuiCol_ResizeGrip,
}; };*/
for (auto color : colors) { for (auto& color : ImGui::GetStyle().Colors) {
change_accent_color(color, accent_color); change_accent_color(color, accent_color);
} }/*
if (dark) { if (dark) {
for (auto color : colors_dark) { for (auto color : colors_dark) {
change_accent_color(color, accent_color); change_accent_color(color, accent_color);
} }
} }*/
} }
// Main code // Main code
int main(int, char**) int main(int, char**)