@@ -139,10 +139,10 @@ void ColorPicker::_notification(int p_what) {
139139 }
140140
141141 if (current_shape != SHAPE_NONE) {
142- btn_shape->set_button_icon (shape_popup->get_item_icon (current_shape ));
142+ btn_shape->set_button_icon (shape_popup->get_item_icon (get_current_shape_index () ));
143143 }
144144
145- for (int i = 0 ; i < SLIDER_COUNT ; i++) {
145+ for (int i = 0 ; i < MODE_SLIDER_COUNT ; i++) {
146146 labels[i]->set_custom_minimum_size (Size2 (theme_cache.label_width , 0 ));
147147 sliders[i]->add_theme_constant_override (SNAME (" center_grabber" ), theme_cache.center_slider_grabbers );
148148 }
@@ -185,7 +185,7 @@ void ColorPicker::_notification(int p_what) {
185185 case NOTIFICATION_FOCUS_ENTER:
186186 case NOTIFICATION_FOCUS_EXIT: {
187187 if (current_shape != SHAPE_NONE) {
188- shapes[current_shape ]->cursor_editing = false ;
188+ shapes[get_current_shape_index () ]->cursor_editing = false ;
189189 }
190190 } break ;
191191
@@ -198,7 +198,7 @@ void ColorPicker::_notification(int p_what) {
198198 input->is_action_just_released (" ui_down" )) {
199199 gamepad_event_delay_ms = DEFAULT_GAMEPAD_EVENT_DELAY_MS;
200200 if (current_shape == SHAPE_NONE) {
201- shapes[current_shape ]->echo_multiplier = 1 ;
201+ shapes[get_current_shape_index () ]->echo_multiplier = 1 ;
202202 }
203203 accept_event ();
204204 set_process_internal (false );
@@ -217,7 +217,7 @@ void ColorPicker::_notification(int p_what) {
217217 input->is_action_pressed (" ui_right" ) - input->is_action_pressed (" ui_left" ),
218218 input->is_action_pressed (" ui_down" ) - input->is_action_pressed (" ui_up" ));
219219
220- shapes[current_shape ]->update_cursor (color_change_vector, true );
220+ shapes[get_current_shape_index () ]->update_cursor (color_change_vector, true );
221221 accept_event ();
222222 }
223223 return ;
@@ -309,7 +309,7 @@ void fragment() {
309309
310310 circle_ok_color_shader.instantiate ();
311311 circle_ok_color_shader->set_code (OK_COLOR_SHADER + R"(
312- // ColorPicker ok color hsv circle shader.
312+ // ColorPicker ok color hsl circle shader.
313313
314314uniform float ok_hsl_l = 1.0;
315315
@@ -330,20 +330,48 @@ void fragment() {
330330 float b4 = float(sqrt(x * x + y * y) < 0.5);
331331 COLOR = vec4(col, (b + b2 + b3 + b4) / 4.00);
332332})" );
333+
334+ rectangle_ok_color_hs_shader.instantiate ();
335+ rectangle_ok_color_hs_shader->set_code (OK_COLOR_SHADER + R"(
336+ // ColorPicker ok color hs rectangle shader.
337+
338+ uniform float ok_hsl_l = 0.0;
339+
340+ void fragment() {
341+ float h = UV.x;
342+ float s = 1.0 - UV.y;
343+ vec3 col = okhsl_to_srgb(vec3(h, s, ok_hsl_l));
344+ COLOR = vec4(col, 1.0);
345+ })" );
346+
347+ rectangle_ok_color_hl_shader.instantiate ();
348+ rectangle_ok_color_hl_shader->set_code (OK_COLOR_SHADER + R"(
349+ // ColorPicker ok color hl rectangle shader.
350+
351+ uniform float ok_hsl_s = 0.0;
352+
353+ void fragment() {
354+ float h = UV.x;
355+ float l = 1.0 - UV.y;
356+ vec3 col = okhsl_to_srgb(vec3(h, ok_hsl_s, l));
357+ COLOR = vec4(col, 1.0);
358+ })" );
333359}
334360
335361void ColorPicker::finish_shaders () {
336362 wheel_shader.unref ();
337363 circle_shader.unref ();
338364 circle_ok_color_shader.unref ();
365+ rectangle_ok_color_hs_shader.unref ();
366+ rectangle_ok_color_hl_shader.unref ();
339367}
340368
341369void ColorPicker::set_focus_on_line_edit () {
342370 callable_mp ((Control *)c_text, &Control::grab_focus).call_deferred ();
343371}
344372
345373void ColorPicker::set_focus_on_picker_shape () {
346- shapes[current_shape ]->grab_focus ();
374+ shapes[get_current_shape_index () ]->grab_focus ();
347375}
348376
349377void ColorPicker::_update_controls () {
@@ -384,7 +412,7 @@ void ColorPicker::_update_controls() {
384412
385413 int i = 0 ;
386414 for (ColorPickerShape *shape : shapes) {
387- bool is_active = current_shape == i;
415+ bool is_active = get_current_shape_index () == i;
388416 i++;
389417
390418 if (!shape->is_initialized ) {
@@ -552,14 +580,14 @@ void ColorPicker::create_slider(GridContainer *gc, int idx) {
552580 slider->connect (" drag_started" , callable_mp (this , &ColorPicker::_slider_drag_started));
553581 slider->connect (SceneStringName (value_changed), callable_mp (this , &ColorPicker::_slider_value_changed).unbind (1 ));
554582 slider->connect (" drag_ended" , callable_mp (this , &ColorPicker::_slider_drag_ended).unbind (1 ));
555- if (idx < SLIDER_COUNT ) {
583+ if (idx < MODE_SLIDER_COUNT ) {
556584 slider->connect (SceneStringName (draw), callable_mp (this , &ColorPicker::_slider_draw).bind (idx));
557585 } else if (idx == SLIDER_ALPHA) {
558586 slider->connect (SceneStringName (draw), callable_mp (this , &ColorPicker::_alpha_slider_draw));
559587 }
560588 slider->connect (SceneStringName (gui_input), callable_mp (this , &ColorPicker::_slider_or_spin_input));
561589
562- if (idx < SLIDER_COUNT ) {
590+ if (idx < MODE_SLIDER_COUNT ) {
563591 sliders[idx] = slider;
564592 values[idx] = val;
565593 labels[idx] = lbl;
@@ -618,10 +646,8 @@ void ColorPicker::set_palette_saved_callback(const Callable &p_palette_saved) {
618646#endif
619647
620648HSlider *ColorPicker::get_slider (int p_idx) {
621- if (p_idx < SLIDER_COUNT) {
622- return sliders[p_idx];
623- }
624- return alpha_slider;
649+ ERR_FAIL_INDEX_V (p_idx, MODE_MAX, nullptr );
650+ return sliders[p_idx];
625651}
626652
627653Vector<float > ColorPicker::get_active_slider_values () {
@@ -649,7 +675,7 @@ void ColorPicker::_copy_normalized_to_hsv_okhsl() {
649675}
650676
651677void ColorPicker::_copy_hsv_okhsl_to_normalized () {
652- if (current_shape != SHAPE_NONE && shapes[current_shape ]->is_ok_hsl ()) {
678+ if (current_shape != SHAPE_NONE && shapes[get_current_shape_index () ]->is_ok_hsl ()) {
653679 color_normalized.set_ok_hsl (ok_hsl_h, ok_hsl_s, ok_hsl_l, color_normalized.a );
654680 } else {
655681 color_normalized.set_hsv (h, s, v, color_normalized.a );
@@ -712,7 +738,7 @@ void ColorPicker::_reset_sliders_theme() {
712738 style_box_flat->set_content_margin (SIDE_TOP, 16 * theme_cache.base_scale );
713739 style_box_flat->set_bg_color (Color (0.2 , 0.23 , 0.31 ).lerp (Color (0 , 0 , 0 , 1 ), 0.3 ).clamp ());
714740
715- for (int i = 0 ; i < SLIDER_COUNT ; i++) {
741+ for (int i = 0 ; i < MODE_SLIDER_COUNT ; i++) {
716742 sliders[i]->begin_bulk_theme_override ();
717743 sliders[i]->add_theme_icon_override (SNAME (" grabber" ), theme_cache.bar_arrow );
718744 sliders[i]->add_theme_icon_override (SNAME (" grabber_highlight" ), theme_cache.bar_arrow );
@@ -815,7 +841,7 @@ void ColorPicker::_update_color(bool p_update_sliders) {
815841 _update_text_value ();
816842
817843 if (current_shape != SHAPE_NONE) {
818- for (Control *control : shapes[current_shape ]->controls ) {
844+ for (Control *control : shapes[get_current_shape_index () ]->controls ) {
819845 control->queue_redraw ();
820846 }
821847 }
@@ -931,11 +957,11 @@ void ColorPicker::set_picker_shape(PickerShapeType p_shape) {
931957 return ;
932958 }
933959 if (current_shape != SHAPE_NONE) {
934- shape_popup->set_item_checked (current_shape , false );
960+ shape_popup->set_item_checked (get_current_shape_index () , false );
935961 }
936962 if (p_shape != SHAPE_NONE) {
937- shape_popup->set_item_checked (p_shape, true );
938- btn_shape->set_button_icon (shape_popup->get_item_icon (p_shape));
963+ shape_popup->set_item_checked (shape_to_index ( p_shape) , true );
964+ btn_shape->set_button_icon (shape_popup->get_item_icon (shape_to_index ( p_shape) ));
939965 }
940966
941967 current_shape = p_shape;
@@ -1018,6 +1044,11 @@ void ColorPicker::_quick_open_palette_file_selected(const String &p_path) {
10181044 file_dialog->set_file_mode (FileDialog::FILE_MODE_OPEN_FILE);
10191045 _palette_file_selected (p_path);
10201046}
1047+
1048+ GridContainer *ColorPicker::get_slider_container () {
1049+ return slider_gc;
1050+ }
1051+
10211052#endif // ifdef TOOLS_ENABLED
10221053
10231054void ColorPicker::_palette_file_selected (const String &p_path) {
@@ -1344,7 +1375,7 @@ void ColorPicker::set_colorize_sliders(bool p_colorize_sliders) {
13441375 if (colorize_sliders) {
13451376 Ref<StyleBoxEmpty> style_box_empty (memnew (StyleBoxEmpty));
13461377
1347- for (int i = 0 ; i < SLIDER_COUNT ; i++) {
1378+ for (int i = 0 ; i < MODE_SLIDER_COUNT ; i++) {
13481379 sliders[i]->add_theme_style_override (" slider" , style_box_empty);
13491380 }
13501381
@@ -1354,7 +1385,7 @@ void ColorPicker::set_colorize_sliders(bool p_colorize_sliders) {
13541385 style_box_flat->set_content_margin (SIDE_TOP, 16 * theme_cache.base_scale );
13551386 style_box_flat->set_bg_color (Color (0.2 , 0.23 , 0.31 ).lerp (Color (0 , 0 , 0 , 1 ), 0.3 ).clamp ());
13561387
1357- for (int i = 0 ; i < SLIDER_COUNT ; i++) {
1388+ for (int i = 0 ; i < MODE_SLIDER_COUNT ; i++) {
13581389 sliders[i]->add_theme_style_override (" slider" , style_box_flat);
13591390 }
13601391
@@ -2051,7 +2082,7 @@ void ColorPicker::_bind_methods() {
20512082 ADD_PROPERTY (PropertyInfo (Variant::BOOL, " edit_intensity" ), " set_edit_intensity" , " is_editing_intensity" );
20522083 ADD_PROPERTY (PropertyInfo (Variant::INT, " color_mode" , PROPERTY_HINT_ENUM, " RGB,HSV,LINEAR,OKHSL" ), " set_color_mode" , " get_color_mode" );
20532084 ADD_PROPERTY (PropertyInfo (Variant::BOOL, " deferred_mode" ), " set_deferred_mode" , " is_deferred_mode" );
2054- ADD_PROPERTY (PropertyInfo (Variant::INT, " picker_shape" , PROPERTY_HINT_ENUM, " HSV Rectangle,HSV Rectangle Wheel,VHS Circle,OKHSL Circle,None" ), " set_picker_shape" , " get_picker_shape" );
2085+ ADD_PROPERTY (PropertyInfo (Variant::INT, " picker_shape" , PROPERTY_HINT_ENUM, " HSV Rectangle,HSV Rectangle Wheel,VHS Circle,OKHSL Circle,OK HS Rectangle:5,OK HL Rectangle, None:4 " ), " set_picker_shape" , " get_picker_shape" );
20552086 ADD_PROPERTY (PropertyInfo (Variant::BOOL, " can_add_swatches" ), " set_can_add_swatches" , " are_swatches_enabled" );
20562087 ADD_GROUP (" Customization" , " " );
20572088 ADD_PROPERTY (PropertyInfo (Variant::BOOL, " sampler_visible" ), " set_sampler_visible" , " is_sampler_visible" );
@@ -2077,6 +2108,8 @@ void ColorPicker::_bind_methods() {
20772108 BIND_ENUM_CONSTANT (SHAPE_VHS_CIRCLE);
20782109 BIND_ENUM_CONSTANT (SHAPE_OKHSL_CIRCLE);
20792110 BIND_ENUM_CONSTANT (SHAPE_NONE);
2111+ BIND_ENUM_CONSTANT (SHAPE_OK_HS_RECTANGLE);
2112+ BIND_ENUM_CONSTANT (SHAPE_OK_HL_RECTANGLE);
20802113
20812114 BIND_THEME_ITEM_CUSTOM (Theme::DATA_TYPE_CONSTANT, ColorPicker, content_margin, " margin" );
20822115 BIND_THEME_ITEM (Theme::DATA_TYPE_CONSTANT, ColorPicker, label_width);
@@ -2158,16 +2191,18 @@ ColorPicker::ColorPicker() {
21582191 add_shape (memnew (ColorPickerShapeWheel (this )));
21592192 add_shape (memnew (ColorPickerShapeVHSCircle (this )));
21602193 add_shape (memnew (ColorPickerShapeOKHSLCircle (this )));
2194+ add_shape (memnew (ColorPickerShapeOKHSRectangle (this )));
2195+ add_shape (memnew (ColorPickerShapeOKHLRectangle (this )));
21612196
21622197 shape_popup = btn_shape->get_popup ();
21632198 {
21642199 int i = 0 ;
21652200 for (const ColorPickerShape *shape : shapes) {
2166- shape_popup->add_radio_check_item (shape->get_name (), i );
2201+ shape_popup->add_radio_check_item (shape->get_name (), index_to_shape (i) );
21672202 i++;
21682203 }
21692204 }
2170- shape_popup->set_item_checked (current_shape , true );
2205+ shape_popup->set_item_checked (get_current_shape_index () , true );
21712206 shape_popup->connect (SceneStringName (id_pressed), callable_mp (this , &ColorPicker::set_picker_shape));
21722207 shape_popup->connect (" about_to_popup" , callable_mp (this , &ColorPicker::_block_input_on_popup_show));
21732208 shape_popup->connect (SNAME (" popup_hide" ), callable_mp (this , &ColorPicker::_enable_input_on_popup_hide));
0 commit comments