Display a revert icon on ColorPicker's old sample

This denotes that the color can be clicked to revert to the old color.
This commit is contained in:
Hugo Locurcio 2023-11-06 14:53:52 +01:00
parent b7449a3d1a
commit 079f1c8ead
No known key found for this signature in database
GPG key ID: 39E8F8BE30B0A49C
5 changed files with 15 additions and 0 deletions

View file

@ -186,6 +186,9 @@
<theme_item name="sample_bg" data_type="icon" type="Texture2D">
Background panel for the color preview box (visible when the color is translucent).
</theme_item>
<theme_item name="sample_revert" data_type="icon" type="Texture2D">
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.
</theme_item>
<theme_item name="screen_picker" data_type="icon" type="Texture2D">
The icon for the screen color picker button.
</theme_item>

View file

@ -2170,6 +2170,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> 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)));

View file

@ -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);

View file

@ -237,6 +237,7 @@ private:
Ref<Texture2D> bar_arrow;
Ref<Texture2D> sample_bg;
Ref<Texture2D> sample_revert;
Ref<Texture2D> overbright_indicator;
Ref<Texture2D> picker_cursor;
Ref<Texture2D> color_hue;

View file

@ -954,6 +954,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &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"]);