Skip to content

Commit

Permalink
Merge pull request #77863 from dinoplane/alien-color-changes
Browse files Browse the repository at this point in the history
Use cached hue for color picker when saturation is 0
  • Loading branch information
akien-mga committed Jun 12, 2023
2 parents 26e5a98 + a374c7d commit bcbc2fb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
13 changes: 10 additions & 3 deletions scene/gui/color_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions scene/gui/color_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions scene/gui/color_picker.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class ColorPicker : public VBoxContainer {
float h = 0.0;
float s = 0.0;
float v = 0.0;
float cached_hue = 0.0;
Color last_color;

struct ThemeCache {
Expand Down Expand Up @@ -294,6 +295,7 @@ class ColorPicker : public VBoxContainer {
#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<float> get_active_slider_values();
Expand Down

0 comments on commit bcbc2fb

Please sign in to comment.