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

Fix ColorPicker deferred mode not working for sliders. #80916

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
25 changes: 18 additions & 7 deletions scene/gui/color_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,11 @@ bool ColorPicker::is_editing_alpha() const {
return edit_alpha;
}

void ColorPicker::_value_changed(double) {
void ColorPicker::_slider_drag_started() {
currently_dragging = true;
}

void ColorPicker::_slider_value_changed() {
if (updating) {
return;
}
Expand All @@ -357,7 +361,16 @@ void ColorPicker::_value_changed(double) {
}

_set_pick_color(color, false);
emit_signal(SNAME("color_changed"), color);
if (!deferred_mode_enabled || !currently_dragging) {
emit_signal(SNAME("color_changed"), color);
}
}

void ColorPicker::_slider_drag_ended() {
currently_dragging = false;
if (deferred_mode_enabled) {
emit_signal(SNAME("color_changed"), color);
}
}

void ColorPicker::add_mode(ColorMode *p_mode) {
Expand Down Expand Up @@ -388,7 +401,9 @@ void ColorPicker::create_slider(GridContainer *gc, int idx) {

slider->set_h_size_flags(SIZE_EXPAND_FILL);

slider->connect("value_changed", callable_mp(this, &ColorPicker::_value_changed));
slider->connect("drag_started", callable_mp(this, &ColorPicker::_slider_drag_started));
slider->connect("value_changed", callable_mp(this, &ColorPicker::_slider_value_changed).unbind(1));
slider->connect("drag_ended", callable_mp(this, &ColorPicker::_slider_drag_ended).unbind(1));
slider->connect("draw", callable_mp(this, &ColorPicker::_slider_draw).bind(idx));
slider->connect("gui_input", callable_mp(this, &ColorPicker::_slider_or_spin_input));

Expand Down Expand Up @@ -1242,7 +1257,6 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event, Control *c) {
_copy_hsv_to_color();
last_color = color;
set_pick_color(color);
_update_color();

if (!deferred_mode_enabled) {
emit_signal(SNAME("color_changed"), color);
Expand Down Expand Up @@ -1293,7 +1307,6 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event, Control *c) {
_copy_hsv_to_color();
last_color = color;
set_pick_color(color);
_update_color();

if (!deferred_mode_enabled) {
emit_signal(SNAME("color_changed"), color);
Expand Down Expand Up @@ -1321,7 +1334,6 @@ void ColorPicker::_w_input(const Ref<InputEvent> &p_event) {
_copy_hsv_to_color();
last_color = color;
set_pick_color(color);
_update_color();

if (!bev->is_pressed() && bev->get_button_index() == MouseButton::LEFT) {
add_recent_preset(color);
Expand All @@ -1347,7 +1359,6 @@ void ColorPicker::_w_input(const Ref<InputEvent> &p_event) {
_copy_hsv_to_color();
last_color = color;
set_pick_color(color);
_update_color();

if (!deferred_mode_enabled) {
emit_signal(SNAME("color_changed"), color);
Expand Down
5 changes: 4 additions & 1 deletion scene/gui/color_picker.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class ColorPicker : public VBoxContainer {
bool hex_visible = true;
bool line_edit_mouse_release = false;
bool text_changed = false;
bool currently_dragging = false;

float h = 0.0;
float s = 0.0;
Expand Down Expand Up @@ -254,7 +255,9 @@ class ColorPicker : public VBoxContainer {
void create_slider(GridContainer *gc, int idx);
void _reset_sliders_theme();
void _html_submitted(const String &p_html);
void _value_changed(double);
void _slider_drag_started();
void _slider_value_changed();
void _slider_drag_ended();
void _update_controls();
void _update_color(bool p_update_sliders = true);
void _update_text_value();
Expand Down
1 change: 1 addition & 0 deletions scene/gui/range.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Range : public Control {

protected:
virtual void _value_changed(double p_value);
void _notify_shared_value_changed() { shared->emit_value_changed(); };

static void _bind_methods();

Expand Down
3 changes: 3 additions & 0 deletions scene/gui/slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,18 @@ void Slider::gui_input(const Ref<InputEvent> &p_event) {
double grab_width = (double)grabber->get_width();
double grab_height = (double)grabber->get_height();
double max = orientation == VERTICAL ? get_size().height - grab_height : get_size().width - grab_width;
set_block_signals(true);
if (orientation == VERTICAL) {
set_as_ratio(1 - (((double)grab.pos - (grab_height / 2.0)) / max));
} else {
set_as_ratio(((double)grab.pos - (grab_width / 2.0)) / max);
}
set_block_signals(false);
grab.active = true;
grab.uvalue = get_as_ratio();

emit_signal(SNAME("drag_started"));
_notify_shared_value_changed();
} else {
grab.active = false;

Expand Down
Loading