From a374c7d519fa2961190c2d49170e4300e5995ecc Mon Sep 17 00:00:00 2001 From: dinoplane Date: Sun, 4 Jun 2023 18:22:24 -0700 Subject: [PATCH] Use cached hue for color picker when saturation is 0 Fixes #76968. --- scene/gui/color_mode.cpp | 13 ++++++++++--- scene/gui/color_picker.cpp | 6 ++++++ scene/gui/color_picker.h | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/scene/gui/color_mode.cpp b/scene/gui/color_mode.cpp index 123938f964e..e95b2b9107e 100644 --- a/scene/gui/color_mode.cpp +++ b/scene/gui/color_mode.cpp @@ -117,8 +117,13 @@ float ColorModeHSV::get_slider_max(int idx) const { float ColorModeHSV::get_slider_value(int idx) const { switch (idx) { - case 0: - return color_picker->get_pick_color().get_h() * 360.0; + case 0: { + if (color_picker->get_pick_color().get_s() > 0) { + return color_picker->get_pick_color().get_h() * 360.0; + } else { + return color_picker->get_cached_hue(); + } + } case 1: return color_picker->get_pick_color().get_s() * 100.0; case 2: @@ -165,7 +170,9 @@ void ColorModeHSV::slider_draw(int p_which) { Color v_col; s_col.set_hsv(color.get_h(), 0, color.get_v()); left_color = (p_which == 1) ? s_col : Color(0, 0, 0); - s_col.set_hsv(color.get_h(), 1, color.get_v()); + + float s_col_hue = (color.get_s() == 0.0) ? color_picker->get_cached_hue() / 360.0 : color.get_h(); + s_col.set_hsv(s_col_hue, 1, color.get_v()); v_col.set_hsv(color.get_h(), color.get_s(), 1); right_color = (p_which == 1) ? s_col : v_col; } diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 2a037864717..768502c6587 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -376,6 +376,12 @@ void ColorPicker::_value_changed(double) { color = modes[current_mode]->get_color(); + if (current_mode == MODE_HSV) { + if (sliders[1]->get_value() > 0 || sliders[0]->get_value() != cached_hue) { + cached_hue = sliders[0]->get_value(); + } + } + if (current_mode == MODE_HSV || current_mode == MODE_OKHSL) { h = sliders[0]->get_value() / 360.0; s = sliders[1]->get_value() / 100.0; diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index 711a3716886..bc7eadf2231 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -204,6 +204,7 @@ private: float h = 0.0; float s = 0.0; float v = 0.0; + float cached_hue = 0.0; Color last_color; struct ThemeCache { @@ -294,6 +295,7 @@ public: #ifdef TOOLS_ENABLED void set_editor_settings(Object *p_editor_settings); #endif + float get_cached_hue() { return cached_hue; }; HSlider *get_slider(int idx); Vector get_active_slider_values();