From 6b2fb2a325db980dd90a3fee00b8dd805f9cf4ed Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Sat, 26 Oct 2024 10:10:15 -0400 Subject: [PATCH] Add `wheel_picker_cursor` theme icon to `ColorPicker` Replaces `ColorPicker`'s HSV wheel hue indicator with `wheel_picker_icon` texture which by default is the same as `picker_cursor` --- doc/classes/ColorPicker.xml | 3 +++ editor/icons/WheelPickerCursor.svg | 1 + editor/themes/editor_theme_manager.cpp | 1 + scene/gui/color_picker.cpp | 14 ++++++-------- scene/gui/color_picker.h | 1 + scene/theme/default_theme.cpp | 1 + scene/theme/icons/color_picker_wheel_cursor.svg | 1 + 7 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 editor/icons/WheelPickerCursor.svg create mode 100644 scene/theme/icons/color_picker_wheel_cursor.svg diff --git a/doc/classes/ColorPicker.xml b/doc/classes/ColorPicker.xml index 51c5c732075..6f0adc10e03 100644 --- a/doc/classes/ColorPicker.xml +++ b/doc/classes/ColorPicker.xml @@ -207,5 +207,8 @@ The icon for rectangular wheel picker shapes. + + The image displayed over the color wheel (depending on the [member picker_shape] being [constant SHAPE_HSV_WHEEL]), marking the currently selected hue. + diff --git a/editor/icons/WheelPickerCursor.svg b/editor/icons/WheelPickerCursor.svg new file mode 100644 index 00000000000..2eaad3c1285 --- /dev/null +++ b/editor/icons/WheelPickerCursor.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/editor/themes/editor_theme_manager.cpp b/editor/themes/editor_theme_manager.cpp index 85b850b7f50..28e8f1affdf 100644 --- a/editor/themes/editor_theme_manager.cpp +++ b/editor/themes/editor_theme_manager.cpp @@ -1771,6 +1771,7 @@ void EditorThemeManager::_populate_standard_styles(const Ref &p_the p_theme->set_icon("overbright_indicator", "ColorPicker", p_theme->get_icon(SNAME("OverbrightIndicator"), EditorStringName(EditorIcons))); p_theme->set_icon("bar_arrow", "ColorPicker", p_theme->get_icon(SNAME("ColorPickerBarArrow"), EditorStringName(EditorIcons))); p_theme->set_icon("picker_cursor", "ColorPicker", p_theme->get_icon(SNAME("PickerCursor"), EditorStringName(EditorIcons))); + p_theme->set_icon("wheel_picker_cursor", "ColorPicker", p_theme->get_icon(SNAME("WheelPickerCursor"), EditorStringName(EditorIcons))); // ColorPickerButton. p_theme->set_icon("bg", "ColorPickerButton", p_theme->get_icon(SNAME("GuiMiniCheckerboard"), EditorStringName(EditorIcons))); diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index d9a116f94d3..ebe4872af7e 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -1217,14 +1217,11 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) { col.set_hsv(h, 1, 1); if (actual_shape == SHAPE_HSV_WHEEL) { - points.resize(4); - double h1 = h - (0.5 / 360); - double h2 = h + (0.5 / 360); - points.set(0, Point2(center.x + (center.x * Math::cos(h1 * Math_TAU)), center.y + (center.y * Math::sin(h1 * Math_TAU)))); - points.set(1, Point2(center.x + (center.x * Math::cos(h1 * Math_TAU) * 0.84), center.y + (center.y * Math::sin(h1 * Math_TAU) * 0.84))); - points.set(2, Point2(center.x + (center.x * Math::cos(h2 * Math_TAU)), center.y + (center.y * Math::sin(h2 * Math_TAU)))); - points.set(3, Point2(center.x + (center.x * Math::cos(h2 * Math_TAU) * 0.84), center.y + (center.y * Math::sin(h2 * Math_TAU) * 0.84))); - c->draw_multiline(points, col.inverted()); + const real_t near_wheel_radius_multiplier = 0.84; + const real_t wheel_radis_center_multipler = near_wheel_radius_multiplier + (1.0 - near_wheel_radius_multiplier) / 2; + real_t wheel_x = center.x + (center.x * Math::cos(h * Math_TAU) * wheel_radis_center_multipler) - (theme_cache.wheel_picker_cursor->get_width() / 2); + real_t wheel_y = center.y + (center.y * Math::sin(h * Math_TAU) * wheel_radis_center_multipler) - (theme_cache.wheel_picker_cursor->get_height() / 2); + c->draw_texture(theme_cache.wheel_picker_cursor, Point2(wheel_x, wheel_y)); } } else if (p_which == 1) { @@ -1819,6 +1816,7 @@ void ColorPicker::_bind_methods() { BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, sample_revert); BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, overbright_indicator); BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, picker_cursor); + BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, wheel_picker_cursor); BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, color_hue); BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, color_okhsl_hue); diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index a87467abc01..8ee1b9fb439 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -242,6 +242,7 @@ class ColorPicker : public VBoxContainer { Ref sample_revert; Ref overbright_indicator; Ref picker_cursor; + Ref wheel_picker_cursor; Ref color_hue; Ref color_okhsl_hue; diff --git a/scene/theme/default_theme.cpp b/scene/theme/default_theme.cpp index 7d404ece823..6db13985a5a 100644 --- a/scene/theme/default_theme.cpp +++ b/scene/theme/default_theme.cpp @@ -1040,6 +1040,7 @@ void fill_default_theme(Ref &theme, const Ref &default_font, const theme->set_icon("overbright_indicator", "ColorPicker", icons["color_picker_overbright"]); theme->set_icon("bar_arrow", "ColorPicker", icons["color_picker_bar_arrow"]); theme->set_icon("picker_cursor", "ColorPicker", icons["color_picker_cursor"]); + theme->set_icon("wheel_picker_cursor", "ColorPicker", icons["color_picker_wheel_cursor"]); { const int precision = 7; diff --git a/scene/theme/icons/color_picker_wheel_cursor.svg b/scene/theme/icons/color_picker_wheel_cursor.svg new file mode 100644 index 00000000000..2eaad3c1285 --- /dev/null +++ b/scene/theme/icons/color_picker_wheel_cursor.svg @@ -0,0 +1 @@ + \ No newline at end of file