summaryrefslogtreecommitdiffstats
path: root/scene/gui
diff options
context:
space:
mode:
authorajreckof <tbonhoure@ymail.Com>2023-09-19 10:47:46 +0200
committerajreckof <tbonhoure@ymail.Com>2023-10-13 14:35:47 +0200
commit3160add2b0b030ae5b8ae0ad3c3b55d4367f2455 (patch)
treee19a8bd5e6d56fd41fe1c4839085bd67afb5ba74 /scene/gui
parent571cd0eb791b37e9a8adda9f909251138170f6b7 (diff)
downloadredot-engine-3160add2b0b030ae5b8ae0ad3c3b55d4367f2455.tar.gz
Fix ColorPicker deferred mode not working for sliders.
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/color_picker.cpp25
-rw-r--r--scene/gui/color_picker.h5
-rw-r--r--scene/gui/range.h1
-rw-r--r--scene/gui/slider.cpp3
4 files changed, 26 insertions, 8 deletions
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index 5ec0714b64..c2512bed66 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -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;
}
@@ -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) {
@@ -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));
@@ -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);
@@ -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);
@@ -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);
@@ -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);
diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h
index 96dbca9a0c..dc547c8b0c 100644
--- a/scene/gui/color_picker.h
+++ b/scene/gui/color_picker.h
@@ -207,6 +207,7 @@ private:
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;
@@ -254,7 +255,9 @@ private:
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();
diff --git a/scene/gui/range.h b/scene/gui/range.h
index 9b4f0707e6..b1c2446ded 100644
--- a/scene/gui/range.h
+++ b/scene/gui/range.h
@@ -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();
diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp
index b1a2f8017e..8bb8eb1d30 100644
--- a/scene/gui/slider.cpp
+++ b/scene/gui/slider.cpp
@@ -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;