summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorHaoyu Qiu <timothyqiu32@gmail.com>2021-12-16 13:59:04 +0800
committerHaoyu Qiu <timothyqiu32@gmail.com>2021-12-18 00:34:28 +0800
commit1fb59d13c2e32b9543195601149071ff4b2887d4 (patch)
tree981177e1076684cde68ce69f0006b3158dcd82f7 /editor
parent58712e96aea12bda2d5111d96961f529d15a693c (diff)
Fix font preview text color on light background
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_settings.cpp2
-rw-r--r--editor/plugins/editor_preview_plugins.cpp4
2 files changed, 4 insertions, 2 deletions
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index 68ac122e63..1ac1d6f048 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -1190,7 +1190,7 @@ bool EditorSettings::is_dark_theme() {
int LIGHT_COLOR = 2;
Color base_color = get("interface/theme/base_color");
int icon_font_color_setting = get("interface/theme/icon_and_font_color");
- return (icon_font_color_setting == AUTO_COLOR && ((base_color.r + base_color.g + base_color.b) / 3.0) < 0.5) || icon_font_color_setting == LIGHT_COLOR;
+ return (icon_font_color_setting == AUTO_COLOR && base_color.get_luminance() < 0.5) || icon_font_color_setting == LIGHT_COLOR;
}
void EditorSettings::list_text_editor_themes() {
diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp
index 3b85fad345..ed1194efce 100644
--- a/editor/plugins/editor_preview_plugins.cpp
+++ b/editor/plugins/editor_preview_plugins.cpp
@@ -851,7 +851,9 @@ Ref<Texture2D> EditorFontPreviewPlugin::generate_from_path(const String &p_path,
Ref<Font> font = sampled_font;
- font->draw_string(canvas_item, pos, sample, HORIZONTAL_ALIGNMENT_LEFT, -1.f, 50, Color(1, 1, 1));
+ const Color c = GLOBAL_GET("rendering/environment/defaults/default_clear_color");
+ const float fg = c.get_luminance() < 0.5 ? 1.0 : 0.0;
+ font->draw_string(canvas_item, pos, sample, HORIZONTAL_ALIGNMENT_LEFT, -1.f, 50, Color(fg, fg, fg));
RS::get_singleton()->connect(SNAME("frame_pre_draw"), callable_mp(const_cast<EditorFontPreviewPlugin *>(this), &EditorFontPreviewPlugin::_generate_frame_started), Vector<Variant>(), Object::CONNECT_ONESHOT);