From b002bdff39bbacfa5932937d5c6d79719b50dd44 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Sun, 24 Sep 2023 10:57:50 +0200 Subject: [PATCH] ui: color chooser for crosshair was changing on its own Only change color when needed and use rounding when converting back to integer. Issue #1074 --- core/rend/gui.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/core/rend/gui.cpp b/core/rend/gui.cpp index 4be8d0bcf..0a48ea75f 100644 --- a/core/rend/gui.cpp +++ b/core/rend/gui.cpp @@ -1770,23 +1770,25 @@ static void gui_display_settings() ((color >> 16) & 0xff) / 255.f, ((color >> 24) & 0xff) / 255.f }; - ImGui::ColorEdit4("Crosshair color", xhairColor, ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_AlphaPreviewHalf + bool colorChanged = ImGui::ColorEdit4("Crosshair color", xhairColor, ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_AlphaPreviewHalf | ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoTooltip | ImGuiColorEditFlags_NoLabel); ImGui::SameLine(); bool enabled = color != 0; - ImGui::Checkbox("Crosshair", &enabled); - if (enabled) + if (ImGui::Checkbox("Crosshair", &enabled) || colorChanged) { - config::CrosshairColor[bus] = (u8)(xhairColor[0] * 255.f) - | ((u8)(xhairColor[1] * 255.f) << 8) - | ((u8)(xhairColor[2] * 255.f) << 16) - | ((u8)(xhairColor[3] * 255.f) << 24); - if (config::CrosshairColor[bus] == 0) - config::CrosshairColor[bus] = 0xC0FFFFFF; - } - else - { - config::CrosshairColor[bus] = 0; + if (enabled) + { + config::CrosshairColor[bus] = (u8)(std::round(xhairColor[0] * 255.f)) + | ((u8)(std::round(xhairColor[1] * 255.f)) << 8) + | ((u8)(std::round(xhairColor[2] * 255.f)) << 16) + | ((u8)(std::round(xhairColor[3] * 255.f)) << 24); + if (config::CrosshairColor[bus] == 0) + config::CrosshairColor[bus] = 0xC0FFFFFF; + } + else + { + config::CrosshairColor[bus] = 0; + } } ImGui::PopID(); }