Skip to content

Commit e68b243

Browse files
committed
[Editor] Simplify native menu icon generation.
1 parent 3a97723 commit e68b243

File tree

6 files changed

+45
-71
lines changed

6 files changed

+45
-71
lines changed

editor/docks/editor_dock_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ void EditorDockManager::update_docks_menu() {
333333
// Add docks.
334334
docks_menu_docks.clear();
335335
int id = 0;
336-
const Callable icon_fetch = callable_mp((Window *)docks_menu, &Window::get_editor_theme_native_menu_icon).bind(global_menu, dark_mode);
336+
const Callable icon_fetch = callable_mp(EditorNode::get_singleton(), &EditorNode::get_editor_theme_native_menu_icon).bind(global_menu, dark_mode);
337337
for (EditorDock *dock : all_docks) {
338338
if (!dock->enabled || !dock->global) {
339339
continue;

editor/editor_node.cpp

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include "scene/main/timer.h"
6666
#include "scene/main/window.h"
6767
#include "scene/property_utils.h"
68+
#include "scene/resources/dpi_texture.h"
6869
#include "scene/resources/image_texture.h"
6970
#include "scene/resources/packed_scene.h"
7071
#include "scene/resources/portable_compressed_texture.h"
@@ -166,6 +167,7 @@
166167
#include "editor/settings/project_settings_editor.h"
167168
#include "editor/shader/editor_native_shader_source_visualizer.h"
168169
#include "editor/shader/visual_shader_editor_plugin.h"
170+
#include "editor/themes/editor_color_map.h"
169171
#include "editor/themes/editor_scale.h"
170172
#include "editor/themes/editor_theme_manager.h"
171173
#include "editor/translations/editor_translation_parser.h"
@@ -683,10 +685,10 @@ void EditorNode::_update_theme(bool p_skip_creation) {
683685
distraction_free->set_button_icon(theme->get_icon(SNAME("DistractionFree"), EditorStringName(EditorIcons)));
684686
update_distraction_free_button_theme();
685687

686-
help_menu->set_item_icon(help_menu->get_item_index(HELP_SEARCH), _get_editor_theme_native_menu_icon(SNAME("HelpSearch"), global_menu, dark_mode));
687-
help_menu->set_item_icon(help_menu->get_item_index(HELP_COPY_SYSTEM_INFO), _get_editor_theme_native_menu_icon(SNAME("ActionCopy"), global_menu, dark_mode));
688-
help_menu->set_item_icon(help_menu->get_item_index(HELP_ABOUT), _get_editor_theme_native_menu_icon(SNAME("Godot"), global_menu, dark_mode));
689-
help_menu->set_item_icon(help_menu->get_item_index(HELP_SUPPORT_GODOT_DEVELOPMENT), _get_editor_theme_native_menu_icon(SNAME("Heart"), global_menu, dark_mode));
688+
help_menu->set_item_icon(help_menu->get_item_index(HELP_SEARCH), get_editor_theme_native_menu_icon(SNAME("HelpSearch"), global_menu, dark_mode));
689+
help_menu->set_item_icon(help_menu->get_item_index(HELP_COPY_SYSTEM_INFO), get_editor_theme_native_menu_icon(SNAME("ActionCopy"), global_menu, dark_mode));
690+
help_menu->set_item_icon(help_menu->get_item_index(HELP_ABOUT), get_editor_theme_native_menu_icon(SNAME("Godot"), global_menu, dark_mode));
691+
help_menu->set_item_icon(help_menu->get_item_index(HELP_SUPPORT_GODOT_DEVELOPMENT), get_editor_theme_native_menu_icon(SNAME("Heart"), global_menu, dark_mode));
690692

691693
_update_renderer_color();
692694
}
@@ -703,16 +705,27 @@ void EditorNode::_update_theme(bool p_skip_creation) {
703705
#endif
704706
}
705707

706-
Ref<Texture2D> EditorNode::_get_editor_theme_native_menu_icon(const StringName &p_name, bool p_global_menu, bool p_dark_mode) const {
707-
if (!p_global_menu) {
708-
return theme->get_icon(p_name, SNAME("EditorIcons"));
708+
Ref<Texture2D> EditorNode::get_editor_theme_native_menu_icon(const StringName &p_name, bool p_global_menu, bool p_dark_mode) const {
709+
Ref<Texture2D> tx = theme->get_icon(p_name, SNAME("EditorIcons"));
710+
if (!p_global_menu || p_dark_mode == EditorThemeManager::is_dark_icon_and_font()) {
711+
return tx;
709712
}
710-
if (p_dark_mode && theme->has_icon(String(p_name) + "Dark", SNAME("EditorIcons"))) {
711-
return theme->get_icon(String(p_name) + "Dark", SNAME("EditorIcons"));
712-
} else if (!p_dark_mode && theme->has_icon(String(p_name) + "Light", SNAME("EditorIcons"))) {
713-
return theme->get_icon(String(p_name) + "Light", SNAME("EditorIcons"));
713+
714+
Ref<DPITexture> new_tx = tx;
715+
if (new_tx.is_null()) {
716+
return tx;
714717
}
715-
return theme->get_icon(p_name, SNAME("EditorIcons"));
718+
new_tx = new_tx->duplicate();
719+
720+
Dictionary color_conversion_map;
721+
if (!p_dark_mode) {
722+
for (KeyValue<Color, Color> &E : EditorColorMap::get_color_conversion_map()) {
723+
color_conversion_map[E.key] = E.value;
724+
}
725+
}
726+
new_tx->set_color_map(color_conversion_map);
727+
728+
return new_tx;
716729
}
717730

718731
void EditorNode::update_preview_themes(int p_mode) {
@@ -3905,10 +3918,10 @@ void EditorNode::_check_system_theme_changed() {
39053918
// Update system menus.
39063919
bool dark_mode = DisplayServer::get_singleton()->is_dark_mode();
39073920

3908-
help_menu->set_item_icon(help_menu->get_item_index(HELP_SEARCH), _get_editor_theme_native_menu_icon(SNAME("HelpSearch"), global_menu, dark_mode));
3909-
help_menu->set_item_icon(help_menu->get_item_index(HELP_COPY_SYSTEM_INFO), _get_editor_theme_native_menu_icon(SNAME("ActionCopy"), global_menu, dark_mode));
3910-
help_menu->set_item_icon(help_menu->get_item_index(HELP_ABOUT), _get_editor_theme_native_menu_icon(SNAME("Godot"), global_menu, dark_mode));
3911-
help_menu->set_item_icon(help_menu->get_item_index(HELP_SUPPORT_GODOT_DEVELOPMENT), _get_editor_theme_native_menu_icon(SNAME("Heart"), global_menu, dark_mode));
3921+
help_menu->set_item_icon(help_menu->get_item_index(HELP_SEARCH), get_editor_theme_native_menu_icon(SNAME("HelpSearch"), global_menu, dark_mode));
3922+
help_menu->set_item_icon(help_menu->get_item_index(HELP_COPY_SYSTEM_INFO), get_editor_theme_native_menu_icon(SNAME("ActionCopy"), global_menu, dark_mode));
3923+
help_menu->set_item_icon(help_menu->get_item_index(HELP_ABOUT), get_editor_theme_native_menu_icon(SNAME("Godot"), global_menu, dark_mode));
3924+
help_menu->set_item_icon(help_menu->get_item_index(HELP_SUPPORT_GODOT_DEVELOPMENT), get_editor_theme_native_menu_icon(SNAME("Heart"), global_menu, dark_mode));
39123925
editor_dock_manager->update_docks_menu();
39133926
}
39143927
}
@@ -8635,23 +8648,23 @@ EditorNode::EditorNode() {
86358648

86368649
ED_SHORTCUT_AND_COMMAND("editor/editor_help", TTRC("Search Help..."), Key::F1);
86378650
ED_SHORTCUT_OVERRIDE("editor/editor_help", "macos", KeyModifierMask::ALT | Key::SPACE);
8638-
help_menu->add_icon_shortcut(_get_editor_theme_native_menu_icon(SNAME("HelpSearch"), global_menu, dark_mode), ED_GET_SHORTCUT("editor/editor_help"), HELP_SEARCH);
8651+
help_menu->add_icon_shortcut(get_editor_theme_native_menu_icon(SNAME("HelpSearch"), global_menu, dark_mode), ED_GET_SHORTCUT("editor/editor_help"), HELP_SEARCH);
86398652
help_menu->add_separator();
86408653
help_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/online_docs", TTRC("Online Documentation")), HELP_DOCS);
86418654
help_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/forum", TTRC("Forum")), HELP_FORUM);
86428655
help_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/community", TTRC("Community")), HELP_COMMUNITY);
86438656
help_menu->add_separator();
8644-
help_menu->add_icon_shortcut(_get_editor_theme_native_menu_icon(SNAME("ActionCopy"), global_menu, dark_mode), ED_SHORTCUT_AND_COMMAND("editor/copy_system_info", TTRC("Copy System Info")), HELP_COPY_SYSTEM_INFO);
8657+
help_menu->add_icon_shortcut(get_editor_theme_native_menu_icon(SNAME("ActionCopy"), global_menu, dark_mode), ED_SHORTCUT_AND_COMMAND("editor/copy_system_info", TTRC("Copy System Info")), HELP_COPY_SYSTEM_INFO);
86458658
help_menu->set_item_tooltip(-1, TTR("Copies the system info as a single-line text into the clipboard."));
86468659
help_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/report_a_bug", TTRC("Report a Bug")), HELP_REPORT_A_BUG);
86478660
help_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/suggest_a_feature", TTRC("Suggest a Feature")), HELP_SUGGEST_A_FEATURE);
86488661
help_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/send_docs_feedback", TTRC("Send Docs Feedback")), HELP_SEND_DOCS_FEEDBACK);
86498662
help_menu->add_separator();
86508663
if (!global_menu || !OS::get_singleton()->has_feature("macos")) {
86518664
// On macOS "Quit" and "About" options are in the "app" menu.
8652-
help_menu->add_icon_shortcut(_get_editor_theme_native_menu_icon(SNAME("Godot"), global_menu, dark_mode), ED_SHORTCUT_AND_COMMAND("editor/about", TTRC("About Godot...")), HELP_ABOUT);
8665+
help_menu->add_icon_shortcut(get_editor_theme_native_menu_icon(SNAME("Godot"), global_menu, dark_mode), ED_SHORTCUT_AND_COMMAND("editor/about", TTRC("About Godot...")), HELP_ABOUT);
86538666
}
8654-
help_menu->add_icon_shortcut(_get_editor_theme_native_menu_icon(SNAME("Heart"), global_menu, dark_mode), ED_SHORTCUT_AND_COMMAND("editor/support_development", TTRC("Support Godot Development")), HELP_SUPPORT_GODOT_DEVELOPMENT);
8667+
help_menu->add_icon_shortcut(get_editor_theme_native_menu_icon(SNAME("Heart"), global_menu, dark_mode), ED_SHORTCUT_AND_COMMAND("editor/support_development", TTRC("Support Godot Development")), HELP_SUPPORT_GODOT_DEVELOPMENT);
86558668

86568669
// Spacer to center 2D / 3D / Script buttons.
86578670
right_spacer = memnew(Control);

editor/editor_node.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,6 @@ class EditorNode : public Node {
698698
bool _is_class_editor_disabled_by_feature_profile(const StringName &p_class);
699699

700700
Ref<Texture2D> _get_class_or_script_icon(const String &p_class, const String &p_script_path, const String &p_fallback = "", bool p_fallback_script_to_theme = false, bool p_skip_fallback_virtual = false);
701-
Ref<Texture2D> _get_editor_theme_native_menu_icon(const StringName &p_name, bool p_global_menu, bool p_dark_mode) const;
702701

703702
void _pick_main_scene_custom_action(const String &p_custom_action_name);
704703

@@ -787,6 +786,8 @@ class EditorNode : public Node {
787786

788787
static void cleanup();
789788

789+
Ref<Texture2D> get_editor_theme_native_menu_icon(const StringName &p_name, bool p_global_menu, bool p_dark_mode) const;
790+
790791
EditorPluginList *get_editor_plugins_force_input_forwarding() { return editor_plugins_force_input_forwarding; }
791792
EditorPluginList *get_editor_plugins_force_over() { return editor_plugins_force_over; }
792793
EditorPluginList *get_editor_plugins_over() { return editor_plugins_over; }

editor/themes/editor_icons.cpp

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,6 @@ void editor_register_icons(const Ref<Theme> &p_theme, bool p_dark_theme, float p
104104

105105
Dictionary color_conversion_map = p_dark_theme ? color_conversion_map_dark : color_conversion_map_light;
106106

107-
// The names of the icons used in native menus.
108-
HashSet<StringName> native_menu_icons;
109-
native_menu_icons.insert("HelpSearch");
110-
native_menu_icons.insert("ActionCopy");
111-
native_menu_icons.insert("Heart");
112-
native_menu_icons.insert("PackedScene");
113-
native_menu_icons.insert("FileAccess");
114-
native_menu_icons.insert("Folder");
115-
native_menu_icons.insert("AnimationTrackList");
116-
native_menu_icons.insert("Signals");
117-
native_menu_icons.insert("Groups");
118-
native_menu_icons.insert("History");
119-
120107
// The names of the icons to exclude from the standard color conversion.
121108
HashSet<StringName> conversion_exceptions = EditorColorMap::get_color_conversion_exceptions();
122109

@@ -149,37 +136,23 @@ void editor_register_icons(const Ref<Theme> &p_theme, bool p_dark_theme, float p
149136
{
150137
for (int i = 0; i < editor_icons_count; i++) {
151138
const String &editor_icon_name = editor_icons_names[i];
152-
if (native_menu_icons.has(editor_icon_name)) {
139+
Ref<DPITexture> icon;
140+
if (accent_color_icons.has(editor_icon_name)) {
141+
icon = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name, p_gizmo_handle_scale), 1.0, accent_color_map);
142+
} else {
153143
float saturation = p_icon_saturation;
154144
if (saturation_exceptions.has(editor_icon_name)) {
155145
saturation = 1.0;
156146
}
157147

158-
Ref<DPITexture> icon_dark = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name, p_gizmo_handle_scale), saturation, color_conversion_map_dark);
159-
Ref<DPITexture> icon_light = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name, p_gizmo_handle_scale), saturation, color_conversion_map_light);
160-
161-
p_theme->set_icon(editor_icon_name + "Dark", EditorStringName(EditorIcons), icon_dark);
162-
p_theme->set_icon(editor_icon_name + "Light", EditorStringName(EditorIcons), icon_light);
163-
p_theme->set_icon(editor_icon_name, EditorStringName(EditorIcons), p_dark_theme ? icon_dark : icon_light);
164-
} else {
165-
Ref<DPITexture> icon;
166-
if (accent_color_icons.has(editor_icon_name)) {
167-
icon = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name, p_gizmo_handle_scale), 1.0, accent_color_map);
148+
if (conversion_exceptions.has(editor_icon_name)) {
149+
icon = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name, p_gizmo_handle_scale), saturation);
168150
} else {
169-
float saturation = p_icon_saturation;
170-
if (saturation_exceptions.has(editor_icon_name)) {
171-
saturation = 1.0;
172-
}
173-
174-
if (conversion_exceptions.has(editor_icon_name)) {
175-
icon = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name, p_gizmo_handle_scale), saturation);
176-
} else {
177-
icon = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name, p_gizmo_handle_scale), saturation, color_conversion_map);
178-
}
151+
icon = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name, p_gizmo_handle_scale), saturation, color_conversion_map);
179152
}
180-
181-
p_theme->set_icon(editor_icon_name, EditorStringName(EditorIcons), icon);
182153
}
154+
155+
p_theme->set_icon(editor_icon_name, EditorStringName(EditorIcons), icon);
183156
}
184157
}
185158

scene/main/window.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,18 +2617,6 @@ Variant Window::get_theme_item(Theme::DataType p_data_type, const StringName &p_
26172617
Ref<Texture2D> Window::get_editor_theme_icon(const StringName &p_name) const {
26182618
return get_theme_icon(p_name, SNAME("EditorIcons"));
26192619
}
2620-
2621-
Ref<Texture2D> Window::get_editor_theme_native_menu_icon(const StringName &p_name, bool p_global_menu, bool p_dark_mode) const {
2622-
if (!p_global_menu) {
2623-
return get_theme_icon(p_name, SNAME("EditorIcons"));
2624-
}
2625-
if (p_dark_mode && has_theme_icon(String(p_name) + "Dark", SNAME("EditorIcons"))) {
2626-
return get_theme_icon(String(p_name) + "Dark", SNAME("EditorIcons"));
2627-
} else if (!p_dark_mode && has_theme_icon(String(p_name) + "Light", SNAME("EditorIcons"))) {
2628-
return get_theme_icon(String(p_name) + "Light", SNAME("EditorIcons"));
2629-
}
2630-
return get_theme_icon(p_name, SNAME("EditorIcons"));
2631-
}
26322620
#endif
26332621

26342622
bool Window::has_theme_icon(const StringName &p_name, const StringName &p_theme_type) const {

scene/main/window.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,6 @@ class Window : public Viewport {
495495
Variant get_theme_item(Theme::DataType p_data_type, const StringName &p_name, const StringName &p_theme_type = StringName()) const;
496496
#ifdef TOOLS_ENABLED
497497
Ref<Texture2D> get_editor_theme_icon(const StringName &p_name) const;
498-
Ref<Texture2D> get_editor_theme_native_menu_icon(const StringName &p_name, bool p_global_menu, bool p_dark_mode) const;
499498
#endif
500499

501500
bool has_theme_icon_override(const StringName &p_name) const;

0 commit comments

Comments
 (0)