From 7c349574d7c813e9c79685e4109db2fa56502db0 Mon Sep 17 00:00:00 2001 From: kobewi Date: Thu, 11 Aug 2022 18:10:07 +0200 Subject: [PATCH] Optimize theme usage in editor log (cherry picked from commit c65360eed1842d1f337e094113f472798131b8f7) --- editor/editor_log.cpp | 35 ++++++++++++++++++++--------------- editor/editor_log.h | 10 ++++++++++ 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp index 0e43b15c8fd..95f73444d1d 100644 --- a/editor/editor_log.cpp +++ b/editor/editor_log.cpp @@ -58,18 +58,23 @@ void EditorLog::_error_handler(void *p_self, const char *p_func, const char *p_f } void EditorLog::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - //button->set_icon(get_icon("Console","EditorIcons")); - log->add_font_override("normal_font", get_font("output_source", "EditorFonts")); - log->add_color_override("selection_color", get_color("accent_color", "Editor") * Color(1, 1, 1, 0.4)); - } else if (p_what == NOTIFICATION_THEME_CHANGED) { - Ref df_output_code = get_font("output_source", "EditorFonts"); - if (df_output_code.is_valid()) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + case NOTIFICATION_THEME_CHANGED: { if (log != nullptr) { - log->add_font_override("normal_font", get_font("output_source", "EditorFonts")); - log->add_color_override("selection_color", get_color("accent_color", "Editor") * Color(1, 1, 1, 0.4)); + Ref df_output_code = get_font("output_source", "EditorFonts"); + if (df_output_code.is_valid()) { + log->add_font_override("normal_font", get_font("output_source", "EditorFonts")); + log->add_color_override("selection_color", get_color("accent_color", "Editor") * Color(1, 1, 1, 0.4)); + } } - } + + theme_cache.error_color = get_color("error_color", "Editor"); + theme_cache.error_icon = get_icon("Error", "EditorIcons"); + theme_cache.warning_color = get_color("warning_color", "Editor"); + theme_cache.warning_icon = get_icon("Warning", "EditorIcons"); + theme_cache.message_color = get_color("font_color", "Editor") * Color(1, 1, 1, 0.6); + } break; } } @@ -104,22 +109,22 @@ void EditorLog::add_message(const String &p_msg, MessageType p_type) { case MSG_TYPE_STD: { } break; case MSG_TYPE_ERROR: { - log->push_color(get_color("error_color", "Editor")); - Ref icon = get_icon("Error", "EditorIcons"); + log->push_color(theme_cache.error_color); + Ref icon = theme_cache.error_icon; log->add_image(icon); log->add_text(" "); tool_button->set_icon(icon); } break; case MSG_TYPE_WARNING: { - log->push_color(get_color("warning_color", "Editor")); - Ref icon = get_icon("Warning", "EditorIcons"); + log->push_color(theme_cache.warning_color); + Ref icon = theme_cache.warning_icon; log->add_image(icon); log->add_text(" "); tool_button->set_icon(icon); } break; case MSG_TYPE_EDITOR: { // Distinguish editor messages from messages printed by the project - log->push_color(get_color("font_color", "Editor") * Color(1, 1, 1, 0.6)); + log->push_color(theme_cache.message_color); } break; } diff --git a/editor/editor_log.h b/editor/editor_log.h index 1dfe7895fb9..e0d6910ea84 100644 --- a/editor/editor_log.h +++ b/editor/editor_log.h @@ -46,6 +46,16 @@ class EditorLog : public VBoxContainer { GDCLASS(EditorLog, VBoxContainer); + struct { + Color error_color; + Ref error_icon; + + Color warning_color; + Ref warning_icon; + + Color message_color; + } theme_cache; + Button *clearbutton; Button *copybutton; Label *title;