Skip to content
Open
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
4 changes: 4 additions & 0 deletions doc/classes/ColorPicker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
<member name="hex_visible" type="bool" setter="set_hex_visible" getter="is_hex_visible" default="true">
If [code]true[/code], the hex color code input field is visible.
</member>
<member name="intensity" type="float" setter="set_intensity" getter="get_intensity" default="0.0">
The currently selected intensity.
Note: [code]set_intensity[/code] clamps the value in the range [code][-10.0, 10.0][/code]
</member>
<member name="old_color" type="Color" setter="set_old_color" getter="get_old_color" default="Color(0, 0, 0, 1)">
The currently stored old color. See also [member display_old_color].
</member>
Expand Down
19 changes: 19 additions & 0 deletions scene/gui/color_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -373,6 +374,21 @@ void ColorPicker::set_focus_on_picker_shape() {
shapes[get_current_shape_index()]->grab_focus();
}

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();
}
Comment thread
Arctis-Fireblight marked this conversation as resolved.

float ColorPicker::get_intensity() {
return intensity;
}

void ColorPicker::_update_controls() {
int mode_sliders_count = modes[current_mode]->get_slider_count();

Expand Down Expand Up @@ -2083,6 +2099,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", "intensity"), &ColorPicker::set_intensity);
ClassDB::bind_method(D_METHOD("get_intensity"), &ColorPicker::get_intensity);
Comment on lines +2102 to +2103
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Please update the API test expectations for the new bindings.

This adds new script-visible methods, and the PR context already notes unit tests are failing. The corresponding API/unit test baseline needs to be updated alongside these bindings.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scene/gui/color_picker.cpp` around lines 2096 - 2097, The new bindings add
script-visible methods ColorPicker::set_intensity and
ColorPicker::get_intensity, so update the API/unit test baseline that enumerates
ColorPicker methods to include these two entries; locate the test that asserts
the class method list or the bindings snapshot for ColorPicker and add
expectations for "set_intensity" and "get_intensity" (or regenerate the baseline
snapshot) so the unit tests reflect the new API surface.


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");
Expand All @@ -2099,6 +2117,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::FLOAT, "intensity"), "set_intensity", "get_intensity");

ADD_SIGNAL(MethodInfo("color_changed", PropertyInfo(Variant::COLOR, "color")));
ADD_SIGNAL(MethodInfo("preset_added", PropertyInfo(Variant::COLOR, "color")));
Expand Down
3 changes: 3 additions & 0 deletions scene/gui/color_picker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down
Loading