Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cached hue for color picker when saturation is 0 #77863

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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