1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-05 17:15:09 +00:00

Merge pull request #113252 from bruvzg/ed_nat_menu_theme

[Editor] Simplify native menu icon generation.
This commit is contained in:
Rémi Verschelde
2025-12-01 11:49:24 +01:00
6 changed files with 45 additions and 71 deletions

View File

@@ -333,7 +333,7 @@ void EditorDockManager::update_docks_menu() {
// Add docks.
docks_menu_docks.clear();
int id = 0;
const Callable icon_fetch = callable_mp((Window *)docks_menu, &Window::get_editor_theme_native_menu_icon).bind(global_menu, dark_mode);
const Callable icon_fetch = callable_mp(EditorNode::get_singleton(), &EditorNode::get_editor_theme_native_menu_icon).bind(global_menu, dark_mode);
for (EditorDock *dock : all_docks) {
if (!dock->enabled || !dock->global) {
continue;

View File

@@ -65,6 +65,7 @@
#include "scene/main/timer.h"
#include "scene/main/window.h"
#include "scene/property_utils.h"
#include "scene/resources/dpi_texture.h"
#include "scene/resources/image_texture.h"
#include "scene/resources/packed_scene.h"
#include "scene/resources/portable_compressed_texture.h"
@@ -166,6 +167,7 @@
#include "editor/settings/project_settings_editor.h"
#include "editor/shader/editor_native_shader_source_visualizer.h"
#include "editor/shader/visual_shader_editor_plugin.h"
#include "editor/themes/editor_color_map.h"
#include "editor/themes/editor_scale.h"
#include "editor/themes/editor_theme_manager.h"
#include "editor/translations/editor_translation_parser.h"
@@ -683,10 +685,10 @@ void EditorNode::_update_theme(bool p_skip_creation) {
distraction_free->set_button_icon(theme->get_icon(SNAME("DistractionFree"), EditorStringName(EditorIcons)));
update_distraction_free_button_theme();
help_menu->set_item_icon(help_menu->get_item_index(HELP_SEARCH), _get_editor_theme_native_menu_icon(SNAME("HelpSearch"), global_menu, dark_mode));
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));
help_menu->set_item_icon(help_menu->get_item_index(HELP_ABOUT), _get_editor_theme_native_menu_icon(SNAME("Godot"), global_menu, dark_mode));
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));
help_menu->set_item_icon(help_menu->get_item_index(HELP_SEARCH), get_editor_theme_native_menu_icon(SNAME("HelpSearch"), global_menu, dark_mode));
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));
help_menu->set_item_icon(help_menu->get_item_index(HELP_ABOUT), get_editor_theme_native_menu_icon(SNAME("Godot"), global_menu, dark_mode));
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));
_update_renderer_color();
}
@@ -703,16 +705,27 @@ void EditorNode::_update_theme(bool p_skip_creation) {
#endif
}
Ref<Texture2D> EditorNode::_get_editor_theme_native_menu_icon(const StringName &p_name, bool p_global_menu, bool p_dark_mode) const {
if (!p_global_menu) {
return theme->get_icon(p_name, SNAME("EditorIcons"));
Ref<Texture2D> EditorNode::get_editor_theme_native_menu_icon(const StringName &p_name, bool p_global_menu, bool p_dark_mode) const {
Ref<Texture2D> tx = theme->get_icon(p_name, SNAME("EditorIcons"));
if (!p_global_menu || p_dark_mode == EditorThemeManager::is_dark_icon_and_font()) {
return tx;
}
if (p_dark_mode && theme->has_icon(String(p_name) + "Dark", SNAME("EditorIcons"))) {
return theme->get_icon(String(p_name) + "Dark", SNAME("EditorIcons"));
} else if (!p_dark_mode && theme->has_icon(String(p_name) + "Light", SNAME("EditorIcons"))) {
return theme->get_icon(String(p_name) + "Light", SNAME("EditorIcons"));
Ref<DPITexture> new_tx = tx;
if (new_tx.is_null()) {
return tx;
}
return theme->get_icon(p_name, SNAME("EditorIcons"));
new_tx = new_tx->duplicate();
Dictionary color_conversion_map;
if (!p_dark_mode) {
for (KeyValue<Color, Color> &E : EditorColorMap::get_color_conversion_map()) {
color_conversion_map[E.key] = E.value;
}
}
new_tx->set_color_map(color_conversion_map);
return new_tx;
}
void EditorNode::update_preview_themes(int p_mode) {
@@ -3905,10 +3918,10 @@ void EditorNode::_check_system_theme_changed() {
// Update system menus.
bool dark_mode = DisplayServer::get_singleton()->is_dark_mode();
help_menu->set_item_icon(help_menu->get_item_index(HELP_SEARCH), _get_editor_theme_native_menu_icon(SNAME("HelpSearch"), global_menu, dark_mode));
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));
help_menu->set_item_icon(help_menu->get_item_index(HELP_ABOUT), _get_editor_theme_native_menu_icon(SNAME("Godot"), global_menu, dark_mode));
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));
help_menu->set_item_icon(help_menu->get_item_index(HELP_SEARCH), get_editor_theme_native_menu_icon(SNAME("HelpSearch"), global_menu, dark_mode));
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));
help_menu->set_item_icon(help_menu->get_item_index(HELP_ABOUT), get_editor_theme_native_menu_icon(SNAME("Godot"), global_menu, dark_mode));
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));
editor_dock_manager->update_docks_menu();
}
}
@@ -8636,13 +8649,13 @@ EditorNode::EditorNode() {
ED_SHORTCUT_AND_COMMAND("editor/editor_help", TTRC("Search Help..."), Key::F1);
ED_SHORTCUT_OVERRIDE("editor/editor_help", "macos", KeyModifierMask::ALT | Key::SPACE);
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);
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);
help_menu->add_separator();
help_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/online_docs", TTRC("Online Documentation")), HELP_DOCS);
help_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/forum", TTRC("Forum")), HELP_FORUM);
help_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/community", TTRC("Community")), HELP_COMMUNITY);
help_menu->add_separator();
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);
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);
help_menu->set_item_tooltip(-1, TTR("Copies the system info as a single-line text into the clipboard."));
help_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/report_a_bug", TTRC("Report a Bug")), HELP_REPORT_A_BUG);
help_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/suggest_a_feature", TTRC("Suggest a Feature")), HELP_SUGGEST_A_FEATURE);
@@ -8650,9 +8663,9 @@ EditorNode::EditorNode() {
help_menu->add_separator();
if (!global_menu || !OS::get_singleton()->has_feature("macos")) {
// On macOS "Quit" and "About" options are in the "app" menu.
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);
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);
}
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);
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);
// Spacer to center 2D / 3D / Script buttons.
right_spacer = memnew(Control);

View File

@@ -698,7 +698,6 @@ private:
bool _is_class_editor_disabled_by_feature_profile(const StringName &p_class);
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);
Ref<Texture2D> _get_editor_theme_native_menu_icon(const StringName &p_name, bool p_global_menu, bool p_dark_mode) const;
void _pick_main_scene_custom_action(const String &p_custom_action_name);
@@ -787,6 +786,8 @@ public:
static void cleanup();
Ref<Texture2D> get_editor_theme_native_menu_icon(const StringName &p_name, bool p_global_menu, bool p_dark_mode) const;
EditorPluginList *get_editor_plugins_force_input_forwarding() { return editor_plugins_force_input_forwarding; }
EditorPluginList *get_editor_plugins_force_over() { return editor_plugins_force_over; }
EditorPluginList *get_editor_plugins_over() { return editor_plugins_over; }

View File

@@ -104,19 +104,6 @@ void editor_register_icons(const Ref<Theme> &p_theme, bool p_dark_theme, float p
Dictionary color_conversion_map = p_dark_theme ? color_conversion_map_dark : color_conversion_map_light;
// The names of the icons used in native menus.
HashSet<StringName> native_menu_icons;
native_menu_icons.insert("HelpSearch");
native_menu_icons.insert("ActionCopy");
native_menu_icons.insert("Heart");
native_menu_icons.insert("PackedScene");
native_menu_icons.insert("FileAccess");
native_menu_icons.insert("Folder");
native_menu_icons.insert("AnimationTrackList");
native_menu_icons.insert("Signals");
native_menu_icons.insert("Groups");
native_menu_icons.insert("History");
// The names of the icons to exclude from the standard color conversion.
HashSet<StringName> conversion_exceptions = EditorColorMap::get_color_conversion_exceptions();
@@ -149,19 +136,6 @@ void editor_register_icons(const Ref<Theme> &p_theme, bool p_dark_theme, float p
{
for (int i = 0; i < editor_icons_count; i++) {
const String &editor_icon_name = editor_icons_names[i];
if (native_menu_icons.has(editor_icon_name)) {
float saturation = p_icon_saturation;
if (saturation_exceptions.has(editor_icon_name)) {
saturation = 1.0;
}
Ref<DPITexture> icon_dark = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name, p_gizmo_handle_scale), saturation, color_conversion_map_dark);
Ref<DPITexture> icon_light = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name, p_gizmo_handle_scale), saturation, color_conversion_map_light);
p_theme->set_icon(editor_icon_name + "Dark", EditorStringName(EditorIcons), icon_dark);
p_theme->set_icon(editor_icon_name + "Light", EditorStringName(EditorIcons), icon_light);
p_theme->set_icon(editor_icon_name, EditorStringName(EditorIcons), p_dark_theme ? icon_dark : icon_light);
} else {
Ref<DPITexture> icon;
if (accent_color_icons.has(editor_icon_name)) {
icon = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name, p_gizmo_handle_scale), 1.0, accent_color_map);
@@ -181,7 +155,6 @@ void editor_register_icons(const Ref<Theme> &p_theme, bool p_dark_theme, float p
p_theme->set_icon(editor_icon_name, EditorStringName(EditorIcons), icon);
}
}
}
// Generate thumbnail icons with the given thumbnail size.
// See editor\icons\editor_icons_builders.py for the code that determines which icons are thumbnails.

View File

@@ -2617,18 +2617,6 @@ Variant Window::get_theme_item(Theme::DataType p_data_type, const StringName &p_
Ref<Texture2D> Window::get_editor_theme_icon(const StringName &p_name) const {
return get_theme_icon(p_name, SNAME("EditorIcons"));
}
Ref<Texture2D> Window::get_editor_theme_native_menu_icon(const StringName &p_name, bool p_global_menu, bool p_dark_mode) const {
if (!p_global_menu) {
return get_theme_icon(p_name, SNAME("EditorIcons"));
}
if (p_dark_mode && has_theme_icon(String(p_name) + "Dark", SNAME("EditorIcons"))) {
return get_theme_icon(String(p_name) + "Dark", SNAME("EditorIcons"));
} else if (!p_dark_mode && has_theme_icon(String(p_name) + "Light", SNAME("EditorIcons"))) {
return get_theme_icon(String(p_name) + "Light", SNAME("EditorIcons"));
}
return get_theme_icon(p_name, SNAME("EditorIcons"));
}
#endif
bool Window::has_theme_icon(const StringName &p_name, const StringName &p_theme_type) const {

View File

@@ -495,7 +495,6 @@ public:
Variant get_theme_item(Theme::DataType p_data_type, const StringName &p_name, const StringName &p_theme_type = StringName()) const;
#ifdef TOOLS_ENABLED
Ref<Texture2D> get_editor_theme_icon(const StringName &p_name) const;
Ref<Texture2D> get_editor_theme_native_menu_icon(const StringName &p_name, bool p_global_menu, bool p_dark_mode) const;
#endif
bool has_theme_icon_override(const StringName &p_name) const;