From c457c343d813f8737b749a947876ae73659c993b Mon Sep 17 00:00:00 2001 From: Pijus Zacharka Date: Fri, 6 Mar 2026 11:31:48 +0200 Subject: [PATCH 1/4] Add a setter and getter for the intensity value of ColorPicker. --- doc/classes/ColorPicker.xml | 3 +++ scene/gui/color_picker.cpp | 11 +++++++++++ scene/gui/color_picker.h | 3 +++ 3 files changed, 17 insertions(+) diff --git a/doc/classes/ColorPicker.xml b/doc/classes/ColorPicker.xml index 771e576586d..5c9d4d1c4ed 100644 --- a/doc/classes/ColorPicker.xml +++ b/doc/classes/ColorPicker.xml @@ -82,6 +82,9 @@ If [code]true[/code], the hex color code input field is visible. + + The currently selected intensity. + The currently stored old color. See also [member display_old_color]. diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 89fe9d88cc1..ccaab67b072 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -373,6 +373,14 @@ void ColorPicker::set_focus_on_picker_shape() { shapes[get_current_shape_index()]->grab_focus(); } +void ColorPicker::set_intensity(float p_intensity) { + intensity_slider->set_value(p_intensity); +} + +float ColorPicker::get_intensity() { + return intensity; +} + void ColorPicker::_update_controls() { int mode_sliders_count = modes[current_mode]->get_slider_count(); @@ -2083,6 +2091,8 @@ void ColorPicker::_bind_methods() { ClassDB::bind_method(D_METHOD("get_recent_presets"), &ColorPicker::get_recent_presets); ClassDB::bind_method(D_METHOD("set_picker_shape", "shape"), &ColorPicker::set_picker_shape); ClassDB::bind_method(D_METHOD("get_picker_shape"), &ColorPicker::get_picker_shape); + ClassDB::bind_method(D_METHOD("set_intensity"), &ColorPicker::set_intensity); + ClassDB::bind_method(D_METHOD("get_intensity"), &ColorPicker::get_intensity); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_pick_color", "get_pick_color"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "old_color"), "set_old_color", "get_old_color"); @@ -2099,6 +2109,7 @@ void ColorPicker::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sliders_visible"), "set_sliders_visible", "are_sliders_visible"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hex_visible"), "set_hex_visible", "is_hex_visible"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "presets_visible"), "set_presets_visible", "are_presets_visible"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "intensity"), "set_intensity", "get_intensity"); ADD_SIGNAL(MethodInfo("color_changed", PropertyInfo(Variant::COLOR, "color"))); ADD_SIGNAL(MethodInfo("preset_added", PropertyInfo(Variant::COLOR, "color"))); diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index da291019109..663d3736e4c 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -504,6 +504,9 @@ class ColorPicker : public VBoxContainer { void set_focus_on_line_edit(); void set_focus_on_picker_shape(); + void set_intensity(float intensity); + float get_intensity(); + ColorPicker(); ~ColorPicker(); }; From 67258044d126b8a338f4949dbdb3f928834fc942 Mon Sep 17 00:00:00 2001 From: Pijus Zacharka Date: Sat, 7 Mar 2026 16:44:52 +0200 Subject: [PATCH 2/4] add paramater name to set_inensity, change set_intensity not to depend on the slider UI element. --- scene/gui/color_picker.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index ccaab67b072..9c5445994a6 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -374,7 +374,9 @@ void ColorPicker::set_focus_on_picker_shape() { } void ColorPicker::set_intensity(float p_intensity) { - intensity_slider->set_value(p_intensity); + intensity = p_intensity; + _normalized_apply_intensity_to_color(); + _update_color(); } float ColorPicker::get_intensity() { @@ -2091,7 +2093,7 @@ void ColorPicker::_bind_methods() { ClassDB::bind_method(D_METHOD("get_recent_presets"), &ColorPicker::get_recent_presets); ClassDB::bind_method(D_METHOD("set_picker_shape", "shape"), &ColorPicker::set_picker_shape); ClassDB::bind_method(D_METHOD("get_picker_shape"), &ColorPicker::get_picker_shape); - ClassDB::bind_method(D_METHOD("set_intensity"), &ColorPicker::set_intensity); + ClassDB::bind_method(D_METHOD("set_intensity", "intensity"), &ColorPicker::set_intensity); ClassDB::bind_method(D_METHOD("get_intensity"), &ColorPicker::get_intensity); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_pick_color", "get_pick_color"); From 06ea4e3ddf1e394aff6d7a6d6a136e5a0ba0b947 Mon Sep 17 00:00:00 2001 From: Pijus Zacharka Date: Sat, 7 Mar 2026 19:55:04 +0200 Subject: [PATCH 3/4] Fix property being set to int instead of float --- scene/gui/color_picker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 9c5445994a6..50b3bd1f5d8 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -2111,7 +2111,7 @@ void ColorPicker::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sliders_visible"), "set_sliders_visible", "are_sliders_visible"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hex_visible"), "set_hex_visible", "is_hex_visible"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "presets_visible"), "set_presets_visible", "are_presets_visible"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "intensity"), "set_intensity", "get_intensity"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "intensity"), "set_intensity", "get_intensity"); ADD_SIGNAL(MethodInfo("color_changed", PropertyInfo(Variant::COLOR, "color"))); ADD_SIGNAL(MethodInfo("preset_added", PropertyInfo(Variant::COLOR, "color"))); From 7225b5faa1c8dadb8f9b57a7d7163207269306fa Mon Sep 17 00:00:00 2001 From: Pijus Zacharka Date: Wed, 11 Mar 2026 13:28:36 +0200 Subject: [PATCH 4/4] changed set_intensity to clamp the parameter to the intensity slider's min and max bounds, reflect that in the docs. --- doc/classes/ColorPicker.xml | 1 + scene/gui/color_picker.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/doc/classes/ColorPicker.xml b/doc/classes/ColorPicker.xml index 5c9d4d1c4ed..f86bab9595d 100644 --- a/doc/classes/ColorPicker.xml +++ b/doc/classes/ColorPicker.xml @@ -84,6 +84,7 @@ The currently selected intensity. + Note: [code]set_intensity[/code] clamps the value in the range [code][-10.0, 10.0][/code] The currently stored old color. See also [member display_old_color]. diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 50b3bd1f5d8..6e9872c7eee 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -34,6 +34,7 @@ #include "core/io/image.h" #include "core/math/expression.h" +#include "core/math/math_funcs.h" #include "scene/gui/color_mode.h" #include "scene/gui/color_picker_shape.h" #include "scene/gui/file_dialog.h" @@ -374,6 +375,11 @@ void ColorPicker::set_focus_on_picker_shape() { } void ColorPicker::set_intensity(float p_intensity) { + p_intensity = CLAMP(p_intensity, this->intensity_slider->get_min(), this->intensity_slider->get_max()); + if (Math::is_equal_approx(intensity, p_intensity)) { + return; + } + intensity = p_intensity; _normalized_apply_intensity_to_color(); _update_color();