diff --git a/doc/classes/ColorPicker.xml b/doc/classes/ColorPicker.xml index dfa8d7d8408..ce450f6786f 100644 --- a/doc/classes/ColorPicker.xml +++ b/doc/classes/ColorPicker.xml @@ -186,6 +186,9 @@ Background panel for the color preview box (visible when the color is translucent). + + The icon for the revert button (visible on the middle of the "old" color when it differs from the currently selected color). This icon is modulated with a dark color if the "old" color is bright enough, so the icon should be bright to ensure visibility in both scenarios. + The icon for the screen color picker button. diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 0dd787f0ea4..f78439d2e7a 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -2170,6 +2170,7 @@ Ref create_editor_theme(const Ref p_theme) { theme->set_icon("shape_rect_wheel", "ColorPicker", theme->get_icon(SNAME("PickerShapeRectangleWheel"), EditorStringName(EditorIcons))); theme->set_icon("add_preset", "ColorPicker", theme->get_icon(SNAME("Add"), EditorStringName(EditorIcons))); theme->set_icon("sample_bg", "ColorPicker", theme->get_icon(SNAME("GuiMiniCheckerboard"), EditorStringName(EditorIcons))); + theme->set_icon("sample_revert", "ColorPicker", theme->get_icon(SNAME("Reload"), EditorStringName(EditorIcons))); theme->set_icon("overbright_indicator", "ColorPicker", theme->get_icon(SNAME("OverbrightIndicator"), EditorStringName(EditorIcons))); theme->set_icon("bar_arrow", "ColorPicker", theme->get_icon(SNAME("ColorPickerBarArrow"), EditorStringName(EditorIcons))); theme->set_icon("picker_cursor", "ColorPicker", theme->get_icon(SNAME("PickerCursor"), EditorStringName(EditorIcons))); diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 669ce11e5d1..5ef9028f0fe 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -1029,6 +1029,14 @@ void ColorPicker::_sample_draw() { sample->draw_rect(rect_old, old_color); + if (!old_color.is_equal_approx(color)) { + // Draw a revert indicator to indicate that the old sample can be clicked to revert to this old color. + // Adapt icon color to the background color (taking alpha checkerboard into account) so that it's always visible. + sample->draw_texture(theme_cache.sample_revert, + rect_old.size * 0.5 - theme_cache.sample_revert->get_size() * 0.5, + Math::lerp(0.75f, old_color.get_luminance(), old_color.a) < 0.455 ? Color(1, 1, 1) : (Color(0.01, 0.01, 0.01))); + } + if (old_color.r > 1 || old_color.g > 1 || old_color.b > 1) { // Draw an indicator to denote that the old color is "overbright" and can't be displayed accurately in the preview. sample->draw_texture(theme_cache.overbright_indicator, Point2()); @@ -1727,6 +1735,7 @@ void ColorPicker::_bind_methods() { BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, bar_arrow); BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, sample_bg); + 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, color_hue); diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index dc547c8b0c0..282926d1ff8 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -237,6 +237,7 @@ private: Ref bar_arrow; Ref sample_bg; + Ref sample_revert; Ref overbright_indicator; Ref picker_cursor; Ref color_hue; diff --git a/scene/theme/default_theme.cpp b/scene/theme/default_theme.cpp index ddec5e826b2..32950a38683 100644 --- a/scene/theme/default_theme.cpp +++ b/scene/theme/default_theme.cpp @@ -954,6 +954,7 @@ void fill_default_theme(Ref &theme, const Ref &default_font, const theme->set_icon("shape_rect_wheel", "ColorPicker", icons["picker_shape_rectangle_wheel"]); theme->set_icon("add_preset", "ColorPicker", icons["add"]); theme->set_icon("sample_bg", "ColorPicker", icons["mini_checkerboard"]); + theme->set_icon("sample_revert", "ColorPicker", icons["reload"]); 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"]);