diff --git a/doc/classes/ColorPicker.xml b/doc/classes/ColorPicker.xml index 3af8df48055..b0d491fc67e 100644 --- a/doc/classes/ColorPicker.xml +++ b/doc/classes/ColorPicker.xml @@ -179,6 +179,9 @@ The texture for the arrow grabber. + + The icon for the button that copies the color in text format to the clipboard. + Custom texture for the hue selection slider on the right. diff --git a/editor/themes/theme_classic.cpp b/editor/themes/theme_classic.cpp index 9d584524b10..85c20741e3a 100644 --- a/editor/themes/theme_classic.cpp +++ b/editor/themes/theme_classic.cpp @@ -1523,6 +1523,7 @@ void ThemeClassic::populate_standard_styles(const Ref &p_theme, Edi p_theme->set_icon("picker_cursor", "ColorPicker", p_theme->get_icon(SNAME("PickerCursor"), EditorStringName(EditorIcons))); p_theme->set_icon("picker_cursor_bg", "ColorPicker", p_theme->get_icon(SNAME("PickerCursorBg"), EditorStringName(EditorIcons))); p_theme->set_icon("color_script", "ColorPicker", p_theme->get_icon(SNAME("Script"), EditorStringName(EditorIcons))); + p_theme->set_icon("color_copy", "ColorPicker", p_theme->get_icon(SNAME("ActionCopy"), EditorStringName(EditorIcons))); // ColorPickerButton. p_theme->set_icon("bg", "ColorPickerButton", p_theme->get_icon(SNAME("GuiMiniCheckerboard"), EditorStringName(EditorIcons))); diff --git a/editor/themes/theme_modern.cpp b/editor/themes/theme_modern.cpp index 20a9f8c8a2d..16803b01e2c 100644 --- a/editor/themes/theme_modern.cpp +++ b/editor/themes/theme_modern.cpp @@ -1563,6 +1563,7 @@ void ThemeModern::populate_standard_styles(const Ref &p_theme, Edit p_theme->set_icon("picker_cursor", "ColorPicker", p_theme->get_icon(SNAME("PickerCursor"), EditorStringName(EditorIcons))); p_theme->set_icon("picker_cursor_bg", "ColorPicker", p_theme->get_icon(SNAME("PickerCursorBg"), EditorStringName(EditorIcons))); p_theme->set_icon("color_script", "ColorPicker", p_theme->get_icon(SNAME("Script"), EditorStringName(EditorIcons))); + p_theme->set_icon("color_copy", "ColorPicker", p_theme->get_icon(SNAME("ActionCopy"), 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 3fd04f37628..e8401d9afad 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -171,6 +171,8 @@ void ColorPicker::_notification(int p_what) { hex_label->set_custom_minimum_size(Size2(38 * theme_cache.base_scale, 0)); // Adjust for the width of the "script" icon. text_type->set_custom_minimum_size(Size2(28 * theme_cache.base_scale, 0)); + text_copy->set_button_icon(theme_cache.color_copy); + text_copy->set_custom_minimum_size(Size2(28 * theme_cache.base_scale, 0)); _update_controls(); // HACK: Deferring updating presets to ensure their size is correct when creating ColorPicker at runtime. @@ -843,6 +845,10 @@ void ColorPicker::_text_type_toggled() { } #endif // TOOLS_ENABLED +void ColorPicker::_text_copy_pressed() { + DisplayServer::get_singleton()->clipboard_set(c_text->get_text()); +} + Color ColorPicker::get_pick_color() const { return color; } @@ -2057,6 +2063,7 @@ void ColorPicker::_bind_methods() { BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, color_hue); BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, color_script); + BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, color_copy); BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_STYLEBOX, ColorPicker, mode_button_normal, "tab_unselected", "TabContainer"); BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_STYLEBOX, ColorPicker, mode_button_pressed, "tab_selected", "TabContainer"); @@ -2224,6 +2231,13 @@ ColorPicker::ColorPicker() { c_text->connect(SceneStringName(text_changed), callable_mp(this, &ColorPicker::_text_changed)); c_text->connect(SceneStringName(focus_exited), callable_mp(this, &ColorPicker::_html_focus_exit)); + text_copy = memnew(Button); + hex_hbc->add_child(text_copy); + text_copy->set_icon_alignment(HORIZONTAL_ALIGNMENT_CENTER); + text_copy->set_tooltip_text(ETR("Copy the color value.")); + text_type->set_accessibility_name(ETR("Copy Color")); + text_copy->connect(SceneStringName(pressed), callable_mp(this, &ColorPicker::_text_copy_pressed)); + _update_controls(); updating = false; diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index 50702d5be7a..ebfa2a8a778 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -246,6 +246,7 @@ private: Button *text_type = nullptr; LineEdit *c_text = nullptr; + Button *text_copy = nullptr; HSlider *alpha_slider = nullptr; SpinBox *alpha_value = nullptr; @@ -340,6 +341,7 @@ private: Ref color_hue; Ref color_script; + Ref color_copy; /* Mode buttons */ Ref mode_button_normal; @@ -367,6 +369,7 @@ private: #ifdef TOOLS_ENABLED void _text_type_toggled(); #endif // TOOLS_ENABLED + void _text_copy_pressed(); void _sample_input(const Ref &p_event); void _sample_draw(); void _slider_draw(int p_which); diff --git a/scene/theme/default_theme.cpp b/scene/theme/default_theme.cpp index 79d25c41f31..51afdd6c539 100644 --- a/scene/theme/default_theme.cpp +++ b/scene/theme/default_theme.cpp @@ -1100,6 +1100,7 @@ void fill_default_theme(Ref &theme, const Ref &default_font, const theme->set_icon("picker_cursor", "ColorPicker", icons["color_picker_cursor"]); theme->set_icon("picker_cursor_bg", "ColorPicker", icons["color_picker_cursor_bg"]); theme->set_icon("color_script", "ColorPicker", icons["script"]); + theme->set_icon("color_copy", "ColorPicker", icons["action_copy"]); { const int precision = 7; diff --git a/scene/theme/icons/action_copy.svg b/scene/theme/icons/action_copy.svg new file mode 100644 index 00000000000..96e5b2bd59e --- /dev/null +++ b/scene/theme/icons/action_copy.svg @@ -0,0 +1 @@ +