Merge pull request #55977 from timothyqiu/font-preview-fg-3.x
This commit is contained in:
commit
e937963007
5 changed files with 17 additions and 2 deletions
|
@ -91,6 +91,10 @@ struct Color {
|
||||||
Color inverted() const;
|
Color inverted() const;
|
||||||
Color contrasted() const;
|
Color contrasted() const;
|
||||||
|
|
||||||
|
_FORCE_INLINE_ float get_luminance() const {
|
||||||
|
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||||
|
}
|
||||||
|
|
||||||
_FORCE_INLINE_ Color linear_interpolate(const Color &p_to, float p_weight) const {
|
_FORCE_INLINE_ Color linear_interpolate(const Color &p_to, float p_weight) const {
|
||||||
Color res = *this;
|
Color res = *this;
|
||||||
|
|
||||||
|
|
|
@ -521,6 +521,7 @@ struct _VariantCall {
|
||||||
VCALL_LOCALMEM0R(Color, to_abgr64);
|
VCALL_LOCALMEM0R(Color, to_abgr64);
|
||||||
VCALL_LOCALMEM0R(Color, to_rgba64);
|
VCALL_LOCALMEM0R(Color, to_rgba64);
|
||||||
VCALL_LOCALMEM0R(Color, gray);
|
VCALL_LOCALMEM0R(Color, gray);
|
||||||
|
VCALL_LOCALMEM0R(Color, get_luminance);
|
||||||
VCALL_LOCALMEM0R(Color, inverted);
|
VCALL_LOCALMEM0R(Color, inverted);
|
||||||
VCALL_LOCALMEM0R(Color, contrasted);
|
VCALL_LOCALMEM0R(Color, contrasted);
|
||||||
VCALL_LOCALMEM2R(Color, linear_interpolate);
|
VCALL_LOCALMEM2R(Color, linear_interpolate);
|
||||||
|
@ -1849,6 +1850,7 @@ void register_variant_methods() {
|
||||||
ADDFUNC0R(COLOR, INT, Color, to_abgr64, varray());
|
ADDFUNC0R(COLOR, INT, Color, to_abgr64, varray());
|
||||||
ADDFUNC0R(COLOR, INT, Color, to_rgba64, varray());
|
ADDFUNC0R(COLOR, INT, Color, to_rgba64, varray());
|
||||||
ADDFUNC0R(COLOR, REAL, Color, gray, varray());
|
ADDFUNC0R(COLOR, REAL, Color, gray, varray());
|
||||||
|
ADDFUNC0R(COLOR, REAL, Color, get_luminance, varray());
|
||||||
ADDFUNC0R(COLOR, COLOR, Color, inverted, varray());
|
ADDFUNC0R(COLOR, COLOR, Color, inverted, varray());
|
||||||
ADDFUNC0R(COLOR, COLOR, Color, contrasted, varray());
|
ADDFUNC0R(COLOR, COLOR, Color, contrasted, varray());
|
||||||
ADDFUNC2R(COLOR, COLOR, Color, linear_interpolate, COLOR, "to", REAL, "weight", varray());
|
ADDFUNC2R(COLOR, COLOR, Color, linear_interpolate, COLOR, "to", REAL, "weight", varray());
|
||||||
|
|
|
@ -111,6 +111,13 @@
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="get_luminance">
|
||||||
|
<return type="float" />
|
||||||
|
<description>
|
||||||
|
Returns the luminance of the color in the [code][0.0, 1.0][/code] range.
|
||||||
|
This is useful when determining light or dark color. Colors with a luminance smaller than 0.5 can be generally considered dark.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="gray">
|
<method name="gray">
|
||||||
<return type="float" />
|
<return type="float" />
|
||||||
<description>
|
<description>
|
||||||
|
|
|
@ -1296,7 +1296,7 @@ bool EditorSettings::is_dark_theme() {
|
||||||
int LIGHT_COLOR = 2;
|
int LIGHT_COLOR = 2;
|
||||||
Color base_color = get("interface/theme/base_color");
|
Color base_color = get("interface/theme/base_color");
|
||||||
int icon_font_color_setting = get("interface/theme/icon_and_font_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() {
|
void EditorSettings::list_text_editor_themes() {
|
||||||
|
|
|
@ -867,7 +867,9 @@ Ref<Texture> EditorFontPreviewPlugin::generate_from_path(const String &p_path, c
|
||||||
|
|
||||||
Ref<Font> font = sampled_font;
|
Ref<Font> font = sampled_font;
|
||||||
|
|
||||||
font->draw(canvas_item, pos, sampled_text);
|
const Color c = GLOBAL_GET("rendering/environment/default_clear_color");
|
||||||
|
const float fg = c.get_luminance() < 0.5 ? 1.0 : 0.0;
|
||||||
|
font->draw(canvas_item, pos, sampled_text, Color(fg, fg, fg));
|
||||||
|
|
||||||
preview_done.clear();
|
preview_done.clear();
|
||||||
VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture
|
VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture
|
||||||
|
|
Loading…
Reference in a new issue