diff --git a/COPYRIGHT.txt b/COPYRIGHT.txt index 011514ef0482..7bb65dced4df 100644 --- a/COPYRIGHT.txt +++ b/COPYRIGHT.txt @@ -157,6 +157,11 @@ Copyright: 2018, Source Foundry Authors 2003, Bitstream Inc. License: Expat and Bitstream Vera Fonts Copyright +Files: ./thirdparty/fonts/Tamsyn*.png +Comment: Tamsyn font +Copyright: 2015, Scott Fial +License: Tamsyn + Files: ./thirdparty/freetype/ Comment: The FreeType Project Copyright: 1996-2020, David Turner, Robert Wilhelm, and Werner Lemberg. @@ -169,6 +174,33 @@ Copyright: 2015-2020 Google, Inc. 2002, NVIDIA Corporation. License: glslang +Files: ./thirdparty/graphite/ +Comment: Graphite engine +Copyright: 2010, SIL International +License: MPL-2.0 + +Files: ./thirdparty/harfbuzz/ +Comment: HarfBuzz text shaping library +Copyright: 2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020 Google, Inc. + 2018,2019,2020 Ebrahim Byagowi + 2019,2020 Facebook, Inc. + 2012 Mozilla Foundation + 2011 Codethink Limited + 2008,2010 Nokia Corporation and/or its subsidiary(-ies) + 2009 Keith Stribley + 2009 Martin Hosken and SIL International + 2007 Chris Wilson + 2006 Behdad Esfahbod + 2005 David Turner + 2004,2007,2008,2009,2010 Red Hat, Inc. + 1998-2004 David Turner and Werner Lemberg +License: HarfBuzz + +Files: ./thirdparty/icu4c/ +Comment: International Components for Unicode +Copyright: 1991-2020, Unicode +License: Unicode + Files: ./thirdparty/jpeg_compressor/ Comment: jpeg-compressor Copyright: 2012, Rich Geldreich @@ -1175,6 +1207,46 @@ License: FTL Robert Wilhelm Werner Lemberg +License: HarfBuzz + HarfBuzz is licensed under the so-called "Old MIT" license. Details follow. + For parts of HarfBuzz that are licensed under different licenses see individual + files names COPYING in subdirectories where applicable. + . + Copyright (C) 2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020 Google, Inc. + Copyright (C) 2018,2019,2020 Ebrahim Byagowi + Copyright (C) 2019,2020 Facebook, Inc. + Copyright (C) 2012 Mozilla Foundation + Copyright (C) 2011 Codethink Limited + Copyright (C) 2008,2010 Nokia Corporation and/or its subsidiary(-ies) + Copyright (C) 2009 Keith Stribley + Copyright (C) 2009 Martin Hosken and SIL International + Copyright (C) 2007 Chris Wilson + Copyright (C) 2006 Behdad Esfahbod + Copyright (C) 2005 David Turner + Copyright (C) 2004,2007,2008,2009,2010 Red Hat, Inc. + Copyright (C) 1998-2004 David Turner and Werner Lemberg + . + For full copyright notices consult the individual files in the package. + . + . + Permission is hereby granted, without written agreement and without + license or royalty fees, to use, copy, modify, and distribute this + software and its documentation for any purpose, provided that the + above copyright notice and the following two paragraphs appear in + all copies of this software. + . + IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + DAMAGE. + . + THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + License: MPL-2.0 Mozilla Public License Version 2.0 ================================== @@ -1633,6 +1705,53 @@ License: OFL-1.1 DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE. +License: Tamsyn + Tamsyn font is free. You are hereby granted permission to use, copy, modify, + and distribute it as you see fit. + . + Tamsyn font is provided "as is" without any express or implied warranty. + . + The author makes no representations about the suitability of this font for + a particular purpose. + . + In no event will the author be held liable for damages arising from the use + of this font. + +License: Unicode + COPYRIGHT AND PERMISSION NOTICE (ICU 58 and later) + . + Copyright (C) 1991-2020 Unicode, Inc. All rights reserved. + Distributed under the Terms of Use in https://www.unicode.org/copyright.html. + . + Permission is hereby granted, free of charge, to any person obtaining + a copy of the Unicode data files and any associated documentation + (the "Data Files") or Unicode software and any associated documentation + (the "Software") to deal in the Data Files or Software + without restriction, including without limitation the rights to use, + copy, modify, merge, publish, distribute, and/or sell copies of + the Data Files or Software, and to permit persons to whom the Data Files + or Software are furnished to do so, provided that either + (a) this copyright and permission notice appear with all copies + of the Data Files or Software, or + (b) this copyright and permission notice appear in associated + Documentation. + . + THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF + ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT OF THIRD PARTY RIGHTS. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS + NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL + DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + PERFORMANCE OF THE DATA FILES OR SOFTWARE. + . + Except as contained in this notice, the name of a copyright holder + shall not be used in advertising or otherwise to promote the sale, + use or other dealings in these Data Files or Software without prior + written authorization of the copyright holder. + License: Zlib This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff --git a/SConstruct b/SConstruct index d82ceb514b23..10f961cff8fa 100644 --- a/SConstruct +++ b/SConstruct @@ -144,6 +144,9 @@ opts.Add(BoolVariable("builtin_certs", "Use the built-in SSL certificates bundle opts.Add(BoolVariable("builtin_enet", "Use the built-in ENet library", True)) opts.Add(BoolVariable("builtin_freetype", "Use the built-in FreeType library", True)) opts.Add(BoolVariable("builtin_glslang", "Use the built-in glslang library", True)) +opts.Add(BoolVariable("builtin_graphite", "Use the built-in Graphite library", True)) +opts.Add(BoolVariable("builtin_harfbuzz", "Use the built-in HarfBuzz library", True)) +opts.Add(BoolVariable("builtin_icu", "Use the built-in ICU library", True)) opts.Add(BoolVariable("builtin_libogg", "Use the built-in libogg library", True)) opts.Add(BoolVariable("builtin_libpng", "Use the built-in libpng library", True)) opts.Add(BoolVariable("builtin_libtheora", "Use the built-in libtheora library", True)) diff --git a/core/core_constants.cpp b/core/core_constants.cpp index 57ea10c07460..db22a9ecf6d8 100644 --- a/core/core_constants.cpp +++ b/core/core_constants.cpp @@ -128,6 +128,7 @@ void register_global_constants() { BIND_CORE_ENUM_CONSTANT(HALIGN_LEFT); BIND_CORE_ENUM_CONSTANT(HALIGN_CENTER); BIND_CORE_ENUM_CONSTANT(HALIGN_RIGHT); + BIND_CORE_ENUM_CONSTANT(HALIGN_FILL); BIND_CORE_ENUM_CONSTANT(VALIGN_TOP); BIND_CORE_ENUM_CONSTANT(VALIGN_CENTER); diff --git a/core/math/math_defs.h b/core/math/math_defs.h index 5192722839d8..4d97f72ebf5e 100644 --- a/core/math/math_defs.h +++ b/core/math/math_defs.h @@ -73,7 +73,8 @@ enum Orientation { enum HAlign { HALIGN_LEFT, HALIGN_CENTER, - HALIGN_RIGHT + HALIGN_RIGHT, + HALIGN_FILL, }; enum VAlign { diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index d29bcd011f1d..9252ba0840b0 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -47,6 +47,7 @@ void MainLoop::_bind_methods() { BIND_CONSTANT(NOTIFICATION_APPLICATION_PAUSED); BIND_CONSTANT(NOTIFICATION_APPLICATION_FOCUS_IN); BIND_CONSTANT(NOTIFICATION_APPLICATION_FOCUS_OUT); + BIND_CONSTANT(NOTIFICATION_TEXT_SERVER_CHANGED); ADD_SIGNAL(MethodInfo("on_request_permissions_result", PropertyInfo(Variant::STRING, "permission"), PropertyInfo(Variant::BOOL, "granted"))); }; diff --git a/core/os/main_loop.h b/core/os/main_loop.h index 8c46ad9b6ae0..7bc91fbb83ca 100644 --- a/core/os/main_loop.h +++ b/core/os/main_loop.h @@ -56,6 +56,7 @@ class MainLoop : public Object { NOTIFICATION_APPLICATION_PAUSED = 2015, NOTIFICATION_APPLICATION_FOCUS_IN = 2016, NOTIFICATION_APPLICATION_FOCUS_OUT = 2017, + NOTIFICATION_TEXT_SERVER_CHANGED = 2018, }; virtual void init(); diff --git a/core/string/translation.cpp b/core/string/translation.cpp index df8a26e5ce49..7b8c28e2e2d8 100644 --- a/core/string/translation.cpp +++ b/core/string/translation.cpp @@ -34,6 +34,11 @@ #include "core/io/resource_loader.h" #include "core/os/os.h" +#ifdef TOOLS_ENABLED +#include "editor/editor_settings.h" +#include "main/main.h" +#endif + // ISO 639-1 language codes, with the addition of glibc locales with their // regional identifiers. This list must match the language names (in English) // of locale_names. @@ -1214,6 +1219,22 @@ void TranslationServer::set_tool_translation(const Ref &p_translati tool_translation = p_translation; } +Ref TranslationServer::get_tool_translation() const { + return tool_translation; +} + +String TranslationServer::get_tool_locale() { +#ifdef TOOLS_ENABLED + if (TranslationServer::get_singleton()->get_tool_translation().is_valid() && (Engine::get_singleton()->is_editor_hint() || Main::is_project_manager())) { + return tool_translation->get_locale(); + } else { +#else + { +#endif + return get_locale(); + } +} + StringName TranslationServer::tool_translate(const StringName &p_message, const StringName &p_context) const { if (tool_translation.is_valid()) { StringName r = tool_translation->get_message(p_message, p_context); diff --git a/core/string/translation.h b/core/string/translation.h index 8d34f7997e4c..c7ffe4d065f2 100644 --- a/core/string/translation.h +++ b/core/string/translation.h @@ -110,7 +110,9 @@ class TranslationServer : public Object { static String standardize_locale(const String &p_locale); static String get_language_code(const String &p_locale); + String get_tool_locale(); void set_tool_translation(const Ref &p_translation); + Ref get_tool_translation() const; StringName tool_translate(const StringName &p_message, const StringName &p_context = "") const; StringName tool_translate_plural(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context = "") const; void set_doc_translation(const Ref &p_translation); diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 213578485e92..d630e987ea9b 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -209,7 +209,6 @@ void CharString::copy_from(const char *p_cstr) { /* String */ /*************************************************************************/ -//TODO: move to TextServer //kind of poor should be rewritten properly String String::word_wrap(int p_chars_per_line) const { int from = 0; @@ -4796,7 +4795,7 @@ Vector String::to_utf16_buffer() const { Char16String charstr = s->utf16(); Vector retval; - size_t len = charstr.length() * 2; + size_t len = charstr.length() * sizeof(char16_t); retval.resize(len); uint8_t *w = retval.ptrw(); copymem(w, (const void *)charstr.ptr(), len); @@ -4811,7 +4810,7 @@ Vector String::to_utf32_buffer() const { } Vector retval; - size_t len = s->length() * 4; + size_t len = s->length() * sizeof(char32_t); retval.resize(len); uint8_t *w = retval.ptrw(); copymem(w, (const void *)s->ptr(), len); diff --git a/core/string/ustring.h b/core/string/ustring.h index bfae16fe647c..7ff78b2d86b6 100644 --- a/core/string/ustring.h +++ b/core/string/ustring.h @@ -28,8 +28,9 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef USTRING_H -#define USTRING_H +#ifndef USTRING_GODOT_H +#define USTRING_GODOT_H +// Note: Renamed to avoid conflict with ICU header with the same name. #include "core/templates/cowdata.h" #include "core/templates/vector.h" @@ -555,4 +556,4 @@ _FORCE_INLINE_ Vector sarray(P... p_args) { return arr; } -#endif // USTRING_H +#endif // USTRING_GODOT_H diff --git a/core/templates/hashfuncs.h b/core/templates/hashfuncs.h index 86bb1b5228e1..1ed9ab198761 100644 --- a/core/templates/hashfuncs.h +++ b/core/templates/hashfuncs.h @@ -114,6 +114,24 @@ static inline uint32_t make_uint32_t(T p_in) { return _u._u32; } +static inline uint64_t hash_djb2_one_float_64(double p_in, uint64_t p_prev = 5381) { + union { + double d; + uint64_t i; + } u; + + // Normalize +/- 0.0 and NaN values so they hash the same. + if (p_in == 0.0f) { + u.d = 0.0; + } else if (Math::is_nan(p_in)) { + u.d = Math_NAN; + } else { + u.d = p_in; + } + + return ((p_prev << 5) + p_prev) + u.i; +} + static inline uint64_t hash_djb2_one_64(uint64_t p_in, uint64_t p_prev = 5381) { return ((p_prev << 5) + p_prev) + p_in; } diff --git a/core/templates/lru.h b/core/templates/lru.h new file mode 100644 index 000000000000..d02c4337d144 --- /dev/null +++ b/core/templates/lru.h @@ -0,0 +1,126 @@ +/*************************************************************************/ +/* lru.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef LRU_H +#define LRU_H + +#include "core/math/math_funcs.h" +#include "hash_map.h" +#include "list.h" + +template +class LRUCache { +private: + struct Pair { + TKey key; + TData data; + + Pair() {} + Pair(const TKey &p_key, const TData &p_data) : + key(p_key), + data(p_data) { + } + }; + + typedef typename List::Element *Element; + + List _list; + HashMap _map; + size_t capacity; + +public: + const TData *insert(const TKey &p_key, const TData &p_value) { + Element *e = _map.getptr(p_key); + Element n = _list.push_front(Pair(p_key, p_value)); + + if (e) { + _list.erase(*e); + _map.erase(p_key); + } + _map[p_key] = _list.front(); + + while (_map.size() > capacity) { + Element d = _list.back(); + _map.erase(d->get().key); + _list.pop_back(); + } + + return &n->get().data; + } + + void clear() { + _map.clear(); + _list.clear(); + } + + bool has(const TKey &p_key) const { + return _map.getptr(p_key); + } + + const TData &get(const TKey &p_key) { + Element *e = _map.getptr(p_key); + CRASH_COND(!e); + _list.move_to_front(*e); + return (*e)->get().data; + }; + + const TData *getptr(const TKey &p_key) { + Element *e = _map.getptr(p_key); + if (!e) { + return nullptr; + } else { + _list.move_to_front(*e); + return &(*e)->get().data; + } + } + + _FORCE_INLINE_ size_t get_capacity() const { return capacity; } + + void set_capacity(size_t p_capacity) { + if (capacity > 0) { + capacity = p_capacity; + while (_map.size() > capacity) { + Element d = _list.back(); + _map.erase(d->get().key); + _list.pop_back(); + } + } + } + + LRUCache() { + capacity = 64; + } + + LRUCache(int p_capacity) { + capacity = p_capacity; + } +}; + +#endif diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 13514b7b9ff9..214c42401350 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -418,7 +418,7 @@ struct _VariantCall { String s; if (p_instance->size() > 0) { const uint8_t *r = p_instance->ptr(); - s.parse_utf16((const char16_t *)r, p_instance->size() / 2); + s.parse_utf16((const char16_t *)r, floor((double)p_instance->size() / (double)sizeof(char16_t))); } return s; } @@ -427,7 +427,7 @@ struct _VariantCall { String s; if (p_instance->size() > 0) { const uint8_t *r = p_instance->ptr(); - s = String((const char32_t *)r, p_instance->size() / 4); + s = String((const char32_t *)r, floor((double)p_instance->size() / (double)sizeof(char32_t))); } return s; } diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index f6b8e0da1942..0216d2ba3500 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -1236,6 +1236,9 @@ The [ResourceSaver] singleton. + + The [TextServerManager] singleton. + The [TranslationServer] singleton. @@ -1286,6 +1289,9 @@ Horizontal right alignment, usually for text-derived classes. + + Expand row to fit width, usually for text-derived classes. + Vertical top alignment, usually for text-derived classes. diff --git a/doc/classes/BitmapFont.xml b/doc/classes/BitmapFont.xml deleted file mode 100644 index 87cffdaca063..000000000000 --- a/doc/classes/BitmapFont.xml +++ /dev/null @@ -1,112 +0,0 @@ - - - - Renders text using fonts under the [url=https://www.angelcode.com/products/bmfont/]BMFont[/url] format. - Handles files with the [code].fnt[/code] extension. - - - Renders text using [code]*.fnt[/code] fonts containing texture atlases. Supports distance fields. For using vector font files like TTF directly, see [DynamicFont]. - - - - - - - - - - - - - - - - - - - Adds a character to the font, where [code]character[/code] is the Unicode value, [code]texture[/code] is the texture index, [code]rect[/code] is the region in the texture (in pixels!), [code]align[/code] is the (optional) alignment for the character and [code]advance[/code] is the (optional) advance. - - - - - - - - - - - - - Adds a kerning pair to the [BitmapFont] as a difference. Kerning pairs are special cases where a typeface advance is determined by the next character. - - - - - - - - - Adds a texture to the [BitmapFont]. - - - - - - - Clears all the font data and settings. - - - - - - - - - Creates a BitmapFont from the [code]*.fnt[/code] file at [code]path[/code]. - - - - - - - - - - - Returns a kerning pair as a difference. - - - - - - - - - Returns the font atlas texture at index [code]idx[/code]. - - - - - - - Returns the number of textures in the BitmapFont atlas. - - - - - - Ascent (number of pixels above the baseline). - - - If [code]true[/code], distance field hint is enabled. - - - The fallback font. - - - Total font height (ascent plus descent) in pixels. - - - - - diff --git a/doc/classes/Button.xml b/doc/classes/Button.xml index df47fa8bec92..e47198a381ef 100644 --- a/doc/classes/Button.xml +++ b/doc/classes/Button.xml @@ -40,6 +40,33 @@ https://godotengine.org/asset-library/asset/677 + + + + + Removes all OpenType features. + + + + + + + + + Returns OpenType feature [code]tag[/code]. + + + + + + + + + + + Sets OpenType feature [code]tag[/code]. More info: [url=https://docs.microsoft.com/en-us/typography/opentype/spec/featuretags]OpenType feature tags[/url]. + + @@ -57,9 +84,15 @@ Button's icon, if text is present the icon will be placed before the text. + + Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead. + The button's text that will be displayed inside the button's area. + + Base text writing direction. + @@ -94,6 +127,12 @@ Text [Color] used when the [Button] is being pressed. + + Text oubline [Color] of the [Button]. + + + Font size of the [Button]'s text. + [StyleBox] used when the [Button] is being hovered. @@ -103,6 +142,9 @@ Default [StyleBox] for the [Button]. + + Size of the [Button]'s text outline. + [StyleBox] used when the [Button] is being pressed. diff --git a/doc/classes/CanvasItem.xml b/doc/classes/CanvasItem.xml index 8efa1adae8c3..d715cf5e493c 100644 --- a/doc/classes/CanvasItem.xml +++ b/doc/classes/CanvasItem.xml @@ -45,18 +45,24 @@ Draws an arc between the given angles. The larger the value of [code]point_count[/code], the smoother the curve. - + - + - + + + + + + + - + Draws a string character using a custom font. Returns the advance, depending on the character width and kerning with an optional next character. @@ -146,6 +152,35 @@ Draws multiple, parallel lines with a uniform [code]width[/code] and segment-by-segment coloring. Colors assigned to line segments match by index between [code]points[/code] and [code]colors[/code]. + + + + + + + + + + + + + + + + + + + + + + + + + + + Breaks [code]text[/code] to the lines and draws it using the specified [code]font[/code] at the [code]position[/code] (top-left corner). The text will have its color multiplied by [code]modulate[/code]. If [code]clip_w[/code] is greater than or equal to 0, the text will be clipped if it exceeds the specified width. + + @@ -253,18 +288,28 @@ Sets a custom transform for drawing via matrix. Anything drawn afterwards will be transformed by this. - + - + - + + + + + + + + + + + - + Draws [code]text[/code] using the specified [code]font[/code] at the [code]position[/code] (top-left corner). The text will have its color multiplied by [code]modulate[/code]. If [code]clip_w[/code] is greater than or equal to 0, the text will be clipped if it exceeds the specified width. @@ -275,17 +320,19 @@ # `default_font` declaration to a member variable assigned in `_ready()` # so the Control is only created once. var default_font = Control.new().get_font("font") - draw_string(default_font, Vector2(64, 64), "Hello world") + var default_font_size = Control.new().get_font_size("font_size") + draw_string(default_font, Vector2(64, 64), "Hello world", HALIGN_LEFT, -1, font_size) [/gdscript] [csharp] // If using this method in a script that redraws constantly, move the // `default_font` declaration to a member variable assigned in `_ready()` // so the Control is only created once. Font defaultFont = new Control().GetFont("font"); - DrawString(defaultFont, new Vector2(64, 64), "Hello world"); + int defaultFontSize = new Control().GetFontSize("font_size"); + DrawString(defaultFont, new Vector2(64, 64), "Hello world", HALIGN_LEFT, -1, defaultFontSize); [/csharp] [/codeblocks] - See also [method Font.draw]. + See also [method Font.draw_string]. diff --git a/doc/classes/CheckBox.xml b/doc/classes/CheckBox.xml index f912bb98c9f7..89fb960e881e 100644 --- a/doc/classes/CheckBox.xml +++ b/doc/classes/CheckBox.xml @@ -48,6 +48,9 @@ The [CheckBox] text's font color when it's pressed. + + Font size of the [CheckBox]'s text. + The [StyleBox] to display as a background when the [CheckBox] is hovered. diff --git a/doc/classes/CheckButton.xml b/doc/classes/CheckButton.xml index b4f91cf3a852..882f1c69f396 100644 --- a/doc/classes/CheckButton.xml +++ b/doc/classes/CheckButton.xml @@ -45,6 +45,9 @@ The [CheckButton] text's font color when it's pressed. + + Font size of the [CheckButton]'s text. + The [StyleBox] to display as a background when the [CheckButton] is hovered. @@ -58,16 +61,28 @@ The [StyleBox] to display as a background. - The icon to display when the [CheckButton] is unchecked. + The icon to display when the [CheckButton] is unchecked (for left-to-right layouts). - The icon to display when the [CheckButton] is unchecked and disabled. + The icon to display when the [CheckButton] is unchecked and disabled (for left-to-right layouts). + + + The icon to display when the [CheckButton] is unchecked and disabled (for right-to-left layouts). + + + The icon to display when the [CheckButton] is unchecked (for right-to-left layouts). - The icon to display when the [CheckButton] is checked. + The icon to display when the [CheckButton] is checked (for left-to-right layouts). - The icon to display when the [CheckButton] is checked and disabled. + The icon to display when the [CheckButton] is checked and disabled (for left-to-right layouts). + + + The icon to display when the [CheckButton] is checked and disabled (for right-to-left layouts). + + + The icon to display when the [CheckButton] is checked (for right-to-left layouts). The [StyleBox] to display as a background when the [CheckButton] is pressed. diff --git a/doc/classes/CodeEdit.xml b/doc/classes/CodeEdit.xml index f6bc9e2ccac6..8834ff82c672 100644 --- a/doc/classes/CodeEdit.xml +++ b/doc/classes/CodeEdit.xml @@ -3,6 +3,7 @@ + [b]Note[/b]: By default [CodeEdit] always use left-to-right text direction to correcly display source code. @@ -109,6 +110,9 @@ + + + @@ -179,6 +183,9 @@ + + Font size of the [CodeEdit]'s text. + diff --git a/doc/classes/ColorPickerButton.xml b/doc/classes/ColorPickerButton.xml index 76cc49a0432a..c04e8b9ea0fd 100644 --- a/doc/classes/ColorPickerButton.xml +++ b/doc/classes/ColorPickerButton.xml @@ -82,6 +82,9 @@ Text [Color] used when the [ColorPickerButton] is being pressed. + + Font size of the [ColorPickerButton]'s text. + [StyleBox] used when the [ColorPickerButton] is being hovered. diff --git a/doc/classes/Control.xml b/doc/classes/Control.xml index eb0b941da563..ae1a8d86a71c 100644 --- a/doc/classes/Control.xml +++ b/doc/classes/Control.xml @@ -121,6 +121,18 @@ [/codeblocks] + + + + + + + + + User defined BiDi algorithm override function. + Return [code]Array[/code] of [code]Vector2i[/code] text ranges, in the left-to-right order. Ranges should cover full source [code]text[/code] without overlaps. BiDi algorithm will be used on each range separately. + + @@ -179,6 +191,17 @@ Overrides the font with given [code]name[/code] in the [member theme] resource the control uses. If [code]font[/code] is [code]null[/code] or invalid, the override is cleared and the font from assigned [Theme] is used. + + + + + + + + + Overrides the font size with given [code]name[/code] in the [member theme] resource the control uses. If [code]font_size[/code] is [code]-1[/code], the override is cleared and the font size from assigned [Theme] is used. + + @@ -443,7 +466,7 @@ - + Returns a color from assigned [Theme] with given [code]name[/code] and associated with [Control] of given [code]node_type[/code]. @@ -466,7 +489,7 @@ - + Returns a constant from assigned [Theme] with given [code]name[/code] and associated with [Control] of given [code]node_type[/code]. @@ -477,18 +500,29 @@ - + Returns a font from assigned [Theme] with given [code]name[/code] and associated with [Control] of given [code]node_type[/code]. + + + + + + + + + Returns a font size from assigned [Theme] with given [code]name[/code] and associated with [Control] of given [code]type[/code]. + + - + Returns an icon from assigned [Theme] with given [code]name[/code] and associated with [Control] of given [code]node_type[/code]. @@ -499,7 +533,7 @@ - + Returns a [StyleBox] from assigned [Theme] with given [code]name[/code] and associated with [Control] of given [code]node_type[/code]. @@ -563,7 +597,7 @@ - + Returns [code]true[/code] if [Color] with given [code]name[/code] and associated with [Control] of given [code]node_type[/code] exists in assigned [Theme]. @@ -583,7 +617,7 @@ - + Returns [code]true[/code] if constant with given [code]name[/code] and associated with [Control] of given [code]node_type[/code] exists in assigned [Theme]. @@ -603,7 +637,7 @@ - + Returns [code]true[/code] if font with given [code]name[/code] and associated with [Control] of given [code]node_type[/code] exists in assigned [Theme]. @@ -618,12 +652,32 @@ Returns [code]true[/code] if font with given [code]name[/code] has a valid override in this [Control] node. + + + + + + + + + Returns [code]true[/code] if font size with given [code]name[/code] and associated with [Control] of given [code]type[/code] exists in assigned [Theme]. + + + + + + + + + Returns [code]true[/code] if font size with given [code]name[/code] has a valid override in this [Control] node. + + - + Returns [code]true[/code] if icon with given [code]name[/code] and associated with [Control] of given [code]node_type[/code] exists in assigned [Theme]. @@ -652,7 +706,7 @@ - + Returns [code]true[/code] if [StyleBox] with given [code]name[/code] and associated with [Control] of given [code]node_type[/code] exists in assigned [Theme]. @@ -667,6 +721,13 @@ Returns [code]true[/code] if [StyleBox] with given [code]name[/code] has a valid override in this [Control] node. + + + + + Returns [code]true[/code] if layout is right-to-left. + + @@ -1015,6 +1076,9 @@ [/csharp] [/codeblocks] + + Controls layout direction and text writing direction. Right-to-left layouts are necessary for certain languages (e.g. Arabic and Hebrew). + Distance between the node's bottom edge and its parent control, based on [member anchor_bottom]. Margins are often controlled by one or multiple parent [Container] nodes, so you should not modify them manually if your node is a direct child of a [Container]. Margins update automatically when you move or resize the node. @@ -1159,6 +1223,9 @@ Sent when this node is inside a [ScrollContainer] which has stopped being scrolled. + + Sent when control layout direction is changed. + Show the system's arrow mouse cursor when the user hovers the node. Use with [member mouse_default_cursor_shape]. @@ -1309,5 +1376,51 @@ Snaps one of the 4 anchor's sides to the end of the node's [code]Rect[/code], in the bottom right. Use it with one of the [code]anchor_*[/code] member variables, like [member anchor_left]. To change all 4 anchors at once, use [method set_anchors_preset]. + + Automatic layout direction, determined from the parent control layout direction. + + + Automatic layout direction, determined from the current locale. + + + Left-to-right layout direction. + + + Right-to-left layout direction. + + + Text writing direction is the same as layout direction. + + + Automatic text writing direction, determined from the current locale and text content. + + + Left-to-right text writing direction. + + + Right-to-left text writing direction. + + + Use default behavior. Same as [code]STRUCTURED_TEXT_NONE[/code] unless specified otherwise in the control description. + + + BiDi override for URI. + + + BiDi override for file path. + + + BiDi override for email. + + + BiDi override for lists. + Structured text options: list separator [code]String[/code]. + + + Use default Unicode BiDi algorithm. + + + User defined structured text BiDi override function. + diff --git a/doc/classes/DynamicFont.xml b/doc/classes/DynamicFont.xml deleted file mode 100644 index d2d0c5476194..000000000000 --- a/doc/classes/DynamicFont.xml +++ /dev/null @@ -1,146 +0,0 @@ - - - - DynamicFont renders vector font files at runtime. - - - DynamicFont renders vector font files (such as TTF or OTF) dynamically at runtime instead of using a prerendered texture atlas like [BitmapFont]. This trades the faster loading time of [BitmapFont]s for the ability to change font parameters like size and spacing during runtime. [DynamicFontData] is used for referencing the font file paths. DynamicFont also supports defining one or more fallback fonts, which will be used when displaying a character not supported by the main font. - DynamicFont uses the [url=https://www.freetype.org/]FreeType[/url] library for rasterization. - [codeblocks] - [gdscript] - var dynamic_font = DynamicFont.new() - dynamic_font.font_data = load("res://BarlowCondensed-Bold.ttf") - dynamic_font.size = 64 - $"Label".set("custom_fonts/font", dynamic_font) - [/gdscript] - [csharp] - var dynamicFont = new DynamicFont(); - dynamicFont.FontData = ResourceLoader.Load<DynamicFontData>("res://BarlowCondensed-Bold.ttf"); - dynamicFont.Size = 64; - GetNode("Label").Set("custom_fonts/font", dynamicFont); - [/csharp] - [/codeblocks] - [b]Note:[/b] DynamicFont doesn't support features such as kerning, right-to-left typesetting, ligatures, text shaping, variable fonts and optional font features yet. If you wish to "bake" an optional font feature into a TTF font file, you can use [url=https://fontforge.org/]FontForge[/url] to do so. In FontForge, use [b]File > Generate Fonts[/b], click [b]Options[/b], choose the desired features then generate the font. - - - https://godotengine.org/asset-library/asset/676 - - - - - - - - - Adds a fallback font. - - - - - - - Returns a string containing all the characters available in the main and all the fallback fonts. - If a given character is included in more than one font, it appears only once in the returned string. - - - - - - - - - Returns the fallback font at index [code]idx[/code]. - - - - - - - Returns the number of fallback fonts. - - - - - - - - - Returns the spacing for the given [code]type[/code] (see [enum SpacingType]). - - - - - - - - - Removes the fallback font at index [code]idx[/code]. - - - - - - - - - - - Sets the fallback font at index [code]idx[/code]. - - - - - - - - - - - Sets the spacing for [code]type[/code] (see [enum SpacingType]) to [code]value[/code] in pixels (not relative to the font size). - - - - - - Extra spacing at the bottom in pixels. - - - Extra spacing for each character in pixels. - This can be a negative number to make the distance between characters smaller. - - - Extra spacing for the space character (in addition to [member extra_spacing_char]) in pixels. - This can be a negative number to make the distance between words smaller. - - - Extra spacing at the top in pixels. - - - The font data. - - - The font outline's color. - [b]Note:[/b] It's recommended to leave this at the default value so that you can adjust it in individual controls. For example, if the outline is made black here, it won't be possible to change its color using a Label's font outline modulate theme item. - - - The font outline's thickness in pixels (not relative to the font size). - - - The font size in pixels. - - - - - Spacing at the top. - - - Spacing at the bottom. - - - Spacing for each character. - - - Spacing for the space character. - - - diff --git a/doc/classes/DynamicFontData.xml b/doc/classes/DynamicFontData.xml deleted file mode 100644 index 45585f17e006..000000000000 --- a/doc/classes/DynamicFontData.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - Used with [DynamicFont] to describe the location of a font file. - - - Used with [DynamicFont] to describe the location of a vector font file for dynamic rendering at runtime. - - - https://godotengine.org/asset-library/asset/676 - - - - - - If [code]true[/code], the font is rendered with anti-aliasing. This property applies both to the main font and its outline (if it has one). - - - The path to the vector font file. - - - The font hinting mode used by FreeType. See [enum Hinting] for options. - - - - - Disables font hinting (smoother but less crisp). - - - Use the light font hinting mode. - - - Use the default font hinting mode (crisper but less smooth). - - - diff --git a/doc/classes/Font.xml b/doc/classes/Font.xml index f49fbf0d2a4a..edd2bd137fc0 100644 --- a/doc/classes/Font.xml +++ b/doc/classes/Font.xml @@ -1,60 +1,167 @@ - Internationalized font and text drawing support. + Font class is set of font data sources used to draw text. - Font contains a Unicode-compatible character set, as well as the ability to draw it with variable width, ascent, descent and kerning. For creating fonts from TTF files (or other font formats), see the editor support for fonts. - [b]Note:[/b] If a DynamicFont doesn't contain a character used in a string, the character in question will be replaced with codepoint [code]0xfffd[/code] if it's available in the DynamicFont. If this replacement character isn't available in the DynamicFont, the character will be hidden without displaying any replacement character in the string. - [b]Note:[/b] If a BitmapFont doesn't contain a character used in a string, the character in question will be hidden without displaying any replacement character in the string. + Font contains a set of glyphs to represent Unicode characters, as well as the ability to draw it with variable width, ascent, descent and kerning. + [b]Note:[/b] A character is a symbol that represents an item (letter, digit etc.) in an abstract way. + [b]Note:[/b] A glyph is a bitmap or shape used to draw a one or more characters in a context-dependent manner. Glyph indices are bound to the specific font data source. + [b]Note:[/b] If a non of the font data sources contain glyphs for a character used in a string, the character in question will be replaced with a box displaying its hexadecimal code. + [codeblocks] + [gdscript] + var font = Font.new() + font.add_data(load("res://BarlowCondensed-Bold.ttf")) + $"Label".set("custom_fonts/font", font) + $"Label".set("custom_fonts/font_size", 64) + [/gdscript] + [csharp] + var font = new Font(); + font.AddData(ResourceLoader.Load<FontData>("res://BarlowCondensed-Bold.ttf")); + GetNode("Label").Set("custom_fonts/font", font); + GetNode("Label").Set("custom_font_sizes/font_size", 64); + [/csharp] + [/codeblocks] + To control font substitution priority use [FontData] language and script support. + Use language overrides to use same [Font] stack for multiple languages: + [codeblocks] + [gdscript] + # Use Naskh font for Persian and Nastaʼlīq font for Urdu text. + var font_data_fa = load("res://NotoNaskhArabicUI_Regular.ttf"); + font_data_fa.set_language_support_override("fa", true); + font_data_fa.set_language_support_override("ur", false); + + var font_data_ur = load("res://NotoNastaliqUrdu_Regular.ttf"); + font_data_ur.set_language_support_override("fa", false); + font_data_ur.set_language_support_override("ur", true); + [/gdscript] + [csharp] + // Use Naskh font for Persian and Nastaʼlīq font for Urdu text. + var fontDataFA = ResourceLoader.Load<FontData>("res://NotoNaskhArabicUI_Regular.ttf"); + fontDataFA.SetLanguageSupportOverride("fa", true); + fontDataFA.SetLanguageSupportOverride("ur", false); + + var fontDataUR = ResourceLoader.Load<FontData>("res://NotoNastaliqUrdu_Regular.ttf"); + fontDataUR.SetLanguageSupportOverride("fa", false); + fontDataUR.SetLanguageSupportOverride("ur", true); + [/csharp] + [/codeblocks] + Use script overrides to specify supported scripts for bitmap font or for less common scripts not directly supported by TrueType format: + [codeblocks] + [gdscript] + # Use specified font for Egyptian hieroglyphs. + var font_data = load("res://unifont.ttf"); + font_data.set_script_support_override("Egyp", true); + [/gdscript] + [csharp] + // Use specified font for Egyptian hieroglyphs. + var fontData = ResourceLoader.Load<FontData>("res://unifont.ttf"); + fontData.SetScriptSupportOverride("Egyp", true); + [/csharp] + [/codeblocks] - + + + + + Add font data source to the set. + + + + + - + + + + + - + - + - + - + - Draw [code]string[/code] into a canvas item using the font at a given position, with [code]modulate[/code] color, and optionally clipping the width. [code]position[/code] specifies the baseline, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis. - See also [method CanvasItem.draw_string]. + Draw a single Unicode character [code]char[/code] into a canvas item using the font, at a given position, with [code]modulate[/code] color, and optionally kerning if [code]next[/code] is passed. [code]position[/code] specifies the baseline, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis. + [b]Note:[/b] Do not use this function to draw strings character by character, use [method draw_string] or [TextLine] instead. - - + + - + - + + + + + + + + + + + + + + + + + + + + Breaks [code]text[/code] to the lines using rules specified by [code]flags[/code] and draws it into a canvas item using the font, at a given position, with [code]modulate[/code] color, optionally clipping the width and aligning horizontally. [code]position[/code] specifies the baseline of the first line, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis. + See also [method CanvasItem.draw_multiline_string]. + + + + + + + + + + + + + + + + + + - + - + - + - Draw character [code]char[/code] into a canvas item using the font at a given position, with [code]modulate[/code] color, and optionally kerning if [code]next[/code] is passed. clipping the width. [code]position[/code] specifies the baseline, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis. The width used by the character is returned, making this function useful for drawing strings character by character. + Draw [code]text[/code] into a canvas item using the font, at a given position, with [code]modulate[/code] color, optionally clipping the width and aligning horizontally. [code]position[/code] specifies the baseline, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis. + See also [method CanvasItem.draw_string]. + + - Returns the font ascent (number of pixels above the baseline). + Returns the average font ascent (number of pixels above the baseline). + [b]Note:[/b] Real ascent of the string is context-dependent and can be significantly different from the value returned by this function. Use it only as rough estimate (e.g. as the ascent of empty line). @@ -64,65 +171,176 @@ + + Returns the size of a character, optionally taking kerning into account if the next character is provided. + [b]Note:[/b] Do not use this function to calculate width of the string character by character, use [method get_string_size] or [TextLine] instead. + + + + + + + + + Returns the font data source at index [code]idx[/code]. If the index does not exist, returns [code]null[/code]. + + + + + + + Returns the number of font data sources. + + - Returns the font descent (number of pixels below the baseline). + Returns the average font descent (number of pixels below the baseline). + [b]Note:[/b] Real descent of the string is context-dependent and can be significantly different from the value returned by this function. Use it only as rough estimate (e.g. as the descent of empty line). + + - Returns the total font height (ascent plus descent) in pixels. + Returns the total average font height (ascent plus descent) in pixels. + [b]Note:[/b] Real height of the string is context-dependent and can be significantly different from the value returned by this function. Use it only as rough estimate (e.g. as the height of empty line). - + - + + + + + + + + + + Returns the size of a bounding box of a string broken into the lines, taking kerning and advance into account. + See also [method draw_multiline_string]. + + + + + + - Returns the size of a string, taking kerning and advance into account. + Returns the spacing for the given [code]type[/code] (see [enum SpacingType]). - + - + - + - Returns the size that the string would have with word wrapping enabled with a fixed [code]width[/code]. + Returns the size size of a bounding box of a string, taking kerning and advance into account. + See also [method draw_string]. - - + + + + + Returns a string containing all the characters available in the font. + If a given character is included in more than one font data source, it appears only once in the returned string. + + + + + + - Returns [code]true[/code] if the font has an outline. + Return average pixel offset of the underline below the baseline. + [b]Note:[/b] Real underline position of the string is context-dependent and can be significantly different from the value returned by this function. Use it only as rough estimate. - + + + + + + + Return average thickness of the underline. + [b]Note:[/b] Real underline thickness of the string is context-dependent and can be significantly different from the value returned by this function. Use it only as rough estimate. + + + + + + + Return [code]true[/code] if a Unicode [code]char[/code] is available in the font. + + + + + + + + + Removes the font data source at index [code]idx[/code]. If the index does not exist, nothing happens. + + + + + + + + + + + Sets the font data source at index [code]idx[/code]. If the index does not exist, nothing happens. + + + + + + + + + + Sets the spacing for [code]type[/code] (see [enum SpacingType]) to [code]value[/code] in pixels (not relative to the font size). - After editing a font (changing size, ascent, char rects, etc.). Call this function to propagate changes to controls that might use it. + After editing a font (changing data sources, etc.). Call this function to propagate changes to controls that might use it. + + + Extra spacing at the bottom in pixels. + + + Extra character spacing in pixels. + + + + Spacing at the top of the line. + + + Spacing at the bottom of the line. + diff --git a/doc/classes/FontData.xml b/doc/classes/FontData.xml new file mode 100644 index 000000000000..cee424394a24 --- /dev/null +++ b/doc/classes/FontData.xml @@ -0,0 +1,302 @@ + + + + Font data source, file or memory buffer. + + + Built-in text servers support font data sources of the following formats: + - Bitmap fonts in the [url=https://www.angelcode.com/products/bmfont/]BMFont[/url] format. Handles [code].fnt, *.font[/code] fonts containing texture atlases. Non-scalable. Supports distance fields. Complex text shaping support is limited. + - Dynamic fonts using the [url=https://www.freetype.org/]FreeType[/url] and [url=https://github.com/silnrsi/graphite/]Graphite[/url] library for rasterization. Handles [code]*.ttf, *.otf[/code] fonts. Scalable. Doesn't support distance fields. Supports complex text shaping and OpenType features. + + + + + + + + + + + + + + + + + + + Draws single glyph into a canvas item at the position, using [code]font[/code] at the size [code]size[/code]. + Returns advance of the glyph for horizontal and vertical layouts. + Note: Glyph index is bound to the font data, use only glyphs indices returned by [method TextServer.shaped_text_get_glyphs] or [method get_glyph_index] for this font data. + + + + + + + + + + + + + + + + + + + Draws single glyph outline of size [code]outline_size[/code] into a canvas item at the position, using [code]font[/code] at the size [code]size[/code]. If outline drawing is not supported, nothing is drawn. + Returns advance of the glyph for horizontal and vertical layouts (regardless of outline drawing support). + Note: Glyph index is bound to the font data, use only glyphs indices returned by [method TextServer.shaped_text_get_glyphs] or [method get_glyph_index] for this font data. + + + + + + + + + Returns the font ascent (number of pixels above the baseline). + + + + + + + Returns the base size of the font (the only size supported for non-scalable fonts, meaningless for scalable fonts). + + + + + + + + + Returns the font descent (number of pixels below the baseline). + + + + + + + + + + + Returns advance of the glyph for horizontal and vertical layouts. + Note: Glyph index is bound to the font data, use only glyphs indices returned by [method TextServer.shaped_text_get_glyphs] or [method get_glyph_index] for this font data. + + + + + + + + + + + Return the glyph index of a [code]char[/code], optionally modified by the [code]variation_selector[/code]. + + + + + + + + + + + + + Returns a kerning of the pair of glyphs for horizontal and vertical layouts. + Note: Glyph index is bound to the font data, use only glyphs indices returned by [method TextServer.shaped_text_get_glyphs] or [method get_glyph_index] for this font data. + + + + + + + + + Returns the total font height (ascent plus descent) in pixels. + + + + + + + + + Returns [code]true[/code] if support override is enabled for the [code]language[/code]. + + + + + + + Returns list of language support overrides. + + + + + + + + + Returns [code]true[/code] if support override is enabled for the [code]script[/code]. + + + + + + + Returns list of script support overrides. + + + + + + + Returns a string containing all the characters available in the font. + + + + + + + + + Returns underline offset (number of pixels below the baseline). + + + + + + + + + Returns underline thickness in pixels. + + + + + + + + + Return [code]true[/code] if a Unicode [code]char[/code] is available in the font. + + + + + + + Returns [code]true[/code], if font supports drawing glyph outlines. + + + + + + + + + Returns [code]true[/code], if font supports given language ([url=https://en.wikipedia.org/wiki/ISO_639-1]ISO 639[/url] code). + + + + + + + + + Returns [code]true[/code], if font supports given script ([url=https://en.wikipedia.org/wiki/ISO_15924]ISO 15924[/url] code). + + + + + + + + + + + + + Creates new font from the data in memory. + Note: For non-scalable fonts [code]base_size[/code] is ignored, use [method get_base_size] to check actual font size. + + + + + + + + + + + Creates new font from the file. + Note: For non-scalable fonts [code]base_size[/code] is ignored, use [method get_base_size] to check actual font size. + + + + + + + + + Remove language support override. + + + + + + + + + Removes script support override. + + + + + + + + + + + Adds override for [method is_language_supported]. + + + + + + + + + + + Adds override for [method is_script_supported]. + + + + + + If [code]true[/code], the font is rendered with anti-aliasing. + + + The path to the font data file. If font data was loaded from memory location is set to [code]"(Memory)"[/code]. + + + If [code]true[/code], distance field hint is enabled. + + + If [code]true[/code], default autohinter is used for font hinting. + + + The font hinting mode used by FreeType. See [enum TextServer.Hinting] for options. + + + + + diff --git a/doc/classes/GraphNode.xml b/doc/classes/GraphNode.xml index 33074536da3f..632d13893241 100644 --- a/doc/classes/GraphNode.xml +++ b/doc/classes/GraphNode.xml @@ -18,6 +18,13 @@ Disables all input and output slots of the GraphNode. + + + + + Removes all OpenType features. + + @@ -95,6 +102,15 @@ Returns the type of the output connection [code]idx[/code]. + + + + + + + Returns OpenType feature [code]tag[/code]. + + @@ -149,6 +165,17 @@ Returns [code]true[/code] if right (output) slot [code]idx[/code] is enabled, [code]false[/code] otherwise. + + + + + + + + + Sets OpenType feature [code]tag[/code]. More info: [url=https://docs.microsoft.com/en-us/typography/opentype/spec/featuretags]OpenType feature tags[/url]. + + @@ -184,6 +211,9 @@ If [code]true[/code], the GraphNode is a comment node. + + Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead. + The offset of the GraphNode, relative to the scroll offset of the [GraphEdit]. @@ -203,6 +233,9 @@ If [code]true[/code], the close button will be visible. [b]Note:[/b] Pressing it will only emit the [signal close_request] signal, the GraphNode needs to be removed manually. + + Base text writing direction. + The text displayed in the GraphNode's title bar. diff --git a/doc/classes/ItemList.xml b/doc/classes/ItemList.xml index fd8bfb4ecefd..0fd0fe7b3d59 100644 --- a/doc/classes/ItemList.xml +++ b/doc/classes/ItemList.xml @@ -43,6 +43,15 @@ Removes all items from the list. + + + + + + + Removes all OpenType features from the item's text. + + @@ -114,6 +123,15 @@ Returns the region of item's icon used. The whole icon will be used if the region has no area. + + + + + + + Returns item's text language code. + + @@ -123,6 +141,17 @@ Returns the metadata value of the specified index. + + + + + + + + + Returns OpenType feature [code]tag[/code] of the item's text. + + @@ -132,6 +161,15 @@ Returns the text associated with the specified index. + + + + + + + Returns item's text base writing direction. + + @@ -336,6 +374,17 @@ Sets whether the item icon will be drawn transposed. + + + + + + + + + Sets language code of item's text used for line-breaking and text shaping algorithms, if left empty current locale is used instead. + + @@ -347,6 +396,19 @@ Sets a value (of any type) to be stored with the item associated with the specified index. + + + + + + + + + + + Sets OpenType feature [code]tag[/code] for the item's text. More info: [url=https://docs.microsoft.com/en-us/typography/opentype/spec/featuretags]OpenType feature tags[/url]. + + @@ -369,6 +431,17 @@ Sets text of the item associated with the specified index. + + + + + + + + + Sets item's text base writing direction. + + @@ -544,6 +617,9 @@ Text [Color] used when the item is selected. + + Font size of the item's text. + [Color] of the guideline. The guideline is a line drawn between each row of items. diff --git a/doc/classes/Label.xml b/doc/classes/Label.xml index 570d7f075bfa..1edf31de4ae2 100644 --- a/doc/classes/Label.xml +++ b/doc/classes/Label.xml @@ -11,6 +11,13 @@ https://godotengine.org/asset-library/asset/515 + + + + + Removes all OpenType features. + + @@ -21,8 +28,21 @@ + + + + Returns the height of the line [code]line[/code]. + If [code]line[/code] is set to [code]-1[/code], returns biggest line height. + If there're no lines returns font size in pixels. + + + + + + + - Returns the font size in pixels. + Returns OpenType feature [code]tag[/code]. @@ -39,6 +59,17 @@ Returns the number of lines shown. Useful if the [Label]'s height cannot currently display all lines. + + + + + + + + + Returns OpenType feature [code]tag[/code]. More info: [url=https://docs.microsoft.com/en-us/typography/opentype/spec/featuretags]OpenType feature tags[/url]. + + @@ -50,6 +81,9 @@ If [code]true[/code], the Label only shows the text that fits inside its bounding rectangle. It also lets you scale the node down freely. + + Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead. + The node ignores the first [code]lines_skipped[/code] lines before it starts to display text. @@ -61,9 +95,18 @@ Limits the amount of visible characters. If you set [code]percent_visible[/code] to 0.5, only up to half of the text's characters will display on screen. Useful to animate the text in a dialog box. + + Set BiDi algorithm override for the structured text. + + + Set additional options for BiDi override. + The text to display on screen. + + Base text writing direction. + If [code]true[/code], all the text displays as UPPERCASE. @@ -85,7 +128,7 @@ Align rows to the right. - Expand row whitespaces to fit the width. + Expand row to fit the width. Align the whole text to the top. @@ -111,7 +154,10 @@ [Color] of the text's shadow effect. - The tint of [Font]'s outline. See [member DynamicFont.outline_color]. + The tint of [Font]'s outline. + + + Font size of the [Label]'s text. Vertical space between lines in multiline [Label]. @@ -119,8 +165,8 @@ Background [StyleBox] for the [Label]. - - Boolean value. If set to 1 ([code]true[/code]), the shadow will be displayed around the whole text as an outline. + + Text outline size. The horizontal offset of the text's shadow. @@ -128,5 +174,8 @@ The vertical offset of the text's shadow. + + Shadow outline size. If set to 1 or greater, the shadow will be displayed around the whole text as an outline. + diff --git a/doc/classes/LineEdit.xml b/doc/classes/LineEdit.xml index b7211419e435..f05121d48c8e 100644 --- a/doc/classes/LineEdit.xml +++ b/doc/classes/LineEdit.xml @@ -10,6 +10,7 @@ - [kbd]Ctrl + X[/kbd]: Cut - [kbd]Ctrl + V[/kbd] or [kbd]Ctrl + Y[/kbd]: Paste/"yank" - [kbd]Ctrl + Z[/kbd]: Undo + - [kbd]Ctrl + ~[/kbd]: Swap input direction. - [kbd]Ctrl + Shift + Z[/kbd]: Redo - [kbd]Ctrl + U[/kbd]: Delete text from the cursor position to the beginning of the line - [kbd]Ctrl + K[/kbd]: Delete text from the cursor position to the end of the line @@ -46,6 +47,13 @@ Erases the [LineEdit]'s [member text]. + + + + + Removes all OpenType features. + + @@ -78,6 +86,15 @@ Returns the [PopupMenu] of this [LineEdit]. By default, this menu is displayed when right-clicking on the [LineEdit]. + + + + + + + Returns OpenType feature [code]tag[/code]. + + @@ -126,6 +143,17 @@ Selects the whole [String]. + + + + + + + + + Returns OpenType feature [code]tag[/code]. More info: [url=https://docs.microsoft.com/en-us/typography/opentype/spec/featuretags]OpenType feature tags[/url]. + + @@ -139,6 +167,10 @@ + + Allow moving caret, selecting and removing the individual composite character components. + Note: [kbd]Backspace[/kbd] is always removing individual composite character components. + The cursor's position inside the [LineEdit]. When set, the text may scroll to accommodate it. @@ -148,6 +180,9 @@ If [code]true[/code], the context menu will appear when right-clicked. + + If [code]true[/code], control characters are displayed. + If [code]false[/code], existing text cannot be modified and new text cannot be added. @@ -155,6 +190,9 @@ If [code]true[/code], the [LineEdit] width will increase to stay longer than the [member text]. It will [b]not[/b] compress if the [member text] is shortened. + + Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead. + Maximum amount of characters that can be entered inside the [LineEdit]. If [code]0[/code], there is no limit. @@ -180,10 +218,19 @@ If [code]false[/code], using shortcuts will be disabled. + + Set BiDi algorithm override for the structured text. + + + Set additional options for BiDi override. + String value of the [LineEdit]. [b]Note:[/b] Changing text using this property won't emit the [signal text_changed] signal. + + Base text writing direction. + If [code]true[/code], the native virtual keyboard is shown when focused on platforms that support it. @@ -220,7 +267,7 @@ Aligns the text on the right-hand side of the [LineEdit]. - Stretches whitespaces to fit the [LineEdit]'s width. + Expand row to fit the [LineEdit]'s width. Cuts (copies and clears) the selected text. @@ -244,7 +291,70 @@ Reverse the last undo action. - + + Sets text direction to inherited. + + + Sets text direction to automatic. + + + Sets text direction to left-to-right. + + + Sets text direction to right-to-left. + + + Toggles control character display. + + + Inserts left-to-right mark (LRM) character. + + + Inserts right-to-left mark (RLM) character. + + + Inserts start of left-to-right embedding (LRE) character. + + + Inserts start of right-to-left embedding (RLE) character. + + + Inserts start of left-to-right override (LRO) character. + + + Inserts start of right-to-left override (RLO) character. + + + Inserts pop direction formatting (PDF) character. + + + Inserts Arabic letter mark (ALM) character. + + + Inserts left-to-right isolate (LRI) character. + + + Inserts right-to-left isolate (RLI) character. + + + Inserts first strong isolate (FSI) character. + + + Inserts pop direction isolate (PDI) character. + + + Inserts zero width joiner (ZWJ) character. + + + Inserts zero width non-joiner (ZWNJ) character. + + + Inserts word joiner (WJ) character. + + + Inserts soft hyphen (SHY) character. + + Represents the size of the [enum MenuItems] enum. @@ -276,6 +386,9 @@ Font color when editing is disabled. + + Font size of the [LineEdit]'s text. + Minimum horizontal space for the text (not counting the clear button and content margins). This value is measured in count of space characters (i.e. this amount of space characters can be displayed without scrolling). diff --git a/doc/classes/LinkButton.xml b/doc/classes/LinkButton.xml index 15307de897ac..4b8ab3a6cf6e 100644 --- a/doc/classes/LinkButton.xml +++ b/doc/classes/LinkButton.xml @@ -10,12 +10,51 @@ + + + + + Removes all OpenType features. + + + + + + + + + Returns OpenType feature [code]tag[/code]. + + + + + + + + + + + Returns OpenType feature [code]tag[/code]. More info: [url=https://docs.microsoft.com/en-us/typography/opentype/spec/featuretags]OpenType feature tags[/url]. + + + + Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead. + + + Set BiDi algorithm override for the structured text. + + + Set additional options for BiDi override. + The button's text that will be displayed inside the button's area. + + Base text writing direction. + Determines when to show the underline. See [enum UnderlineMode] for options. @@ -47,6 +86,9 @@ Text [Color] used when the [LinkButton] is being pressed. + + Font size of the [LinkButton]'s text. + The vertical space between the baseline of text and the underline. diff --git a/doc/classes/MainLoop.xml b/doc/classes/MainLoop.xml index 3c3cbbfa2925..7682379b64c1 100644 --- a/doc/classes/MainLoop.xml +++ b/doc/classes/MainLoop.xml @@ -126,5 +126,8 @@ Notification received from the OS when the application is defocused, i.e. when changing the focus from any open window of the Godot instance to the OS desktop or a thirdparty application. Implemented on desktop platforms. + + Notification received when text server is changed. + diff --git a/doc/classes/MenuButton.xml b/doc/classes/MenuButton.xml index fe38c0828047..ac371d1e7b2a 100644 --- a/doc/classes/MenuButton.xml +++ b/doc/classes/MenuButton.xml @@ -67,6 +67,9 @@ Text [Color] used when the [MenuButton] is being pressed. + + Font size of the [MenuButton]'s text. + [StyleBox] used when the [MenuButton] is being hovered. diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml index e3fc87ffb517..62d88afa517c 100644 --- a/doc/classes/Node.xml +++ b/doc/classes/Node.xml @@ -1013,6 +1013,9 @@ Notification received from the OS when the application is defocused, i.e. when changing the focus from any open window of the Godot instance to the OS desktop or a thirdparty application. Implemented on desktop platforms. + + Notification received when text server is changed. + Inherits pause mode from the node's parent. For the root node, it is equivalent to [constant PAUSE_MODE_STOP]. Default. diff --git a/doc/classes/OptionButton.xml b/doc/classes/OptionButton.xml index 510f952feae1..53309bae9675 100644 --- a/doc/classes/OptionButton.xml +++ b/doc/classes/OptionButton.xml @@ -239,7 +239,10 @@ The horizontal space between the arrow icon and the right edge of the button. - [StyleBox] used when the [OptionButton] is disabled. + [StyleBox] used when the [OptionButton] is disabled (for left-to-right layouts). + + + [StyleBox] used when the [OptionButton] is disabled (for right-to-left layouts). [StyleBox] used when the [OptionButton] is focused. It is displayed over the current [StyleBox], so using [StyleBoxEmpty] will just disable the focus visual effect. @@ -259,17 +262,29 @@ Text [Color] used when the [OptionButton] is being pressed. + + Font size of the [OptionButton]'s text. + - [StyleBox] used when the [OptionButton] is being hovered. + [StyleBox] used when the [OptionButton] is being hovered (for left-to-right layouts). + + + [StyleBox] used when the [OptionButton] is being hovered (for right-to-left layouts). The horizontal space between [OptionButton]'s icon and text. - Default [StyleBox] for the [OptionButton]. + Default [StyleBox] for the [OptionButton] (for left-to-right layouts). + + + Default [StyleBox] for the [OptionButton] (for right-to-left layouts). - [StyleBox] used when the [OptionButton] is being pressed. + [StyleBox] used when the [OptionButton] is being pressed (for left-to-right layouts). + + + [StyleBox] used when the [OptionButton] is being pressed (for right-to-left layouts). diff --git a/doc/classes/PopupMenu.xml b/doc/classes/PopupMenu.xml index b1ec9a222a48..c663f26d8439 100644 --- a/doc/classes/PopupMenu.xml +++ b/doc/classes/PopupMenu.xml @@ -244,6 +244,15 @@ Removes all items from the [PopupMenu]. + + + + + + + Removes all OpenType features form the item's text. + + @@ -293,6 +302,15 @@ Returns the index of the item containing the specified [code]id[/code]. Index is automatically assigned to each item by the engine. Index can not be set manually. + + + + + + + Returns item's text language code. + + @@ -302,6 +320,17 @@ Returns the metadata of the specified item, which might be of any type. You can set it with [method set_item_metadata], which provides a simple way of assigning context data to items. + + + + + + + + + Returns OpenType feature [code]tag[/code] of the item's text. + + @@ -329,6 +358,15 @@ Returns the text of the item at index [code]idx[/code]. + + + + + + + Returns item's text base writing direction. + + @@ -494,6 +532,17 @@ Sets the [code]id[/code] of the item at index [code]idx[/code]. + + + + + + + + + Sets language code of item's text used for line-breaking and text shaping algorithms, if left empty current locale is used instead. + + @@ -516,6 +565,19 @@ Sets the state of an multistate item. See [method add_multistate_item] for details. + + + + + + + + + + + Sets OpenType feature [code]tag[/code] for the item's text. More info: [url=https://docs.microsoft.com/en-us/typography/opentype/spec/featuretags]OpenType feature tags[/url]. + + @@ -562,6 +624,17 @@ Sets the text of the item at index [code]idx[/code]. + + + + + + + + + Sets item's text base writing direction. + + @@ -653,6 +726,9 @@ [Color] used for the hovered text. + + Font size of the menu items. + [StyleBox] displayed when the [PopupMenu] item is hovered. @@ -681,7 +757,10 @@ [StyleBox] used for the separators. See [method add_separator]. - [Texture2D] icon for the submenu arrow. + [Texture2D] icon for the submenu arrow (for left-to-right layouts). + + + [Texture2D] icon for the submenu arrow (for right-to-left layouts). [Texture2D] icon for the unchecked checkbox items. diff --git a/doc/classes/ProgressBar.xml b/doc/classes/ProgressBar.xml index c957d6f18212..c05cbf44131f 100644 --- a/doc/classes/ProgressBar.xml +++ b/doc/classes/ProgressBar.xml @@ -35,5 +35,8 @@ The color of the text's shadow. + + Font size used to draw the fill percentage if [member percent_visible] is [code]true[/code]. + diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 96d71db383df..e81160b362d8 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -453,6 +453,9 @@ If [code]true[/code], keeps the screen on (even in case of inactivity), so the screensaver does not take over. Works on desktop and mobile platforms. + + Force layout direction and text writing direction to RTL for all locales. + Default orientation on mobile devices. @@ -491,6 +494,9 @@ Specifies the tablet driver to use. If left empty, the default driver will be used. + + Specifies the [TextServer] to use. If left empty, the default will be used. + If [code]true[/code], enables vertical synchronization. This eliminates tearing that may appear in moving scenes, at the cost of higher input latency and stuttering at lower framerates. If [code]false[/code], vertical synchronization will be disabled, however, many platforms will enforce it regardless (such as mobile platforms and HTML5). diff --git a/doc/classes/RichTextLabel.xml b/doc/classes/RichTextLabel.xml index faf0d97766de..4faff95fd3b8 100644 --- a/doc/classes/RichTextLabel.xml +++ b/doc/classes/RichTextLabel.xml @@ -329,6 +329,9 @@ The raw text of the label. When set, clears the tag stack and adds a raw text tag to the top of it. Does not parse BBCodes. Does not modify [member bbcode_text]. + + Base text writing direction. + The restricted number of characters to display in the label. If [code]-1[/code], all characters will be displayed. diff --git a/doc/classes/TabContainer.xml b/doc/classes/TabContainer.xml index d56781105b73..9f45a361f39f 100644 --- a/doc/classes/TabContainer.xml +++ b/doc/classes/TabContainer.xml @@ -204,6 +204,9 @@ Font color of the currently selected tab. + + Font size of the tab names. + Space between tab's name and its icon. diff --git a/doc/classes/Tabs.xml b/doc/classes/Tabs.xml index 15c2d3504cbc..5c698a4aa882 100644 --- a/doc/classes/Tabs.xml +++ b/doc/classes/Tabs.xml @@ -20,6 +20,15 @@ Adds a new tab. + + + + + + + Removes all OpenType features from the tab title. + + @@ -75,6 +84,15 @@ Returns the [Texture2D] for the tab at index [code]tab_idx[/code] or [code]null[/code] if the tab has no [Texture2D]. + + + + + + + Returns tab title language code. + + @@ -82,6 +100,17 @@ Returns the number of hidden tabs offsetted to the left. + + + + + + + + + Returns OpenType feature [code]tag[/code] of the tab title. + + @@ -91,6 +120,15 @@ Returns tab [Rect2] with local position and size. + + + + + + + Returns tab title text base writing direction. + + @@ -159,6 +197,41 @@ Sets an [code]icon[/code] for the tab at index [code]tab_idx[/code]. + + + + + + + + + Sets language code of tab title used for line-breaking and text shaping algorithms, if left empty current locale is used instead. + + + + + + + + + + + + + Sets OpenType feature [code]tag[/code] for the tab title. More info: [url=https://docs.microsoft.com/en-us/typography/opentype/spec/featuretags]OpenType feature tags[/url]. + + + + + + + + + + + Sets tab title base writing direction. + + @@ -295,6 +368,9 @@ Font color of the currently selected tab. + + Font size of the tab names. + The horizontal separation between the tabs. diff --git a/doc/classes/TextEdit.xml b/doc/classes/TextEdit.xml index 168cc8a1c334..eedf3b848f96 100644 --- a/doc/classes/TextEdit.xml +++ b/doc/classes/TextEdit.xml @@ -33,6 +33,13 @@ Centers the viewport on the line the editing cursor is at. This also resets the [member scroll_horizontal] value to [code]0[/code]. + + + + + Removes all OpenType features. + + @@ -213,6 +220,15 @@ Returns the [PopupMenu] of this [TextEdit]. By default, this menu is displayed when right-clicking on the [TextEdit]. + + + + + + + Returns OpenType feature [code]tag[/code]. + + @@ -573,6 +589,17 @@ + + + + + + + + + Sets OpenType feature [code]tag[/code]. More info: [url=https://docs.microsoft.com/en-us/typography/opentype/spec/featuretags]OpenType feature tags[/url]. + + @@ -629,6 +656,10 @@ If [code]true[/code], the caret displays as a rectangle. If [code]false[/code], the caret displays as a bar. + + Allow moving caret, selecting and removing the individual composite character components. + Note: [kbd]Backspace[/kbd] is always removing individual composite character components. + If [code]true[/code], a right-click moves the cursor at the mouse position before displaying the context menu. If [code]false[/code], the context menu disregards mouse location. @@ -636,6 +667,9 @@ If [code]true[/code], a right-click displays the context menu. + + If [code]true[/code], control characters are displayed. + If [code]true[/code], the "space" character will have a visible representation. @@ -652,6 +686,9 @@ If [code]true[/code], the line containing the cursor is highlighted. + + Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead. + If [code]true[/code], a minimap is shown, providing an outline of your source code. @@ -681,11 +718,20 @@ If [code]true[/code], sets the [code]step[/code] of the scrollbars to [code]0.25[/code] which results in smoother scrolling. + + Set BiDi algorithm override for the structured text. + + + Set additional options for BiDi override. + String value of the [TextEdit]. + + Base text writing direction. + Vertical scroll sensitivity. @@ -799,7 +845,70 @@ Redoes the previous action. - + + Sets text direction to inherited. + + + Sets text direction to automatic. + + + Sets text direction to left-to-right. + + + Sets text direction to right-to-left. + + + Toggles control character display. + + + Inserts left-to-right mark (LRM) character. + + + Inserts right-to-left mark (RLM) character. + + + Inserts start of left-to-right embedding (LRE) character. + + + Inserts start of right-to-left embedding (RLE) character. + + + Inserts start of left-to-right override (LRO) character. + + + Inserts start of right-to-left override (RLO) character. + + + Inserts pop direction formatting (PDF) character. + + + Inserts Arabic letter mark (ALM) character. + + + Inserts left-to-right isolate (LRI) character. + + + Inserts right-to-left isolate (RLI) character. + + + Inserts first strong isolate (FSI) character. + + + Inserts pop direction isolate (PDI) character. + + + Inserts zero width joiner (ZWJ) character. + + + Inserts zero width non-joiner (ZWNJ) character. + + + Inserts word joiner (WJ) character. + + + Inserts soft hyphen (SHY) character. + + Represents the size of the [enum MenuItems] enum. @@ -849,6 +958,9 @@ Sets the [Color] of the selected text. [member override_selected_font_color] has to be enabled. + + Sets default font size. + Sets the spacing between the lines. @@ -865,6 +977,7 @@ Sets the highlight [Color] of text selections. + Sets a custom [Texture2D] for space text characters. Sets a custom [Texture2D] for tab text characters. diff --git a/doc/classes/TextLine.xml b/doc/classes/TextLine.xml new file mode 100644 index 000000000000..c21da09edb81 --- /dev/null +++ b/doc/classes/TextLine.xml @@ -0,0 +1,212 @@ + + + + Holds a line of text. + + + Abstraction over [TextServer] for handling single line of text. + + + + + + + + + + + + + + + + + Adds inline object to the text buffer, [code]key[/code] must be unique. In the text, object is represented as [code]length[/code] object replacement characters. + + + + + + + + + + + + + + + + + Adds text span and font to draw it. + + + + + + + Clears text line (removes text and inline objects). + + + + + + + + + + + + + Draw text into a canvas item at a given position, with [code]color[/code]. [code]pos[/code] specifies the top left corner of the bounding box. + + + + + + + + + + + + + + + Draw text into a canvas item at a given position, with [code]color[/code]. [code]pos[/code] specifies the top left corner of the bounding box. + + + + + + + Returns the text ascent (number of pixels above the baseline for horizontal layout or to the left of baseline for vertical). + + + + + + + Returns the text descent (number of pixels below the baseline for horizontal layout or to the right of baseline for vertical). + + + + + + + Returns pixel offset of the underline below the baseline. + + + + + + + Returns thickness of the underline. + + + + + + + Returns width (for horizontal layout) or height (for vertical) of the text. + + + + + + + + + Returns bounding rectangle of the inline object. + + + + + + + Returns array of inline objects. + + + + + + + Returns TextServer buffer RID. + + + + + + + Returns size of the bounding box of the text. + + + + + + + + + Returns caret character offset at the specified pixel offset at the baseline. This function always returns a valid position. + + + + + + + + + + + + + Sets new size and alignment of embedded object. + + + + + + + + + Overrides BiDi for the structured text. + Override ranges should cover full source text without overlaps. BiDi algorithm will be used on each range separately. + + + + + + + + + Aligns text to the given tab-stops. + + + + + + Text horizontal alignment. + + + Text writing direction. + + + Line Alignment rules. For more info see [TextServer]. + + + Text orientation. + + + If set to [code]true[/code] text will display control characters. + + + If set to [code]true[/code] text will display invalid characters. + + + Text line width. + + + + + diff --git a/doc/classes/TextParagraph.xml b/doc/classes/TextParagraph.xml new file mode 100644 index 000000000000..fabf22eef71b --- /dev/null +++ b/doc/classes/TextParagraph.xml @@ -0,0 +1,299 @@ + + + + Holds a paragraph of text. + + + Abstraction over [TextServer] for handling paragraph of text. + + + + + + + + + + + + + + + + + Adds inline object to the text buffer, [code]key[/code] must be unique. In the text, object is represented as [code]length[/code] object replacement characters. + + + + + + + + + + + + + + + + + Adds text span and font to draw it. + + + + + + + Clears text paragraph (removes text and inline objects). + + + + + + + + + + + + + Draw text into a canvas item at a given position, with [code]color[/code]. [code]pos[/code] specifies the top left corner of the bounding box. + + + + + + + + + + + + + + + Draw single line of text into a canvas item at a given position, with [code]color[/code]. [code]pos[/code] specifies the top left corner of the bounding box. + + + + + + + + + + + + + + + + + Draw outline of the single line of text into a canvas item at a given position, with [code]color[/code]. [code]pos[/code] specifies the top left corner of the bounding box. + + + + + + + + + + + + + + + Draw outline of the text into a canvas item at a given position, with [code]color[/code]. [code]pos[/code] specifies the top left corner of the bounding box. + + + + + + + + + Returns the text line ascent (number of pixels above the baseline for horizontal layout or to the left of baseline for vertical). + + + + + + + Returns number of lines in the paragraph. + + + + + + + + + Returns the text line descent (number of pixels below the baseline for horizontal layout or to the right of baseline for vertical). + + + + + + + + + + + Returns bounding rectangle of the inline object. + + + + + + + + + Returns array of inline objects in the line. + + + + + + + + + Returns character range of the line. + + + + + + + + + Returns TextServer line buffer RID. + + + + + + + + + Returns size of the bounding box of the line of text. + + + + + + + + + Returns pixel offset of the underline below the baseline. + + + + + + + + + Returns thickness of the underline. + + + + + + + + + Returns width (for horizontal layout) or height (for vertical) of the line of text. + + + + + + + Returns the size of the bounding box of the paragraph, without line breaks. + + + + + + + Returns TextServer full string buffer RID. + + + + + + + Returns the size of the bounding box of the paragraph. + + + + + + + + + Returns caret character offset at the specified coordinates. This function always returns a valid position. + + + + + + + + + + + + + Sets new size and alignment of embedded object. + + + + + + + + + Overrides BiDi for the structured text. + Override ranges should cover full source text without overlaps. BiDi algorithm will be used on each range separately. + + + + + + + + + Aligns paragraph to the given tab-stops. + + + + + + Paragraph horizontal alignment. + + + Text writing direction. + + + Line breaking and alignment rules. For more info see [TextServer]. + + + Text orientation. + + + If set to [code]true[/code] text will display control characters. + + + If set to [code]true[/code] text will display invalid characters. + + + Paragraph width. + + + + + diff --git a/doc/classes/TextServer.xml b/doc/classes/TextServer.xml new file mode 100644 index 000000000000..43388bb7f150 --- /dev/null +++ b/doc/classes/TextServer.xml @@ -0,0 +1,1167 @@ + + + + Interface for the fonts and complex text layouts. + + + [TextServer] is the API backend for managing fonts, and rendering complex text. + + + + + + + + + + + + + + + Creates new font from the data in memory. To free the resulting font, use [method free_rid] method. + Note: For non-scalable fonts [code]base_size[/code] is ignored, use [method font_get_base_size] to check actual font size. + + + + + + + + + + + Creates new font from the file. To free the resulting font, use [method free_rid] method. + Note: For non-scalable fonts [code]base_size[/code] is ignored, use [method font_get_base_size] to check actual font size. + + + + + + + + + + + Creates new font from the system font. To free the resulting font, use [method free_rid] method. + Note: This method is supported by servers with the [code]FEATURE_FONT_SYSTEM[/code] feature. + Note: For non-scalable fonts [code]base_size[/code] is ignored, use [method font_get_base_size] to check actual font size. + + + + + + + + + + + Creates new buffer for complex text layout, with the given [code]direction[/code] and [code]orientation[/code]. To free the resulting buffer, use [method free_rid] method. + Note: Direction is ignored if server does not support [code]FEATURE_BIDI_LAYOUT[/code] feature. + Note: Orientation is ignored if server does not support [code]FEATURE_VERTICAL_LAYOUT[/code] feature. + + + + + + + + + + + + + + + + + Draws box displaying character hexadecimal code. Used for replacing missing characters. + + + + + + + + + + + + + + + + + + + Draws single glyph into a canvas item at the position, using [code]font[/code] at the size [code]size[/code]. + Note: Glyph index is specific to the font, use glyphs indices returned by [method shaped_text_get_glyphs] or [method font_get_glyph_index]. + + + + + + + + + + + + + + + + + + + + + Draws single glyph outline of size [code]outline_size[/code] into a canvas item at the position, using [code]font[/code] at the size [code]size[/code]. + Note: Glyph index is specific to the font, use glyphs indices returned by [method shaped_text_get_glyphs] or [method font_get_glyph_index]. + + + + + + + + + Returns [code]true[/code], if font anti-aliasing is supported and enabled. + + + + + + + + + + + Returns the font ascent (number of pixels above the baseline). + + + + + + + + + Returns the default size of the font. + + + + + + + + + + + Returns the font descent (number of pixels below the baseline). + + + + + + + + + Returns [code]true[/code], if distance field hint is enabled. + + + + + + + + + Returns list of OpenType features supported by font. + + + + + + + + + Returns [code]true[/code], if autohinter is supported and enabled. + + + + + + + + + + + + + Returns advance of the glyph. + + + + + + + + + + + + + Returns the glyph index of a [code]char[/code], optionally modified by the [code]variation_selector[/code]. + + + + + + + + + + + + + + + Returns a kerning of the pair of glyphs. + + + + + + + + + + + Returns the total font height (ascent plus descent) in pixels. + + + + + + + + + Returns the font hinting. + + + + + + + + + + + Returns [code]true[/code] if support override is enabled for the [code]language[/code]. + + + + + + + + + Returns list of language support overrides. + + + + + + + Returns the font oversampling factor, shared by all fonts in the TextServer. + + + + + + + + + + + Returns [code]true[/code] if support override is enabled for the [code]script[/code]. + + + + + + + + + Returns list of script support overrides. + + + + + + + + + Returns a string containing all the characters available in the font. + + + + + + + + + + + Returns underline offset (number of pixels below the baseline). + + + + + + + + + + + Returns underline thickness in pixels. + + + + + + + + + + + Returns [code]true[/code] if [code]char[/code] is available in the font. + + + + + + + + + Returns [code]true[/code], if font supports glyph outlines. + + + + + + + + + + + Returns [code]true[/code], if font supports given language (ISO 639 code). + + + + + + + + + + + Returns [code]true[/code], if font supports given script (ISO 15924 code). + + + + + + + + + + + Remove language support override. + + + + + + + + + + + Removes script support override. + + + + + + + + + + + Sets font anti-aliasing. + + + + + + + + + + + Sets font distance field hint. + + + + + + + + + + + Enables/disables default autohinter. + + + + + + + + + + + Sets font hinting. + + + + + + + + + + + + + Adds override for [method font_is_language_supported]. + + + + + + + + + Sets oversampling factor, shared by all font in the TextServer. + + + + + + + + + + + + + Adds override for [method font_is_script_supported]. + + + + + + + + + + + Converts a number from the Western Arabic (0..9) to the numeral systems used in [code]language[/code]. + + + + + + + + + Frees an object created by this [TextServer]. + + + + + + + + + + + Returns size of the replacement character (box with character hexadecimal code that is drawn in place of invalid characters). + + + + + + + Returns the name of the server interface. + + + + + + + Returns list of available system fonts. + Note: This method is supported by servers with the [code]FEATURE_FONT_SYSTEM[/code] feature. + + + + + + + + + Returns [code]true[/code] if [code]rid[/code] is valid resource owned by this text server. + + + + + + + + + Returns [code]true[/code] if the server supports a feature. + + + + + + + + + Returns [code]true[/code] if locale is right-to-left. + + + + + + + + + Loads optional TextServer database (e.g. ICU break iterators and dictionaries). + Note: This function should be called before any other TextServer functions used, otherwise it won't have any effect. + + + + + + + + + Converts readable feature, variation, script or language name to OpenType tag. + + + + + + + + + + + Converts a number from the numeral systems used in [code]language[/code] to Western Arabic (0..9). + + + + + + + + + Returns percent sign used in the [code]language[/code]. + + + + + + + + + + + + + + + + + Adds inline object to the text buffer, [code]key[/code] must be unique. In the text, object is represented as [code]length[/code] object replacement characters. + + + + + + + + + + + + + + + + + + + Adds text span and font to draw it to the text buffer. + + + + + + + + + Clears text buffer (removes text and inline objects). + + + + + + + + + + + + + + + + + + + Draw shaped text into a canvas item at a given position, with [code]color[/code]. [code]pos[/code] specifies the leftmost point of the baseline (for horizontal layout) or topmost point of the baseline (for vertical layout). + + + + + + + + + + + + + + + + + + + + + Draw the outline of the shaped text into a canvas item at a given position, with [code]color[/code]. [code]pos[/code] specifies the leftmost point of the baseline (for horizontal layout) or topmost point of the baseline (for vertical layout). + + + + + + + + + + + + + Adjusts text with to fit to specified width, returns new text width. + + + + + + + + + Returns the text ascent (number of pixels above the baseline for horizontal layout or to the left of baseline for vertical). + Note: overall ascent can be higher than font ascent, if some glyphs are displaced from the baseline. + + + + + + + + + + + Returns shapes of the carets corresponding to the character offset [code]position[/code] in the text. Returned caret shape is 1 pixel wide rectangle. + + + + + + + + + Returns the text descent (number of pixels below the baseline for horizontal layout or to the right of baseline for vertical). + Note: overall descent can be higher than font descent, if some glyphs are displaced from the baseline. + + + + + + + + + Returns direction of the text. + + + + + + + + + + + + + Returns dominant direction of in the range of text. + + + + + + + + + Returns text glyphs. + + + + + + + + + + + + + + + Breaks text to the lines and returns character ranges for each line. + + + + + + + + + + + + + + + + + Breaks text to the lines and columns. Returns character ranges for each segment. + + + + + + + + + + + Returns bounding rectangle of the inline object. + + + + + + + + + Returns array of inline objects. + + + + + + + + + Returns text orientation. + + + + + + + + + Sets text orientation. + + + + + + + + + Returns [code]true[/code] if text buffer is configured to display control characters. + + + + + + + + + Returns [code]true[/code] if text buffer is configured to display hexadecimal codes in place of invalid characters. + Note: If set to [code]false[/code], nothing is displayed in place of invalid characters. + + + + + + + + + Returns substring buffer character range in the parent buffer. + + + + + + + + + + + + + Returns selection rectangles for the specified character range. + + + + + + + + + Returns size of the text. + + + + + + + + + Returns pixel offset of the underline below the baseline. + + + + + + + + + Returns thickness of the underline. + + + + + + + + + Returns width (for horizontal layout) or height (for vertical) of the text. + + + + + + + + + Breaks text into words and returns array of character ranges. + + + + + + + + + + + Returns grapheme index at the specified pixel offset at the baseline, or [code]-1[/code] if none is found. + + + + + + + + + + + Returns caret character offset at the specified pixel offset at the baseline. This function always returns a valid position. + + + + + + + + + Returns [code]true[/code] if buffer is successfully shaped. + + + + + + + + + + + Returns composite character end position closest to the [code]pos[/code]. + + + + + + + + + + + Returns composite character start position closest to the [code]pos[/code]. + + + + + + + + + + + + + + + Sets new size and alignment of embedded object. + + + + + + + + + + + Overrides BiDi for the structured text. + Override ranges should cover full source text without overlaps. BiDi algorithm will be used on each range separately. + + + + + + + + + + + Sets desired text direction. If set to [code]TEXT_DIRECTION_AUTO[/code], direction will be detected based on the buffer contents and current locale. + Note: Direction is ignored if server does not support [code]FEATURE_BIDI_LAYOUT[/code] feature. + + + + + + + + + + + Sets desired text orientation. + Note: Orientation is ignored if server does not support [code]FEATURE_VERTICAL_LAYOUT[/code] feature. + + + + + + + + + + + If set to [code]true[/code] text buffer will display control characters. + + + + + + + + + + + If set to [code]true[/code] text buffer will display invalid characters as hexadecimal codes, otherwise nothing is displayed. + + + + + + + + + Shapes buffer if it's not shaped. Returns [code]true[/code] if the string is shaped successfully. + Note: It is not necessary to call this function manually, buffer will be shaped automatically as soon as any of its output data is requested. + + + + + + + + + + + + + Returns text buffer for the substring of the text in the [code]shaped[/code] text buffer (including inline objects). + + + + + + + + + + + Aligns shaped text to the given tab-stops. + + + + + + + + + Converts OpenType tag to readable feature, variation, script or language name. + + + + + + Text direction is determined based on contents and current locale. + + + Text is written from left to right. + + + Text is written from right to left. + + + Text is written horizontally. + + + Left to right text is written vertically from top to bottom. + Right to left text is written vertically from bottom to top. + + + Do not justify text. + + + Justify text by adding and removing kashidas. + + + Justify text by changing width of the spaces between the words. + + + Remove trailing and leading spaces from the justified text. + + + Only apply justification to the part of the text after the last tab. + + + Do not break the line. + + + Break the line at the line mandatory break characters (e.g. [code]"\n"[/code]). + + + Break the line between the words. + + + Break the line between any unconnected graphemes. + + + Grapheme is part of right-to-left or bottom-to-top run. + + + Grapheme is not part of source text, it was added by justification process. + + + Grapheme is whitespace. + + + Grapheme is mandatory break point (e.g. [code]"\n"[/code]). + + + Grapheme is optional break point (e.g. space). + + + Grapheme is the tabulation character. + + + Grapheme is kashida. + + + Disables font hinting (smoother but less crisp). + + + Use the light font hinting mode. + + + Use the default font hinting mode (crisper but less smooth). + + + TextServer supports bidirectional layouts. + + + TextServer supports vertical layouts. + + + TextServer supports complex text shaping. + + + TextServer supports justification using kashidas. + + + TextServer supports complex line/word breaking rules (e.g. dictionary based). + + + TextServer supports loading system fonts. + + + TextServer require external data file for some features. + + + diff --git a/doc/classes/TextServerManager.xml b/doc/classes/TextServerManager.xml new file mode 100644 index 000000000000..29586f30b4bd --- /dev/null +++ b/doc/classes/TextServerManager.xml @@ -0,0 +1,82 @@ + + + + Manager for the font and complex text layout servers. + + + [TextServerManager] is the API backend for loading, enumeration and switching [TextServer]s. + Note: Switching text server at runtime is possible, but will invalidate all fonts and text buffers. Make sure to unload all controls, fonts, and themes before doing so. + + + + + + + + + + + Finds an interface by its name. + + + + + + + + + Returns the interface registered at a given index. + + + + + + + Returns the number of interfaces currently registered. + + + + + + + + + Returns text server supported features (binary OR). + + + + + + + + + Returns the interface name registered at a given index. + + + + + + + Returns a list of available interfaces the index and name of each interface. + + + + + + + Returns the primary [TextServer] interface. + + + + + + + + + Sets (and initializes it if required) interface registered at a given index as the primary. Invalidates all references to the fonts and text buffers. + + + + + + diff --git a/doc/classes/Theme.xml b/doc/classes/Theme.xml index 783614c4aff5..1af6610f6f36 100644 --- a/doc/classes/Theme.xml +++ b/doc/classes/Theme.xml @@ -51,6 +51,17 @@ Clears the [Font] at [code]name[/code] if the theme has [code]node_type[/code]. + + + + + + + + + Clears the font size [code]name[/code] if the theme has [code]node_type[/code]. + + @@ -149,6 +160,26 @@ Returns all the [Font]s as a [PackedStringArray] filled with each [Font]'s name, for use in [method get_font], if the theme has [code]node_type[/code]. + + + + + + + + + Returns the font size at [code]name[/code] if the theme has [code]node_type[/code]. + + + + + + + + + Returns all the font sizes as a [PackedStringArray] filled with each font size name, for use in [method get_font_size], if the theme has [code]node_type[/code]. + + @@ -241,6 +272,18 @@ Returns [code]false[/code] if the theme does not have [code]node_type[/code]. + + + + + + + + + Returns [code]true[/code] if font size with [code]name[/code] is in [code]node_type[/code]. + Returns [code]false[/code] if the theme does not have [code]node_type[/code]. + + @@ -307,6 +350,20 @@ Does nothing if the theme does not have [code]node_type[/code]. + + + + + + + + + + + Sets the theme's font size to [code]font_size[/code] at [code]name[/code] in [code]node_type[/code]. + Does nothing if the theme does not have [code]node_type[/code]. + + @@ -340,6 +397,9 @@ The theme's default font. + + The theme's default font size. Set to [code]-1[/code] to ignore and use global default. + diff --git a/doc/classes/Tree.xml b/doc/classes/Tree.xml index 73575b430964..01818e2993b2 100644 --- a/doc/classes/Tree.xml +++ b/doc/classes/Tree.xml @@ -35,6 +35,15 @@ Clears the tree. This removes all items. + + + + + + + Removes all OpenType features from the item's text. + + @@ -75,6 +84,35 @@ Returns the column's title. + + + + + + + Returns column title base writing direction. + + + + + + + + + Returns column title language code. + + + + + + + + + + + Returns OpenType feature [code]tag[/code] of the column title. + + @@ -225,6 +263,41 @@ Sets the title of a column. + + + + + + + + + Sets column title base writing direction. + + + + + + + + + + + Sets language code of column title used for line-breaking and text shaping algorithms, if left empty current locale is used instead. + + + + + + + + + + + + + Sets OpenType feature [code]tag[/code] for the column title. + + @@ -398,7 +471,10 @@ The arrow icon used when a foldable item is not collapsed. - The arrow icon used when a foldable item is collapsed. + The arrow icon used when a foldable item is collapsed (for left-to-right layouts). + + + The arrow icon used when a foldable item is collapsed (for right-to-left layouts). Default [StyleBox] for the [Tree], i.e. used when the control is not being focused. @@ -451,6 +527,9 @@ Text [Color] used when the item is selected. + + Font size of the item's text. + [Color] of the guideline. diff --git a/doc/classes/TreeItem.xml b/doc/classes/TreeItem.xml index 22e643a51d96..e97c1e580cba 100644 --- a/doc/classes/TreeItem.xml +++ b/doc/classes/TreeItem.xml @@ -54,6 +54,15 @@ Resets the color for the given column to default. + + + + + + + Removes all OpenType features. + + @@ -184,6 +193,15 @@ Returns the icon [Texture2D] region as [Rect2]. + + + + + + + Returns item's text language code. + + @@ -209,6 +227,17 @@ If [code]wrap[/code] is enabled, the method will wrap around to the first visible element in the tree when called on the last visible element, otherwise it returns [code]null[/code]. + + + + + + + + + Returns OpenType feature [code]tag[/code] of the item's text. + + @@ -249,6 +278,22 @@ + + + + + + + + + + + + + + + + @@ -275,6 +320,15 @@ Returns the given column's text alignment. + + + + + + + Returns item's text base writing direction. + + @@ -533,6 +587,17 @@ Sets the given column's icon's texture region. + + + + + + + + + Sets language code of item's text used for line-breaking and text shaping algorithms, if left empty current locale is used instead. + + @@ -543,6 +608,19 @@ + + + + + + + + + + + Sets OpenType feature [code]tag[/code] for the item's text. + + @@ -580,6 +658,26 @@ If [code]true[/code], the given column is selectable. + + + + + + + + + + + + + + + + + + + + @@ -611,6 +709,17 @@ Sets the given column's text alignment. See [enum TextAlign] for possible values. + + + + + + + + + Sets item's text base writing direction. + + diff --git a/doc/classes/Window.xml b/doc/classes/Window.xml index a0711b4214ed..0f887c770591 100644 --- a/doc/classes/Window.xml +++ b/doc/classes/Window.xml @@ -27,6 +27,13 @@ + + + + + Returns layout direction and text writing direction. + + @@ -61,6 +68,18 @@ + Returns the [Font] at [code]name[/code] if the theme has [code]type[/code]. + + + + + + + + + + + Returns the font size at [code]name[/code] if the theme has [code]type[/code]. @@ -123,6 +142,20 @@ + Returns [code]true[/code] if [Font] with [code]name[/code] is in [code]type[/code]. + Returns [code]false[/code] if the theme does not have [code]type[/code]. + + + + + + + + + + + Returns [code]true[/code] if font size with [code]name[/code] is in [code]type[/code]. + Returns [code]false[/code] if the theme does not have [code]type[/code]. @@ -157,6 +190,13 @@ + + + + + Returns [code]true[/code] if layout is right-to-left. + + @@ -249,6 +289,15 @@ + + + + + + + Sets layout direction and text writing direction. Right-to-left layouts are necessary for certain languages (e.g. Arabic and Hebrew). + + @@ -393,6 +442,18 @@ + + Automatic layout direction, determined from the parent control layout direction. + + + Automatic layout direction, determined from the current locale. + + + Left-to-right layout direction. + + + Right-to-left layout direction. + diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index 17b03fd47977..22adf4f2671d 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -32,6 +32,7 @@ #include "editor/editor_node.h" #include "editor_scale.h" +#include "scene/resources/text_line.h" float AnimationBezierTrackEdit::_bezier_h_to_pixel(float p_h) { float h = p_h; @@ -247,6 +248,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) { } Ref font = get_theme_font("font", "Label"); + int font_size = get_theme_font_size("font_size", "Label"); Color color = get_theme_color("font_color", "Label"); int hsep = get_theme_constant("hseparation", "ItemList"); int vsep = get_theme_constant("vseparation", "ItemList"); @@ -286,26 +288,27 @@ void AnimationBezierTrackEdit::_notification(int p_what) { String text; - int h = font->get_height(); - if (node) { int ofs = 0; Ref icon = EditorNode::get_singleton()->get_object_icon(node, "Node"); - h = MAX(h, icon->get_height()); + text = node->get_name(); + ofs += hsep; + ofs += icon->get_width(); + + TextLine text_buf = TextLine(text, font, font_size); + text_buf.set_width(limit - ofs - hsep); + + int h = MAX(text_buf.get_size().y, icon->get_height()); draw_texture(icon, Point2(ofs, vofs + int(h - icon->get_height()) / 2)); margin = icon->get_width(); - text = node->get_name(); - ofs += hsep; - ofs += icon->get_width(); - - Vector2 string_pos = Point2(ofs, vofs + (h - font->get_height()) / 2 + font->get_ascent()); + Vector2 string_pos = Point2(ofs, vofs + (h - text_buf.get_size().y) / 2 + text_buf.get_line_ascent()); string_pos = string_pos.floor(); - draw_string(font, string_pos, text, color, limit - ofs - hsep); + text_buf.draw(get_canvas_item(), string_pos, color); vofs += h + vsep; } @@ -327,7 +330,10 @@ void AnimationBezierTrackEdit::_notification(int p_what) { path = path.replace_first(base_path, ""); Color cc = color; - Rect2 rect = Rect2(margin, vofs, limit - margin - hsep, font->get_height() + vsep); + TextLine text_buf = TextLine(path, font, font_size); + text_buf.set_width(limit - margin - hsep); + + Rect2 rect = Rect2(margin, vofs, limit - margin - hsep, text_buf.get_size().y + vsep); if (i != track) { cc.a *= 0.7; uint32_t hash = path.hash(); @@ -338,7 +344,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) { Color subcolor; subcolor.set_hsv(h, 0.2, 0.8); subcolor.a = 0.5; - draw_rect(Rect2(0, vofs + font->get_height() * 0.1, margin - hsep, font->get_height() * 0.8), subcolor); + draw_rect(Rect2(0, vofs + text_buf.get_size().y * 0.1, margin - hsep, text_buf.get_size().y * 0.8), subcolor); subtrack_colors[i] = subcolor; subtracks[i] = rect; @@ -347,15 +353,17 @@ void AnimationBezierTrackEdit::_notification(int p_what) { ac.a = 0.5; draw_rect(rect, ac); } - draw_string(font, Point2(margin, vofs + font->get_ascent()), path, cc, limit - margin - hsep); - vofs += font->get_height() + vsep; + Vector2 string_pos = Point2(margin, vofs + text_buf.get_line_ascent()); + text_buf.draw(get_canvas_item(), string_pos, cc); + + vofs += text_buf.get_size().y + vsep; } Color accent = get_theme_color("accent_color", "Editor"); { //guides - float min_left_scale = font->get_height() + vsep; + float min_left_scale = font->get_height(font_size) + vsep; float scale = (min_left_scale * 2) * v_zoom; float step = Math::pow(10.0, Math::round(Math::log(scale / 5.0) / Math::log(10.0))) * 5.0; @@ -367,7 +375,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) { bool first = true; int prev_iv = 0; - for (int i = font->get_height(); i < get_size().height; i++) { + for (int i = font->get_height(font_size); i < get_size().height; i++) { float ofs = get_size().height / 2 - i; ofs *= v_zoom; ofs += v_scroll; @@ -382,7 +390,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) { draw_line(Point2(limit, i), Point2(right_limit, i), lc); Color c = color; c.a *= 0.5; - draw_string(font, Point2(limit + 8, i - 2), rtos(Math::stepify((iv + 1) * scale, step)), c); + draw_string(font, Point2(limit + 8, i - 2), TS->format_number(rtos(Math::stepify((iv + 1) * scale, step))), HALIGN_LEFT, -1, font_size, c); } first = false; @@ -453,8 +461,8 @@ void AnimationBezierTrackEdit::_notification(int p_what) { ep.point_rect.size = bezier_icon->get_size(); if (selection.has(i)) { draw_texture(selected_icon, ep.point_rect.position); - draw_string(font, ep.point_rect.position + Vector2(8, -font->get_height() - 4), TTR("Time:") + " " + rtos(Math::stepify(offset, 0.001)), accent); - draw_string(font, ep.point_rect.position + Vector2(8, -8), TTR("Value:") + " " + rtos(Math::stepify(value, 0.001)), accent); + draw_string(font, ep.point_rect.position + Vector2(8, -font->get_height(font_size) - 4), TTR("Time:") + " " + TS->format_number(rtos(Math::stepify(offset, 0.001))), HALIGN_LEFT, -1, font_size, accent); + draw_string(font, ep.point_rect.position + Vector2(8, -8), TTR("Value:") + " " + TS->format_number(rtos(Math::stepify(value, 0.001))), HALIGN_LEFT, -1, font_size, accent); } else { draw_texture(bezier_icon, ep.point_rect.position); } diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 6f30d5a492d5..d4d4c7d8099e 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -1397,6 +1397,7 @@ void AnimationTimelineEdit::_notification(int p_what) { } Ref font = get_theme_font("font", "Label"); + int font_size = get_theme_font_size("font_size", "Label"); Color color = get_theme_color("font_color", "Label"); int zoomw = key_range; @@ -1488,10 +1489,10 @@ void AnimationTimelineEdit::_notification(int p_what) { int decimals = 2; bool step_found = false; - const int period_width = font->get_char_size('.').width; - int max_digit_width = font->get_char_size('0').width; + const int period_width = font->get_char_size('.', 0, font_size).width; + int max_digit_width = font->get_char_size('0', 0, font_size).width; for (int i = 1; i <= 9; i++) { - const int digit_width = font->get_char_size('0' + i).width; + const int digit_width = font->get_char_size('0' + i, 0, font_size).width; max_digit_width = MAX(digit_width, max_digit_width); } const int max_sc = int(Math::ceil(zoomw / scale)); @@ -1538,8 +1539,8 @@ void AnimationTimelineEdit::_notification(int p_what) { if (frame != prev_frame && i >= prev_frame_ofs) { draw_line(Point2(get_name_limit() + i, 0), Point2(get_name_limit() + i, h), linecolor, Math::round(EDSCALE)); - draw_string(font, Point2(get_name_limit() + i + 3 * EDSCALE, (h - font->get_height()) / 2 + font->get_ascent()).floor(), itos(frame), sub ? color_time_dec : color_time_sec, zoomw - i); - prev_frame_ofs = i + font->get_string_size(itos(frame)).x + 5 * EDSCALE; + draw_string(font, Point2(get_name_limit() + i + 3 * EDSCALE, (h - font->get_height(font_size)) / 2 + font->get_ascent(font_size)).floor(), itos(frame), HALIGN_LEFT, zoomw - i, font_size, sub ? color_time_dec : color_time_sec); + prev_frame_ofs = i + font->get_string_size(itos(frame), font_size).x + 5 * EDSCALE; } } } @@ -1556,7 +1557,7 @@ void AnimationTimelineEdit::_notification(int p_what) { if ((sc / step) != (prev_sc / step) || (prev_sc < 0 && sc >= 0)) { int scd = sc < 0 ? prev_sc : sc; draw_line(Point2(get_name_limit() + i, 0), Point2(get_name_limit() + i, h), linecolor, Math::round(EDSCALE)); - draw_string(font, Point2(get_name_limit() + i + 3, (h - font->get_height()) / 2 + font->get_ascent()).floor(), String::num((scd - (scd % step)) / double(SC_ADJ), decimals), sub ? color_time_dec : color_time_sec, zoomw - i); + draw_string(font, Point2(get_name_limit() + i + 3, (h - font->get_height(font_size)) / 2 + font->get_ascent(font_size)).floor(), String::num((scd - (scd % step)) / double(SC_ADJ), decimals), HALIGN_LEFT, zoomw - i, font_size, sub ? color_time_dec : color_time_sec); } } } @@ -1583,7 +1584,8 @@ void AnimationTimelineEdit::set_animation(const Ref &p_animation) { Size2 AnimationTimelineEdit::get_minimum_size() const { Size2 ms = add_track->get_minimum_size(); Ref font = get_theme_font("font", "Label"); - ms.height = MAX(ms.height, font->get_height()); + int font_size = get_theme_font_size("font_size", "Label"); + ms.height = MAX(ms.height, font->get_height(font_size)); ms.width = get_buttons_width() + add_track->get_minimum_size().width + get_theme_icon("Hsize", "EditorIcons")->get_width() + 2; return ms; } @@ -1798,6 +1800,8 @@ AnimationTimelineEdit::AnimationTimelineEdit() { panning_timeline = false; dragging_timeline = false; dragging_hsize = false; + + set_layout_direction(Control::LAYOUT_DIRECTION_LTR); } //////////////////////////////////// @@ -1819,6 +1823,7 @@ void AnimationTrackEdit::_notification(int p_what) { } Ref font = get_theme_font("font", "Label"); + int font_size = get_theme_font_size("font_size", "Label"); Color color = get_theme_color("font_color", "Label"); Ref type_icons[6] = { get_theme_icon("KeyValue", "EditorIcons"), @@ -1890,9 +1895,9 @@ void AnimationTrackEdit::_notification(int p_what) { path_rect = Rect2(ofs, 0, limit - ofs - hsep, get_size().height); - Vector2 string_pos = Point2(ofs, (get_size().height - font->get_height()) / 2 + font->get_ascent()); + Vector2 string_pos = Point2(ofs, (get_size().height - font->get_height(font_size)) / 2 + font->get_ascent(font_size)); string_pos = string_pos.floor(); - draw_string(font, string_pos, text, text_color, limit - ofs - hsep); + draw_string(font, string_pos, text, HALIGN_LEFT, limit - ofs - hsep, font_size, text_color); draw_line(Point2(limit, 0), Point2(limit, get_size().height), linecolor, Math::round(EDSCALE)); } @@ -2173,6 +2178,7 @@ void AnimationTrackEdit::draw_key(int p_index, float p_pixels_sec, int p_x, bool if (animation->track_get_type(track) == Animation::TYPE_METHOD) { Ref font = get_theme_font("font", "Label"); + int font_size = get_theme_font_size("font_size", "Label"); Color color = get_theme_color("font_color", "Label"); color.a = 0.5; @@ -2197,7 +2203,7 @@ void AnimationTrackEdit::draw_key(int p_index, float p_pixels_sec, int p_x, bool int limit = MAX(0, p_clip_right - p_x - icon_to_draw->get_width()); if (limit > 0) { - draw_string(font, Vector2(p_x + icon_to_draw->get_width(), int(get_size().height - font->get_height()) / 2 + font->get_ascent()), text, color, limit); + draw_string(font, Vector2(p_x + icon_to_draw->get_width(), int(get_size().height - font->get_height(font_size)) / 2 + font->get_ascent(font_size)), text, HALIGN_LEFT, limit, font_size, color); } } @@ -2302,9 +2308,10 @@ NodePath AnimationTrackEdit::get_path() const { Size2 AnimationTrackEdit::get_minimum_size() const { Ref texture = get_theme_icon("Object", "EditorIcons"); Ref font = get_theme_font("font", "Label"); + int font_size = get_theme_font_size("font_size", "Label"); int separation = get_theme_constant("vseparation", "ItemList"); - int max_h = MAX(texture->get_height(), font->get_height()); + int max_h = MAX(texture->get_height(), font->get_height(font_size)); max_h = MAX(max_h, get_key_height()); return Vector2(1, max_h + separation); @@ -3036,6 +3043,7 @@ AnimationTrackEdit *AnimationTrackEditPlugin::create_animation_track_edit(Object void AnimationTrackEditGroup::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { Ref font = get_theme_font("font", "Label"); + int font_size = get_theme_font_size("font_size", "Label"); int separation = get_theme_constant("hseparation", "ItemList"); Color color = get_theme_color("font_color", "Label"); @@ -3059,7 +3067,7 @@ void AnimationTrackEditGroup::_notification(int p_what) { int ofs = 0; draw_texture(icon, Point2(ofs, int(get_size().height - icon->get_height()) / 2)); ofs += separation + icon->get_width(); - draw_string(font, Point2(ofs, int(get_size().height - font->get_height()) / 2 + font->get_ascent()), node_name, color, timeline->get_name_limit() - ofs); + draw_string(font, Point2(ofs, int(get_size().height - font->get_height(font_size)) / 2 + font->get_ascent(font_size)), node_name, HALIGN_LEFT, timeline->get_name_limit() - ofs, font_size, color); int px = (-timeline->get_value() + timeline->get_play_position()) * timeline->get_zoom_scale() + timeline->get_name_limit(); @@ -3080,9 +3088,10 @@ void AnimationTrackEditGroup::set_type_and_name(const Ref &p_type, co Size2 AnimationTrackEditGroup::get_minimum_size() const { Ref font = get_theme_font("font", "Label"); + int font_size = get_theme_font_size("font_size", "Label"); int separation = get_theme_constant("vseparation", "ItemList"); - return Vector2(0, MAX(font->get_height(), icon->get_height()) + separation); + return Vector2(0, MAX(font->get_height(font_size), icon->get_height()) + separation); } void AnimationTrackEditGroup::set_timeline(AnimationTimelineEdit *p_timeline) { diff --git a/editor/animation_track_editor_plugins.cpp b/editor/animation_track_editor_plugins.cpp index 9fc67000f905..4d9628934373 100644 --- a/editor/animation_track_editor_plugins.cpp +++ b/editor/animation_track_editor_plugins.cpp @@ -37,6 +37,7 @@ #include "scene/2d/sprite_2d.h" #include "scene/3d/sprite_3d.h" #include "scene/animation/animation_player.h" +#include "scene/resources/text_line.h" #include "servers/audio/audio_stream.h" /// BOOL /// @@ -80,12 +81,14 @@ void AnimationTrackEditBool::draw_key(int p_index, float p_pixels_sec, int p_x, int AnimationTrackEditColor::get_key_height() const { Ref font = get_theme_font("font", "Label"); - return font->get_height() * 0.8; + int font_size = get_theme_font_size("font_size", "Label"); + return font->get_height(font_size) * 0.8; } Rect2 AnimationTrackEditColor::get_key_rect(int p_index, float p_pixels_sec) { Ref font = get_theme_font("font", "Label"); - int fh = font->get_height() * 0.8; + int font_size = get_theme_font_size("font_size", "Label"); + int fh = font->get_height(font_size) * 0.8; return Rect2(-fh / 2, 0, fh, get_size().height); } @@ -95,7 +98,8 @@ bool AnimationTrackEditColor::is_key_selectable_by_distance() const { void AnimationTrackEditColor::draw_key_link(int p_index, float p_pixels_sec, int p_x, int p_next_x, int p_clip_left, int p_clip_right) { Ref font = get_theme_font("font", "Label"); - int fh = (font->get_height() * 0.8); + int font_size = get_theme_font_size("font_size", "Label"); + int fh = (font->get_height(font_size) * 0.8); int x_from = p_x + fh / 2 - 1; int x_to = p_next_x - fh / 2 + 1; @@ -144,7 +148,8 @@ void AnimationTrackEditColor::draw_key(int p_index, float p_pixels_sec, int p_x, Color color = get_animation()->track_get_key_value(get_track(), p_index); Ref font = get_theme_font("font", "Label"); - int fh = font->get_height() * 0.8; + int font_size = get_theme_font_size("font_size", "Label"); + int fh = font->get_height(font_size) * 0.8; Rect2 rect(Vector2(p_x - fh / 2, int(get_size().height - fh) / 2), Size2(fh, fh)); @@ -182,7 +187,8 @@ int AnimationTrackEditAudio::get_key_height() const { } Ref font = get_theme_font("font", "Label"); - return int(font->get_height() * 1.5); + int font_size = get_theme_font_size("font_size", "Label"); + return int(font->get_height(font_size) * 1.5); } Rect2 AnimationTrackEditAudio::get_key_rect(int p_index, float p_pixels_sec) { @@ -214,7 +220,8 @@ Rect2 AnimationTrackEditAudio::get_key_rect(int p_index, float p_pixels_sec) { return Rect2(0, 0, len * p_pixels_sec, get_size().height); } else { Ref font = get_theme_font("font", "Label"); - int fh = font->get_height() * 0.8; + int font_size = get_theme_font_size("font_size", "Label"); + int fh = font->get_height(font_size) * 0.8; return Rect2(0, 0, fh, get_size().height); } } @@ -277,7 +284,8 @@ void AnimationTrackEditAudio::draw_key(int p_index, float p_pixels_sec, int p_x, } Ref font = get_theme_font("font", "Label"); - float fh = int(font->get_height() * 1.5); + int font_size = get_theme_font_size("font_size", "Label"); + float fh = int(font->get_height(font_size) * 1.5); Rect2 rect = Rect2(from_x, (get_size().height - fh) / 2, to_x - from_x, fh); draw_rect(rect, Color(0.25, 0.25, 0.25)); @@ -307,7 +315,8 @@ void AnimationTrackEditAudio::draw_key(int p_index, float p_pixels_sec, int p_x, } } else { Ref font = get_theme_font("font", "Label"); - int fh = font->get_height() * 0.8; + int font_size = get_theme_font_size("font_size", "Label"); + int fh = font->get_height(font_size) * 0.8; Rect2 rect(Vector2(p_x, int(get_size().height - fh) / 2), Size2(fh, fh)); Color color = get_theme_color("font_color", "Label"); @@ -339,7 +348,8 @@ int AnimationTrackEditSpriteFrame::get_key_height() const { } Ref font = get_theme_font("font", "Label"); - return int(font->get_height() * 2); + int font_size = get_theme_font_size("font_size", "Label"); + return int(font->get_height(font_size) * 2); } Rect2 AnimationTrackEditSpriteFrame::get_key_rect(int p_index, float p_pixels_sec) { @@ -406,7 +416,8 @@ Rect2 AnimationTrackEditSpriteFrame::get_key_rect(int p_index, float p_pixels_se size = size.floor(); Ref font = get_theme_font("font", "Label"); - int height = int(font->get_height() * 2); + int font_size = get_theme_font_size("font_size", "Label"); + int height = int(font->get_height(font_size) * 2); int width = height * size.width / size.height; return Rect2(0, 0, width, get_size().height); @@ -496,7 +507,8 @@ void AnimationTrackEditSpriteFrame::draw_key(int p_index, float p_pixels_sec, in } Ref font = get_theme_font("font", "Label"); - int height = int(font->get_height() * 2); + int font_size = get_theme_font_size("font_size", "Label"); + int height = int(font->get_height(font_size) * 2); int width = height * region.size.width / region.size.height; @@ -539,7 +551,8 @@ int AnimationTrackEditSubAnim::get_key_height() const { } Ref font = get_theme_font("font", "Label"); - return int(font->get_height() * 1.5); + int font_size = get_theme_font_size("font_size", "Label"); + return int(font->get_height(font_size) * 1.5); } Rect2 AnimationTrackEditSubAnim::get_key_rect(int p_index, float p_pixels_sec) { @@ -567,7 +580,8 @@ Rect2 AnimationTrackEditSubAnim::get_key_rect(int p_index, float p_pixels_sec) { return Rect2(0, 0, len * p_pixels_sec, get_size().height); } else { Ref font = get_theme_font("font", "Label"); - int fh = font->get_height() * 0.8; + int font_size = get_theme_font_size("font_size", "Label"); + int fh = font->get_height(font_size) * 0.8; return Rect2(0, 0, fh, get_size().height); } } @@ -621,7 +635,8 @@ void AnimationTrackEditSubAnim::draw_key(int p_index, float p_pixels_sec, int p_ } Ref font = get_theme_font("font", "Label"); - int fh = font->get_height() * 1.5; + int font_size = get_theme_font_size("font_size", "Label"); + int fh = font->get_height(font_size) * 1.5; Rect2 rect(from_x, int(get_size().height - fh) / 2, to_x - from_x, fh); @@ -664,7 +679,7 @@ void AnimationTrackEditSubAnim::draw_key(int p_index, float p_pixels_sec, int p_ int limit = to_x - from_x - 4; if (limit > 0) { - draw_string(font, Point2(from_x + 2, int(get_size().height - font->get_height()) / 2 + font->get_ascent()), anim, color); + draw_string(font, Point2(from_x + 2, int(get_size().height - font->get_height(font_size)) / 2 + font->get_ascent(font_size)), anim, HALIGN_LEFT, -1, font_size, color); } if (p_selected) { @@ -673,7 +688,8 @@ void AnimationTrackEditSubAnim::draw_key(int p_index, float p_pixels_sec, int p_ } } else { Ref font = get_theme_font("font", "Label"); - int fh = font->get_height() * 0.8; + int font_size = get_theme_font_size("font_size", "Label"); + int fh = font->get_height(font_size) * 0.8; Rect2 rect(Vector2(p_x, int(get_size().height - fh) / 2), Size2(fh, fh)); Color color = get_theme_color("font_color", "Label"); @@ -771,7 +787,8 @@ void AnimationTrackEditTypeAudio::_preview_changed(ObjectID p_which) { int AnimationTrackEditTypeAudio::get_key_height() const { Ref font = get_theme_font("font", "Label"); - return int(font->get_height() * 1.5); + int font_size = get_theme_font_size("font_size", "Label"); + return int(font->get_height(font_size) * 1.5); } Rect2 AnimationTrackEditTypeAudio::get_key_rect(int p_index, float p_pixels_sec) { @@ -835,7 +852,8 @@ void AnimationTrackEditTypeAudio::draw_key(int p_index, float p_pixels_sec, int } Ref font = get_theme_font("font", "Label"); - float fh = int(font->get_height() * 1.5); + int font_size = get_theme_font_size("font_size", "Label"); + float fh = int(font->get_height(font_size) * 1.5); float len = stream->get_length(); @@ -1104,7 +1122,8 @@ int AnimationTrackEditTypeAnimation::get_key_height() const { } Ref font = get_theme_font("font", "Label"); - return int(font->get_height() * 1.5); + int font_size = get_theme_font_size("font_size", "Label"); + return int(font->get_height(font_size) * 1.5); } Rect2 AnimationTrackEditTypeAnimation::get_key_rect(int p_index, float p_pixels_sec) { @@ -1132,7 +1151,8 @@ Rect2 AnimationTrackEditTypeAnimation::get_key_rect(int p_index, float p_pixels_ return Rect2(0, 0, len * p_pixels_sec, get_size().height); } else { Ref font = get_theme_font("font", "Label"); - int fh = font->get_height() * 0.8; + int font_size = get_theme_font_size("font_size", "Label"); + int fh = font->get_height(font_size) * 0.8; return Rect2(0, 0, fh, get_size().height); } } @@ -1186,7 +1206,8 @@ void AnimationTrackEditTypeAnimation::draw_key(int p_index, float p_pixels_sec, } Ref font = get_theme_font("font", "Label"); - int fh = font->get_height() * 1.5; + int font_size = get_theme_font_size("font_size", "Label"); + int fh = font->get_height(font_size) * 1.5; Rect2 rect(from_x, int(get_size().height - fh) / 2, to_x - from_x, fh); @@ -1229,7 +1250,7 @@ void AnimationTrackEditTypeAnimation::draw_key(int p_index, float p_pixels_sec, int limit = to_x - from_x - 4; if (limit > 0) { - draw_string(font, Point2(from_x + 2, int(get_size().height - font->get_height()) / 2 + font->get_ascent()), anim, color); + draw_string(font, Point2(from_x + 2, int(get_size().height - font->get_height(font_size)) / 2 + font->get_ascent(font_size)), anim, HALIGN_LEFT, -1, font_size, color); } if (p_selected) { @@ -1238,7 +1259,8 @@ void AnimationTrackEditTypeAnimation::draw_key(int p_index, float p_pixels_sec, } } else { Ref font = get_theme_font("font", "Label"); - int fh = font->get_height() * 0.8; + int font_size = get_theme_font_size("font_size", "Label"); + int fh = font->get_height(font_size) * 0.8; Rect2 rect(Vector2(p_x, int(get_size().height - fh) / 2), Size2(fh, fh)); Color color = get_theme_color("font_color", "Label"); diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 3182bca0ebc1..8f5b5612fc56 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -38,7 +38,7 @@ #include "editor_settings.h" #include "scene/gui/margin_container.h" #include "scene/gui/separator.h" -#include "scene/resources/dynamic_font.h" +#include "scene/resources/font.h" void GotoLineDialog::popup_find_line(CodeEdit *p_edit) { text_editor = p_edit; @@ -731,17 +731,10 @@ void CodeTextEditor::_text_editor_gui_input(const Ref &p_event) { Ref magnify_gesture = p_event; if (magnify_gesture.is_valid()) { - Ref font = text_editor->get_theme_font("font"); + font_size = text_editor->get_theme_font_size("font_size"); + font_size *= powf(magnify_gesture->get_factor(), 0.25); - if (font.is_valid()) { - if (font->get_size() != (int)font_size) { - font_size = font->get_size(); - } - - font_size *= powf(magnify_gesture->get_factor(), 0.25); - - _add_font_size((int)font_size - font->get_size()); - } + _add_font_size((int)font_size - text_editor->get_theme_font_size("font_size")); return; } @@ -779,12 +772,8 @@ void CodeTextEditor::_zoom_changed() { } void CodeTextEditor::_reset_zoom() { - Ref font = text_editor->get_theme_font("font"); // Reset source font size to default. - - if (font.is_valid()) { - EditorSettings::get_singleton()->set("interface/editor/code_font_size", 14); - font->set_size(14); - } + EditorSettings::get_singleton()->set("interface/editor/code_font_size", 14); + text_editor->add_theme_font_size_override("font_size", 14 * EDSCALE); } void CodeTextEditor::_line_col_changed() { @@ -900,20 +889,15 @@ void CodeTextEditor::_font_resize_timeout() { } bool CodeTextEditor::_add_font_size(int p_delta) { - Ref font = text_editor->get_theme_font("font"); + int old_size = text_editor->get_theme_font_size("font_size"); + int new_size = CLAMP(old_size + p_delta, 8 * EDSCALE, 96 * EDSCALE); - if (font.is_valid()) { - int new_size = CLAMP(font->get_size() + p_delta, 8 * EDSCALE, 96 * EDSCALE); - - if (new_size != font->get_size()) { - EditorSettings::get_singleton()->set("interface/editor/code_font_size", new_size / EDSCALE); - font->set_size(new_size); - } - - return true; - } else { - return false; + if (new_size != old_size) { + EditorSettings::get_singleton()->set("interface/editor/code_font_size", new_size / EDSCALE); + text_editor->add_theme_font_size_override("font_size", new_size); } + + return true; } void CodeTextEditor::update_editor_settings() { @@ -1486,17 +1470,22 @@ void CodeTextEditor::goto_error() { void CodeTextEditor::_update_font() { text_editor->add_theme_font_override("font", get_theme_font("source", "EditorFonts")); + text_editor->add_theme_font_size_override("font_size", get_theme_font_size("source_size", "EditorFonts")); error->add_theme_font_override("font", get_theme_font("status_source", "EditorFonts")); + error->add_theme_font_size_override("font_size", get_theme_font_size("status_source_size", "EditorFonts")); error->add_theme_color_override("font_color", get_theme_color("error_color", "Editor")); Ref status_bar_font = get_theme_font("status_source", "EditorFonts"); + int status_bar_font_size = get_theme_font_size("status_source_size", "EditorFonts"); error->add_theme_font_override("font", status_bar_font); + error->add_theme_font_size_override("font_size", status_bar_font_size); int count = status_bar->get_child_count(); for (int i = 0; i < count; i++) { Control *n = Object::cast_to(status_bar->get_child(i)); if (n) { n->add_theme_font_override("font", status_bar_font); + n->add_theme_font_size_override("font_size", status_bar_font_size); } } } @@ -1506,6 +1495,31 @@ void CodeTextEditor::_on_settings_change() { font_size = EditorSettings::get_singleton()->get("interface/editor/code_font_size"); + int ot_mode = EditorSettings::get_singleton()->get("interface/editor/code_font_contextual_ligatures"); + switch (ot_mode) { + case 1: { // Disable ligatures. + text_editor->clear_opentype_features(); + text_editor->set_opentype_feature("calt", 0); + } break; + case 2: { // Custom. + text_editor->clear_opentype_features(); + Vector subtag = String(EditorSettings::get_singleton()->get("interface/editor/code_font_custom_opentype_features")).split(","); + Dictionary ftrs; + for (int i = 0; i < subtag.size(); i++) { + Vector subtag_a = subtag[i].split("="); + if (subtag_a.size() == 2) { + text_editor->set_opentype_feature(subtag_a[0], subtag_a[1].to_int()); + } else if (subtag_a.size() == 1) { + text_editor->set_opentype_feature(subtag_a[0], 1); + } + } + } break; + default: { // Default. + text_editor->clear_opentype_features(); + text_editor->set_opentype_feature("calt", 1); + } break; + } + // Auto brace completion. text_editor->set_auto_brace_completion( EDITOR_GET("text_editor/completion/auto_brace_complete")); @@ -1547,7 +1561,11 @@ void CodeTextEditor::_set_show_warnings_panel(bool p_show) { } void CodeTextEditor::_toggle_scripts_pressed() { - toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->toggle_scripts_panel() ? get_theme_icon("Back", "EditorIcons") : get_theme_icon("Forward", "EditorIcons")); + if (is_layout_rtl()) { + toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->toggle_scripts_panel() ? get_theme_icon("Back", "EditorIcons") : get_theme_icon("Forward", "EditorIcons")); + } else { + toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->toggle_scripts_panel() ? get_theme_icon("Forward", "EditorIcons") : get_theme_icon("Back", "EditorIcons")); + } } void CodeTextEditor::_error_pressed(const Ref &p_event) { @@ -1668,7 +1686,11 @@ void CodeTextEditor::show_toggle_scripts_button() { } void CodeTextEditor::update_toggle_scripts_button() { - toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? get_theme_icon("Back", "EditorIcons") : get_theme_icon("Forward", "EditorIcons")); + if (is_layout_rtl()) { + toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? get_theme_icon("Back", "EditorIcons") : get_theme_icon("Forward", "EditorIcons")); + } else { + toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? get_theme_icon("Forward", "EditorIcons") : get_theme_icon("Back", "EditorIcons")); + } toggle_scripts_button->set_tooltip(TTR("Toggle Scripts Panel") + " (" + ED_GET_SHORTCUT("script_editor/toggle_scripts_panel")->get_as_text() + ")"); } @@ -1682,6 +1704,31 @@ CodeTextEditor::CodeTextEditor() { add_child(text_editor); text_editor->set_v_size_flags(SIZE_EXPAND_FILL); + int ot_mode = EditorSettings::get_singleton()->get("interface/editor/code_font_contextual_ligatures"); + switch (ot_mode) { + case 1: { // Disable ligatures. + text_editor->clear_opentype_features(); + text_editor->set_opentype_feature("calt", 0); + } break; + case 2: { // Custom. + text_editor->clear_opentype_features(); + Vector subtag = String(EditorSettings::get_singleton()->get("interface/editor/code_font_custom_opentype_features")).split(","); + Dictionary ftrs; + for (int i = 0; i < subtag.size(); i++) { + Vector subtag_a = subtag[i].split("="); + if (subtag_a.size() == 2) { + text_editor->set_opentype_feature(subtag_a[0], subtag_a[1].to_int()); + } else if (subtag_a.size() == 1) { + text_editor->set_opentype_feature(subtag_a[0], 1); + } + } + } break; + default: { // Default. + text_editor->clear_opentype_features(); + text_editor->set_opentype_feature("calt", 1); + } break; + } + // Added second so it opens at the bottom, so it won't shift the entire text editor when opening. find_replace_bar = memnew(FindReplaceBar); add_child(find_replace_bar); @@ -1750,6 +1797,7 @@ CodeTextEditor::CodeTextEditor() { warning_count_label->set_tooltip(TTR("Warnings")); warning_count_label->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color("warning_color", "Editor")); warning_count_label->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("status_source", "EditorFonts")); + warning_count_label->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("status_source_size", "EditorFonts")); warning_count_label->connect("gui_input", callable_mp(this, &CodeTextEditor::_warning_label_gui_input)); is_warnings_panel_opened = false; @@ -1760,6 +1808,7 @@ CodeTextEditor::CodeTextEditor() { status_bar->add_child(line_and_col_txt); line_and_col_txt->set_v_size_flags(SIZE_EXPAND | SIZE_SHRINK_CENTER); line_and_col_txt->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("status_source", "EditorFonts")); + line_and_col_txt->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("status_source_size", "EditorFonts")); line_and_col_txt->set_tooltip(TTR("Line and column numbers.")); line_and_col_txt->set_mouse_filter(MOUSE_FILTER_STOP); diff --git a/editor/debugger/editor_performance_profiler.cpp b/editor/debugger/editor_performance_profiler.cpp index 47fe28275880..44c5f83e9a0a 100644 --- a/editor/debugger/editor_performance_profiler.cpp +++ b/editor/debugger/editor_performance_profiler.cpp @@ -82,10 +82,10 @@ String EditorPerformanceProfiler::_create_label(float p_value, Performance::Moni return String::humanize_size(p_value); } case Performance::MONITOR_TYPE_TIME: { - return rtos(p_value * 1000).pad_decimals(2) + " ms"; + return TS->format_number(rtos(p_value * 1000).pad_decimals(2)) + " " + RTR("ms"); } default: { - return rtos(p_value); + return TS->format_number(rtos(p_value)); } } } @@ -111,6 +111,7 @@ void EditorPerformanceProfiler::_monitor_draw() { Ref graph_style_box = get_theme_stylebox("normal", "TextEdit"); Ref graph_font = get_theme_font("font", "TextEdit"); + int font_size = get_theme_font_size("font_size", "TextEdit"); int columns = int(Math::ceil(Math::sqrt(float(active.size())))); int rows = int(Math::ceil(float(active.size()) / float(columns))); @@ -131,19 +132,19 @@ void EditorPerformanceProfiler::_monitor_draw() { rect.size -= graph_style_box->get_minimum_size(); Color draw_color = get_theme_color("accent_color", "Editor"); draw_color.set_hsv(Math::fmod(hue_shift * float(current.frame_index), 0.9f), draw_color.get_s() * 0.9f, draw_color.get_v() * value_multiplier, 0.6f); - monitor_draw->draw_string(graph_font, rect.position + Point2(0, graph_font->get_ascent()), current.item->get_text(0), draw_color, rect.size.x); + monitor_draw->draw_string(graph_font, rect.position + Point2(0, graph_font->get_ascent(font_size)), current.item->get_text(0), HALIGN_LEFT, rect.size.x, font_size, draw_color); draw_color.a = 0.9f; - float value_position = rect.size.width - graph_font->get_string_size(current.item->get_text(1)).width; + float value_position = rect.size.width - graph_font->get_string_size(current.item->get_text(1), font_size).width; if (value_position < 0) { value_position = 0; } - monitor_draw->draw_string(graph_font, rect.position + Point2(value_position, graph_font->get_ascent()), current.item->get_text(1), draw_color, rect.size.x); + monitor_draw->draw_string(graph_font, rect.position + Point2(value_position, graph_font->get_ascent(font_size)), current.item->get_text(1), HALIGN_LEFT, rect.size.x, font_size, draw_color); - rect.position.y += graph_font->get_height(); - rect.size.height -= graph_font->get_height(); + rect.position.y += graph_font->get_height(font_size); + rect.size.height -= graph_font->get_height(font_size); - int line_count = rect.size.height / (graph_font->get_height() * 2); + int line_count = rect.size.height / (graph_font->get_height(font_size) * 2); if (line_count > 5) { line_count = 5; } @@ -151,12 +152,12 @@ void EditorPerformanceProfiler::_monitor_draw() { Color horizontal_line_color; horizontal_line_color.set_hsv(draw_color.get_h(), draw_color.get_s() * 0.5f, draw_color.get_v() * 0.5f, 0.3f); monitor_draw->draw_line(rect.position, rect.position + Vector2(rect.size.width, 0), horizontal_line_color, Math::round(EDSCALE)); - monitor_draw->draw_string(graph_font, rect.position + Vector2(0, graph_font->get_ascent()), _create_label(current.max, current.type), horizontal_line_color, rect.size.width); + monitor_draw->draw_string(graph_font, rect.position + Vector2(0, graph_font->get_ascent(font_size)), _create_label(current.max, current.type), HALIGN_LEFT, rect.size.width, font_size, horizontal_line_color); for (int j = 0; j < line_count; j++) { Vector2 y_offset = Vector2(0, rect.size.height * (1.0f - float(j) / float(line_count))); monitor_draw->draw_line(rect.position + y_offset, rect.position + Vector2(rect.size.width, 0) + y_offset, horizontal_line_color, Math::round(EDSCALE)); - monitor_draw->draw_string(graph_font, rect.position - Vector2(0, graph_font->get_descent()) + y_offset, _create_label(current.max * float(j) / float(line_count), current.type), horizontal_line_color, rect.size.width); + monitor_draw->draw_string(graph_font, rect.position - Vector2(0, graph_font->get_descent(font_size)) + y_offset, _create_label(current.max * float(j) / float(line_count), current.type), HALIGN_LEFT, rect.size.width, font_size, horizontal_line_color); } } @@ -182,7 +183,7 @@ void EditorPerformanceProfiler::_monitor_draw() { monitor_draw->draw_line(rect.position + Point2(from, 0), rect.position + Point2(from, rect.size.y), line_color, Math::round(EDSCALE)); String label = _create_label(e->get(), current.type); - Size2 size = graph_font->get_string_size(label); + Size2 size = graph_font->get_string_size(label, font_size); Vector2 text_top_left_position = Vector2(from, h2) - (size + Vector2(MARKER_MARGIN, MARKER_MARGIN)); if (text_top_left_position.x < 0) { text_top_left_position.x = from + MARKER_MARGIN; @@ -190,7 +191,7 @@ void EditorPerformanceProfiler::_monitor_draw() { if (text_top_left_position.y < 0) { text_top_left_position.y = h2 + MARKER_MARGIN; } - monitor_draw->draw_string(graph_font, rect.position + text_top_left_position + Point2(0, graph_font->get_ascent()), label, line_color, rect.size.x); + monitor_draw->draw_string(graph_font, rect.position + text_top_left_position + Point2(0, graph_font->get_ascent(font_size)), label, HALIGN_LEFT, rect.size.x, font_size, line_color); } prev = h2; e = e->next(); diff --git a/editor/debugger/editor_profiler.cpp b/editor/debugger/editor_profiler.cpp index 8bd21fff5c24..930aca6e5a62 100644 --- a/editor/debugger/editor_profiler.cpp +++ b/editor/debugger/editor_profiler.cpp @@ -103,19 +103,19 @@ static String _get_percent_txt(float p_value, float p_total) { p_total = 0.00001; } - return String::num((p_value / p_total) * 100, 1) + "%"; + return TS->format_number(String::num((p_value / p_total) * 100, 1)) + TS->percent_sign(); } String EditorProfiler::_get_time_as_text(const Metric &m, float p_time, int p_calls) { const int dmode = display_mode->get_selected(); if (dmode == DISPLAY_FRAME_TIME) { - return rtos(p_time * 1000).pad_decimals(2) + " ms"; + return TS->format_number(rtos(p_time * 1000).pad_decimals(2)) + " " + RTR("ms"); } else if (dmode == DISPLAY_AVERAGE_TIME) { if (p_calls == 0) { - return "0.00 ms"; + return TS->format_number("0.00") + " " + RTR("ms"); } else { - return rtos((p_time / p_calls) * 1000).pad_decimals(2) + " ms"; + return TS->format_number(rtos((p_time / p_calls) * 1000).pad_decimals(2)) + " " + RTR("ms"); } } else if (dmode == DISPLAY_FRAME_PERCENT) { return _get_percent_txt(p_time, m.frame_time); @@ -423,7 +423,7 @@ void EditorProfiler::_clear_pressed() { } void EditorProfiler::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED || p_what == NOTIFICATION_TRANSLATION_CHANGED) { activate->set_icon(get_theme_icon("Play", "EditorIcons")); clear_button->set_icon(get_theme_icon("Clear", "EditorIcons")); } diff --git a/editor/debugger/editor_visual_profiler.cpp b/editor/debugger/editor_visual_profiler.cpp index baeb06794a68..d7a09d6b0cbc 100644 --- a/editor/debugger/editor_visual_profiler.cpp +++ b/editor/debugger/editor_visual_profiler.cpp @@ -114,9 +114,9 @@ String EditorVisualProfiler::_get_time_as_text(float p_time) { int dmode = display_mode->get_selected(); if (dmode == DISPLAY_FRAME_TIME) { - return rtos(p_time) + "ms"; + return TS->format_number(rtos(p_time)) + " " + RTR("ms"); } else if (dmode == DISPLAY_FRAME_PERCENT) { - return String::num(p_time * 100 / graph_limit, 2) + "%"; + return TS->format_number(String::num(p_time * 100 / graph_limit, 2)) + " " + TS->percent_sign(); } return "err"; @@ -423,8 +423,12 @@ void EditorVisualProfiler::_clear_pressed() { } void EditorVisualProfiler::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - activate->set_icon(get_theme_icon("Play", "EditorIcons")); + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED || p_what == NOTIFICATION_TRANSLATION_CHANGED) { + if (is_layout_rtl()) { + activate->set_icon(get_theme_icon("PlayBackwards", "EditorIcons")); + } else { + activate->set_icon(get_theme_icon("Play", "EditorIcons")); + } clear_button->set_icon(get_theme_icon("Clear", "EditorIcons")); } } @@ -434,6 +438,7 @@ void EditorVisualProfiler::_graph_tex_draw() { return; } Ref font = get_theme_font("font", "Label"); + int font_size = get_theme_font_size("font_size", "Label"); if (seeking) { int max_frames = frame_metrics.size(); int frame = cursor_metric_edit->get_value() - (frame_metrics[last_metric].frame_number - max_frames + 1); @@ -457,7 +462,7 @@ void EditorVisualProfiler::_graph_tex_draw() { graph->draw_line(Vector2(0, frame_y), Vector2(half_width, frame_y), Color(1, 1, 1, 0.3)); String limit_str = String::num(graph_limit, 2); - graph->draw_string(font, Vector2(half_width - font->get_string_size(limit_str).x - 2, frame_y - 2), limit_str, Color(1, 1, 1, 0.6)); + graph->draw_string(font, Vector2(half_width - font->get_string_size(limit_str, font_size).x - 2, frame_y - 2), limit_str, HALIGN_LEFT, -1, font_size, Color(1, 1, 1, 0.6)); } if (graph_height_gpu > 0) { @@ -468,11 +473,11 @@ void EditorVisualProfiler::_graph_tex_draw() { graph->draw_line(Vector2(half_width, frame_y), Vector2(graph->get_size().x, frame_y), Color(1, 1, 1, 0.3)); String limit_str = String::num(graph_limit, 2); - graph->draw_string(font, Vector2(half_width * 2 - font->get_string_size(limit_str).x - 2, frame_y - 2), limit_str, Color(1, 1, 1, 0.6)); + graph->draw_string(font, Vector2(half_width * 2 - font->get_string_size(limit_str, font_size).x - 2, frame_y - 2), limit_str, HALIGN_LEFT, -1, font_size, Color(1, 1, 1, 0.6)); } - graph->draw_string(font, Vector2(font->get_string_size("X").x, font->get_ascent() + 2), "CPU:", Color(1, 1, 1, 0.8)); - graph->draw_string(font, Vector2(font->get_string_size("X").x + graph->get_size().width / 2, font->get_ascent() + 2), "GPU:", Color(1, 1, 1, 0.8)); + graph->draw_string(font, Vector2(font->get_string_size("X", font_size).x, font->get_ascent(font_size) + 2), "CPU:", HALIGN_LEFT, -1, font_size, Color(1, 1, 1, 0.8)); + graph->draw_string(font, Vector2(font->get_string_size("X", font_size).x + graph->get_size().width / 2, font->get_ascent(font_size) + 2), "GPU:", HALIGN_LEFT, -1, font_size, Color(1, 1, 1, 0.8)); /* if (hover_metric != -1 && frame_metrics[hover_metric].valid) { diff --git a/editor/doc_data.cpp b/editor/doc_data.cpp index 8504d61d2f98..165a5c8546f5 100644 --- a/editor/doc_data.cpp +++ b/editor/doc_data.cpp @@ -523,6 +523,14 @@ void DocData::generate(bool p_basic_types) { c.theme_properties.push_back(pd); } l.clear(); + Theme::get_default()->get_font_size_list(cname, &l); + for (List::Element *E = l.front(); E; E = E->next()) { + PropertyDoc pd; + pd.name = E->get(); + pd.type = "int"; + c.theme_properties.push_back(pd); + } + l.clear(); Theme::get_default()->get_stylebox_list(cname, &l); for (List::Element *E = l.front(); E; E = E->next()) { PropertyDoc pd; diff --git a/editor/editor_about.cpp b/editor/editor_about.cpp index cbde7d593af4..95802a0b9c15 100644 --- a/editor/editor_about.cpp +++ b/editor/editor_about.cpp @@ -40,9 +40,12 @@ void EditorAbout::_theme_changed() { Control *base = EditorNode::get_singleton()->get_gui_base(); Ref font = base->get_theme_font("source", "EditorFonts"); + int font_size = base->get_theme_font_size("source_size", "EditorFonts"); _tpl_text->add_theme_font_override("normal_font", font); + _tpl_text->add_theme_font_size_override("normal_font_size", font_size); _tpl_text->add_theme_constant_override("line_separation", 6 * EDSCALE); _license_text->add_theme_font_override("normal_font", font); + _license_text->add_theme_font_size_override("normal_font_size", font_size); _license_text->add_theme_constant_override("line_separation", 6 * EDSCALE); _logo->set_texture(base->get_theme_icon("Logo", "EditorIcons")); } @@ -213,7 +216,7 @@ EditorAbout::EditorAbout() { for (int component_index = 0; component_index < COPYRIGHT_INFO_COUNT; component_index++) { const ComponentCopyright &component = COPYRIGHT_INFO[component_index]; TreeItem *ti = _tpl_tree->create_item(tpl_ti_tp); - String component_name = component.name; + String component_name = String::utf8(component.name); ti->set_text(0, component_name); String text = component_name + "\n"; long_text += "- " + component_name + "\n"; @@ -221,7 +224,7 @@ EditorAbout::EditorAbout() { const ComponentCopyrightPart &part = component.parts[part_index]; text += "\n Files:"; for (int file_num = 0; file_num < part.file_count; file_num++) { - text += "\n " + String(part.files[file_num]); + text += "\n " + String::utf8(part.files[file_num]); } String copyright; for (int copyright_index = 0; copyright_index < part.copyright_count; copyright_index++) { @@ -229,7 +232,7 @@ EditorAbout::EditorAbout() { } text += copyright; long_text += copyright; - String license = "\n License: " + String(part.license) + "\n"; + String license = "\n License: " + String::utf8(part.license) + "\n"; text += license; long_text += license + "\n"; } @@ -237,10 +240,10 @@ EditorAbout::EditorAbout() { } for (int i = 0; i < LICENSE_COUNT; i++) { TreeItem *ti = _tpl_tree->create_item(tpl_ti_lc); - String licensename = String(LICENSE_NAMES[i]); + String licensename = String::utf8(LICENSE_NAMES[i]); ti->set_text(0, licensename); long_text += "- " + licensename + "\n\n"; - String licensebody = String(LICENSE_BODIES[i]); + String licensebody = String::utf8(LICENSE_BODIES[i]); ti->set_metadata(0, licensebody); long_text += " " + licensebody.replace("\n", "\n ") + "\n\n"; } diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index a3deb9513067..6dc0fffd925c 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -1379,14 +1379,15 @@ void EditorAudioMeterNotches::add_notch(float p_normalized_offset, float p_db_va Size2 EditorAudioMeterNotches::get_minimum_size() const { Ref font = get_theme_font("font", "Label"); - float font_height = font->get_height(); + int font_size = get_theme_font_size("font_size", "Label"); + float font_height = font->get_height(font_size); float width = 0; float height = top_padding + btm_padding; for (int i = 0; i < notches.size(); i++) { if (notches[i].render_db_value) { - width = MAX(width, font->get_string_size(String::num(Math::abs(notches[i].db_value)) + "dB").x); + width = MAX(width, font->get_string_size(String::num(Math::abs(notches[i].db_value)) + "dB", font_size).x); height += font_height; } } @@ -1413,7 +1414,8 @@ void EditorAudioMeterNotches::_notification(int p_what) { void EditorAudioMeterNotches::_draw_audio_notches() { Ref font = get_theme_font("font", "Label"); - float font_height = font->get_height(); + int font_size = get_theme_font_size("font_size", "Label"); + float font_height = font->get_height(font_size); for (int i = 0; i < notches.size(); i++) { AudioNotch n = notches[i]; @@ -1427,6 +1429,7 @@ void EditorAudioMeterNotches::_draw_audio_notches() { Vector2(line_length + label_space, (1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + (font_height / 4) + top_padding), String::num(Math::abs(n.db_value)) + "dB", + HALIGN_LEFT, -1, font_size, notch_color); } } diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index 69edefd75c05..f7cb5428ce32 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -398,7 +398,11 @@ Error EditorExportPlatform::_save_zip_file(void *p_userdata, const String &p_pat Ref EditorExportPlatform::get_option_icon(int p_index) const { Ref theme = EditorNode::get_singleton()->get_editor_theme(); ERR_FAIL_COND_V(theme.is_null(), Ref()); - return theme->get_icon("Play", "EditorIcons"); + if (EditorNode::get_singleton()->get_viewport()->is_layout_rtl()) { + return theme->get_icon("PlayBackwards", "EditorIcons"); + } else { + return theme->get_icon("Play", "EditorIcons"); + } } String EditorExportPlatform::find_export_template(String template_file_name, String *err) const { @@ -972,6 +976,15 @@ Error EditorExportPlatform::export_project_files(const Ref & p_func(p_udata, splash, array, idx, total, enc_in_filters, enc_ex_filters, key); } + // Store text server data if exists. + if (TS->has_feature(TextServer::FEATURE_USE_SUPPORT_DATA)) { + String ts_data = "res://" + TS->get_support_data_filename(); + if (FileAccess::exists(ts_data)) { + Vector array = FileAccess::get_file_as_array(ts_data); + p_func(p_udata, ts_data, array, idx, total, enc_in_filters, enc_ex_filters, key); + } + } + String config_file = "project.binary"; String engine_cfb = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp" + config_file); ProjectSettings::get_singleton()->save_custom(engine_cfb, custom_map, custom_list); diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index e3923a48c5ec..ffdd7c7fa847 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -59,12 +59,17 @@ VBoxContainer *EditorFileDialog::get_vbox() { } void EditorFileDialog::_notification(int p_what) { - if (p_what == NOTIFICATION_READY || p_what == NOTIFICATION_THEME_CHANGED) { + if (p_what == NOTIFICATION_READY || p_what == NOTIFICATION_THEME_CHANGED || p_what == Control::NOTIFICATION_LAYOUT_DIRECTION_CHANGED || p_what == NOTIFICATION_TRANSLATION_CHANGED) { // Update icons. mode_thumbnails->set_icon(item_list->get_theme_icon("FileThumbnail", "EditorIcons")); mode_list->set_icon(item_list->get_theme_icon("FileList", "EditorIcons")); - dir_prev->set_icon(item_list->get_theme_icon("Back", "EditorIcons")); - dir_next->set_icon(item_list->get_theme_icon("Forward", "EditorIcons")); + if (is_layout_rtl()) { + dir_prev->set_icon(item_list->get_theme_icon("Forward", "EditorIcons")); + dir_next->set_icon(item_list->get_theme_icon("Back", "EditorIcons")); + } else { + dir_prev->set_icon(item_list->get_theme_icon("Back", "EditorIcons")); + dir_next->set_icon(item_list->get_theme_icon("Forward", "EditorIcons")); + } dir_up->set_icon(item_list->get_theme_icon("ArrowUp", "EditorIcons")); refresh->set_icon(item_list->get_theme_icon("Reload", "EditorIcons")); favorite->set_icon(item_list->get_theme_icon("Favorites", "EditorIcons")); @@ -97,8 +102,13 @@ void EditorFileDialog::_notification(int p_what) { // Update icons. mode_thumbnails->set_icon(item_list->get_theme_icon("FileThumbnail", "EditorIcons")); mode_list->set_icon(item_list->get_theme_icon("FileList", "EditorIcons")); - dir_prev->set_icon(item_list->get_theme_icon("Back", "EditorIcons")); - dir_next->set_icon(item_list->get_theme_icon("Forward", "EditorIcons")); + if (is_layout_rtl()) { + dir_prev->set_icon(item_list->get_theme_icon("Forward", "EditorIcons")); + dir_next->set_icon(item_list->get_theme_icon("Back", "EditorIcons")); + } else { + dir_prev->set_icon(item_list->get_theme_icon("Back", "EditorIcons")); + dir_next->set_icon(item_list->get_theme_icon("Forward", "EditorIcons")); + } dir_up->set_icon(item_list->get_theme_icon("ArrowUp", "EditorIcons")); refresh->set_icon(item_list->get_theme_icon("Reload", "EditorIcons")); favorite->set_icon(item_list->get_theme_icon("Favorites", "EditorIcons")); @@ -1486,6 +1496,7 @@ EditorFileDialog::EditorFileDialog() { pathhb->add_child(drives_container); dir = memnew(LineEdit); + dir->set_structured_text_bidi_override(Control::STRUCTURED_TEXT_FILE); pathhb->add_child(dir); dir->set_h_size_flags(Control::SIZE_EXPAND_FILL); @@ -1624,6 +1635,7 @@ EditorFileDialog::EditorFileDialog() { file_box = memnew(HBoxContainer); file_box->add_child(memnew(Label(TTR("File:")))); file = memnew(LineEdit); + file->set_structured_text_bidi_override(Control::STRUCTURED_TEXT_FILE); file->set_stretch_ratio(4); file->set_h_size_flags(Control::SIZE_EXPAND_FILL); file_box->add_child(file); @@ -1662,6 +1674,7 @@ EditorFileDialog::EditorFileDialog() { makedialog->add_child(makevb); makedirname = memnew(LineEdit); + makedirname->set_structured_text_bidi_override(Control::STRUCTURED_TEXT_FILE); makevb->add_margin_child(TTR("Name:"), makedirname); add_child(makedialog); makedialog->register_text_enter(makedirname); diff --git a/editor/editor_fonts.cpp b/editor/editor_fonts.cpp index 100c76c32b7f..f5bb4921d487 100644 --- a/editor/editor_fonts.cpp +++ b/editor/editor_fonts.cpp @@ -35,57 +35,61 @@ #include "editor_scale.h" #include "editor_settings.h" #include "scene/resources/default_theme/default_theme.h" -#include "scene/resources/dynamic_font.h" - -#define MAKE_FALLBACKS(m_name) \ - m_name->add_fallback(FontArabic); \ - m_name->add_fallback(FontHebrew); \ - m_name->add_fallback(FontThai); \ - m_name->add_fallback(FontHindi); \ - m_name->add_fallback(FontJapanese); \ - m_name->add_fallback(FontFallback); +#include "scene/resources/font.h" + +#define MAKE_FALLBACKS(m_name) \ + m_name->add_data(FontArabic); \ + m_name->add_data(FontBengali); \ + m_name->add_data(FontGeorgian); \ + m_name->add_data(FontMalayalam); \ + m_name->add_data(FontOriya); \ + m_name->add_data(FontSinhala); \ + m_name->add_data(FontTamil); \ + m_name->add_data(FontTelugu); \ + m_name->add_data(FontHebrew); \ + m_name->add_data(FontThai); \ + m_name->add_data(FontHindi); \ + m_name->add_data(FontJapanese); \ + m_name->add_data(FontFallback); // the custom spacings might only work with Noto Sans -#define MAKE_DEFAULT_FONT(m_name, m_size) \ - Ref m_name; \ - m_name.instance(); \ - m_name->set_size(m_size); \ - if (CustomFont.is_valid()) { \ - m_name->set_font_data(CustomFont); \ - m_name->add_fallback(DefaultFont); \ - } else { \ - m_name->set_font_data(DefaultFont); \ - } \ - m_name->set_spacing(DynamicFont::SPACING_TOP, -EDSCALE); \ - m_name->set_spacing(DynamicFont::SPACING_BOTTOM, -EDSCALE); \ +#define MAKE_DEFAULT_FONT(m_name) \ + Ref m_name; \ + m_name.instance(); \ + if (CustomFont.is_valid()) { \ + m_name->add_data(CustomFont); \ + m_name->add_data(DefaultFont); \ + } else { \ + m_name->add_data(DefaultFont); \ + } \ + m_name->set_spacing(Font::SPACING_TOP, -EDSCALE); \ + m_name->set_spacing(Font::SPACING_BOTTOM, -EDSCALE); \ MAKE_FALLBACKS(m_name); -#define MAKE_BOLD_FONT(m_name, m_size) \ - Ref m_name; \ - m_name.instance(); \ - m_name->set_size(m_size); \ - if (CustomFontBold.is_valid()) { \ - m_name->set_font_data(CustomFontBold); \ - m_name->add_fallback(DefaultFontBold); \ - } else { \ - m_name->set_font_data(DefaultFontBold); \ - } \ - m_name->set_spacing(DynamicFont::SPACING_TOP, -EDSCALE); \ - m_name->set_spacing(DynamicFont::SPACING_BOTTOM, -EDSCALE); \ +#define MAKE_BOLD_FONT(m_name) \ + Ref m_name; \ + m_name.instance(); \ + if (CustomFontBold.is_valid()) { \ + m_name->add_data(CustomFontBold); \ + m_name->add_data(DefaultFontBold); \ + } else { \ + m_name->add_data(DefaultFontBold); \ + } \ + m_name->set_spacing(Font::SPACING_TOP, -EDSCALE); \ + m_name->set_spacing(Font::SPACING_BOTTOM, -EDSCALE); \ MAKE_FALLBACKS(m_name); -#define MAKE_SOURCE_FONT(m_name, m_size) \ - Ref m_name; \ - m_name.instance(); \ - m_name->set_size(m_size); \ - if (CustomFontSource.is_valid()) { \ - m_name->set_font_data(CustomFontSource); \ - m_name->add_fallback(dfmono); \ - } else { \ - m_name->set_font_data(dfmono); \ - } \ - m_name->set_spacing(DynamicFont::SPACING_TOP, -EDSCALE); \ - m_name->set_spacing(DynamicFont::SPACING_BOTTOM, -EDSCALE); \ +#define MAKE_SOURCE_FONT(m_name) \ + Ref m_name; \ + m_name.instance(); \ + if (CustomFontSource.is_valid()) { \ + m_name->add_data(CustomFontSource); \ + m_name->add_data(dfmono); \ + } else { \ + m_name->add_data(dfmono); \ + } \ + m_name->set_spacing(Font::SPACING_TOP, -EDSCALE); \ + m_name->set_spacing(Font::SPACING_BOTTOM, -EDSCALE); \ MAKE_FALLBACKS(m_name); void editor_register_fonts(Ref p_theme) { @@ -96,7 +100,7 @@ void editor_register_fonts(Ref p_theme) { bool font_antialiased = (bool)EditorSettings::get_singleton()->get("interface/editor/font_antialiased"); int font_hinting_setting = (int)EditorSettings::get_singleton()->get("interface/editor/font_hinting"); - DynamicFontData::Hinting font_hinting; + TextServer::Hinting font_hinting; switch (font_hinting_setting) { case 0: // The "Auto" setting uses the setting that best matches the OS' font rendering: @@ -104,29 +108,31 @@ void editor_register_fonts(Ref p_theme) { // - Windows uses ClearType, which is in between "Light" and "Normal" hinting. // - Linux has configurable font hinting, but most distributions including Ubuntu default to "Light". #ifdef OSX_ENABLED - font_hinting = DynamicFontData::HINTING_NONE; + font_hinting = TextServer::HINTING_NONE; #else - font_hinting = DynamicFontData::HINTING_LIGHT; + font_hinting = TextServer::HINTING_LIGHT; #endif break; case 1: - font_hinting = DynamicFontData::HINTING_NONE; + font_hinting = TextServer::HINTING_NONE; break; case 2: - font_hinting = DynamicFontData::HINTING_LIGHT; + font_hinting = TextServer::HINTING_LIGHT; break; default: - font_hinting = DynamicFontData::HINTING_NORMAL; + font_hinting = TextServer::HINTING_NORMAL; break; } + int default_font_size = int(EDITOR_GET("interface/editor/main_font_size")) * EDSCALE; + String custom_font_path = EditorSettings::get_singleton()->get("interface/editor/main_font"); - Ref CustomFont; + Ref CustomFont; if (custom_font_path.length() > 0 && dir->file_exists(custom_font_path)) { CustomFont.instance(); + CustomFont->load_resource(custom_font_path, default_font_size); CustomFont->set_antialiased(font_antialiased); CustomFont->set_hinting(font_hinting); - CustomFont->set_font_path(custom_font_path); CustomFont->set_force_autohinter(true); //just looks better..i think? } else { EditorSettings::get_singleton()->set_manually("interface/editor/main_font", ""); @@ -135,12 +141,12 @@ void editor_register_fonts(Ref p_theme) { /* Custom Bold font */ String custom_font_path_bold = EditorSettings::get_singleton()->get("interface/editor/main_font_bold"); - Ref CustomFontBold; + Ref CustomFontBold; if (custom_font_path_bold.length() > 0 && dir->file_exists(custom_font_path_bold)) { CustomFontBold.instance(); + CustomFontBold->load_resource(custom_font_path_bold, default_font_size); CustomFontBold->set_antialiased(font_antialiased); CustomFontBold->set_hinting(font_hinting); - CustomFontBold->set_font_path(custom_font_path_bold); CustomFontBold->set_force_autohinter(true); //just looks better..i think? } else { EditorSettings::get_singleton()->set_manually("interface/editor/main_font_bold", ""); @@ -149,12 +155,12 @@ void editor_register_fonts(Ref p_theme) { /* Custom source code font */ String custom_font_path_source = EditorSettings::get_singleton()->get("interface/editor/code_font"); - Ref CustomFontSource; + Ref CustomFontSource; if (custom_font_path_source.length() > 0 && dir->file_exists(custom_font_path_source)) { CustomFontSource.instance(); + CustomFontSource->load_resource(custom_font_path_source, default_font_size); CustomFontSource->set_antialiased(font_antialiased); CustomFontSource->set_hinting(font_hinting); - CustomFontSource->set_font_path(custom_font_path_source); } else { EditorSettings::get_singleton()->set_manually("interface/editor/code_font", ""); } @@ -163,115 +169,167 @@ void editor_register_fonts(Ref p_theme) { /* Droid Sans */ - Ref DefaultFont; + Ref DefaultFont; DefaultFont.instance(); + DefaultFont->load_memory(_font_NotoSansUI_Regular, _font_NotoSansUI_Regular_size, "ttf", default_font_size); DefaultFont->set_antialiased(font_antialiased); DefaultFont->set_hinting(font_hinting); - DefaultFont->set_font_ptr(_font_NotoSansUI_Regular, _font_NotoSansUI_Regular_size); DefaultFont->set_force_autohinter(true); //just looks better..i think? - Ref DefaultFontBold; + Ref DefaultFontBold; DefaultFontBold.instance(); + DefaultFontBold->load_memory(_font_NotoSansUI_Bold, _font_NotoSansUI_Bold_size, "ttf", default_font_size); DefaultFontBold->set_antialiased(font_antialiased); DefaultFontBold->set_hinting(font_hinting); - DefaultFontBold->set_font_ptr(_font_NotoSansUI_Bold, _font_NotoSansUI_Bold_size); DefaultFontBold->set_force_autohinter(true); // just looks better..i think? - Ref FontFallback; + Ref FontFallback; FontFallback.instance(); + FontFallback->load_memory(_font_DroidSansFallback, _font_DroidSansFallback_size, "ttf", default_font_size); FontFallback->set_antialiased(font_antialiased); FontFallback->set_hinting(font_hinting); - FontFallback->set_font_ptr(_font_DroidSansFallback, _font_DroidSansFallback_size); FontFallback->set_force_autohinter(true); //just looks better..i think? - Ref FontJapanese; + Ref FontJapanese; FontJapanese.instance(); + FontJapanese->load_memory(_font_DroidSansJapanese, _font_DroidSansJapanese_size, "ttf", default_font_size); FontJapanese->set_antialiased(font_antialiased); FontJapanese->set_hinting(font_hinting); - FontJapanese->set_font_ptr(_font_DroidSansJapanese, _font_DroidSansJapanese_size); FontJapanese->set_force_autohinter(true); //just looks better..i think? - Ref FontArabic; + Ref FontArabic; FontArabic.instance(); + FontArabic->load_memory(_font_NotoNaskhArabicUI_Regular, _font_NotoNaskhArabicUI_Regular_size, "ttf", default_font_size); FontArabic->set_antialiased(font_antialiased); FontArabic->set_hinting(font_hinting); - FontArabic->set_font_ptr(_font_NotoNaskhArabicUI_Regular, _font_NotoNaskhArabicUI_Regular_size); FontArabic->set_force_autohinter(true); //just looks better..i think? - Ref FontHebrew; + Ref FontBengali; + FontBengali.instance(); + FontBengali->load_memory(_font_NotoSansBengali_Regular, _font_NotoSansBengali_Regular_size, "ttf", default_font_size); + FontBengali->set_antialiased(font_antialiased); + FontBengali->set_hinting(font_hinting); + FontBengali->set_force_autohinter(true); //just looks better..i think? + + Ref FontGeorgian; + FontGeorgian.instance(); + FontGeorgian->load_memory(_font_NotoSansGeorgian_Regular, _font_NotoSansGeorgian_Regular_size, "ttf", default_font_size); + FontGeorgian->set_antialiased(font_antialiased); + FontGeorgian->set_hinting(font_hinting); + FontGeorgian->set_force_autohinter(true); //just looks better..i think? + + Ref FontHebrew; FontHebrew.instance(); + FontHebrew->load_memory(_font_NotoSansHebrew_Regular, _font_NotoSansHebrew_Regular_size, "ttf", default_font_size); FontHebrew->set_antialiased(font_antialiased); FontHebrew->set_hinting(font_hinting); - FontHebrew->set_font_ptr(_font_NotoSansHebrew_Regular, _font_NotoSansHebrew_Regular_size); FontHebrew->set_force_autohinter(true); //just looks better..i think? - Ref FontThai; + Ref FontMalayalam; + FontMalayalam.instance(); + FontMalayalam->load_memory(_font_NotoSansMalayalamUI_Regular, _font_NotoSansMalayalamUI_Regular_size, "ttf", default_font_size); + FontMalayalam->set_antialiased(font_antialiased); + FontMalayalam->set_hinting(font_hinting); + FontMalayalam->set_force_autohinter(true); //just looks better..i think? + + Ref FontOriya; + FontOriya.instance(); + FontOriya->load_memory(_font_NotoSansOriyaUI_Regular, _font_NotoSansOriyaUI_Regular_size, "ttf", default_font_size); + FontOriya->set_antialiased(font_antialiased); + FontOriya->set_hinting(font_hinting); + FontOriya->set_force_autohinter(true); //just looks better..i think? + + Ref FontSinhala; + FontSinhala.instance(); + FontSinhala->load_memory(_font_NotoSansSinhalaUI_Regular, _font_NotoSansSinhalaUI_Regular_size, "ttf", default_font_size); + FontSinhala->set_antialiased(font_antialiased); + FontSinhala->set_hinting(font_hinting); + FontSinhala->set_force_autohinter(true); //just looks better..i think? + + Ref FontTamil; + FontTamil.instance(); + FontTamil->load_memory(_font_NotoSansTamilUI_Regular, _font_NotoSansTamilUI_Regular_size, "ttf", default_font_size); + FontTamil->set_antialiased(font_antialiased); + FontTamil->set_hinting(font_hinting); + FontTamil->set_force_autohinter(true); //just looks better..i think? + + Ref FontTelugu; + FontTelugu.instance(); + FontTelugu->load_memory(_font_NotoSansTeluguUI_Regular, _font_NotoSansTeluguUI_Regular_size, "ttf", default_font_size); + FontTelugu->set_antialiased(font_antialiased); + FontTelugu->set_hinting(font_hinting); + FontTelugu->set_force_autohinter(true); //just looks better..i think? + + Ref FontThai; FontThai.instance(); + FontThai->load_memory(_font_NotoSansThaiUI_Regular, _font_NotoSansThaiUI_Regular_size, "ttf", default_font_size); FontThai->set_antialiased(font_antialiased); FontThai->set_hinting(font_hinting); - FontThai->set_font_ptr(_font_NotoSansThaiUI_Regular, _font_NotoSansThaiUI_Regular_size); FontThai->set_force_autohinter(true); //just looks better..i think? - Ref FontHindi; + Ref FontHindi; FontHindi.instance(); + FontHindi->load_memory(_font_NotoSansDevanagariUI_Regular, _font_NotoSansDevanagariUI_Regular_size, "ttf", default_font_size); FontHindi->set_antialiased(font_antialiased); FontHindi->set_hinting(font_hinting); - FontHindi->set_font_ptr(_font_NotoSansDevanagariUI_Regular, _font_NotoSansDevanagariUI_Regular_size); FontHindi->set_force_autohinter(true); //just looks better..i think? /* Hack */ - Ref dfmono; + Ref dfmono; dfmono.instance(); + dfmono->load_memory(_font_Hack_Regular, _font_Hack_Regular_size, "ttf", default_font_size); dfmono->set_antialiased(font_antialiased); dfmono->set_hinting(font_hinting); - dfmono->set_font_ptr(_font_Hack_Regular, _font_Hack_Regular_size); - - int default_font_size = int(EDITOR_GET("interface/editor/main_font_size")) * EDSCALE; // Default font - MAKE_DEFAULT_FONT(df, default_font_size); - p_theme->set_default_font(df); // Default theme font + MAKE_DEFAULT_FONT(df); + p_theme->set_default_theme_font(df); // Default theme font + p_theme->set_default_theme_font_size(default_font_size); + + p_theme->set_font_size("main_size", "EditorFonts", default_font_size); p_theme->set_font("main", "EditorFonts", df); // Bold font - MAKE_BOLD_FONT(df_bold, default_font_size); + MAKE_BOLD_FONT(df_bold); + p_theme->set_font_size("bold_size", "EditorFonts", default_font_size); p_theme->set_font("bold", "EditorFonts", df_bold); // Title font - MAKE_BOLD_FONT(df_title, default_font_size + 2 * EDSCALE); - p_theme->set_font("title", "EditorFonts", df_title); + p_theme->set_font_size("title_size", "EditorFonts", default_font_size + 2 * EDSCALE); + p_theme->set_font("title", "EditorFonts", df_bold); // Documentation fonts - MAKE_DEFAULT_FONT(df_doc, int(EDITOR_GET("text_editor/help/help_font_size")) * EDSCALE); - MAKE_BOLD_FONT(df_doc_bold, int(EDITOR_GET("text_editor/help/help_font_size")) * EDSCALE); - MAKE_BOLD_FONT(df_doc_title, int(EDITOR_GET("text_editor/help/help_title_font_size")) * EDSCALE); - MAKE_SOURCE_FONT(df_doc_code, int(EDITOR_GET("text_editor/help/help_source_font_size")) * EDSCALE); - MAKE_SOURCE_FONT(df_doc_kbd, (int(EDITOR_GET("text_editor/help/help_source_font_size")) - 1) * EDSCALE); - p_theme->set_font("doc", "EditorFonts", df_doc); - p_theme->set_font("doc_bold", "EditorFonts", df_doc_bold); - p_theme->set_font("doc_title", "EditorFonts", df_doc_title); - p_theme->set_font("doc_source", "EditorFonts", df_doc_code); - p_theme->set_font("doc_keyboard", "EditorFonts", df_doc_kbd); + MAKE_SOURCE_FONT(df_code); + p_theme->set_font_size("doc_size", "EditorFonts", int(EDITOR_GET("text_editor/help/help_font_size")) * EDSCALE); + p_theme->set_font("doc", "EditorFonts", df); + p_theme->set_font_size("doc_bold_size", "EditorFonts", int(EDITOR_GET("text_editor/help/help_font_size")) * EDSCALE); + p_theme->set_font("doc_bold", "EditorFonts", df_bold); + p_theme->set_font_size("doc_title_size", "EditorFonts", int(EDITOR_GET("text_editor/help/help_title_font_size")) * EDSCALE); + p_theme->set_font("doc_title", "EditorFonts", df_bold); + p_theme->set_font_size("doc_source_size", "EditorFonts", int(EDITOR_GET("text_editor/help/help_source_font_size")) * EDSCALE); + p_theme->set_font("doc_source", "EditorFonts", df_code); + p_theme->set_font_size("doc_keyboard_size", "EditorFonts", (int(EDITOR_GET("text_editor/help/help_source_font_size")) - 1) * EDSCALE); + p_theme->set_font("doc_keyboard", "EditorFonts", df_code); // Ruler font - MAKE_DEFAULT_FONT(df_rulers, 8 * EDSCALE); - p_theme->set_font("rulers", "EditorFonts", df_rulers); + p_theme->set_font_size("rulers_size", "EditorFonts", 8 * EDSCALE); + p_theme->set_font("rulers", "EditorFonts", df); // Rotation widget font - MAKE_DEFAULT_FONT(df_rotation_control, 14 * EDSCALE); - p_theme->set_font("rotation_control", "EditorFonts", df_rotation_control); + p_theme->set_font_size("rotation_control_size", "EditorFonts", 14 * EDSCALE); + p_theme->set_font("rotation_control", "EditorFonts", df); // Code font - MAKE_SOURCE_FONT(df_code, int(EDITOR_GET("interface/editor/code_font_size")) * EDSCALE); + p_theme->set_font_size("source_size", "EditorFonts", int(EDITOR_GET("interface/editor/code_font_size")) * EDSCALE); p_theme->set_font("source", "EditorFonts", df_code); - MAKE_SOURCE_FONT(df_expression, (int(EDITOR_GET("interface/editor/code_font_size")) - 1) * EDSCALE); - p_theme->set_font("expression", "EditorFonts", df_expression); + p_theme->set_font_size("expression_size", "EditorFonts", (int(EDITOR_GET("interface/editor/code_font_size")) - 1) * EDSCALE); + p_theme->set_font("expression", "EditorFonts", df_code); - MAKE_SOURCE_FONT(df_output_code, int(EDITOR_GET("run/output/font_size")) * EDSCALE); - p_theme->set_font("output_source", "EditorFonts", df_output_code); + p_theme->set_font_size("output_source_size", "EditorFonts", int(EDITOR_GET("run/output/font_size")) * EDSCALE); + p_theme->set_font("output_source", "EditorFonts", df_code); - MAKE_SOURCE_FONT(df_text_editor_status_code, default_font_size); - p_theme->set_font("status_source", "EditorFonts", df_text_editor_status_code); + p_theme->set_font_size("status_source_size", "EditorFonts", default_font_size); + p_theme->set_font("status_source", "EditorFonts", df_code); } diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 30aebd2b1fde..72bd2b57eb97 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -168,7 +168,8 @@ void EditorHelp::_class_desc_resized() { // Add extra horizontal margins for better readability. // The margins increase as the width of the editor help container increases. Ref doc_code_font = get_theme_font("doc_source", "EditorFonts"); - real_t char_width = doc_code_font->get_char_size('x').width; + int font_size = get_theme_font_size("doc_source_size", "EditorFonts"); + real_t char_width = doc_code_font->get_char_size('x', 0, font_size).width; const int display_margin = MAX(30 * EDSCALE, get_parent_anchorable_rect().size.width - char_width * 120 * EDSCALE) * 0.5; Ref class_desc_stylebox = EditorNode::get_singleton()->get_theme_base()->get_theme_stylebox("normal", "RichTextLabel")->duplicate(); diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 371100652ffc..0c419168c037 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -41,7 +41,8 @@ Size2 EditorProperty::get_minimum_size() const { Size2 ms; Ref font = get_theme_font("font", "Tree"); - ms.height = font->get_height(); + int font_size = get_theme_font_size("font_size", "Tree"); + ms.height = font->get_height(font_size); for (int i = 0; i < get_child_count(); i++) { Control *c = Object::cast_to(get_child(i)); @@ -108,7 +109,8 @@ void EditorProperty::_notification(int p_what) { { int child_room = size.width * (1.0 - split_ratio); Ref font = get_theme_font("font", "Tree"); - int height = font->get_height(); + int font_size = get_theme_font_size("font_size", "Tree"); + int height = font->get_height(font_size); bool no_children = true; //compute room needed @@ -135,7 +137,11 @@ void EditorProperty::_notification(int p_what) { rect = Rect2(size.width - 1, 0, 1, height); } else { text_size = MAX(0, size.width - (child_room + 4 * EDSCALE)); - rect = Rect2(size.width - child_room, 0, child_room, height); + if (is_layout_rtl()) { + rect = Rect2(1, 0, child_room, height); + } else { + rect = Rect2(size.width - child_room, 0, child_room, height); + } } if (bottom_editor) { @@ -154,6 +160,9 @@ void EditorProperty::_notification(int p_what) { } rect.size.x -= key->get_width() + get_theme_constant("hseparator", "Tree"); + if (is_layout_rtl()) { + rect.position.x += key->get_width() + get_theme_constant("hseparator", "Tree"); + } if (no_children) { text_size -= key->get_width() + 4 * EDSCALE; @@ -167,6 +176,10 @@ void EditorProperty::_notification(int p_what) { rect.size.x -= close->get_width() + get_theme_constant("hseparator", "Tree"); + if (is_layout_rtl()) { + rect.position.x += close->get_width() + get_theme_constant("hseparator", "Tree"); + } + if (no_children) { text_size -= close->get_width() + 4 * EDSCALE; } @@ -200,7 +213,9 @@ void EditorProperty::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { Ref font = get_theme_font("font", "Tree"); + int font_size = get_theme_font_size("font_size", "Tree"); Color dark_color = get_theme_color("dark_color_2", "Editor"); + bool rtl = is_layout_rtl(); Size2 size = get_size(); if (bottom_editor) { @@ -249,7 +264,11 @@ void EditorProperty::_notification(int p_what) { color2.b *= 1.2; } check_rect = Rect2(ofs, ((size.height - checkbox->get_height()) / 2), checkbox->get_width(), checkbox->get_height()); - draw_texture(checkbox, check_rect.position, color2); + if (rtl) { + draw_texture(checkbox, Vector2(size.width - check_rect.position.x - checkbox->get_width(), check_rect.position.y), color2); + } else { + draw_texture(checkbox, check_rect.position, color2); + } ofs += get_theme_constant("hseparator", "Tree") + checkbox->get_width() + get_theme_constant("hseparation", "CheckBox"); text_limit -= ofs; } else { @@ -267,14 +286,21 @@ void EditorProperty::_notification(int p_what) { color2.g *= 1.2; color2.b *= 1.2; } - - draw_texture(reload_icon, revert_rect.position, color2); + if (rtl) { + draw_texture(reload_icon, Vector2(size.width - revert_rect.position.x - reload_icon->get_width(), revert_rect.position.y), color2); + } else { + draw_texture(reload_icon, revert_rect.position, color2); + } } else { revert_rect = Rect2(); } - int v_ofs = (size.height - font->get_height()) / 2; - draw_string(font, Point2(ofs, v_ofs + font->get_ascent()), label, color, text_limit); + int v_ofs = (size.height - font->get_height(font_size)) / 2; + if (rtl) { + draw_string(font, Point2(size.width - ofs - text_limit, v_ofs + font->get_ascent(font_size)), label, HALIGN_RIGHT, text_limit, font_size, color); + } else { + draw_string(font, Point2(ofs, v_ofs + font->get_ascent(font_size)), label, HALIGN_LEFT, text_limit, font_size, color); + } if (keying) { Ref key; @@ -294,7 +320,12 @@ void EditorProperty::_notification(int p_what) { color2.b *= 1.2; } keying_rect = Rect2(ofs, ((size.height - key->get_height()) / 2), key->get_width(), key->get_height()); - draw_texture(key, keying_rect.position, color2); + if (rtl) { + draw_texture(key, Vector2(size.width - keying_rect.position.x - key->get_width(), keying_rect.position.y), color2); + } else { + draw_texture(key, keying_rect.position, color2); + } + } else { keying_rect = Rect2(); } @@ -313,7 +344,11 @@ void EditorProperty::_notification(int p_what) { color2.b *= 1.2; } delete_rect = Rect2(ofs, ((size.height - close->get_height()) / 2), close->get_width(), close->get_height()); - draw_texture(close, delete_rect.position, color2); + if (rtl) { + draw_texture(close, Vector2(size.width - delete_rect.position.x - close->get_width(), delete_rect.position.y), color2); + } else { + draw_texture(close, delete_rect.position, color2); + } } else { delete_rect = Rect2(); } @@ -648,27 +683,31 @@ void EditorProperty::_gui_input(const Ref &p_event) { Ref me = p_event; if (me.is_valid()) { + Vector2 mpos = me->get_position(); + if (is_layout_rtl()) { + mpos.x = get_size().x - mpos.x; + } bool button_left = me->get_button_mask() & BUTTON_MASK_LEFT; - bool new_keying_hover = keying_rect.has_point(me->get_position()) && !button_left; + bool new_keying_hover = keying_rect.has_point(mpos) && !button_left; if (new_keying_hover != keying_hover) { keying_hover = new_keying_hover; update(); } - bool new_delete_hover = delete_rect.has_point(me->get_position()) && !button_left; + bool new_delete_hover = delete_rect.has_point(mpos) && !button_left; if (new_delete_hover != delete_hover) { delete_hover = new_delete_hover; update(); } - bool new_revert_hover = revert_rect.has_point(me->get_position()) && !button_left; + bool new_revert_hover = revert_rect.has_point(mpos) && !button_left; if (new_revert_hover != revert_hover) { revert_hover = new_revert_hover; update(); } - bool new_check_hover = check_rect.has_point(me->get_position()) && !button_left; + bool new_check_hover = check_rect.has_point(mpos) && !button_left; if (new_check_hover != check_hover) { check_hover = new_check_hover; update(); @@ -678,13 +717,18 @@ void EditorProperty::_gui_input(const Ref &p_event) { Ref mb = p_event; if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { + Vector2 mpos = mb->get_position(); + if (is_layout_rtl()) { + mpos.x = get_size().x - mpos.x; + } + if (!selected && selectable) { selected = true; emit_signal("selected", property, -1); update(); } - if (keying_rect.has_point(mb->get_position())) { + if (keying_rect.has_point(mpos)) { emit_signal("property_keyed", property, use_keying_next()); if (use_keying_next()) { @@ -704,11 +748,11 @@ void EditorProperty::_gui_input(const Ref &p_event) { call_deferred("update_property"); } } - if (delete_rect.has_point(mb->get_position())) { + if (delete_rect.has_point(mpos)) { emit_signal("property_deleted", property); } - if (revert_rect.has_point(mb->get_position())) { + if (revert_rect.has_point(mpos)) { Variant vorig; Node *node = Object::cast_to(object); @@ -744,7 +788,7 @@ void EditorProperty::_gui_input(const Ref &p_event) { return; } } - if (check_rect.has_point(mb->get_position())) { + if (check_rect.has_point(mpos)) { checked = !checked; update(); emit_signal("property_checked", property, checked); @@ -1024,10 +1068,11 @@ void EditorInspectorCategory::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { draw_rect(Rect2(Vector2(), get_size()), bg_color); Ref font = get_theme_font("font", "Tree"); + int font_size = get_theme_font_size("font_size", "Tree"); int hs = get_theme_constant("hseparation", "Tree"); - int w = font->get_string_size(label).width; + int w = font->get_string_size(label, font_size).width; if (icon.is_valid()) { w += hs + icon->get_width(); } @@ -1040,7 +1085,7 @@ void EditorInspectorCategory::_notification(int p_what) { } Color color = get_theme_color("font_color", "Tree"); - draw_string(font, Point2(ofs, font->get_ascent() + (get_size().height - font->get_height()) / 2).floor(), label, color, get_size().width); + draw_string(font, Point2(ofs, font->get_ascent(font_size) + (get_size().height - font->get_height(font_size)) / 2).floor(), label, HALIGN_LEFT, get_size().width, font_size, color); } } @@ -1069,10 +1114,11 @@ Control *EditorInspectorCategory::make_custom_tooltip(const String &p_text) cons Size2 EditorInspectorCategory::get_minimum_size() const { Ref font = get_theme_font("font", "Tree"); + int font_size = get_theme_font_size("font_size", "Tree"); Size2 ms; ms.width = 1; - ms.height = font->get_height(); + ms.height = font->get_height(font_size); if (icon.is_valid()) { ms.height = MAX(icon->get_height(), ms.height); } @@ -1105,19 +1151,24 @@ void EditorInspectorSection::_test_unfold() { void EditorInspectorSection::_notification(int p_what) { if (p_what == NOTIFICATION_SORT_CHILDREN) { Ref font = get_theme_font("font", "Tree"); + int font_size = get_theme_font_size("font_size", "Tree"); Ref arrow; if (foldable) { if (object->editor_is_section_unfolded(section)) { arrow = get_theme_icon("arrow", "Tree"); } else { - arrow = get_theme_icon("arrow_collapsed", "Tree"); + if (is_layout_rtl()) { + arrow = get_theme_icon("arrow_collapsed_mirrored", "Tree"); + } else { + arrow = get_theme_icon("arrow_collapsed", "Tree"); + } } } Size2 size = get_size(); Point2 offset; - offset.y = font->get_height(); + offset.y = font->get_height(font_size); if (arrow.is_valid()) { offset.y = MAX(offset.y, arrow->get_height()); } @@ -1148,18 +1199,20 @@ void EditorInspectorSection::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { Ref arrow; + bool rtl = is_layout_rtl(); if (foldable) { - if (object->editor_is_section_unfolded(section)) { - arrow = get_theme_icon("arrow", "Tree"); + if (rtl) { + arrow = get_theme_icon("arrow_collapsed_mirrored", "Tree"); } else { arrow = get_theme_icon("arrow_collapsed", "Tree"); } } Ref font = get_theme_font("font", "Tree"); + int font_size = get_theme_font_size("font_size", "Tree"); - int h = font->get_height(); + int h = font->get_height(font_size); if (arrow.is_valid()) { h = MAX(h, arrow->get_height()); } @@ -1169,10 +1222,15 @@ void EditorInspectorSection::_notification(int p_what) { const int arrow_margin = 3; Color color = get_theme_color("font_color", "Tree"); - draw_string(font, Point2(Math::round((16 + arrow_margin) * EDSCALE), font->get_ascent() + (h - font->get_height()) / 2).floor(), label, color, get_size().width); + float text_width = get_size().width - Math::round((16 + arrow_margin) * EDSCALE); + draw_string(font, Point2(rtl ? 0 : Math::round((16 + arrow_margin) * EDSCALE), font->get_ascent(font_size) + (h - font->get_height(font_size)) / 2).floor(), label, rtl ? HALIGN_RIGHT : HALIGN_LEFT, text_width, font_size, color); if (arrow.is_valid()) { - draw_texture(arrow, Point2(Math::round(arrow_margin * EDSCALE), (h - arrow->get_height()) / 2).floor()); + if (rtl) { + draw_texture(arrow, Point2(get_size().width - arrow->get_width() - Math::round(arrow_margin * EDSCALE), (h - arrow->get_height()) / 2).floor()); + } else { + draw_texture(arrow, Point2(Math::round(arrow_margin * EDSCALE), (h - arrow->get_height()) / 2).floor()); + } } if (dropping && !vbox->is_visible_in_tree()) { @@ -1237,7 +1295,8 @@ Size2 EditorInspectorSection::get_minimum_size() const { } Ref font = get_theme_font("font", "Tree"); - ms.height += font->get_height() + get_theme_constant("vseparation", "Tree"); + int font_size = get_theme_font_size("font_size", "Tree"); + ms.height += font->get_height(font_size) + get_theme_constant("vseparation", "Tree"); ms.width += get_theme_constant("inspector_margin", "Editor"); return ms; @@ -1273,7 +1332,8 @@ void EditorInspectorSection::_gui_input(const Ref &p_event) { Ref mb = p_event; if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { Ref font = get_theme_font("font", "Tree"); - if (mb->get_position().y > font->get_height()) { //clicked outside + int font_size = get_theme_font_size("font_size", "Tree"); + if (mb->get_position().y > font->get_height(font_size)) { //clicked outside return; } diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index 36b80a7dd42c..10b10134860c 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -69,13 +69,13 @@ class EditorProperty : public Container { Rect2 bottom_child_rect; Rect2 keying_rect; - bool keying_hover; + bool keying_hover = false; Rect2 revert_rect; - bool revert_hover; + bool revert_hover = false; Rect2 check_rect; - bool check_hover; + bool check_hover = false; Rect2 delete_rect; - bool delete_hover; + bool delete_hover = false; bool can_revert; diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp index 6fbafc7ff3ea..9c713f748e0f 100644 --- a/editor/editor_log.cpp +++ b/editor/editor_log.cpp @@ -35,7 +35,7 @@ #include "editor_node.h" #include "editor_scale.h" #include "scene/gui/center_container.h" -#include "scene/resources/dynamic_font.h" +#include "scene/resources/font.h" void EditorLog::_error_handler(void *p_self, const char *p_func, const char *p_file, int p_line, const char *p_error, const char *p_errorexp, ErrorHandlerType p_type) { EditorLog *self = (EditorLog *)p_self; @@ -61,12 +61,14 @@ void EditorLog::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { //button->set_icon(get_icon("Console","EditorIcons")); log->add_theme_font_override("normal_font", get_theme_font("output_source", "EditorFonts")); + log->add_theme_font_size_override("normal_font_size", get_theme_font_size("output_source_size", "EditorFonts")); log->add_theme_color_override("selection_color", get_theme_color("accent_color", "Editor") * Color(1, 1, 1, 0.4)); } else if (p_what == NOTIFICATION_THEME_CHANGED) { - Ref df_output_code = get_theme_font("output_source", "EditorFonts"); + Ref df_output_code = get_theme_font("output_source", "EditorFonts"); if (df_output_code.is_valid()) { if (log != nullptr) { log->add_theme_font_override("normal_font", get_theme_font("output_source", "EditorFonts")); + log->add_theme_font_size_override("normal_font_size", get_theme_font_size("output_source_size", "EditorFonts")); log->add_theme_color_override("selection_color", get_theme_color("accent_color", "Editor") * Color(1, 1, 1, 0.4)); } } diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 9fcb5fff356d..ff8f089c265f 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -125,6 +125,7 @@ #include "editor/plugins/debugger_editor_plugin.h" #include "editor/plugins/editor_debugger_plugin.h" #include "editor/plugins/editor_preview_plugins.h" +#include "editor/plugins/font_editor_plugin.h" #include "editor/plugins/gi_probe_editor_plugin.h" #include "editor/plugins/gpu_particles_2d_editor_plugin.h" #include "editor/plugins/gpu_particles_3d_editor_plugin.h" @@ -140,6 +141,7 @@ #include "editor/plugins/multimesh_editor_plugin.h" #include "editor/plugins/navigation_polygon_editor_plugin.h" #include "editor/plugins/node_3d_editor_plugin.h" +#include "editor/plugins/ot_features_plugin.h" #include "editor/plugins/packed_scene_translation_parser_plugin.h" #include "editor/plugins/path_2d_editor_plugin.h" #include "editor/plugins/path_3d_editor_plugin.h" @@ -336,7 +338,11 @@ void EditorNode::_update_scene_tabs() { if (scene_tabs->get_offset_buttons_visible()) { // move add button to fixed position on the tabbar if (scene_tab_add->get_parent() == scene_tabs) { - scene_tab_add->set_position(Point2(0, 0)); + if (scene_tabs->is_layout_rtl()) { + scene_tab_add->set_position(Point2(tabbar_container->get_size().x - scene_tab_add->get_size().x, 0)); + } else { + scene_tab_add->set_position(Point2(0, 0)); + } scene_tabs->remove_child(scene_tab_add); tabbar_container->add_child(scene_tab_add); tabbar_container->move_child(scene_tab_add, 1); @@ -351,7 +357,11 @@ void EditorNode::_update_scene_tabs() { if (scene_tabs->get_tab_count() != 0) { last_tab = scene_tabs->get_tab_rect(scene_tabs->get_tab_count() - 1); } - scene_tab_add->set_position(Point2(last_tab.get_position().x + last_tab.get_size().x + 3, last_tab.get_position().y)); + if (scene_tabs->is_layout_rtl()) { + scene_tab_add->set_position(Point2(last_tab.get_position().x - scene_tab_add->get_size().x - 3, last_tab.get_position().y)); + } else { + scene_tab_add->set_position(Point2(last_tab.get_position().x + last_tab.get_size().x + 3, last_tab.get_position().y)); + } } } @@ -647,8 +657,13 @@ void EditorNode::_notification(int p_what) { bottom_panel_raise->set_icon(gui_base->get_theme_icon("ExpandBottomDock", "EditorIcons")); // clear_button->set_icon(gui_base->get_icon("Close", "EditorIcons")); don't have access to that node. needs to become a class property - dock_tab_move_left->set_icon(theme->get_icon("Back", "EditorIcons")); - dock_tab_move_right->set_icon(theme->get_icon("Forward", "EditorIcons")); + if (gui_base->is_layout_rtl()) { + dock_tab_move_left->set_icon(theme->get_icon("Forward", "EditorIcons")); + dock_tab_move_right->set_icon(theme->get_icon("Back", "EditorIcons")); + } else { + dock_tab_move_left->set_icon(theme->get_icon("Back", "EditorIcons")); + dock_tab_move_right->set_icon(theme->get_icon("Forward", "EditorIcons")); + } PopupMenu *p = help_menu->get_popup(); p->set_item_icon(p->get_item_index(HELP_SEARCH), gui_base->get_theme_icon("HelpSearch", "EditorIcons")); @@ -5878,7 +5893,11 @@ EditorNode::EditorNode() { HBoxContainer *dock_hb = memnew(HBoxContainer); dock_tab_move_left = memnew(Button); dock_tab_move_left->set_flat(true); - dock_tab_move_left->set_icon(theme->get_icon("Back", "EditorIcons")); + if (gui_base->is_layout_rtl()) { + dock_tab_move_left->set_icon(theme->get_icon("Forward", "EditorIcons")); + } else { + dock_tab_move_left->set_icon(theme->get_icon("Back", "EditorIcons")); + } dock_tab_move_left->set_focus_mode(Control::FOCUS_NONE); dock_tab_move_left->connect("pressed", callable_mp(this, &EditorNode::_dock_move_left)); dock_hb->add_child(dock_tab_move_left); @@ -5891,7 +5910,11 @@ EditorNode::EditorNode() { dock_tab_move_right = memnew(Button); dock_tab_move_right->set_flat(true); - dock_tab_move_right->set_icon(theme->get_icon("Forward", "EditorIcons")); + if (gui_base->is_layout_rtl()) { + dock_tab_move_right->set_icon(theme->get_icon("Forward", "EditorIcons")); + } else { + dock_tab_move_right->set_icon(theme->get_icon("Back", "EditorIcons")); + } dock_tab_move_right->set_focus_mode(Control::FOCUS_NONE); dock_tab_move_right->connect("pressed", callable_mp(this, &EditorNode::_dock_move_right)); @@ -6349,6 +6372,7 @@ EditorNode::EditorNode() { video_driver->set_focus_mode(Control::FOCUS_NONE); video_driver->connect("item_selected", callable_mp(this, &EditorNode::_video_driver_selected)); video_driver->add_theme_font_override("font", gui_base->get_theme_font("bold", "EditorFonts")); + video_driver->add_theme_font_size_override("font_size", gui_base->get_theme_font_size("bold_size", "EditorFonts")); // TODO re-enable when GLES2 is ported video_driver->set_disabled(true); right_menu_hb->add_child(video_driver); @@ -6648,6 +6672,8 @@ EditorNode::EditorNode() { add_editor_plugin(memnew(GradientEditorPlugin(this))); add_editor_plugin(memnew(CollisionShape2DEditorPlugin(this))); add_editor_plugin(memnew(CurveEditorPlugin(this))); + add_editor_plugin(memnew(FontEditorPlugin(this))); + add_editor_plugin(memnew(OpenTypeFeaturesEditorPlugin(this))); add_editor_plugin(memnew(TextureEditorPlugin(this))); add_editor_plugin(memnew(TextureLayeredEditorPlugin(this))); add_editor_plugin(memnew(Texture3DEditorPlugin(this))); diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 1443302f3fb5..2c4e403a817a 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -36,7 +36,7 @@ #include "editor_properties_array_dict.h" #include "editor_scale.h" #include "scene/main/window.h" -#include "scene/resources/dynamic_font.h" +#include "scene/resources/font.h" ///////////////////// NULL ///////////////////////// @@ -146,7 +146,8 @@ void EditorPropertyMultilineText::_notification(int p_what) { Ref df = get_theme_icon("DistractionFree", "EditorIcons"); open_big_text->set_icon(df); Ref font = get_theme_font("font", "Label"); - text->set_custom_minimum_size(Vector2(0, font->get_height() * 6)); + int font_size = get_theme_font_size("font_size", "Label"); + text->set_custom_minimum_size(Vector2(0, font->get_height(font_size) * 6)); } break; } @@ -290,6 +291,7 @@ EditorPropertyPath::EditorPropertyPath() { HBoxContainer *path_hb = memnew(HBoxContainer); add_child(path_hb); path = memnew(LineEdit); + path->set_structured_text_bidi_override(Control::STRUCTURED_TEXT_FILE); path_hb->add_child(path); path->connect("text_entered", callable_mp(this, &EditorPropertyPath::_path_selected)); path->connect("focus_exited", callable_mp(this, &EditorPropertyPath::_path_focus_exited)); @@ -587,7 +589,8 @@ class EditorPropertyLayersGrid : public Control { virtual Size2 get_minimum_size() const override { Ref font = get_theme_font("font", "Label"); - return Vector2(0, font->get_height() * 2); + int font_size = get_theme_font_size("font_size", "Label"); + return Vector2(0, font->get_height(font_size) * 2); } virtual String get_tooltip(const Point2 &p_pos) const override { @@ -985,6 +988,7 @@ void EditorPropertyEasing::_draw_easing() { const float exp = get_edited_object()->get(get_edited_property()); const Ref f = get_theme_font("font", "Label"); + int font_size = get_theme_font_size("font_size", "Label"); const Color font_color = get_theme_color("font_color", "Label"); Color line_color; if (dragging) { @@ -1022,7 +1026,7 @@ void EditorPropertyEasing::_draw_easing() { } else { decimals = 1; } - f->draw(ci, Point2(10, 10 + f->get_ascent()), rtos(exp).pad_decimals(decimals), font_color); + f->draw_string(ci, Point2(10, 10 + f->get_ascent(font_size)), TS->format_number(rtos(exp).pad_decimals(decimals)), HALIGN_LEFT, -1, font_size, font_color); } void EditorPropertyEasing::update_property() { @@ -1039,7 +1043,7 @@ void EditorPropertyEasing::_set_preset(int p_preset) { void EditorPropertyEasing::_setup_spin() { setting = true; spin->setup_and_show(); - spin->get_line_edit()->set_text(rtos(get_edited_object()->get(get_edited_property()))); + spin->get_line_edit()->set_text(TS->format_number(rtos(get_edited_object()->get(get_edited_property())))); setting = false; spin->show(); } @@ -1088,7 +1092,7 @@ void EditorPropertyEasing::_notification(int p_what) { preset->add_icon_item(get_theme_icon("CurveInOut", "EditorIcons"), "In-Out", EASING_IN_OUT); preset->add_icon_item(get_theme_icon("CurveOutIn", "EditorIcons"), "Out-In", EASING_OUT_IN); } - easing_draw->set_custom_minimum_size(Size2(0, get_theme_font("font", "Label")->get_height() * 2)); + easing_draw->set_custom_minimum_size(Size2(0, get_theme_font("font", "Label")->get_height(get_theme_font_size("font_size", "Label")) * 2)); } break; } } @@ -3016,7 +3020,7 @@ bool EditorPropertyResource::_is_drop_valid(const Dictionary &p_drag_data) const } else if (at == "ShaderMaterial") { allowed_types.append("Shader"); } else if (at == "Font") { - allowed_types.append("DynamicFontData"); + allowed_types.append("FontData"); } } @@ -3115,9 +3119,9 @@ void EditorPropertyResource::drop_data_fw(const Point2 &p_point, const Variant & break; } - if (at == "Font" && ClassDB::is_parent_class(res->get_class(), "DynamicFontData")) { - Ref font = memnew(DynamicFont); - font->set_font_data(res); + if (at == "Font" && ClassDB::is_parent_class(res->get_class(), "FontData")) { + Ref font = memnew(Font); + font->add_data(res); res = font; break; } diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 2cf0bed7d001..0ea112d48c0e 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -262,13 +262,30 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { String host_lang = OS::get_singleton()->get_locale(); host_lang = TranslationServer::standardize_locale(host_lang); - // Some locales are not properly supported currently in Godot due to lack of font shaping - // (e.g. Arabic or Hindi), so even though we have work in progress translations for them, - // we skip them as they don't render properly. (GH-28577) - const Vector locales_to_skip = String("ar,bn,fa,he,hi,ml,si,ta,te,ur").split(","); + // Skip locales if Text server lack required features. + Vector locales_to_skip; + if (!TS->has_feature(TextServer::FEATURE_BIDI_LAYOUT) || !TS->has_feature(TextServer::FEATURE_SHAPING)) { + locales_to_skip.push_back("ar"); // Arabic + locales_to_skip.push_back("fa"); // Persian + locales_to_skip.push_back("ur"); // Urdu + } + if (!TS->has_feature(TextServer::FEATURE_BIDI_LAYOUT)) { + locales_to_skip.push_back("he"); // Hebrew + } + if (!TS->has_feature(TextServer::FEATURE_SHAPING)) { + locales_to_skip.push_back("bn"); // Bengali + locales_to_skip.push_back("hi"); // Hindi + locales_to_skip.push_back("ml"); // Malayalam + locales_to_skip.push_back("si"); // Sinhala + locales_to_skip.push_back("ta"); // Tamil + locales_to_skip.push_back("te"); // Telugu + } - String best; + if (!locales_to_skip.empty()) { + WARN_PRINT("Some locales are not properly supported by selected Text Server and are disabled."); + } + String best; EditorTranslationList *etl = _editor_translations; while (etl->data) { @@ -316,6 +333,9 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { hints["interface/editor/main_font_size"] = PropertyInfo(Variant::INT, "interface/editor/main_font_size", PROPERTY_HINT_RANGE, "8,48,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); _initial_set("interface/editor/code_font_size", 14); hints["interface/editor/code_font_size"] = PropertyInfo(Variant::INT, "interface/editor/code_font_size", PROPERTY_HINT_RANGE, "8,48,1", PROPERTY_USAGE_DEFAULT); + _initial_set("interface/editor/code_font_contextual_ligatures", 0); + hints["interface/editor/code_font_contextual_ligatures"] = PropertyInfo(Variant::INT, "interface/editor/code_font_contextual_ligatures", PROPERTY_HINT_ENUM, "Default,Disable contextual alternates (coding ligatures),Use custom OpenType feature set", PROPERTY_USAGE_DEFAULT); + _initial_set("interface/editor/code_font_custom_opentype_features", ""); _initial_set("interface/editor/font_antialiased", true); _initial_set("interface/editor/font_hinting", 0); hints["interface/editor/font_hinting"] = PropertyInfo(Variant::INT, "interface/editor/font_hinting", PROPERTY_HINT_ENUM, "Auto,None,Light,Normal", PROPERTY_USAGE_DEFAULT); diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index efc966c6c44f..d72510d40d19 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -37,13 +37,13 @@ String EditorSpinSlider::get_tooltip(const Point2 &p_pos) const { if (grabber->is_visible()) { - return rtos(get_value()) + "\n\n" + TTR("Hold Ctrl to round to integers. Hold Shift for more precise changes."); + return TS->format_number(rtos(get_value())) + "\n\n" + TTR("Hold Ctrl to round to integers. Hold Shift for more precise changes."); } - return rtos(get_value()); + return TS->format_number(rtos(get_value())); } String EditorSpinSlider::get_text_value() const { - return String::num(get_value(), Math::range_step_decimals(get_step())); + return TS->format_number(String::num(get_value(), Math::range_step_decimals(get_step()))); } void EditorSpinSlider::_gui_input(const Ref &p_event) { @@ -214,10 +214,11 @@ void EditorSpinSlider::_notification(int p_what) { draw_style_box(sb, Rect2(Vector2(), get_size())); } Ref font = get_theme_font("font", "LineEdit"); + int font_size = get_theme_font_size("font_size", "LineEdit"); int sep_base = 4 * EDSCALE; int sep = sep_base + sb->get_offset().x; //make it have the same margin on both sides, looks better - int string_width = font->get_string_size(label).width; + int string_width = font->get_string_size(label, font_size).width; int number_width = get_size().width - sb->get_minimum_size().width - string_width - sep; Ref updown = get_theme_icon("updown", "SpinBox"); @@ -228,7 +229,7 @@ void EditorSpinSlider::_notification(int p_what) { String numstr = get_text_value(); - int vofs = (get_size().height - font->get_height()) / 2 + font->get_ascent(); + int vofs = (get_size().height - font->get_height(font_size)) / 2 + font->get_ascent(font_size); Color fc = get_theme_color("font_color", "LineEdit"); Color lc; @@ -248,9 +249,9 @@ void EditorSpinSlider::_notification(int p_what) { draw_style_box(focus, Rect2(Vector2(), get_size())); } - draw_string(font, Vector2(Math::round(sb->get_offset().x), vofs), label, lc * Color(1, 1, 1, 0.5)); + draw_string(font, Vector2(Math::round(sb->get_offset().x), vofs), label, HALIGN_LEFT, -1, font_size, lc * Color(1, 1, 1, 0.5)); - draw_string(font, Vector2(Math::round(sb->get_offset().x + string_width + sep), vofs), numstr, fc, number_width); + draw_string(font, Vector2(Math::round(sb->get_offset().x + string_width + sep), vofs), numstr, HALIGN_LEFT, number_width, font_size, fc); if (get_step() == 1) { Ref updown2 = get_theme_icon("updown", "SpinBox"); @@ -330,9 +331,10 @@ void EditorSpinSlider::_notification(int p_what) { Size2 EditorSpinSlider::get_minimum_size() const { Ref sb = get_theme_stylebox("normal", "LineEdit"); Ref font = get_theme_font("font", "LineEdit"); + int font_size = get_theme_font_size("font_size", "LineEdit"); Size2 ms = sb->get_minimum_size(); - ms.height += font->get_height(); + ms.height += font->get_height(font_size); return ms; } @@ -360,7 +362,7 @@ void EditorSpinSlider::_evaluate_input_text() { // This prevents using functions like `pow()`, but using functions // in EditorSpinSlider is a barely known (and barely used) feature. // Instead, we'd rather support German/French keyboard layouts out of the box. - const String text = value_input->get_text().replace(",", "."); + const String text = TS->parse_number(value_input->get_text().replace(",", ".")); Ref expr; expr.instance(); diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 768e5bccbcdd..88976ed332ec 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -600,12 +600,18 @@ Ref create_editor_theme(const Ref p_theme) { theme->set_color("icon_color_pressed", "Button", icon_color_pressed); // OptionButton + theme->set_stylebox("focus", "OptionButton", style_widget_focus); + theme->set_stylebox("normal", "OptionButton", style_widget); theme->set_stylebox("hover", "OptionButton", style_widget_hover); theme->set_stylebox("pressed", "OptionButton", style_widget_pressed); - theme->set_stylebox("focus", "OptionButton", style_widget_focus); theme->set_stylebox("disabled", "OptionButton", style_widget_disabled); + theme->set_stylebox("normal_mirrored", "OptionButton", style_widget); + theme->set_stylebox("hover_mirrored", "OptionButton", style_widget_hover); + theme->set_stylebox("pressed_mirrored", "OptionButton", style_widget_pressed); + theme->set_stylebox("disabled_mirrored", "OptionButton", style_widget_disabled); + theme->set_color("font_color", "OptionButton", font_color); theme->set_color("font_color_hover", "OptionButton", font_color_hl); theme->set_color("font_color_pressed", "OptionButton", accent_color); @@ -627,6 +633,11 @@ Ref create_editor_theme(const Ref p_theme) { theme->set_icon("off", "CheckButton", theme->get_icon("GuiToggleOff", "EditorIcons")); theme->set_icon("off_disabled", "CheckButton", theme->get_icon("GuiToggleOffDisabled", "EditorIcons")); + theme->set_icon("on_mirrored", "CheckButton", theme->get_icon("GuiToggleOnMirrored", "EditorIcons")); + theme->set_icon("on_disabled_mirrored", "CheckButton", theme->get_icon("GuiToggleOnDisabledMirrored", "EditorIcons")); + theme->set_icon("off_mirrored", "CheckButton", theme->get_icon("GuiToggleOffMirrored", "EditorIcons")); + theme->set_icon("off_disabled_mirrored", "CheckButton", theme->get_icon("GuiToggleOffDisabledMirrored", "EditorIcons")); + theme->set_color("font_color", "CheckButton", font_color); theme->set_color("font_color_hover", "CheckButton", font_color_hl); theme->set_color("font_color_pressed", "CheckButton", accent_color); @@ -679,6 +690,7 @@ Ref create_editor_theme(const Ref p_theme) { theme->set_icon("radio_checked", "PopupMenu", theme->get_icon("GuiRadioChecked", "EditorIcons")); theme->set_icon("radio_unchecked", "PopupMenu", theme->get_icon("GuiRadioUnchecked", "EditorIcons")); theme->set_icon("submenu", "PopupMenu", theme->get_icon("ArrowRight", "EditorIcons")); + theme->set_icon("submenu_mirrored", "PopupMenu", theme->get_icon("ArrowLeft", "EditorIcons")); theme->set_icon("visibility_hidden", "PopupMenu", theme->get_icon("GuiVisibilityHidden", "EditorIcons")); theme->set_icon("visibility_visible", "PopupMenu", theme->get_icon("GuiVisibilityVisible", "EditorIcons")); theme->set_icon("visibility_xray", "PopupMenu", theme->get_icon("GuiVisibilityXray", "EditorIcons")); @@ -707,6 +719,7 @@ Ref create_editor_theme(const Ref p_theme) { theme->set_icon("unchecked", "Tree", theme->get_icon("GuiUnchecked", "EditorIcons")); theme->set_icon("arrow", "Tree", theme->get_icon("GuiTreeArrowDown", "EditorIcons")); theme->set_icon("arrow_collapsed", "Tree", theme->get_icon("GuiTreeArrowRight", "EditorIcons")); + theme->set_icon("arrow_collapsed_mirrored", "Tree", theme->get_icon("GuiTreeArrowLeft", "EditorIcons")); theme->set_icon("updown", "Tree", theme->get_icon("GuiTreeUpdown", "EditorIcons")); theme->set_icon("select_arrow", "Tree", theme->get_icon("GuiDropdown", "EditorIcons")); theme->set_stylebox("bg_focus", "Tree", style_focus); @@ -851,7 +864,7 @@ Ref create_editor_theme(const Ref p_theme) { theme->set_stylebox("DebuggerPanel", "EditorStyles", style_panel_debugger); Ref style_panel_invisible_top = style_content_panel->duplicate(); - int stylebox_offset = theme->get_font("tab_fg", "TabContainer")->get_height() + theme->get_stylebox("tab_fg", "TabContainer")->get_minimum_size().height + theme->get_stylebox("panel", "TabContainer")->get_default_margin(MARGIN_TOP); + int stylebox_offset = theme->get_font("tab_fg", "TabContainer")->get_height(theme->get_font_size("tab_fg", "TabContainer")) + theme->get_stylebox("tab_fg", "TabContainer")->get_minimum_size().height + theme->get_stylebox("panel", "TabContainer")->get_default_margin(MARGIN_TOP); style_panel_invisible_top->set_expand_margin_size(MARGIN_TOP, -stylebox_offset); style_panel_invisible_top->set_default_margin(MARGIN_TOP, 0); theme->set_stylebox("BottomPanelDebuggerOverride", "EditorStyles", style_panel_invisible_top); @@ -931,6 +944,7 @@ Ref create_editor_theme(const Ref p_theme) { theme->set_constant("title_height", "Window", 24 * EDSCALE); theme->set_constant("resize_margin", "Window", 4 * EDSCALE); theme->set_font("title_font", "Window", theme->get_font("title", "EditorFonts")); + theme->set_font_size("title_font_size", "Window", theme->get_font_size("title_size", "EditorFonts")); // complex window, for now only Editor settings and Project settings Ref style_complex_window = style_window->duplicate(); diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 543546b1528b..c65c796e5e81 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -68,6 +68,7 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory } subdirectory_item->set_text(0, dname); + subdirectory_item->set_structured_text_bidi_override(0, STRUCTURED_TEXT_FILE); subdirectory_item->set_icon(0, get_theme_icon("Folder", "EditorIcons")); subdirectory_item->set_icon_modulate(0, get_theme_color("folder_icon_modulate", "FileDialog")); subdirectory_item->set_selectable(0, true); @@ -136,6 +137,7 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory TreeItem *file_item = tree->create_item(subdirectory_item); file_item->set_text(0, fi.name); + file_item->set_structured_text_bidi_override(0, STRUCTURED_TEXT_FILE); file_item->set_icon(0, _get_tree_item_icon(!fi.import_broken, fi.type)); String file_metadata = lpath.plus_file(fi.name); file_item->set_metadata(0, file_metadata); @@ -320,6 +322,8 @@ void FileSystemDock::_update_display_mode(bool p_force) { void FileSystemDock::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_TRANSLATION_CHANGED: + case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: case NOTIFICATION_ENTER_TREE: { if (initialized) { return; @@ -348,8 +352,13 @@ void FileSystemDock::_notification(int p_what) { file_list_search_box->set_clear_button_enabled(true); file_list_button_sort->set_icon(get_theme_icon("Sort", ei)); - button_hist_next->set_icon(get_theme_icon("Forward", ei)); - button_hist_prev->set_icon(get_theme_icon("Back", ei)); + if (is_layout_rtl()) { + button_hist_next->set_icon(get_theme_icon("Back", ei)); + button_hist_prev->set_icon(get_theme_icon("Forward", ei)); + } else { + button_hist_next->set_icon(get_theme_icon("Forward", ei)); + button_hist_prev->set_icon(get_theme_icon("Back", ei)); + } file_list_popup->connect("id_pressed", callable_mp(this, &FileSystemDock::_file_list_rmb_option)); tree_popup->connect("id_pressed", callable_mp(this, &FileSystemDock::_tree_rmb_option)); @@ -402,8 +411,13 @@ void FileSystemDock::_notification(int p_what) { String ei = "EditorIcons"; button_reload->set_icon(get_theme_icon("Reload", ei)); button_toggle_display_mode->set_icon(get_theme_icon("Panels2", ei)); - button_hist_next->set_icon(get_theme_icon("Forward", ei)); - button_hist_prev->set_icon(get_theme_icon("Back", ei)); + if (is_layout_rtl()) { + button_hist_next->set_icon(get_theme_icon("Back", ei)); + button_hist_prev->set_icon(get_theme_icon("Forward", ei)); + } else { + button_hist_next->set_icon(get_theme_icon("Forward", ei)); + button_hist_prev->set_icon(get_theme_icon("Back", ei)); + } if (file_list_display_mode == FILE_LIST_DISPLAY_LIST) { button_file_list_display_mode->set_icon(get_theme_icon("FileThumbnail", "EditorIcons")); } else { @@ -2693,6 +2707,7 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { toolbar_hbc->add_child(button_hist_next); current_path = memnew(LineEdit); + current_path->set_structured_text_bidi_override(Control::STRUCTURED_TEXT_FILE); current_path->set_h_size_flags(SIZE_EXPAND_FILL); _set_current_path_text(path); toolbar_hbc->add_child(current_path); diff --git a/editor/find_in_files.cpp b/editor/find_in_files.cpp index c2ccbdb08cae..8d3f0eb21f6e 100644 --- a/editor/find_in_files.cpp +++ b/editor/find_in_files.cpp @@ -571,6 +571,7 @@ FindInFilesPanel::FindInFilesPanel() { _search_text_label = memnew(Label); _search_text_label->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("source", "EditorFonts")); + _search_text_label->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("source_size", "EditorFonts")); hbc->add_child(_search_text_label); _progress_bar = memnew(ProgressBar); @@ -599,6 +600,7 @@ FindInFilesPanel::FindInFilesPanel() { _results_display = memnew(Tree); _results_display->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("source", "EditorFonts")); + _results_display->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("source_size", "EditorFonts")); _results_display->set_v_size_flags(SIZE_EXPAND_FILL); _results_display->connect("item_selected", callable_mp(this, &FindInFilesPanel::_on_result_selected)); _results_display->connect("item_edited", callable_mp(this, &FindInFilesPanel::_on_item_edited)); @@ -755,10 +757,11 @@ void FindInFilesPanel::draw_result_text(Object *item_obj, Rect2 rect) { Result r = E->value(); String item_text = item->get_text(_with_replace ? 1 : 0); Ref font = _results_display->get_theme_font("font"); + int font_size = _results_display->get_theme_font_size("font_size"); Rect2 match_rect = rect; - match_rect.position.x += font->get_string_size(item_text.left(r.begin_trimmed)).x; - match_rect.size.x = font->get_string_size(_search_text_label->get_text()).x; + match_rect.position.x += font->get_string_size(item_text.left(r.begin_trimmed), font_size).x; + match_rect.size.x = font->get_string_size(_search_text_label->get_text(), font_size).x; match_rect.position.y += 1 * EDSCALE; match_rect.size.y -= 2 * EDSCALE; diff --git a/editor/groups_editor.cpp b/editor/groups_editor.cpp index 4e6e2d023762..f3bad8d86d74 100644 --- a/editor/groups_editor.cpp +++ b/editor/groups_editor.cpp @@ -361,9 +361,16 @@ void GroupDialog::_delete_group_item(const String &p_name) { void GroupDialog::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_TRANSLATION_CHANGED: + case Control::NOTIFICATION_LAYOUT_DIRECTION_CHANGED: case NOTIFICATION_ENTER_TREE: { - add_button->set_icon(groups->get_theme_icon("Forward", "EditorIcons")); - remove_button->set_icon(groups->get_theme_icon("Back", "EditorIcons")); + if (is_layout_rtl()) { + add_button->set_icon(groups->get_theme_icon("Back", "EditorIcons")); + remove_button->set_icon(groups->get_theme_icon("Forward", "EditorIcons")); + } else { + add_button->set_icon(groups->get_theme_icon("Forward", "EditorIcons")); + remove_button->set_icon(groups->get_theme_icon("Back", "EditorIcons")); + } add_filter->set_right_icon(groups->get_theme_icon("Search", "EditorIcons")); add_filter->set_clear_button_enabled(true); diff --git a/editor/icons/AutoEndBackwards.svg b/editor/icons/AutoEndBackwards.svg new file mode 100644 index 000000000000..c6de305069f3 --- /dev/null +++ b/editor/icons/AutoEndBackwards.svg @@ -0,0 +1 @@ + diff --git a/editor/icons/AutoPlayBackwards.svg b/editor/icons/AutoPlayBackwards.svg new file mode 100644 index 000000000000..20602ba348a1 --- /dev/null +++ b/editor/icons/AutoPlayBackwards.svg @@ -0,0 +1 @@ + diff --git a/editor/icons/BitmapFont.svg b/editor/icons/BitmapFont.svg deleted file mode 100644 index d3ab5f7dd7f0..000000000000 --- a/editor/icons/BitmapFont.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/editor/icons/DynamicFont.svg b/editor/icons/DynamicFont.svg deleted file mode 100644 index bbaa12ea1bb8..000000000000 --- a/editor/icons/DynamicFont.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/editor/icons/DynamicFontData.svg b/editor/icons/FontData.svg similarity index 100% rename from editor/icons/DynamicFontData.svg rename to editor/icons/FontData.svg diff --git a/editor/icons/GuiResizerMirrored.svg b/editor/icons/GuiResizerMirrored.svg new file mode 100644 index 000000000000..8227f5b648dc --- /dev/null +++ b/editor/icons/GuiResizerMirrored.svg @@ -0,0 +1 @@ + diff --git a/editor/icons/GuiTabMirrored.svg b/editor/icons/GuiTabMirrored.svg new file mode 100644 index 000000000000..a0011a5b2dc8 --- /dev/null +++ b/editor/icons/GuiTabMirrored.svg @@ -0,0 +1 @@ + diff --git a/editor/icons/GuiToggleOffMirrored.svg b/editor/icons/GuiToggleOffMirrored.svg new file mode 100644 index 000000000000..d650de9cdaee --- /dev/null +++ b/editor/icons/GuiToggleOffMirrored.svg @@ -0,0 +1 @@ + diff --git a/editor/icons/GuiToggleOnMirrored.svg b/editor/icons/GuiToggleOnMirrored.svg new file mode 100644 index 000000000000..7339b6efd2a0 --- /dev/null +++ b/editor/icons/GuiToggleOnMirrored.svg @@ -0,0 +1 @@ + diff --git a/editor/icons/GuiTreeArrowLeft.svg b/editor/icons/GuiTreeArrowLeft.svg new file mode 100644 index 000000000000..d0f7b36fab94 --- /dev/null +++ b/editor/icons/GuiTreeArrowLeft.svg @@ -0,0 +1 @@ + diff --git a/editor/inspector_dock.cpp b/editor/inspector_dock.cpp index c88cd8ea5fb9..75f89fbfb5a8 100644 --- a/editor/inspector_dock.cpp +++ b/editor/inspector_dock.cpp @@ -332,13 +332,20 @@ Container *InspectorDock::get_addon_area() { void InspectorDock::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_TRANSLATION_CHANGED: + case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { set_theme(editor->get_gui_base()->get_theme()); resource_new_button->set_icon(get_theme_icon("New", "EditorIcons")); resource_load_button->set_icon(get_theme_icon("Load", "EditorIcons")); resource_save_button->set_icon(get_theme_icon("Save", "EditorIcons")); - backward_button->set_icon(get_theme_icon("Back", "EditorIcons")); - forward_button->set_icon(get_theme_icon("Forward", "EditorIcons")); + if (is_layout_rtl()) { + backward_button->set_icon(get_theme_icon("Forward", "EditorIcons")); + forward_button->set_icon(get_theme_icon("Back", "EditorIcons")); + } else { + backward_button->set_icon(get_theme_icon("Back", "EditorIcons")); + forward_button->set_icon(get_theme_icon("Forward", "EditorIcons")); + } history_menu->set_icon(get_theme_icon("History", "EditorIcons")); object_menu->set_icon(get_theme_icon("Tools", "EditorIcons")); warning->set_icon(get_theme_icon("NodeWarning", "EditorIcons")); @@ -524,7 +531,11 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) { backward_button = memnew(Button); backward_button->set_flat(true); general_options_hb->add_child(backward_button); - backward_button->set_icon(get_theme_icon("Back", "EditorIcons")); + if (is_layout_rtl()) { + backward_button->set_icon(get_theme_icon("Forward", "EditorIcons")); + } else { + backward_button->set_icon(get_theme_icon("Back", "EditorIcons")); + } backward_button->set_flat(true); backward_button->set_tooltip(TTR("Go to the previous edited object in history.")); backward_button->set_disabled(true); @@ -533,7 +544,11 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) { forward_button = memnew(Button); forward_button->set_flat(true); general_options_hb->add_child(forward_button); - forward_button->set_icon(get_theme_icon("Forward", "EditorIcons")); + if (is_layout_rtl()) { + forward_button->set_icon(get_theme_icon("Back", "EditorIcons")); + } else { + forward_button->set_icon(get_theme_icon("Forward", "EditorIcons")); + } forward_button->set_flat(true); forward_button->set_tooltip(TTR("Go to the next edited object in history.")); forward_button->set_disabled(true); diff --git a/editor/localization_editor.cpp b/editor/localization_editor.cpp index e725ce482d3d..2a21885c4cdb 100644 --- a/editor/localization_editor.cpp +++ b/editor/localization_editor.cpp @@ -37,6 +37,24 @@ #include "scene/gui/control.h" void LocalizationEditor::_notification(int p_what) { + if (p_what == NOTIFICATION_TEXT_SERVER_CHANGED) { + ts_name->set_text(TTR("Text server: ") + TS->get_name()); + + FileAccessRef file_check = FileAccess::create(FileAccess::ACCESS_RESOURCES); + if (TS->has_feature(TextServer::FEATURE_USE_SUPPORT_DATA)) { + if (file_check->file_exists("res://" + TS->get_support_data_filename())) { + ts_data_status->set_text(TTR("Support data: ") + TTR("Installed")); + ts_install->set_disabled(true); + } else { + ts_data_status->set_text(TTR("Support data: ") + TTR("Not installed")); + ts_install->set_disabled(false); + } + } else { + ts_data_status->set_text(TTR("Support data: ") + TTR("Not supported")); + ts_install->set_disabled(false); + } + ts_data_info->set_text(TTR("Info: ") + TS->get_support_data_info()); + } if (p_what == NOTIFICATION_ENTER_TREE) { translation_list->connect("button_pressed", callable_mp(this, &LocalizationEditor::_translation_delete)); translation_pot_list->connect("button_pressed", callable_mp(this, &LocalizationEditor::_pot_delete)); @@ -622,6 +640,26 @@ void LocalizationEditor::update_translations() { updating_translations = false; } +void LocalizationEditor::_install_ts_data() { + if (TS->has_feature(TextServer::FEATURE_USE_SUPPORT_DATA)) { + TS->save_support_data("res://" + TS->get_support_data_filename()); + } + + FileAccessRef file_check = FileAccess::create(FileAccess::ACCESS_RESOURCES); + if (TS->has_feature(TextServer::FEATURE_USE_SUPPORT_DATA)) { + if (file_check->file_exists("res://" + TS->get_support_data_filename())) { + ts_data_status->set_text(TTR("Support data: ") + TTR("Installed")); + ts_install->set_disabled(true); + } else { + ts_data_status->set_text(TTR("Support data: ") + TTR("Not installed")); + ts_install->set_disabled(false); + } + } else { + ts_data_status->set_text(TTR("Support data: ") + TTR("Not supported")); + ts_install->set_disabled(false); + } +} + void LocalizationEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("update_translations"), &LocalizationEditor::update_translations); @@ -791,4 +829,37 @@ LocalizationEditor::LocalizationEditor() { pot_file_open_dialog->connect("file_selected", callable_mp(this, &LocalizationEditor::_pot_add)); add_child(pot_file_open_dialog); } + + { + VBoxContainer *tvb = memnew(VBoxContainer); + tvb->set_name(TTR("Text Server Data")); + translations->add_child(tvb); + + ts_name = memnew(Label(TTR("Text server: ") + TS->get_name())); + tvb->add_child(ts_name); + + ts_data_status = memnew(Label(TTR("Support data: "))); + tvb->add_child(ts_data_status); + + ts_data_info = memnew(Label(TTR("Info: ") + TS->get_support_data_info())); + tvb->add_child(ts_data_info); + + ts_install = memnew(Button(TTR("Install support data..."))); + ts_install->connect("pressed", callable_mp(this, &LocalizationEditor::_install_ts_data)); + tvb->add_child(ts_install); + + FileAccessRef file_check = FileAccess::create(FileAccess::ACCESS_RESOURCES); + if (TS->has_feature(TextServer::FEATURE_USE_SUPPORT_DATA)) { + if (file_check->file_exists("res://" + TS->get_support_data_filename())) { + ts_data_status->set_text(TTR("Support data: ") + TTR("Installed")); + ts_install->set_disabled(true); + } else { + ts_data_status->set_text(TTR("Support data: ") + TTR("Not installed")); + ts_install->set_disabled(false); + } + } else { + ts_data_status->set_text(TTR("Support data: ") + TTR("Not supported")); + ts_install->set_disabled(false); + } + } } diff --git a/editor/localization_editor.h b/editor/localization_editor.h index 3c077d9c77e2..43b6bb60f628 100644 --- a/editor/localization_editor.h +++ b/editor/localization_editor.h @@ -58,6 +58,11 @@ class LocalizationEditor : public VBoxContainer { Vector translation_filter_treeitems; Vector translation_locales_idxs_remap; + Label *ts_name; + Label *ts_data_status; + Label *ts_data_info; + Button *ts_install; + Tree *translation_pot_list; EditorFileDialog *pot_file_open_dialog; EditorFileDialog *pot_generate_dialog; @@ -89,6 +94,8 @@ class LocalizationEditor : public VBoxContainer { void _pot_generate(const String &p_file); void _update_pot_file_extensions(); + void _install_ts_data(); + protected: void _notification(int p_what); static void _bind_methods(); diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp index 7a3fb1ff52a6..0b61db6835ff 100644 --- a/editor/plugins/abstract_polygon_2d_editor.cpp +++ b/editor/plugins/abstract_polygon_2d_editor.cpp @@ -551,9 +551,10 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl if (vertex == hover_point) { Ref font = get_theme_font("font", "Label"); + int font_size = get_theme_font_size("font_size", "Label"); String num = String::num(vertex.vertex); - Size2 num_size = font->get_string_size(num); - p_overlay->draw_string(font, point - num_size * 0.5, num, Color(1.0, 1.0, 1.0, 0.5)); + Size2 num_size = font->get_string_size(num, font_size); + p_overlay->draw_string(font, point - num_size * 0.5, num, HALIGN_LEFT, -1, font_size, Color(1.0, 1.0, 1.0, 0.5)); } } } diff --git a/editor/plugins/animation_blend_space_1d_editor.cpp b/editor/plugins/animation_blend_space_1d_editor.cpp index d335b29c2f8f..223484044aa1 100644 --- a/editor/plugins/animation_blend_space_1d_editor.cpp +++ b/editor/plugins/animation_blend_space_1d_editor.cpp @@ -201,6 +201,7 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_draw() { linecolor_soft.a *= 0.5; Ref font = get_theme_font("font", "Label"); + int font_size = get_theme_font_size("font_size", "Label"); Ref icon = get_theme_icon("KeyValue", "EditorIcons"); Ref icon_selected = get_theme_icon("KeySelected", "EditorIcons"); @@ -221,7 +222,7 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_draw() { float x = point; blend_space_draw->draw_line(Point2(x, s.height - 1), Point2(x, s.height - 5 * EDSCALE), linecolor); - blend_space_draw->draw_string(font, Point2(x + 2 * EDSCALE, s.height - 2 * EDSCALE - font->get_height() + font->get_ascent()), "0", linecolor); + blend_space_draw->draw_string(font, Point2(x + 2 * EDSCALE, s.height - 2 * EDSCALE - font->get_height(font_size) + font->get_ascent(font_size)), "0", HALIGN_LEFT, -1, font_size, linecolor); blend_space_draw->draw_line(Point2(x, s.height - 5 * EDSCALE), Point2(x, 0), linecolor_soft); } diff --git a/editor/plugins/animation_blend_space_2d_editor.cpp b/editor/plugins/animation_blend_space_2d_editor.cpp index 60a5188af79c..94785a54224e 100644 --- a/editor/plugins/animation_blend_space_2d_editor.cpp +++ b/editor/plugins/animation_blend_space_2d_editor.cpp @@ -396,6 +396,7 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_draw() { Color linecolor_soft = linecolor; linecolor_soft.a *= 0.5; Ref font = get_theme_font("font", "Label"); + int font_size = get_theme_font_size("font_size", "Label"); Ref icon = get_theme_icon("KeyValue", "EditorIcons"); Ref icon_selected = get_theme_icon("KeySelected", "EditorIcons"); @@ -412,14 +413,14 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_draw() { if (blend_space->get_min_space().y < 0) { int y = (blend_space->get_max_space().y / (blend_space->get_max_space().y - blend_space->get_min_space().y)) * s.height; blend_space_draw->draw_line(Point2(0, y), Point2(5 * EDSCALE, y), linecolor); - blend_space_draw->draw_string(font, Point2(2 * EDSCALE, y - font->get_height() + font->get_ascent()), "0", linecolor); + blend_space_draw->draw_string(font, Point2(2 * EDSCALE, y - font->get_height(font_size) + font->get_ascent(font_size)), "0", HALIGN_LEFT, -1, font_size, linecolor); blend_space_draw->draw_line(Point2(5 * EDSCALE, y), Point2(s.width, y), linecolor_soft); } if (blend_space->get_min_space().x < 0) { int x = (-blend_space->get_min_space().x / (blend_space->get_max_space().x - blend_space->get_min_space().x)) * s.width; blend_space_draw->draw_line(Point2(x, s.height - 1), Point2(x, s.height - 5 * EDSCALE), linecolor); - blend_space_draw->draw_string(font, Point2(x + 2 * EDSCALE, s.height - 2 * EDSCALE - font->get_height() + font->get_ascent()), "0", linecolor); + blend_space_draw->draw_string(font, Point2(x + 2 * EDSCALE, s.height - 2 * EDSCALE - font->get_height(font_size) + font->get_ascent(font_size)), "0", HALIGN_LEFT, -1, font_size, linecolor); blend_space_draw->draw_line(Point2(x, s.height - 5 * EDSCALE), Point2(x, 0), linecolor_soft); } diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 1e56e3d11f2d..6b30aa325ca9 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -105,6 +105,8 @@ void AnimationPlayerEditor::_notification(int p_what) { case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { add_theme_style_override("panel", editor->get_gui_base()->get_theme_stylebox("panel", "Panel")); } break; + case NOTIFICATION_TRANSLATION_CHANGED: + case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: case NOTIFICATION_THEME_CHANGED: { autoplay->set_icon(get_theme_icon("AutoPlay", "EditorIcons")); diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index 4634d1594196..c59e056f4f22 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -559,6 +559,7 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { Ref style_selected = get_theme_stylebox("state_machine_selectedframe", "GraphNode"); Ref font = get_theme_font("title_font", "GraphNode"); + int font_size = get_theme_font_size("title_font_size", "GraphNode"); Color font_color = get_theme_color("title_color", "GraphNode"); Ref play = get_theme_icon("Play", "EditorIcons"); Ref auto_play = get_theme_icon("AutoPlay", "EditorIcons"); @@ -612,9 +613,9 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { Ref sb = E->get() == selected_node ? style_selected : style; Size2 s = sb->get_minimum_size(); - int strsize = font->get_string_size(name).width; + int strsize = font->get_string_size(name, font_size).width; s.width += strsize; - s.height += MAX(font->get_height(), play->get_height()); + s.height += MAX(font->get_height(font_size), play->get_height()); s.width += sep + play->get_width(); if (needs_editor) { s.width += sep + edit->get_width(); @@ -741,7 +742,7 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { Ref anode = state_machine->get_node(name); bool needs_editor = AnimationTreeEditor::get_singleton()->can_edit(anode); Ref sb = name == selected_node ? style_selected : style; - int strsize = font->get_string_size(name).width; + int strsize = font->get_string_size(name, font_size).width; NodeRect &nr = node_rects.write[i]; @@ -759,12 +760,12 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { bool onstart = state_machine->get_start_node() == name; if (onstart) { - state_machine_draw->draw_string(font, offset + Vector2(0, -font->get_height() - 3 * EDSCALE + font->get_ascent()), TTR("Start"), font_color); + state_machine_draw->draw_string(font, offset + Vector2(0, -font->get_height(font_size) - 3 * EDSCALE + font->get_ascent(font_size)), TTR("Start"), HALIGN_LEFT, -1, font_size, font_color); } if (state_machine->get_end_node() == name) { - int endofs = nr.node.size.x - font->get_string_size(TTR("End")).x; - state_machine_draw->draw_string(font, offset + Vector2(endofs, -font->get_height() - 3 * EDSCALE + font->get_ascent()), TTR("End"), font_color); + int endofs = nr.node.size.x - font->get_string_size(TTR("End"), font_size).x; + state_machine_draw->draw_string(font, offset + Vector2(endofs, -font->get_height(font_size) - 3 * EDSCALE + font->get_ascent(font_size)), TTR("End"), HALIGN_LEFT, -1, font_size, font_color); } offset.x += sb->get_offset().x; @@ -781,10 +782,10 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { } offset.x += sep + play->get_width(); - nr.name.position = offset + Vector2(0, (h - font->get_height()) / 2).floor(); - nr.name.size = Vector2(strsize, font->get_height()); + nr.name.position = offset + Vector2(0, (h - font->get_height(font_size)) / 2).floor(); + nr.name.size = Vector2(strsize, font->get_height(font_size)); - state_machine_draw->draw_string(font, nr.name.position + Vector2(0, font->get_ascent()), name, font_color); + state_machine_draw->draw_string(font, nr.name.position + Vector2(0, font->get_ascent(font_size)), name, HALIGN_LEFT, -1, font_size, font_color); offset.x += strsize + sep; if (needs_editor) { @@ -880,7 +881,7 @@ void AnimationNodeStateMachineEditor::_update_graph() { } void AnimationNodeStateMachineEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED || p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED || p_what == NOTIFICATION_TRANSLATION_CHANGED) { error_panel->add_theme_style_override("panel", get_theme_stylebox("bg", "Tree")); error_label->add_theme_color_override("font_color", get_theme_color("error_color", "Editor")); panel->add_theme_style_override("panel", get_theme_stylebox("bg", "Tree")); diff --git a/editor/plugins/audio_stream_editor_plugin.cpp b/editor/plugins/audio_stream_editor_plugin.cpp index e6f6b6f2e0e0..998916349c45 100644 --- a/editor/plugins/audio_stream_editor_plugin.cpp +++ b/editor/plugins/audio_stream_editor_plugin.cpp @@ -236,11 +236,13 @@ AudioStreamEditor::AudioStreamEditor() { _current_label->set_align(Label::ALIGN_RIGHT); _current_label->set_h_size_flags(SIZE_EXPAND_FILL); _current_label->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("status_source", "EditorFonts")); + _current_label->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("status_source_size", "EditorFonts")); _current_label->set_modulate(Color(1, 1, 1, 0.5)); hbox->add_child(_current_label); _duration_label = memnew(Label); _duration_label->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("status_source", "EditorFonts")); + _duration_label->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("status_source_size", "EditorFonts")); hbox->add_child(_duration_label); } diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 6acf80a2c102..47a30ad5d714 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -52,7 +52,6 @@ #include "scene/gui/subviewport_container.h" #include "scene/main/canvas_layer.h" #include "scene/main/window.h" -#include "scene/resources/dynamic_font.h" #include "scene/resources/packed_scene.h" // Min and Max are power of two in order to play nicely with successive increment. @@ -857,7 +856,11 @@ Vector2 CanvasItemEditor::_anchor_to_position(const Control *p_control, Vector2 Transform2D parent_transform = p_control->get_transform().affine_inverse(); Rect2 parent_rect = p_control->get_parent_anchorable_rect(); - return parent_transform.xform(parent_rect.position + Vector2(parent_rect.size.x * anchor.x, parent_rect.size.y * anchor.y)); + if (p_control->is_layout_rtl()) { + return parent_transform.xform(parent_rect.position + Vector2(parent_rect.size.x - parent_rect.size.x * anchor.x, parent_rect.size.y * anchor.y)); + } else { + return parent_transform.xform(parent_rect.position + Vector2(parent_rect.size.x * anchor.x, parent_rect.size.y * anchor.y)); + } } Vector2 CanvasItemEditor::_position_to_anchor(const Control *p_control, Vector2 position) { @@ -866,7 +869,11 @@ Vector2 CanvasItemEditor::_position_to_anchor(const Control *p_control, Vector2 Rect2 parent_rect = p_control->get_parent_anchorable_rect(); Vector2 output = Vector2(); - output.x = (parent_rect.size.x == 0) ? 0.0 : (p_control->get_transform().xform(position).x - parent_rect.position.x) / parent_rect.size.x; + if (p_control->is_layout_rtl()) { + output.x = (parent_rect.size.x == 0) ? 0.0 : (parent_rect.size.x - p_control->get_transform().xform(position).x - parent_rect.position.x) / parent_rect.size.x; + } else { + output.x = (parent_rect.size.x == 0) ? 0.0 : (p_control->get_transform().xform(position).x - parent_rect.position.x) / parent_rect.size.x; + } output.y = (parent_rect.size.y == 0) ? 0.0 : (p_control->get_transform().xform(position).y - parent_rect.position.y) / parent_rect.size.y; return output; } @@ -1628,7 +1635,11 @@ bool CanvasItemEditor::_gui_input_anchors(const Ref &p_event) { for (int i = 0; i < 4; i++) { anchor_pos[i] = (transform * control->get_global_transform_with_canvas()).xform(_anchor_to_position(control, anchor_pos[i])); anchor_rects[i] = Rect2(anchor_pos[i], anchor_handle->get_size()); - anchor_rects[i].position -= anchor_handle->get_size() * Vector2(float(i == 0 || i == 3), float(i <= 1)); + if (control->is_layout_rtl()) { + anchor_rects[i].position -= anchor_handle->get_size() * Vector2(float(i == 1 || i == 2), float(i <= 1)); + } else { + anchor_rects[i].position -= anchor_handle->get_size() * Vector2(float(i == 0 || i == 3), float(i <= 1)); + } } DragType dragger[] = { @@ -2771,7 +2782,8 @@ void CanvasItemEditor::_draw_text_at_position(Point2 p_position, String p_string Color color = get_theme_color("font_color", "Editor"); color.a = 0.8; Ref font = get_theme_font("font", "Label"); - Size2 text_size = font->get_string_size(p_string); + int font_size = get_theme_font_size("font_size", "Label"); + Size2 text_size = font->get_string_size(p_string, font_size); switch (p_side) { case MARGIN_LEFT: p_position += Vector2(-text_size.x - 5, text_size.y / 2); @@ -2786,18 +2798,18 @@ void CanvasItemEditor::_draw_text_at_position(Point2 p_position, String p_string p_position += Vector2(-text_size.x / 2, text_size.y + 5); break; } - viewport->draw_string(font, p_position, p_string, color); + viewport->draw_string(font, p_position, p_string, HALIGN_LEFT, -1, font_size, color); } void CanvasItemEditor::_draw_margin_at_position(int p_value, Point2 p_position, Margin p_side) { - String str = vformat("%d px", p_value); + String str = TS->format_number(vformat("%d " + TTR("px"), p_value)); if (p_value != 0) { _draw_text_at_position(p_position, str, p_side); } } void CanvasItemEditor::_draw_percentage_at_position(float p_value, Point2 p_position, Margin p_side) { - String str = vformat("%.1f %%", p_value * 100.0); + String str = TS->format_number(vformat("%.1f ", p_value * 100.0)) + TS->percent_sign(); if (p_value != 0) { _draw_text_at_position(p_position, str, p_side); } @@ -2841,17 +2853,19 @@ void CanvasItemEditor::_draw_guides() { Color text_color = get_theme_color("font_color", "Editor"); text_color.a = 0.5; if (drag_type == DRAG_DOUBLE_GUIDE || drag_type == DRAG_V_GUIDE) { - String str = vformat("%d px", Math::round(xform.affine_inverse().xform(dragged_guide_pos).x)); + String str = TS->format_number(vformat("%d px", Math::round(xform.affine_inverse().xform(dragged_guide_pos).x))); Ref font = get_theme_font("font", "Label"); - Size2 text_size = font->get_string_size(str); - viewport->draw_string(font, Point2(dragged_guide_pos.x + 10, RULER_WIDTH + text_size.y / 2 + 10), str, text_color); + int font_size = get_theme_font_size("font_size", "Label"); + Size2 text_size = font->get_string_size(str, font_size); + viewport->draw_string(font, Point2(dragged_guide_pos.x + 10, RULER_WIDTH + text_size.y / 2 + 10), str, HALIGN_LEFT, -1, font_size, text_color); viewport->draw_line(Point2(dragged_guide_pos.x, 0), Point2(dragged_guide_pos.x, viewport->get_size().y), guide_color, Math::round(EDSCALE)); } if (drag_type == DRAG_DOUBLE_GUIDE || drag_type == DRAG_H_GUIDE) { - String str = vformat("%d px", Math::round(xform.affine_inverse().xform(dragged_guide_pos).y)); + String str = TS->format_number(vformat("%d px", Math::round(xform.affine_inverse().xform(dragged_guide_pos).y))); Ref font = get_theme_font("font", "Label"); - Size2 text_size = font->get_string_size(str); - viewport->draw_string(font, Point2(RULER_WIDTH + 10, dragged_guide_pos.y + text_size.y / 2 + 10), str, text_color); + int font_size = get_theme_font_size("font_size", "Label"); + Size2 text_size = font->get_string_size(str, font_size); + viewport->draw_string(font, Point2(RULER_WIDTH + 10, dragged_guide_pos.y + text_size.y / 2 + 10), str, HALIGN_LEFT, -1, font_size, text_color); viewport->draw_line(Point2(0, dragged_guide_pos.y), Point2(viewport->get_size().x, dragged_guide_pos.y), guide_color, Math::round(EDSCALE)); } } @@ -2876,6 +2890,7 @@ void CanvasItemEditor::_draw_rulers() { Color font_color = get_theme_color("font_color", "Editor"); font_color.a = 0.8; Ref font = get_theme_font("rulers", "EditorFonts"); + int font_size = get_theme_font_size("rulers_size", "EditorFonts"); // The rule transform Transform2D ruler_transform = Transform2D(); @@ -2922,7 +2937,7 @@ void CanvasItemEditor::_draw_rulers() { if (i % (major_subdivision * minor_subdivision) == 0) { viewport->draw_line(Point2(position.x, 0), Point2(position.x, RULER_WIDTH), graduation_color, Math::round(EDSCALE)); float val = (ruler_transform * major_subdivide * minor_subdivide).xform(Point2(i, 0)).x; - viewport->draw_string(font, Point2(position.x + 2, font->get_height()), vformat(((int)val == val) ? "%d" : "%.1f", val), font_color); + viewport->draw_string(font, Point2(position.x + 2, font->get_height(font_size)), TS->format_number(vformat(((int)val == val) ? "%d" : "%.1f", val)), HALIGN_LEFT, -1, font_size, font_color); } else { if (i % minor_subdivision == 0) { viewport->draw_line(Point2(position.x, RULER_WIDTH * 0.33), Point2(position.x, RULER_WIDTH), graduation_color, Math::round(EDSCALE)); @@ -2940,9 +2955,9 @@ void CanvasItemEditor::_draw_rulers() { viewport->draw_line(Point2(0, position.y), Point2(RULER_WIDTH, position.y), graduation_color, Math::round(EDSCALE)); float val = (ruler_transform * major_subdivide * minor_subdivide).xform(Point2(0, i)).y; - Transform2D text_xform = Transform2D(-Math_PI / 2.0, Point2(font->get_height(), position.y - 2)); + Transform2D text_xform = Transform2D(-Math_PI / 2.0, Point2(font->get_height(font_size), position.y - 2)); viewport->draw_set_transform_matrix(viewport->get_transform() * text_xform); - viewport->draw_string(font, Point2(), vformat(((int)val == val) ? "%d" : "%.1f", val), font_color); + viewport->draw_string(font, Point2(), TS->format_number(vformat(((int)val == val) ? "%d" : "%.1f", val)), HALIGN_LEFT, -1, font_size, font_color); viewport->draw_set_transform_matrix(viewport->get_transform()); } else { @@ -3054,17 +3069,18 @@ void CanvasItemEditor::_draw_ruler_tool() { } Ref font = get_theme_font("bold", "EditorFonts"); + int font_size = get_theme_font_size("bold_size", "EditorFonts"); Color font_color = get_theme_color("font_color", "Editor"); Color font_secondary_color = font_color; font_secondary_color.a = 0.5; - float text_height = font->get_height(); + float text_height = font->get_height(font_size); const float text_width = 76; const float angle_text_width = 54; Point2 text_pos = (begin + end) / 2 - Vector2(text_width / 2, text_height / 2); text_pos.x = CLAMP(text_pos.x, text_width / 2, viewport->get_rect().size.x - text_width * 1.5); text_pos.y = CLAMP(text_pos.y, text_height * 1.5, viewport->get_rect().size.y - text_height * 1.5); - viewport->draw_string(font, text_pos, vformat("%.2f px", length_vector.length()), font_color); + viewport->draw_string(font, text_pos, TS->format_number(vformat("%.2f " + TTR("px"), length_vector.length())), HALIGN_LEFT, -1, font_size, font_color); if (draw_secondary_lines) { const float horizontal_angle_rad = atan2(length_vector.y, length_vector.x); @@ -3074,16 +3090,16 @@ void CanvasItemEditor::_draw_ruler_tool() { Point2 text_pos2 = text_pos; text_pos2.x = begin.x < text_pos.x ? MIN(text_pos.x - text_width, begin.x - text_width / 2) : MAX(text_pos.x + text_width, begin.x - text_width / 2); - viewport->draw_string(font, text_pos2, vformat("%.2f px", length_vector.y), font_secondary_color); + viewport->draw_string(font, text_pos2, TS->format_number(vformat("%.2f " + TTR("px"), length_vector.y)), HALIGN_LEFT, -1, font_size, font_secondary_color); Point2 v_angle_text_pos = Point2(); v_angle_text_pos.x = CLAMP(begin.x - angle_text_width / 2, angle_text_width / 2, viewport->get_rect().size.x - angle_text_width); v_angle_text_pos.y = begin.y < end.y ? MIN(text_pos2.y - 2 * text_height, begin.y - text_height * 0.5) : MAX(text_pos2.y + text_height * 3, begin.y + text_height * 1.5); - viewport->draw_string(font, v_angle_text_pos, vformat("%d deg", vertical_angle), font_secondary_color); + viewport->draw_string(font, v_angle_text_pos, TS->format_number(vformat("%d " + TTR("deg"), vertical_angle)), HALIGN_LEFT, -1, font_size, font_secondary_color); text_pos2 = text_pos; text_pos2.y = end.y < text_pos.y ? MIN(text_pos.y - text_height * 2, end.y - text_height / 2) : MAX(text_pos.y + text_height * 2, end.y - text_height / 2); - viewport->draw_string(font, text_pos2, vformat("%.2f px", length_vector.x), font_secondary_color); + viewport->draw_string(font, text_pos2, TS->format_number(vformat("%.2f " + TTR("px"), length_vector.x)), HALIGN_LEFT, -1, font_size, font_secondary_color); Point2 h_angle_text_pos = Point2(); h_angle_text_pos.x = CLAMP(end.x - angle_text_width / 2, angle_text_width / 2, viewport->get_rect().size.x - angle_text_width); @@ -3100,7 +3116,7 @@ void CanvasItemEditor::_draw_ruler_tool() { h_angle_text_pos.y = MIN(text_pos.y - height_multiplier * text_height, MIN(end.y - text_height * 0.5, text_pos2.y - height_multiplier * text_height)); } } - viewport->draw_string(font, h_angle_text_pos, vformat("%d deg", horizontal_angle), font_secondary_color); + viewport->draw_string(font, h_angle_text_pos, TS->format_number(vformat("%d " + TTR("deg"), horizontal_angle)), HALIGN_LEFT, -1, font_size, font_secondary_color); // Angle arcs int arc_point_count = 8; @@ -3137,17 +3153,17 @@ void CanvasItemEditor::_draw_ruler_tool() { text_pos.y = CLAMP(text_pos.y, text_height * 2.5, viewport->get_rect().size.y - text_height / 2); if (draw_secondary_lines) { - viewport->draw_string(font, text_pos, vformat("%.2f units", (length_vector / grid_step).length()), font_color); + viewport->draw_string(font, text_pos, TS->format_number(vformat("%.2f " + TTR("units"), (length_vector / grid_step).length())), HALIGN_LEFT, -1, font_size, font_color); Point2 text_pos2 = text_pos; text_pos2.x = begin.x < text_pos.x ? MIN(text_pos.x - text_width, begin.x - text_width / 2) : MAX(text_pos.x + text_width, begin.x - text_width / 2); - viewport->draw_string(font, text_pos2, vformat("%d units", roundf(length_vector.y / grid_step.y)), font_secondary_color); + viewport->draw_string(font, text_pos2, TS->format_number(vformat("%d " + TTR("units"), roundf(length_vector.y / grid_step.y))), HALIGN_LEFT, -1, font_size, font_secondary_color); text_pos2 = text_pos; text_pos2.y = end.y < text_pos.y ? MIN(text_pos.y - text_height * 2, end.y + text_height / 2) : MAX(text_pos.y + text_height * 2, end.y + text_height / 2); - viewport->draw_string(font, text_pos2, vformat("%d units", roundf(length_vector.x / grid_step.x)), font_secondary_color); + viewport->draw_string(font, text_pos2, TS->format_number(vformat("%d " + TTR("units"), roundf(length_vector.x / grid_step.x))), HALIGN_LEFT, -1, font_size, font_secondary_color); } else { - viewport->draw_string(font, text_pos, vformat("%d units", roundf((length_vector / grid_step).length())), font_color); + viewport->draw_string(font, text_pos, TS->format_number(vformat("%d " + TTR("units"), roundf((length_vector / grid_step).length()))), HALIGN_LEFT, -1, font_size, font_color); } } } else { @@ -3177,10 +3193,17 @@ void CanvasItemEditor::_draw_control_anchors(Control *control) { // Draw the anchors handles Rect2 anchor_rects[4]; - anchor_rects[0] = Rect2(anchors_pos[0] - anchor_handle->get_size(), anchor_handle->get_size()); - anchor_rects[1] = Rect2(anchors_pos[1] - Vector2(0.0, anchor_handle->get_size().y), Point2(-anchor_handle->get_size().x, anchor_handle->get_size().y)); - anchor_rects[2] = Rect2(anchors_pos[2], -anchor_handle->get_size()); - anchor_rects[3] = Rect2(anchors_pos[3] - Vector2(anchor_handle->get_size().x, 0.0), Point2(anchor_handle->get_size().x, -anchor_handle->get_size().y)); + if (control->is_layout_rtl()) { + anchor_rects[0] = Rect2(anchors_pos[0] - Vector2(0.0, anchor_handle->get_size().y), Point2(-anchor_handle->get_size().x, anchor_handle->get_size().y)); + anchor_rects[1] = Rect2(anchors_pos[1] - anchor_handle->get_size(), anchor_handle->get_size()); + anchor_rects[2] = Rect2(anchors_pos[2] - Vector2(anchor_handle->get_size().x, 0.0), Point2(anchor_handle->get_size().x, -anchor_handle->get_size().y)); + anchor_rects[3] = Rect2(anchors_pos[3], -anchor_handle->get_size()); + } else { + anchor_rects[0] = Rect2(anchors_pos[0] - anchor_handle->get_size(), anchor_handle->get_size()); + anchor_rects[1] = Rect2(anchors_pos[1] - Vector2(0.0, anchor_handle->get_size().y), Point2(-anchor_handle->get_size().x, anchor_handle->get_size().y)); + anchor_rects[2] = Rect2(anchors_pos[2], -anchor_handle->get_size()); + anchor_rects[3] = Rect2(anchors_pos[3] - Vector2(anchor_handle->get_size().x, 0.0), Point2(anchor_handle->get_size().x, -anchor_handle->get_size().y)); + } for (int i = 0; i < 4; i++) { anchor_handle->draw_rect(ci, anchor_rects[i]); @@ -3744,6 +3767,7 @@ void CanvasItemEditor::_draw_hover() { String node_name = hovering_results[i].name; Ref font = get_theme_font("font", "Label"); + int font_size = get_theme_font_size("font_size", "Label"); Size2 node_name_size = font->get_string_size(node_name); Size2 item_size = Size2(node_icon->get_size().x + 4 + node_name_size.x, MAX(node_icon->get_size().y, node_name_size.y - 3)); @@ -3761,7 +3785,7 @@ void CanvasItemEditor::_draw_hover() { viewport->draw_texture(node_icon, pos, Color(1.0, 1.0, 1.0, 0.5)); // Draw name - viewport->draw_string(font, pos + Point2(node_icon->get_size().x + 4, item_size.y - 3), node_name, Color(1.0, 1.0, 1.0, 0.5)); + viewport->draw_string(font, pos + Point2(node_icon->get_size().x + 4, item_size.y - 3), node_name, HALIGN_LEFT, -1, font_size, Color(1.0, 1.0, 1.0, 0.5)); } } @@ -4342,8 +4366,13 @@ void CanvasItemEditor::_update_scrollbars() { } // Move and resize the scrollbars, avoiding overlap. - v_scroll->set_begin(Point2(size.width - vmin.width, (show_rulers) ? RULER_WIDTH : 0)); - v_scroll->set_end(Point2(size.width, size.height - (h_scroll->is_visible() ? hmin.height : 0))); + if (is_layout_rtl()) { + v_scroll->set_begin(Point2(0, (show_rulers) ? RULER_WIDTH : 0)); + v_scroll->set_end(Point2(vmin.width, size.height - (h_scroll->is_visible() ? hmin.height : 0))); + } else { + v_scroll->set_begin(Point2(size.width - vmin.width, (show_rulers) ? RULER_WIDTH : 0)); + v_scroll->set_end(Point2(size.width, size.height - (h_scroll->is_visible() ? hmin.height : 0))); + } h_scroll->set_begin(Point2((show_rulers) ? RULER_WIDTH : 0, size.height - hmin.height)); h_scroll->set_end(Point2(size.width - (v_scroll->is_visible() ? vmin.width : 0), size.height)); @@ -4540,9 +4569,9 @@ void CanvasItemEditor::_update_zoom_label() { // even if their display doesn't have a particularly low DPI. if (zoom >= 10) { // Don't show a decimal when the zoom level is higher than 1000 %. - zoom_text = rtos(Math::round((zoom / MAX(1, EDSCALE)) * 100)) + " %"; + zoom_text = TS->format_number(rtos(Math::round((zoom / MAX(1, EDSCALE)) * 100))) + " " + TS->percent_sign(); } else { - zoom_text = rtos(Math::stepify((zoom / MAX(1, EDSCALE)) * 100, 0.1)) + " %"; + zoom_text = TS->format_number(rtos(Math::stepify((zoom / MAX(1, EDSCALE)) * 100, 0.1))) + " " + TS->percent_sign(); } zoom_reset->set_text(zoom_text); @@ -5703,6 +5732,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { warning_child_of_container->set_text(TTR("Warning: Children of a container get their position and size determined only by their parent.")); warning_child_of_container->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color("warning_color", "Editor")); warning_child_of_container->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("main", "EditorFonts")); + warning_child_of_container->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("main_size", "EditorFonts")); add_control_to_info_overlay(warning_child_of_container); h_scroll = memnew(HScrollBar); @@ -5727,10 +5757,8 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { zoom_reset = memnew(Button); zoom_reset->set_flat(true); zoom_hb->add_child(zoom_reset); - Ref font = zoom_reset->get_theme_font("font")->duplicate(false); - font->set_outline_size(1); - font->set_outline_color(Color(0, 0, 0)); - zoom_reset->add_theme_font_override("font", font); + zoom_reset->add_theme_constant_override("outline_size", 1); + zoom_reset->add_theme_color_override("font_outline_modulate", Color(0, 0, 0)); zoom_reset->add_theme_color_override("font_color", Color(1, 1, 1)); zoom_reset->connect("pressed", callable_mp(this, &CanvasItemEditor::_button_zoom_reset)); zoom_reset->set_shortcut(ED_SHORTCUT("canvas_item_editor/zoom_reset", TTR("Zoom Reset"), KEY_MASK_CMD | KEY_0)); diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp index 539ab03f5bd2..4768cac21701 100644 --- a/editor/plugins/curve_editor_plugin.cpp +++ b/editor/plugins/curve_editor_plugin.cpp @@ -518,7 +518,9 @@ void CurveEditor::set_hover_point_index(int index) { void CurveEditor::update_view_transform() { Ref font = get_theme_font("font", "Label"); - const real_t margin = font->get_height() + 2 * EDSCALE; + int font_size = get_theme_font_size("font_size", "Label"); + + const real_t margin = font->get_height(font_size) + 2 * EDSCALE; float min_y = 0; float max_y = 1; @@ -662,18 +664,19 @@ void CurveEditor::_draw() { draw_set_transform_matrix(Transform2D()); Ref font = get_theme_font("font", "Label"); - float font_height = font->get_height(); + int font_size = get_theme_font_size("font_size", "Label"); + float font_height = font->get_height(font_size); Color text_color = get_theme_color("font_color", "Editor"); { // X axis float y = curve.get_min_value(); Vector2 off(0, font_height - 1); - draw_string(font, get_view_pos(Vector2(0, y)) + off, "0.0", text_color); - draw_string(font, get_view_pos(Vector2(0.25, y)) + off, "0.25", text_color); - draw_string(font, get_view_pos(Vector2(0.5, y)) + off, "0.5", text_color); - draw_string(font, get_view_pos(Vector2(0.75, y)) + off, "0.75", text_color); - draw_string(font, get_view_pos(Vector2(1, y)) + off, "1.0", text_color); + draw_string(font, get_view_pos(Vector2(0, y)) + off, "0.0", HALIGN_LEFT, -1, font_size, text_color); + draw_string(font, get_view_pos(Vector2(0.25, y)) + off, "0.25", HALIGN_LEFT, -1, font_size, text_color); + draw_string(font, get_view_pos(Vector2(0.5, y)) + off, "0.5", HALIGN_LEFT, -1, font_size, text_color); + draw_string(font, get_view_pos(Vector2(0.75, y)) + off, "0.75", HALIGN_LEFT, -1, font_size, text_color); + draw_string(font, get_view_pos(Vector2(1, y)) + off, "1.0", HALIGN_LEFT, -1, font_size, text_color); } { @@ -682,9 +685,9 @@ void CurveEditor::_draw() { float m1 = 0.5 * (curve.get_min_value() + curve.get_max_value()); float m2 = curve.get_max_value(); Vector2 off(1, -1); - draw_string(font, get_view_pos(Vector2(0, m0)) + off, String::num(m0, 2), text_color); - draw_string(font, get_view_pos(Vector2(0, m1)) + off, String::num(m1, 2), text_color); - draw_string(font, get_view_pos(Vector2(0, m2)) + off, String::num(m2, 3), text_color); + draw_string(font, get_view_pos(Vector2(0, m0)) + off, String::num(m0, 2), HALIGN_LEFT, -1, font_size, text_color); + draw_string(font, get_view_pos(Vector2(0, m1)) + off, String::num(m1, 2), HALIGN_LEFT, -1, font_size, text_color); + draw_string(font, get_view_pos(Vector2(0, m2)) + off, String::num(m2, 3), HALIGN_LEFT, -1, font_size, text_color); } // Draw tangents for current point @@ -744,10 +747,10 @@ void CurveEditor::_draw() { if (_selected_point > 0 && _selected_point + 1 < curve.get_point_count()) { text_color.a *= 0.4; - draw_string(font, Vector2(50 * EDSCALE, font_height), TTR("Hold Shift to edit tangents individually"), text_color); + draw_string(font, Vector2(50 * EDSCALE, font_height), TTR("Hold Shift to edit tangents individually"), HALIGN_LEFT, -1, font_size, text_color); } else if (curve.get_point_count() == 0) { text_color.a *= 0.4; - draw_string(font, Vector2(50 * EDSCALE, font_height), TTR("Right click to add point"), text_color); + draw_string(font, Vector2(50 * EDSCALE, font_height), TTR("Right click to add point"), HALIGN_LEFT, -1, font_size, text_color); } } diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index 3cf4dc5ac84e..2fc0e35f8226 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -37,7 +37,7 @@ #include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "scene/resources/bit_map.h" -#include "scene/resources/dynamic_font.h" +#include "scene/resources/font.h" #include "scene/resources/material.h" #include "scene/resources/mesh.h" #include "servers/audio/audio_stream.h" @@ -798,25 +798,79 @@ void EditorFontPreviewPlugin::_bind_methods() { } bool EditorFontPreviewPlugin::handles(const String &p_type) const { - return ClassDB::is_parent_class(p_type, "DynamicFontData") || ClassDB::is_parent_class(p_type, "DynamicFont"); -} + return ClassDB::is_parent_class(p_type, "FontData") || ClassDB::is_parent_class(p_type, "Font"); +} + +struct FSample { + String script; + String sample; +}; + +static FSample _samples[] = { + { "hani", U"漢語" }, + { "armn", U"Աբ" }, + { "copt", U"Αα" }, + { "cyrl", U"Аб" }, + { "grek", U"Αα" }, + { "hebr", U"אב" }, + { "arab", U"اب" }, + { "syrc", U"ܐܒ" }, + { "thaa", U"ހށ" }, + { "deva", U"आ" }, + { "beng", U"আ" }, + { "guru", U"ਆ" }, + { "gujr", U"આ" }, + { "orya", U"ଆ" }, + { "taml", U"ஆ" }, + { "telu", U"ఆ" }, + { "knda", U"ಆ" }, + { "mylm", U"ആ" }, + { "sinh", U"ආ" }, + { "thai", U"กิ" }, + { "laoo", U"ກິ" }, + { "tibt", U"ༀ" }, + { "mymr", U"က" }, + { "geor", U"Ⴀა" }, + { "hang", U"한글" }, + { "ethi", U"ሀ" }, + { "cher", U"Ꭳ" }, + { "cans", U"ᐁ" }, + { "ogam", U"ᚁ" }, + { "runr", U"ᚠ" }, + { "tglg", U"ᜀ" }, + { "hano", U"ᜠ" }, + { "buhd", U"ᝀ" }, + { "tagb", U"ᝠ" }, + { "khmr", U"ក" }, + { "mong", U"ᠠ" }, + { "limb", U"ᤁ" }, + { "tale", U"ᥐ" }, + { "latn", U"Ab" }, + { "zyyy", U"😀" }, + { "", U"" } +}; Ref EditorFontPreviewPlugin::generate_from_path(const String &p_path, const Size2 &p_size) const { RES res = ResourceLoader::load(p_path); - Ref sampled_font; - if (res->is_class("DynamicFont")) { + Ref sampled_font; + if (res->is_class("Font")) { sampled_font = res->duplicate(); - if (sampled_font->get_outline_color() == Color(1, 1, 1, 1)) { - sampled_font->set_outline_color(Color(0, 0, 0, 1)); - } - } else if (res->is_class("DynamicFontData")) { + } else if (res->is_class("FontData")) { sampled_font.instance(); - sampled_font->set_font_data(res); + sampled_font->add_data(res->duplicate()); } - sampled_font->set_size(50); - String sampled_text = "Abg"; - Vector2 size = sampled_font->get_string_size(sampled_text); + String sample; + for (int j = 0; j < sampled_font->get_data_count(); j++) { + for (int i = 0; _samples[i].script != String(); i++) { + if (sampled_font->get_data(j)->is_script_supported(_samples[i].script)) { + if (sampled_font->get_data(j)->has_char(_samples[i].sample[0])) { + sample += _samples[i].sample; + } + } + } + } + Vector2 size = sampled_font->get_string_size(sample, 50); Vector2 pos; @@ -825,7 +879,7 @@ Ref EditorFontPreviewPlugin::generate_from_path(const String &p_path, Ref font = sampled_font; - font->draw(canvas_item, pos, sampled_text); + font->draw_string(canvas_item, pos, sample, HALIGN_LEFT, -1.f, 50, Color(1, 1, 1)); preview_done = false; RS::get_singleton()->viewport_set_update_mode(viewport, RS::VIEWPORT_UPDATE_ONCE); //once used for capture diff --git a/editor/plugins/font_editor_plugin.cpp b/editor/plugins/font_editor_plugin.cpp new file mode 100644 index 000000000000..a82547182cab --- /dev/null +++ b/editor/plugins/font_editor_plugin.cpp @@ -0,0 +1,331 @@ +/*************************************************************************/ +/* font_editor_plugin.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "font_editor_plugin.h" + +#include "editor/editor_scale.h" + +void FontDataPreview::_notification(int p_what) { + if (p_what == NOTIFICATION_DRAW) { + Color text_color = get_theme_color("font_color", "Label"); + Color line_color = text_color; + line_color.a *= 0.6; + Vector2 pos = (get_size() - line->get_size()) / 2; + line->draw(get_canvas_item(), pos, text_color); + draw_line(Vector2(0, pos.y + line->get_line_ascent()), Vector2(pos.x - 5, pos.y + line->get_line_ascent()), line_color); + draw_line(Vector2(pos.x + line->get_size().x + 5, pos.y + line->get_line_ascent()), Vector2(get_size().x, pos.y + line->get_line_ascent()), line_color); + } +} + +void FontDataPreview::_bind_methods() {} + +Size2 FontDataPreview::get_minimum_size() const { + return Vector2(64, 64) * EDSCALE; +} + +struct FSample { + String script; + String sample; +}; + +static FSample _samples[] = { + { "hani", U"漢語" }, + { "armn", U"Աբ" }, + { "copt", U"Αα" }, + { "cyrl", U"Аб" }, + { "grek", U"Αα" }, + { "hebr", U"אב" }, + { "arab", U"اب" }, + { "syrc", U"ܐܒ" }, + { "thaa", U"ހށ" }, + { "deva", U"आ" }, + { "beng", U"আ" }, + { "guru", U"ਆ" }, + { "gujr", U"આ" }, + { "orya", U"ଆ" }, + { "taml", U"ஆ" }, + { "telu", U"ఆ" }, + { "knda", U"ಆ" }, + { "mylm", U"ആ" }, + { "sinh", U"ආ" }, + { "thai", U"กิ" }, + { "laoo", U"ກິ" }, + { "tibt", U"ༀ" }, + { "mymr", U"က" }, + { "geor", U"Ⴀა" }, + { "hang", U"한글" }, + { "ethi", U"ሀ" }, + { "cher", U"Ꭳ" }, + { "cans", U"ᐁ" }, + { "ogam", U"ᚁ" }, + { "runr", U"ᚠ" }, + { "tglg", U"ᜀ" }, + { "hano", U"ᜠ" }, + { "buhd", U"ᝀ" }, + { "tagb", U"ᝠ" }, + { "khmr", U"ក" }, + { "mong", U"ᠠ" }, + { "limb", U"ᤁ" }, + { "tale", U"ᥐ" }, + { "latn", U"Ab" }, + { "zyyy", U"😀" }, + { "", U"" } +}; + +void FontDataPreview::set_data(const Ref &p_data) { + Ref f = memnew(Font); + f->add_data(p_data); + + line->clear(); + + String sample; + for (int i = 0; _samples[i].script != String(); i++) { + if (p_data->is_script_supported(_samples[i].script)) { + if (p_data->has_char(_samples[i].sample[0])) { + sample += _samples[i].sample; + } + } + } + line->add_string(sample, f, 72); + + update(); +} + +FontDataPreview::FontDataPreview() { + line.instance(); +} + +/*************************************************************************/ + +void FontDataEditor::_notification(int p_what) { + if (p_what == NOTIFICATION_SORT_CHILDREN) { + int split_width = get_name_split_ratio() * get_size().width; + button->set_size(Size2(get_theme_icon("Add", "EditorIcons")->get_width(), get_size().height)); + if (is_layout_rtl()) { + if (le != nullptr) { + fit_child_in_rect(le, Rect2(Vector2(split_width, 0), Size2(split_width, get_size().height))); + } + fit_child_in_rect(chk, Rect2(Vector2(split_width - chk->get_size().x, 0), Size2(chk->get_size().x, get_size().height))); + fit_child_in_rect(button, Rect2(Vector2(0, 0), Size2(button->get_size().width, get_size().height))); + } else { + if (le != nullptr) { + fit_child_in_rect(le, Rect2(Vector2(0, 0), Size2(split_width, get_size().height))); + } + fit_child_in_rect(chk, Rect2(Vector2(split_width, 0), Size2(chk->get_size().x, get_size().height))); + fit_child_in_rect(button, Rect2(Vector2(get_size().width - button->get_size().width, 0), Size2(button->get_size().width, get_size().height))); + } + update(); + } + if (p_what == NOTIFICATION_DRAW) { + int split_width = get_name_split_ratio() * get_size().width; + Color dark_color = get_theme_color("dark_color_2", "Editor"); + if (is_layout_rtl()) { + draw_rect(Rect2(Vector2(0, 0), Size2(split_width, get_size().height)), dark_color); + } else { + draw_rect(Rect2(Vector2(split_width, 0), Size2(split_width, get_size().height)), dark_color); + } + } + if (p_what == NOTIFICATION_THEME_CHANGED) { + if (le != nullptr) { + button->set_icon(get_theme_icon("Add", "EditorIcons")); + } else { + button->set_icon(get_theme_icon("Remove", "EditorIcons")); + } + queue_sort(); + } + if (p_what == NOTIFICATION_RESIZED) { + queue_sort(); + } +} + +void FontDataEditor::update_property() { + if (le == nullptr) { + bool c = get_edited_object()->get(get_edited_property()); + chk->set_pressed(c); + chk->set_disabled(is_read_only()); + } +} + +Size2 FontDataEditor::get_minimum_size() const { + return Size2(0, 60); +} + +void FontDataEditor::_bind_methods() { +} + +void FontDataEditor::init_lang_add() { + le = memnew(LineEdit); + le->set_placeholder("Language code"); + le->set_custom_minimum_size(Size2(get_size().width / 2, 0)); + le->set_editable(true); + add_child(le); + + button->set_icon(get_theme_icon("Add", "EditorIcons")); + button->connect("pressed", callable_mp(this, &FontDataEditor::add_lang)); +} + +void FontDataEditor::init_lang_edit() { + button->set_icon(get_theme_icon("Remove", "EditorIcons")); + button->connect("pressed", callable_mp(this, &FontDataEditor::remove_lang)); + chk->connect("toggled", callable_mp(this, &FontDataEditor::toggle_lang)); +} + +void FontDataEditor::init_script_add() { + le = memnew(LineEdit); + le->set_placeholder("Script code"); + le->set_custom_minimum_size(Size2(get_size().width / 2, 0)); + le->set_editable(true); + add_child(le); + + button->set_icon(get_theme_icon("Add", "EditorIcons")); + button->connect("pressed", callable_mp(this, &FontDataEditor::add_script)); +} + +void FontDataEditor::init_script_edit() { + button->set_icon(get_theme_icon("Remove", "EditorIcons")); + button->connect("pressed", callable_mp(this, &FontDataEditor::remove_script)); + chk->connect("toggled", callable_mp(this, &FontDataEditor::toggle_script)); +} + +void FontDataEditor::add_lang() { + FontData *fd = Object::cast_to(get_edited_object()); + if (fd != nullptr && !le->get_text().empty()) { + fd->set_language_support_override(le->get_text(), chk->is_pressed()); + le->set_text(""); + chk->set_pressed(false); + } +} + +void FontDataEditor::add_script() { + FontData *fd = Object::cast_to(get_edited_object()); + if (fd != nullptr && le->get_text().length() == 4) { + fd->set_script_support_override(le->get_text(), chk->is_pressed()); + le->set_text(""); + chk->set_pressed(false); + } +} + +void FontDataEditor::toggle_lang(bool p_pressed) { + FontData *fd = Object::cast_to(get_edited_object()); + if (fd != nullptr) { + String lang = String(get_edited_property()).replace("language_support_override/", ""); + fd->set_language_support_override(lang, p_pressed); + } +} + +void FontDataEditor::toggle_script(bool p_pressed) { + FontData *fd = Object::cast_to(get_edited_object()); + if (fd != nullptr) { + String script = String(get_edited_property()).replace("script_support_override/", ""); + fd->set_script_support_override(script, p_pressed); + } +} + +void FontDataEditor::remove_lang() { + FontData *fd = Object::cast_to(get_edited_object()); + if (fd != nullptr) { + String lang = String(get_edited_property()).replace("language_support_override/", ""); + fd->remove_language_support_override(lang); + } +} + +void FontDataEditor::remove_script() { + FontData *fd = Object::cast_to(get_edited_object()); + if (fd != nullptr) { + String script = String(get_edited_property()).replace("script_support_override/", ""); + fd->remove_script_support_override(script); + } +} + +FontDataEditor::FontDataEditor() { + chk = memnew(CheckBox); + chk->set_text(TTR("On")); + chk->set_flat(true); + add_child(chk); + + button = memnew(Button); + button->set_flat(true); + add_child(button); +} + +/*************************************************************************/ + +bool EditorInspectorPluginFont::can_handle(Object *p_object) { + return Object::cast_to(p_object) != nullptr; +} + +void EditorInspectorPluginFont::parse_begin(Object *p_object) { + FontData *fd = Object::cast_to(p_object); + ERR_FAIL_COND(!fd); + + FontDataPreview *editor = memnew(FontDataPreview); + editor->set_data(fd); + add_custom_control(editor); +} + +bool EditorInspectorPluginFont::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) { + if (p_path.begins_with("language_support_override/") && p_object->is_class("FontData")) { + String lang = p_path.replace("language_support_override/", ""); + + FontDataEditor *editor = memnew(FontDataEditor); + if (lang != "_new") { + editor->init_lang_edit(); + } else { + editor->init_lang_add(); + } + add_property_editor(p_path, editor); + + return true; + } + + if (p_path.begins_with("script_support_override/") && p_object->is_class("FontData")) { + String script = p_path.replace("script_support_override/", ""); + + FontDataEditor *editor = memnew(FontDataEditor); + if (script != "_new") { + editor->init_script_edit(); + } else { + editor->init_script_add(); + } + add_property_editor(p_path, editor); + + return true; + } + + return false; +} + +/*************************************************************************/ + +FontEditorPlugin::FontEditorPlugin(EditorNode *p_node) { + Ref fd_plugin; + fd_plugin.instance(); + EditorInspector::add_inspector_plugin(fd_plugin); +} diff --git a/editor/plugins/font_editor_plugin.h b/editor/plugins/font_editor_plugin.h new file mode 100644 index 000000000000..1d3ffc885772 --- /dev/null +++ b/editor/plugins/font_editor_plugin.h @@ -0,0 +1,111 @@ +/*************************************************************************/ +/* font_editor_plugin.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef FONT_EDITOR_PLUGIN_H +#define FONT_EDITOR_PLUGIN_H + +#include "editor/editor_node.h" +#include "editor/editor_plugin.h" +#include "scene/resources/font.h" +#include "scene/resources/text_line.h" + +class FontDataPreview : public Control { + GDCLASS(FontDataPreview, Control); + +protected: + void _notification(int p_what); + static void _bind_methods(); + + Ref line; + +public: + virtual Size2 get_minimum_size() const override; + + void set_data(const Ref &p_data); + + FontDataPreview(); +}; + +/*************************************************************************/ + +class FontDataEditor : public EditorProperty { + GDCLASS(FontDataEditor, EditorProperty); + + LineEdit *le = nullptr; + CheckBox *chk = nullptr; + Button *button = nullptr; + + void toggle_lang(bool p_pressed); + void toggle_script(bool p_pressed); + void add_lang(); + void add_script(); + void remove_lang(); + void remove_script(); + +protected: + void _notification(int p_what); + + static void _bind_methods(); + +public: + virtual Size2 get_minimum_size() const override; + virtual void update_property() override; + + void init_lang_add(); + void init_lang_edit(); + void init_script_add(); + void init_script_edit(); + + FontDataEditor(); +}; + +/*************************************************************************/ + +class EditorInspectorPluginFont : public EditorInspectorPlugin { + GDCLASS(EditorInspectorPluginFont, EditorInspectorPlugin); + +public: + virtual bool can_handle(Object *p_object) override; + virtual void parse_begin(Object *p_object) override; + virtual bool parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) override; +}; + +/*************************************************************************/ + +class FontEditorPlugin : public EditorPlugin { + GDCLASS(FontEditorPlugin, EditorPlugin); + +public: + FontEditorPlugin(EditorNode *p_node); + + virtual String get_name() const override { return "Font"; } +}; + +#endif // FONT_EDITOR_PLUGIN_H diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 8420faa3021a..fd5c4df3f384 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -138,7 +138,7 @@ void ViewportRotationControl::_draw_axis(const Axis2D &p_axis) { if (front) { String axis_name = direction == 0 ? "X" : (direction == 1 ? "Y" : "Z"); draw_circle(p_axis.screen_point, AXIS_CIRCLE_RADIUS, c); - draw_char(get_theme_font("rotation_control", "EditorFonts"), p_axis.screen_point + Vector2i(-4, 5) * EDSCALE, axis_name, "", Color(0.3, 0.3, 0.3)); + draw_char(get_theme_font("rotation_control", "EditorFonts"), p_axis.screen_point + Vector2i(-4, 5) * EDSCALE, axis_name, "", get_theme_font_size("rotation_control_size", "EditorFonts"), Color(0.3, 0.3, 0.3)); } else { draw_circle(p_axis.screen_point, AXIS_CIRCLE_RADIUS * (0.55 + (0.2 * (1.0 + p_axis.z_axis))), c); } @@ -2593,7 +2593,7 @@ void Node3DEditorViewport::_notification(int p_what) { } } -static void draw_indicator_bar(Control &surface, real_t fill, const Ref icon, const Ref font, const String &text) { +static void draw_indicator_bar(Control &surface, real_t fill, const Ref icon, const Ref font, int font_size, const String &text) { // Adjust bar size from control height const Vector2 surface_size = surface.get_size(); const real_t h = surface_size.y / 2.0; @@ -2613,7 +2613,7 @@ static void draw_indicator_bar(Control &surface, real_t fill, const Ref 0) { Ref font = get_theme_font("font", "Label"); + int font_size = get_theme_font_size("font_size", "Label"); Point2 msgpos = Point2(5, get_size().y - 20); - font->draw(ci, msgpos + Point2(1, 1), message, Color(0, 0, 0, 0.8)); - font->draw(ci, msgpos + Point2(-1, -1), message, Color(0, 0, 0, 0.8)); - font->draw(ci, msgpos, message, Color(1, 1, 1, 1)); + font->draw_string(ci, msgpos + Point2(1, 1), message, HALIGN_LEFT, -1, font_size, Color(0, 0, 0, 0.8)); + font->draw_string(ci, msgpos + Point2(-1, -1), message, HALIGN_LEFT, -1, font_size, Color(0, 0, 0, 0.8)); + font->draw_string(ci, msgpos, message, HALIGN_LEFT, -1, font_size, Color(1, 1, 1, 1)); } if (_edit.mode == TRANSFORM_ROTATE) { @@ -2717,6 +2718,7 @@ void Node3DEditorViewport::_draw() { 1.0 - logscale_t, get_theme_icon("ViewportSpeed", "EditorIcons"), get_theme_font("font", "Label"), + get_theme_font_size("font_size", "Label"), vformat("%s u/s", String::num(freelook_speed).pad_decimals(precision))); } @@ -2743,6 +2745,7 @@ void Node3DEditorViewport::_draw() { logscale_t, get_theme_icon("ViewportZoom", "EditorIcons"), get_theme_font("font", "Label"), + get_theme_font_size("font_size", "Label"), vformat("%s u", String::num(cursor.distance).pad_decimals(precision))); } } diff --git a/editor/plugins/ot_features_plugin.cpp b/editor/plugins/ot_features_plugin.cpp new file mode 100644 index 000000000000..34781485215e --- /dev/null +++ b/editor/plugins/ot_features_plugin.cpp @@ -0,0 +1,213 @@ +/*************************************************************************/ +/* ot_features_plugin.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "ot_features_plugin.h" + +#include "editor/editor_scale.h" + +void OpenTypeFeaturesEditor::_value_changed(double val) { + if (setting) { + return; + } + + emit_changed(get_edited_property(), spin->get_value()); +} + +void OpenTypeFeaturesEditor::update_property() { + double val = get_edited_object()->get(get_edited_property()); + setting = true; + spin->set_value(val); + setting = false; +} + +void OpenTypeFeaturesEditor::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + Color base = get_theme_color("accent_color", "Editor"); + + button->set_icon(get_theme_icon("Remove", "EditorIcons")); + button->set_size(get_theme_icon("Remove", "EditorIcons")->get_size()); + spin->set_custom_label_color(true, base); + } +} + +void OpenTypeFeaturesEditor::_remove_feature() { + get_edited_object()->set(get_edited_property(), -1); +} + +void OpenTypeFeaturesEditor::_bind_methods() { +} + +OpenTypeFeaturesEditor::OpenTypeFeaturesEditor() { + HBoxContainer *bc = memnew(HBoxContainer); + add_child(bc); + + spin = memnew(EditorSpinSlider); + spin->set_flat(true); + bc->add_child(spin); + add_focusable(spin); + spin->connect("value_changed", callable_mp(this, &OpenTypeFeaturesEditor::_value_changed)); + spin->set_h_size_flags(SIZE_EXPAND_FILL); + + spin->set_min(0); + spin->set_max(65536); + spin->set_step(1); + spin->set_hide_slider(false); + spin->set_allow_greater(false); + spin->set_allow_lesser(false); + + button = memnew(Button); + button->set_tooltip(RTR("Remove feature")); + button->set_flat(true); + bc->add_child(button); + + button->connect("pressed", callable_mp(this, &OpenTypeFeaturesEditor::_remove_feature)); + + setting = false; +} + +/*************************************************************************/ + +void OpenTypeFeaturesAdd::_add_feature(int p_option) { + get_edited_object()->set("opentype_features/" + TS->tag_to_name(p_option), 1); +} + +void OpenTypeFeaturesAdd::update_property() { + menu->clear(); + menu_ss->clear(); + menu_cv->clear(); + menu_cu->clear(); + bool have_ss = false; + bool have_cv = false; + bool have_cu = false; + Dictionary features = Object::cast_to(get_edited_object())->get_theme_font("font")->get_feature_list(); + for (const Variant *ftr = features.next(nullptr); ftr != nullptr; ftr = features.next(ftr)) { + String ftr_name = TS->tag_to_name(*ftr); + if (ftr_name.begins_with("stylistic_set_")) { + menu_ss->add_item(ftr_name.capitalize(), (int32_t)*ftr); + have_ss = true; + } else if (ftr_name.begins_with("character_variant_")) { + menu_cv->add_item(ftr_name.capitalize(), (int32_t)*ftr); + have_cv = true; + } else if (ftr_name.begins_with("custom_")) { + menu_cu->add_item(ftr_name.replace("custom_", ""), (int32_t)*ftr); + have_cu = true; + } else { + menu->add_item(ftr_name.capitalize(), (int32_t)*ftr); + } + } + if (have_ss) { + menu->add_submenu_item(RTR("Stylistic Sets"), "SSMenu"); + } + if (have_cv) { + menu->add_submenu_item(RTR("Character Variants"), "CVMenu"); + } + if (have_cu) { + menu->add_submenu_item(RTR("Custom"), "CUMenu"); + } +} + +void OpenTypeFeaturesAdd::_features_menu() { + Size2 size = get_size(); + menu->set_position(get_screen_position() + Size2(0, size.height * get_global_transform().get_scale().y)); + menu->popup(); +} + +void OpenTypeFeaturesAdd::_notification(int p_what) { + if (p_what == NOTIFICATION_THEME_CHANGED || p_what == NOTIFICATION_ENTER_TREE) { + set_label(""); + button->set_icon(get_theme_icon("Add", "EditorIcons")); + button->set_size(get_theme_icon("Add", "EditorIcons")->get_size()); + } +} + +void OpenTypeFeaturesAdd::_bind_methods() { +} + +OpenTypeFeaturesAdd::OpenTypeFeaturesAdd() { + menu = memnew(PopupMenu); + add_child(menu); + + menu_cv = memnew(PopupMenu); + menu_cv->set_name("CVMenu"); + menu->add_child(menu_cv); + + menu_ss = memnew(PopupMenu); + menu_ss->set_name("SSMenu"); + menu->add_child(menu_ss); + + menu_cu = memnew(PopupMenu); + menu_cu->set_name("CUMenu"); + menu->add_child(menu_cu); + + button = memnew(Button); + button->set_flat(true); + button->set_text(RTR("Add feature...")); + button->set_tooltip(RTR("Add feature...")); + add_child(button); + + button->connect("pressed", callable_mp(this, &OpenTypeFeaturesAdd::_features_menu)); + menu->connect("id_pressed", callable_mp(this, &OpenTypeFeaturesAdd::_add_feature)); + menu_cv->connect("id_pressed", callable_mp(this, &OpenTypeFeaturesAdd::_add_feature)); + menu_ss->connect("id_pressed", callable_mp(this, &OpenTypeFeaturesAdd::_add_feature)); + menu_cu->connect("id_pressed", callable_mp(this, &OpenTypeFeaturesAdd::_add_feature)); +} + +/*************************************************************************/ + +bool EditorInspectorPluginOpenTypeFeatures::can_handle(Object *p_object) { + return (Object::cast_to(p_object) != nullptr); +} + +void EditorInspectorPluginOpenTypeFeatures::parse_begin(Object *p_object) { +} + +void EditorInspectorPluginOpenTypeFeatures::parse_category(Object *p_object, const String &p_parse_category) { +} + +bool EditorInspectorPluginOpenTypeFeatures::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) { + if (p_path == "opentype_features/_new") { + OpenTypeFeaturesAdd *editor = memnew(OpenTypeFeaturesAdd); + add_property_editor(p_path, editor); + return true; + } else if (p_path.begins_with("opentype_features")) { + OpenTypeFeaturesEditor *editor = memnew(OpenTypeFeaturesEditor); + add_property_editor(p_path, editor); + return true; + } + return false; +} + +/*************************************************************************/ + +OpenTypeFeaturesEditorPlugin::OpenTypeFeaturesEditorPlugin(EditorNode *p_node) { + Ref ftr_plugin; + ftr_plugin.instance(); + EditorInspector::add_inspector_plugin(ftr_plugin); +} diff --git a/editor/plugins/ot_features_plugin.h b/editor/plugins/ot_features_plugin.h new file mode 100644 index 000000000000..5b5f367b2482 --- /dev/null +++ b/editor/plugins/ot_features_plugin.h @@ -0,0 +1,105 @@ +/*************************************************************************/ +/* ot_features_plugin.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef OT_FEATURES_PLUGIN_H +#define OT_FEATURES_PLUGIN_H + +#include "editor/editor_node.h" +#include "editor/editor_plugin.h" +#include "editor/editor_properties.h" + +/*************************************************************************/ + +class OpenTypeFeaturesEditor : public EditorProperty { + GDCLASS(OpenTypeFeaturesEditor, EditorProperty); + EditorSpinSlider *spin; + bool setting = true; + void _value_changed(double p_val); + Button *button = nullptr; + + void _remove_feature(); + +protected: + void _notification(int p_what); + static void _bind_methods(); + +public: + virtual void update_property() override; + OpenTypeFeaturesEditor(); +}; + +/*************************************************************************/ + +class OpenTypeFeaturesAdd : public EditorProperty { + GDCLASS(OpenTypeFeaturesAdd, EditorProperty); + + Button *button = nullptr; + PopupMenu *menu = nullptr; + PopupMenu *menu_ss = nullptr; + PopupMenu *menu_cv = nullptr; + PopupMenu *menu_cu = nullptr; + + void _add_feature(int p_option); + void _features_menu(); + +protected: + void _notification(int p_what); + static void _bind_methods(); + +public: + virtual void update_property() override; + + OpenTypeFeaturesAdd(); +}; + +/*************************************************************************/ + +class EditorInspectorPluginOpenTypeFeatures : public EditorInspectorPlugin { + GDCLASS(EditorInspectorPluginOpenTypeFeatures, EditorInspectorPlugin); + +public: + virtual bool can_handle(Object *p_object) override; + virtual void parse_begin(Object *p_object) override; + virtual void parse_category(Object *p_object, const String &p_parse_category) override; + virtual bool parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) override; +}; + +/*************************************************************************/ + +class OpenTypeFeaturesEditorPlugin : public EditorPlugin { + GDCLASS(OpenTypeFeaturesEditorPlugin, EditorPlugin); + +public: + OpenTypeFeaturesEditorPlugin(EditorNode *p_node); + + virtual String get_name() const override { return "OpenTypeFeatures"; } +}; + +#endif // OT_FEATURES_PLUGIN_H diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 8dd7d6d6e2cb..e7b6959ac6eb 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -1485,12 +1485,19 @@ void ScriptEditor::_notification(int p_what) { EditorFileSystem::get_singleton()->connect("filesystem_changed", callable_mp(this, &ScriptEditor::_filesystem_changed)); [[fallthrough]]; } + case NOTIFICATION_TRANSLATION_CHANGED: + case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: case NOTIFICATION_THEME_CHANGED: { help_search->set_icon(get_theme_icon("HelpSearch", "EditorIcons")); site_search->set_icon(get_theme_icon("Instance", "EditorIcons")); - script_forward->set_icon(get_theme_icon("Forward", "EditorIcons")); - script_back->set_icon(get_theme_icon("Back", "EditorIcons")); + if (is_layout_rtl()) { + script_forward->set_icon(get_theme_icon("Back", "EditorIcons")); + script_back->set_icon(get_theme_icon("Forward", "EditorIcons")); + } else { + script_forward->set_icon(get_theme_icon("Forward", "EditorIcons")); + script_back->set_icon(get_theme_icon("Back", "EditorIcons")); + } members_overview_alphabeta_sort_button->set_icon(get_theme_icon("Sort", "EditorIcons")); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 7feb7cb3d3f6..fbd3612c720e 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -912,6 +912,7 @@ void ScriptTextEditor::update_toggle_scripts_button() { void ScriptTextEditor::_update_connected_methods() { CodeEdit *text_edit = code_editor->get_text_editor(); + text_edit->set_gutter_width(connection_gutter, text_edit->get_row_height()); for (int i = 0; i < text_edit->get_line_count(); i++) { if (text_edit->get_line_gutter_metadata(i, connection_gutter) == "") { continue; @@ -1352,7 +1353,8 @@ void ScriptTextEditor::_change_syntax_highlighter(int p_idx) { void ScriptTextEditor::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_THEME_CHANGED: { + case NOTIFICATION_THEME_CHANGED: + case NOTIFICATION_ENTER_TREE: { code_editor->get_text_editor()->set_gutter_width(connection_gutter, code_editor->get_text_editor()->get_row_height()); } break; default: @@ -1697,6 +1699,8 @@ void ScriptTextEditor::_enable_code_editor() { editor_box->add_child(warnings_panel); warnings_panel->add_theme_font_override( "normal_font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("main", "EditorFonts")); + warnings_panel->add_theme_font_size_override( + "normal_font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("main_size", "EditorFonts")); warnings_panel->connect("meta_clicked", callable_mp(this, &ScriptTextEditor::_warning_clicked)); add_child(context_menu); diff --git a/editor/plugins/skeleton_3d_editor_plugin.cpp b/editor/plugins/skeleton_3d_editor_plugin.cpp index 52da8dea19a1..d66271475283 100644 --- a/editor/plugins/skeleton_3d_editor_plugin.cpp +++ b/editor/plugins/skeleton_3d_editor_plugin.cpp @@ -114,10 +114,11 @@ void BoneTransformEditor::_notification(int p_what) { } case NOTIFICATION_SORT_CHILDREN: { const Ref font = get_theme_font("font", "Tree"); + int font_size = get_theme_font_size("font_size", "Tree"); Point2 buffer; buffer.x += get_theme_constant("inspector_margin", "Editor"); - buffer.y += font->get_height(); + buffer.y += font->get_height(font_size); buffer.y += get_theme_constant("vseparation", "Tree"); const float vector_height = translation_property->get_size().y; diff --git a/editor/plugins/texture_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp index f8facb0fd515..9b760c0e50ab 100644 --- a/editor/plugins/texture_editor_plugin.cpp +++ b/editor/plugins/texture_editor_plugin.cpp @@ -79,6 +79,7 @@ void TextureEditor::_notification(int p_what) { draw_texture_rect(texture, Rect2(ofs_x, ofs_y, tex_width, tex_height)); Ref font = get_theme_font("font", "Label"); + int font_size = get_theme_font_size("font_size", "Label"); String format; if (Object::cast_to(*texture)) { @@ -90,16 +91,16 @@ void TextureEditor::_notification(int p_what) { } String text = itos(texture->get_width()) + "x" + itos(texture->get_height()) + " " + format; - Size2 rect = font->get_string_size(text); + Size2 rect = font->get_string_size(text, font_size); - Vector2 draw_from = size - rect + Size2(-2, font->get_ascent() - 2); + Vector2 draw_from = size - rect + Size2(-2, font->get_ascent(font_size) - 2); if (draw_from.x < 0) { draw_from.x = 0; } - draw_string(font, draw_from + Vector2(2, 2), text, Color(0, 0, 0, 0.5), size.width); - draw_string(font, draw_from - Vector2(2, 2), text, Color(0, 0, 0, 0.5), size.width); - draw_string(font, draw_from, text, Color(1, 1, 1, 1), size.width); + draw_string(font, draw_from + Vector2(2, 2), text, HALIGN_LEFT, size.width, font_size, Color(0, 0, 0, 0.5)); + draw_string(font, draw_from - Vector2(2, 2), text, HALIGN_LEFT, size.width, font_size, Color(0, 0, 0, 0.5)); + draw_string(font, draw_from, text, HALIGN_LEFT, size.width, font_size, Color(1, 1, 1, 1)); } } diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index 932ded693881..8ab82b63c3eb 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -78,9 +78,12 @@ void ThemeEditor::_name_menu_about_to_show() { Theme::get_default()->get_font_list(fromtype, &names); break; case 3: - Theme::get_default()->get_color_list(fromtype, &names); + Theme::get_default()->get_font_size_list(fromtype, &names); break; case 4: + Theme::get_default()->get_color_list(fromtype, &names); + break; + case 5: Theme::get_default()->get_constant_list(fromtype, &names); break; } @@ -88,6 +91,7 @@ void ThemeEditor::_name_menu_about_to_show() { theme->get_icon_list(fromtype, &names); theme->get_stylebox_list(fromtype, &names); theme->get_font_list(fromtype, &names); + theme->get_font_size_list(fromtype, &names); theme->get_color_list(fromtype, &names); theme->get_constant_list(fromtype, &names); } @@ -120,6 +124,7 @@ struct _TECategory { Set> stylebox_items; Set> font_items; + Set> font_size_items; Set> icon_items; Set> color_items; @@ -160,6 +165,15 @@ void ThemeEditor::_save_template_cbk(String fname) { tc.font_items.insert(it); } + List font_size_list; + Theme::get_default()->get_font_size_list(E->key(), &font_list); + for (List::Element *F = font_size_list.front(); F; F = F->next()) { + _TECategory::Item it; + it.name = F->get(); + it.item = Theme::get_default()->get_font_size(F->get(), E->key()); + tc.font_size_items.insert(it); + } + List icon_list; Theme::get_default()->get_icon_list(E->key(), &icon_list); for (List::Element *F = icon_list.front(); F; F = F->next()) { @@ -284,6 +298,14 @@ void ThemeEditor::_save_template_cbk(String fname) { file->store_line(E->key() + "." + F->get().name + " = default"); } + if (tc.font_size_items.size()) { + file->store_line("\n; Font Size Items:\n"); + } + + for (Set<_TECategory::Item>::Element *F = tc.font_size_items.front(); F; F = F->next()) { + file->store_line(E->key() + "." + F->get().name + " = default"); + } + if (tc.icon_items.size()) { file->store_line("\n; Icon Items:\n"); } @@ -327,9 +349,12 @@ void ThemeEditor::_dialog_cbk() { theme->set_font(name_edit->get_text(), type_edit->get_text(), Ref()); break; case 3: - theme->set_color(name_edit->get_text(), type_edit->get_text(), Color()); + theme->set_font_size(name_edit->get_text(), type_edit->get_text(), -1); break; case 4: + theme->set_color(name_edit->get_text(), type_edit->get_text(), Color()); + break; + case 5: theme->set_constant(name_edit->get_text(), type_edit->get_text(), 0); break; } @@ -360,6 +385,13 @@ void ThemeEditor::_dialog_cbk() { theme->set_font(E->get(), fromtype, Ref()); } } + { + names.clear(); + Theme::get_default()->get_font_size_list(fromtype, &names); + for (List::Element *E = names.front(); E; E = E->next()) { + theme->set_font_size(E->get(), fromtype, Theme::get_default()->get_font_size(E->get(), fromtype)); + } + } { names.clear(); Theme::get_default()->get_color_list(fromtype, &names); @@ -387,9 +419,12 @@ void ThemeEditor::_dialog_cbk() { theme->clear_font(name_edit->get_text(), type_edit->get_text()); break; case 3: - theme->clear_color(name_edit->get_text(), type_edit->get_text()); + theme->clear_font_size(name_edit->get_text(), type_edit->get_text()); break; case 4: + theme->clear_color(name_edit->get_text(), type_edit->get_text()); + break; + case 5: theme->clear_constant(name_edit->get_text(), type_edit->get_text()); break; } @@ -420,6 +455,13 @@ void ThemeEditor::_dialog_cbk() { theme->clear_font(E->get(), fromtype); } } + { + names.clear(); + Theme::get_default()->get_font_size_list(fromtype, &names); + for (List::Element *E = names.front(); E; E = E->next()) { + theme->clear_font_size(E->get(), fromtype); + } + } { names.clear(); Theme::get_default()->get_color_list(fromtype, &names); @@ -486,6 +528,13 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { theme->set_font(E->get(), type, Ref()); } + List font_sizes; + base_theme->get_font_size_list(type, &font_sizes); + + for (List::Element *E = font_sizes.front(); E; E = E->next()) { + theme->set_font_size(E->get(), type, base_theme->get_font_size(E->get(), type)); + } + List colors; base_theme->get_color_list(type, &colors); @@ -860,6 +909,7 @@ ThemeEditor::ThemeEditor() { type_select->add_item(TTR("Icon")); type_select->add_item(TTR("Style")); type_select->add_item(TTR("Font")); + type_select->add_item(TTR("Font Size")); type_select->add_item(TTR("Color")); type_select->add_item(TTR("Constant")); diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp index 7b516175b230..ceec3f183046 100644 --- a/editor/plugins/tile_map_editor_plugin.cpp +++ b/editor/plugins/tile_map_editor_plugin.cpp @@ -2165,6 +2165,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { tile_info->set_modulate(Color(1, 1, 1, 0.8)); tile_info->set_mouse_filter(MOUSE_FILTER_IGNORE); tile_info->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("main", "EditorFonts")); + tile_info->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("main_size", "EditorFonts")); // The tile info is only displayed after a tile has been hovered. tile_info->hide(); CanvasItemEditor::get_singleton()->add_control_to_info_overlay(tile_info); diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp index 714f38bd5612..9dc01d83d78d 100644 --- a/editor/plugins/tile_set_editor_plugin.cpp +++ b/editor/plugins/tile_set_editor_plugin.cpp @@ -279,6 +279,8 @@ void TileSetEditor::_notification(int p_what) { case NOTIFICATION_READY: { add_theme_constant_override("autohide", 1); // Fixes the dragger always showing up. } break; + case NOTIFICATION_TRANSLATION_CHANGED: + case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { tileset_toolbar_buttons[TOOL_TILESET_ADD_TEXTURE]->set_icon(get_theme_icon("ToolAddNode", "EditorIcons")); @@ -296,8 +298,13 @@ void TileSetEditor::_notification(int p_what) { tools[BITMASK_CLEAR]->set_icon(get_theme_icon("Clear", "EditorIcons")); tools[SHAPE_NEW_POLYGON]->set_icon(get_theme_icon("CollisionPolygon2D", "EditorIcons")); tools[SHAPE_NEW_RECTANGLE]->set_icon(get_theme_icon("CollisionShape2D", "EditorIcons")); - tools[SELECT_PREVIOUS]->set_icon(get_theme_icon("ArrowLeft", "EditorIcons")); - tools[SELECT_NEXT]->set_icon(get_theme_icon("ArrowRight", "EditorIcons")); + if (is_layout_rtl()) { + tools[SELECT_PREVIOUS]->set_icon(get_theme_icon("ArrowLeft", "EditorIcons")); + tools[SELECT_NEXT]->set_icon(get_theme_icon("ArrowRight", "EditorIcons")); + } else { + tools[SELECT_PREVIOUS]->set_icon(get_theme_icon("ArrowRight", "EditorIcons")); + tools[SELECT_NEXT]->set_icon(get_theme_icon("ArrowLeft", "EditorIcons")); + } tools[SHAPE_DELETE]->set_icon(get_theme_icon("Remove", "EditorIcons")); tools[SHAPE_KEEP_INSIDE_TILE]->set_icon(get_theme_icon("Snap", "EditorIcons")); tools[TOOL_GRID_SNAP]->set_icon(get_theme_icon("SnapGrid", "EditorIcons")); @@ -1173,11 +1180,12 @@ void TileSetEditor::_on_workspace_overlay_draw() { } String tile_id_name = String::num(t_id, 0) + ": " + tileset->tile_get_name(t_id); Ref font = get_theme_font("font", "Label"); - region.set_size(font->get_string_size(tile_id_name)); + int font_size = get_theme_font_size("font_size", "Label"); + region.set_size(font->get_string_size(tile_id_name, font_size)); workspace_overlay->draw_rect(region, c); region.position.y += region.size.y - 2; c = Color(0.1, 0.1, 0.1); - workspace_overlay->draw_string(font, region.position, tile_id_name, c); + workspace_overlay->draw_string(font, region.position, tile_id_name, HALIGN_LEFT, -1, font_size, c); } delete tiles; } diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index f3fc22b3138f..31168850658d 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -713,6 +713,7 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) { } expression_box->add_theme_font_override("font", VisualShaderEditor::get_singleton()->get_theme_font("expression", "EditorFonts")); + expression_box->add_theme_font_size_override("font_size", VisualShaderEditor::get_singleton()->get_theme_font_size("expression_size", "EditorFonts")); expression_box->add_theme_color_override("font_color", text_color); expression_syntax_highlighter->set_number_color(number_color); expression_syntax_highlighter->set_symbol_color(symbol_color); @@ -2237,6 +2238,7 @@ void VisualShaderEditor::_notification(int p_what) { } preview_text->add_theme_font_override("font", get_theme_font("expression", "EditorFonts")); + preview_text->add_theme_font_size_override("font_size", get_theme_font_size("expression_size", "EditorFonts")); preview_text->add_theme_color_override("font_color", text_color); syntax_highlighter->set_number_color(number_color); syntax_highlighter->set_symbol_color(symbol_color); @@ -2247,6 +2249,7 @@ void VisualShaderEditor::_notification(int p_what) { syntax_highlighter->add_color_region("//", "", comment_color, true); error_text->add_theme_font_override("font", get_theme_font("status_source", "EditorFonts")); + error_text->add_theme_font_size_override("font_size", get_theme_font_size("status_source_size", "EditorFonts")); error_text->add_theme_color_override("font_color", get_theme_color("error_color", "Editor")); } diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index f26d44d75af4..bbe6a73f8f23 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -804,6 +804,7 @@ class ProjectDialog : public ConfirmationDialog { project_path = memnew(LineEdit); project_path->set_h_size_flags(Control::SIZE_EXPAND_FILL); + project_path->set_structured_text_bidi_override(Control::STRUCTURED_TEXT_FILE); pphb->add_child(project_path); install_path_container = memnew(VBoxContainer); @@ -818,6 +819,7 @@ class ProjectDialog : public ConfirmationDialog { install_path = memnew(LineEdit); install_path->set_h_size_flags(Control::SIZE_EXPAND_FILL); + install_path->set_structured_text_bidi_override(Control::STRUCTURED_TEXT_FILE); iphb->add_child(install_path); // status icon @@ -956,7 +958,7 @@ class ProjectListItemControl : public HBoxContainer { } break; case NOTIFICATION_DRAW: { if (hover) { - draw_style_box(get_theme_stylebox("hover", "Tree"), Rect2(Point2(), get_size() - Size2(10, 0) * EDSCALE)); + draw_style_box(get_theme_stylebox("hover", "Tree"), Rect2(Point2(), get_size())); } } break; } @@ -1367,6 +1369,7 @@ void ProjectList::create_project_item_control(int p_index) { vb->add_child(ec); Label *title = memnew(Label(!item.missing ? item.project_name : TTR("Missing Project"))); title->add_theme_font_override("font", get_theme_font("title", "EditorFonts")); + title->add_theme_font_size_override("font_size", get_theme_font_size("title_size", "EditorFonts")); title->add_theme_color_override("font_color", font_color); title->set_clip_text(true); vb->add_child(title); @@ -1393,6 +1396,7 @@ void ProjectList::create_project_item_control(int p_index) { } Label *fpath = memnew(Label(item.path)); + fpath->set_structured_text_bidi_override(Control::STRUCTURED_TEXT_FILE); path_hb->add_child(fpath); fpath->set_h_size_flags(Control::SIZE_EXPAND_FILL); fpath->set_modulate(Color(1, 1, 1, 0.5)); @@ -1723,12 +1727,16 @@ void ProjectList::erase_selected_projects() { void ProjectList::_panel_draw(Node *p_hb) { Control *hb = Object::cast_to(p_hb); - hb->draw_line(Point2(0, hb->get_size().y + 1), Point2(hb->get_size().x - 10, hb->get_size().y + 1), get_theme_color("guide_color", "Tree")); + if (is_layout_rtl() && get_v_scrollbar()->is_visible_in_tree()) { + hb->draw_line(Point2(get_v_scrollbar()->get_minimum_size().x, hb->get_size().y + 1), Point2(hb->get_size().x, hb->get_size().y + 1), get_theme_color("guide_color", "Tree")); + } else { + hb->draw_line(Point2(0, hb->get_size().y + 1), Point2(hb->get_size().x, hb->get_size().y + 1), get_theme_color("guide_color", "Tree")); + } String key = _projects[p_hb->get_index()].project_key; if (_selected_project_keys.has(key)) { - hb->draw_style_box(get_theme_stylebox("selected", "Tree"), Rect2(Point2(), hb->get_size() - Size2(10, 0) * EDSCALE)); + hb->draw_style_box(get_theme_stylebox("selected", "Tree"), Rect2(Point2(), hb->get_size())); } } @@ -1814,6 +1822,11 @@ void ProjectList::_bind_methods() { void ProjectManager::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_TRANSLATION_CHANGED: + case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: { + settings_hb->set_anchors_and_margins_preset(Control::PRESET_TOP_RIGHT); + update(); + } break; case NOTIFICATION_ENTER_TREE: { search_box->set_right_icon(get_theme_icon("Search", "EditorIcons")); search_box->set_clear_button_enabled(true); @@ -2417,10 +2430,13 @@ ProjectManager::ProjectManager() { DisplayServer::get_singleton()->window_set_size(DisplayServer::get_singleton()->window_get_size() * MAX(1, EDSCALE)); } - String cp; - cp += 0xA9; // TRANSLATORS: This refers to the application where users manage their Godot projects. - DisplayServer::get_singleton()->window_set_title(VERSION_NAME + String(" - ") + TTR("Project Manager") + " - " + cp + " 2007-2020 Juan Linietsky, Ariel Manzur & Godot Contributors"); + if (TS->is_locale_right_to_left(TranslationServer::get_singleton()->get_tool_locale())) { + // For RTL languages, embed translated part of the title (using control characters) to ensure correct order. + DisplayServer::get_singleton()->window_set_title(VERSION_NAME + String(" - ") + String::chr(0x202B) + TTR("Project Manager") + String::chr(0x202C) + String::chr(0x200E) + " - " + String::chr(0xA9) + " 2007-2020 Juan Linietsky, Ariel Manzur & Godot Contributors"); + } else { + DisplayServer::get_singleton()->window_set_title(VERSION_NAME + String(" - ") + TTR("Project Manager") + " - " + String::chr(0xA9) + " 2007-2020 Juan Linietsky, Ariel Manzur & Godot Contributors"); + } FileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("filesystem/file_dialog/show_hidden_files")); @@ -2552,9 +2568,10 @@ ProjectManager::ProjectManager() { { // Version info and language options - HBoxContainer *settings_hb = memnew(HBoxContainer); + settings_hb = memnew(HBoxContainer); settings_hb->set_alignment(BoxContainer::ALIGN_END); settings_hb->set_h_grow_direction(Control::GROW_DIRECTION_BEGIN); + settings_hb->set_anchors_and_margins_preset(Control::PRESET_TOP_RIGHT); Label *version_label = memnew(Label); String hash = String(VERSION_HASH); @@ -2598,7 +2615,6 @@ ProjectManager::ProjectManager() { settings_hb->add_child(language_btn); center_box->add_child(settings_hb); - settings_hb->set_anchors_and_margins_preset(Control::PRESET_TOP_RIGHT); } if (StreamPeerSSL::is_available()) { diff --git a/editor/project_manager.h b/editor/project_manager.h index 212d693f1db4..0a8a86eb4f2d 100644 --- a/editor/project_manager.h +++ b/editor/project_manager.h @@ -74,6 +74,8 @@ class ProjectManager : public Control { ConfirmationDialog *ask_update_settings; ConfirmationDialog *open_templates; + HBoxContainer *settings_hb; + AcceptDialog *run_error_diag; AcceptDialog *dialog_error; ProjectDialog *npdialog; diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index 1e4ed0c55216..847af0f2c2cf 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -501,7 +501,7 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: List names; names.push_back("value:"); config_value_editors(1, 1, 50, names); - value_editor[0]->set_text(String::num(v)); + value_editor[0]->set_text(TS->format_number(String::num(v))); } } break; @@ -1389,6 +1389,7 @@ void CustomPropertyEditor::_draw_easing() { bool flip = hint_text == "attenuation"; Ref f = easing_draw->get_theme_font("font", "Label"); + int font_size = easing_draw->get_theme_font_size("font_size", "Label"); Color color = easing_draw->get_theme_color("font_color", "Label"); for (int i = 1; i <= points; i++) { @@ -1406,7 +1407,7 @@ void CustomPropertyEditor::_draw_easing() { prev = h; } - f->draw(ci, Point2(10, 10 + f->get_ascent()), String::num(exp, 2), color); + f->draw_string(ci, Point2(10, 10 + f->get_ascent(font_size)), String::num(exp, 2), HALIGN_LEFT, -1, font_size, color); } void CustomPropertyEditor::_text_edit_changed() { @@ -1432,7 +1433,7 @@ void CustomPropertyEditor::_modified(String p_string) { updating = true; switch (type) { case Variant::INT: { - String text = value_editor[0]->get_text(); + String text = TS->parse_number(value_editor[0]->get_text()); Ref expr; expr.instance(); Error err = expr->parse(text); @@ -1447,7 +1448,7 @@ void CustomPropertyEditor::_modified(String p_string) { } break; case Variant::FLOAT: { if (hint != PROPERTY_HINT_EXP_EASING) { - String text = value_editor[0]->get_text(); + String text = TS->parse_number(value_editor[0]->get_text()); v = _parse_real_expression(text); emit_signal("variant_changed"); } diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index ec225c3c3804..d946a08fbf22 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -1990,6 +1990,9 @@ void SceneTreeDock::_do_create(Node *p_parent) { if (ms.height < 4) { ms.height = 40; } + if (ct->is_layout_rtl()) { + ct->set_position(ct->get_position() - Vector2(ms.x, 0)); + } ct->set_size(ms); } } diff --git a/editor/shader_globals_editor.cpp b/editor/shader_globals_editor.cpp index 915aec6d9a9a..8345c49a926b 100644 --- a/editor/shader_globals_editor.cpp +++ b/editor/shader_globals_editor.cpp @@ -483,5 +483,8 @@ ShaderGlobalsEditor::ShaderGlobalsEditor() { } ShaderGlobalsEditor::~ShaderGlobalsEditor() { + if (is_visible_in_tree()) { + inspector->edit(nullptr); + } memdelete(interface); } diff --git a/main/main.cpp b/main/main.cpp index 82be327cbb56..3bef04b15d3c 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -72,6 +72,7 @@ #include "servers/register_server_types.h" #include "servers/rendering/rendering_server_raster.h" #include "servers/rendering/rendering_server_wrap_mt.h" +#include "servers/text_server.h" #include "servers/xr_server.h" #ifdef TESTS_ENABLED @@ -113,6 +114,7 @@ static DisplayServer *display_server = nullptr; static RenderingServer *rendering_server = nullptr; static CameraServer *camera_server = nullptr; static XRServer *xr_server = nullptr; +static TextServerManager *tsman = nullptr; static PhysicsServer3D *physics_server = nullptr; static PhysicsServer2D *physics_2d_server = nullptr; static NavigationServer3D *navigation_server = nullptr; @@ -122,6 +124,8 @@ static bool _start_success = false; // Drivers +String text_driver = ""; +static int text_driver_idx = -1; static int display_driver_idx = -1; static int audio_driver_idx = -1; @@ -304,7 +308,11 @@ void Main::print_help(const char *p_binary) { OS::get_singleton()->print(")"); } OS::get_singleton()->print("].\n"); + OS::get_singleton()->print(" --rendering-driver Rendering driver (depends on display driver).\n"); + + OS::get_singleton()->print(" --text-driver Text driver (Fonts, BiDi, shaping)\n"); + OS::get_singleton()->print("\n"); #ifndef SERVER_ENABLED @@ -649,6 +657,14 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph OS::get_singleton()->print("Missing audio driver argument, aborting.\n"); goto error; } + } else if (I->get() == "--text-driver") { + if (I->next()) { + text_driver = I->next()->get(); + N = I->next()->next(); + } else { + OS::get_singleton()->print("Missing text driver argument, aborting.\n"); + goto error; + } } else if (I->get() == "--display-driver") { // force video driver @@ -1228,6 +1244,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } } + GLOBAL_DEF("display/window/force_right_to_left_layout_direction", false); + if (!force_lowdpi) { OS::get_singleton()->_allow_hidpi = GLOBAL_DEF("display/window/dpi/allow_hidpi", false); } @@ -1388,6 +1406,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph error: + text_driver = ""; display_driver = ""; audio_driver = ""; tablet_driver = ""; @@ -1449,6 +1468,65 @@ Error Main::setup2(Thread::ID p_main_tid_override) { Thread::_main_thread_id = p_main_tid_override; } + /* Determine text driver */ + + GLOBAL_DEF("display/window/text_name", ""); + if (text_driver == "") { + text_driver = GLOBAL_GET("display/window/text_name"); + } + + if (text_driver != "") { + /* Load user selected text server. */ + for (int i = 0; i < TextServerManager::get_interface_count(); i++) { + if (text_driver == TextServerManager::get_interface_name(i)) { + text_driver_idx = i; + break; + } + } + } + + if (text_driver_idx < 0) { + /* If not selected, use one with the most features available. */ + int max_features = 0; + for (int i = 0; i < TextServerManager::get_interface_count(); i++) { + uint32_t ftrs = TextServerManager::get_interface_features(i); + int features = 0; + while (ftrs) { + features += ftrs & 1; + ftrs >>= 1; + } + if (features >= max_features) { + max_features = features; + text_driver_idx = i; + } + } + } + printf("Using %s text server...\n", TextServerManager::get_interface_name(text_driver_idx).utf8().get_data()); + + /* Initialize Text Server */ + + { + tsman = memnew(TextServerManager); + Error err; + TextServer *text_server = TextServerManager::initialize(text_driver_idx, err); + if (err != OK || text_server == nullptr) { + for (int i = 0; i < TextServerManager::get_interface_count(); i++) { + if (i == text_driver_idx) { + continue; //don't try the same twice + } + text_server = TextServerManager::initialize(i, err); + if (err == OK && text_server != nullptr) { + break; + } + } + } + + if (err != OK || text_server == nullptr) { + ERR_PRINT("Unable to create TextServer, all text drivers failed."); + return err; + } + } + /* Initialize Input */ input = memnew(Input); @@ -1459,23 +1537,21 @@ Error Main::setup2(Thread::ID p_main_tid_override) { String rendering_driver; // temp broken Error err; - display_server = DisplayServer::create(display_driver_idx, rendering_driver, window_mode, window_flags, - window_size, err); - if (err != OK) { + display_server = DisplayServer::create(display_driver_idx, rendering_driver, window_mode, window_flags, window_size, err); + if (err != OK || display_server == nullptr) { //ok i guess we can't use this display server, try other ones for (int i = 0; i < DisplayServer::get_create_function_count(); i++) { if (i == display_driver_idx) { continue; //don't try the same twice } - display_server = DisplayServer::create(display_driver_idx, rendering_driver, window_mode, window_flags, - window_size, err); - if (err == OK) { + display_server = DisplayServer::create(i, rendering_driver, window_mode, window_flags, window_size, err); + if (err == OK && display_server != nullptr) { break; } } } - if (!display_server || err != OK) { + if (err != OK || display_server == nullptr) { ERR_PRINT("Unable to create DisplayServer, all display drivers failed."); return err; } @@ -2572,6 +2648,10 @@ void Main::cleanup() { finalize_navigation_server(); finalize_display(); + if (tsman) { + memdelete(tsman); + } + if (input) { memdelete(input); } diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub index bd06347afbb9..45354ce69274 100644 --- a/modules/gdnative/SCsub +++ b/modules/gdnative/SCsub @@ -20,6 +20,7 @@ SConscript("net/SCsub") SConscript("xr/SCsub") SConscript("pluginscript/SCsub") SConscript("videodecoder/SCsub") +SConscript("text/SCsub") import gdnative_builders diff --git a/modules/gdnative/gdnative/array.cpp b/modules/gdnative/gdnative/array.cpp index a5567f1e6bcd..863889acbc9a 100644 --- a/modules/gdnative/gdnative/array.cpp +++ b/modules/gdnative/gdnative/array.cpp @@ -90,6 +90,18 @@ void GDAPI godot_array_new_packed_vector2_array(godot_array *r_dest, const godot } } +void GDAPI godot_array_new_packed_vector2i_array(godot_array *r_dest, const godot_packed_vector2i_array *p_pv2a) { + Array *dest = (Array *)r_dest; + Vector *pca = (Vector *)p_pv2a; + memnew_placement(dest, Array); + dest->resize(pca->size()); + + for (int i = 0; i < dest->size(); i++) { + Variant v = pca->operator[](i); + dest->operator[](i) = v; + } +} + void GDAPI godot_array_new_packed_string_array(godot_array *r_dest, const godot_packed_string_array *p_psa) { Array *dest = (Array *)r_dest; Vector *pca = (Vector *)p_psa; diff --git a/modules/gdnative/gdnative/packed_arrays.cpp b/modules/gdnative/gdnative/packed_arrays.cpp index 9139fd89a1a4..cc1e05b8a409 100644 --- a/modules/gdnative/gdnative/packed_arrays.cpp +++ b/modules/gdnative/gdnative/packed_arrays.cpp @@ -49,6 +49,7 @@ static_assert(sizeof(godot_packed_float32_array) == sizeof(Vector), "Vect static_assert(sizeof(godot_packed_float64_array) == sizeof(Vector), "Vector size mismatch"); static_assert(sizeof(godot_packed_string_array) == sizeof(Vector), "Vector size mismatch"); static_assert(sizeof(godot_packed_vector2_array) == sizeof(Vector), "Vector size mismatch"); +static_assert(sizeof(godot_packed_vector2i_array) == sizeof(Vector), "Vector size mismatch"); static_assert(sizeof(godot_packed_vector3_array) == sizeof(Vector), "Vector size mismatch"); static_assert(sizeof(godot_packed_color_array) == sizeof(Vector), "Vector size mismatch"); @@ -799,6 +800,118 @@ void GDAPI godot_packed_vector2_array_destroy(godot_packed_vector2_array *p_self ((Vector *)p_self)->~Vector(); } +// vector2i + +void GDAPI godot_packed_vector2i_array_new(godot_packed_vector2i_array *r_dest) { + Vector *dest = (Vector *)r_dest; + memnew_placement(dest, Vector); +} + +void GDAPI godot_packed_vector2i_array_new_copy(godot_packed_vector2i_array *r_dest, const godot_packed_vector2i_array *p_src) { + Vector *dest = (Vector *)r_dest; + const Vector *src = (const Vector *)p_src; + memnew_placement(dest, Vector(*src)); +} + +void GDAPI godot_packed_vector2i_array_new_with_array(godot_packed_vector2i_array *r_dest, const godot_array *p_a) { + Vector *dest = (Vector *)r_dest; + Array *a = (Array *)p_a; + memnew_placement(dest, Vector); + + dest->resize(a->size()); + for (int i = 0; i < a->size(); i++) { + dest->set(i, (*a)[i]); + } +} + +const godot_vector2i GDAPI *godot_packed_vector2i_array_ptr(const godot_packed_vector2i_array *p_self) { + const Vector *self = (const Vector *)p_self; + return (const godot_vector2i *)self->ptr(); +} + +godot_vector2i GDAPI *godot_packed_vector2i_array_ptrw(godot_packed_vector2i_array *p_self) { + Vector *self = (Vector *)p_self; + return (godot_vector2i *)self->ptrw(); +} + +void GDAPI godot_packed_vector2i_array_append(godot_packed_vector2i_array *p_self, const godot_vector2i *p_data) { + Vector *self = (Vector *)p_self; + Vector2i &s = *(Vector2i *)p_data; + self->push_back(s); +} + +void GDAPI godot_packed_vector2i_array_append_array(godot_packed_vector2i_array *p_self, const godot_packed_vector2i_array *p_array) { + Vector *self = (Vector *)p_self; + Vector *array = (Vector *)p_array; + self->append_array(*array); +} + +godot_error GDAPI godot_packed_vector2i_array_insert(godot_packed_vector2i_array *p_self, const godot_int p_idx, const godot_vector2i *p_data) { + Vector *self = (Vector *)p_self; + Vector2i &s = *(Vector2i *)p_data; + return (godot_error)self->insert(p_idx, s); +} + +godot_bool GDAPI godot_packed_vector2i_array_has(godot_packed_vector2i_array *p_self, const godot_vector2i *p_value) { + Vector *self = (Vector *)p_self; + Vector2i &v = *(Vector2i *)p_value; + return (godot_bool)self->has(v); +} + +void GDAPI godot_packed_vector2i_array_sort(godot_packed_vector2i_array *p_self) { + Vector *self = (Vector *)p_self; + self->sort(); +} + +void GDAPI godot_packed_vector2i_array_invert(godot_packed_vector2i_array *p_self) { + Vector *self = (Vector *)p_self; + self->invert(); +} + +void GDAPI godot_packed_vector2i_array_push_back(godot_packed_vector2i_array *p_self, const godot_vector2i *p_data) { + Vector *self = (Vector *)p_self; + Vector2i &s = *(Vector2i *)p_data; + self->push_back(s); +} + +void GDAPI godot_packed_vector2i_array_remove(godot_packed_vector2i_array *p_self, const godot_int p_idx) { + Vector *self = (Vector *)p_self; + self->remove(p_idx); +} + +void GDAPI godot_packed_vector2i_array_resize(godot_packed_vector2i_array *p_self, const godot_int p_size) { + Vector *self = (Vector *)p_self; + self->resize(p_size); +} + +void GDAPI godot_packed_vector2i_array_set(godot_packed_vector2i_array *p_self, const godot_int p_idx, const godot_vector2i *p_data) { + Vector *self = (Vector *)p_self; + Vector2i &s = *(Vector2i *)p_data; + self->set(p_idx, s); +} + +godot_vector2i GDAPI godot_packed_vector2i_array_get(const godot_packed_vector2i_array *p_self, const godot_int p_idx) { + const Vector *self = (const Vector *)p_self; + godot_vector2i v; + Vector2i *s = (Vector2i *)&v; + *s = self->get(p_idx); + return v; +} + +godot_int GDAPI godot_packed_vector2i_array_size(const godot_packed_vector2i_array *p_self) { + const Vector *self = (const Vector *)p_self; + return self->size(); +} + +godot_bool GDAPI godot_packed_vector2i_array_empty(const godot_packed_vector2i_array *p_self) { + const Vector *self = (const Vector *)p_self; + return self->empty(); +} + +void GDAPI godot_packed_vector2i_array_destroy(godot_packed_vector2i_array *p_self) { + ((Vector *)p_self)->~Vector(); +} + // vector3 void GDAPI godot_packed_vector3_array_new(godot_packed_vector3_array *r_dest) { diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json index 40d0f7587176..84b36b3745cc 100644 --- a/modules/gdnative/gdnative_api.json +++ b/modules/gdnative/gdnative_api.json @@ -259,6 +259,14 @@ ["const godot_packed_vector2_array *", "p_pv2a"] ] }, + { + "name": "godot_array_new_packed_vector2i_array", + "return_type": "void", + "arguments": [ + ["godot_array *", "r_dest"], + ["const godot_packed_vector2i_array *", "p_pv2a"] + ] + }, { "name": "godot_array_new_packed_string_array", "return_type": "void", @@ -2637,6 +2645,152 @@ ["godot_packed_vector2_array *", "p_self"] ] }, + { + "name": "godot_packed_vector2i_array_new", + "return_type": "void", + "arguments": [ + ["godot_packed_vector2i_array *", "r_dest"] + ] + }, + { + "name": "godot_packed_vector2i_array_new_copy", + "return_type": "void", + "arguments": [ + ["godot_packed_vector2i_array *", "r_dest"], + ["const godot_packed_vector2i_array *", "p_src"] + ] + }, + { + "name": "godot_packed_vector2i_array_new_with_array", + "return_type": "void", + "arguments": [ + ["godot_packed_vector2i_array *", "r_dest"], + ["const godot_array *", "p_a"] + ] + }, + { + "name": "godot_packed_vector2i_array_empty", + "return_type": "godot_bool", + "arguments": [ + ["const godot_packed_vector2i_array *", "p_self"] + ] + }, + { + "name": "godot_packed_vector2i_array_append", + "return_type": "void", + "arguments": [ + ["godot_packed_vector2i_array *", "p_self"], + ["const godot_vector2i *", "p_data"] + ] + }, + { + "name": "godot_packed_vector2i_array_append_array", + "return_type": "void", + "arguments": [ + ["godot_packed_vector2i_array *", "p_self"], + ["const godot_packed_vector2i_array *", "p_array"] + ] + }, + { + "name": "godot_packed_vector2i_array_insert", + "return_type": "godot_error", + "arguments": [ + ["godot_packed_vector2i_array *", "p_self"], + ["const godot_int", "p_idx"], + ["const godot_vector2i *", "p_data"] + ] + }, + { + "name": "godot_packed_vector2i_array_has", + "return_type": "godot_bool", + "arguments": [ + ["godot_packed_vector2i_array *", "p_self"], + ["const godot_vector2i *", "p_value"] + ] + }, + { + "name": "godot_packed_vector2i_array_sort", + "return_type": "void", + "arguments": [ + ["godot_packed_vector2i_array *", "p_self"] + ] + }, + { + "name": "godot_packed_vector2i_array_invert", + "return_type": "void", + "arguments": [ + ["godot_packed_vector2i_array *", "p_self"] + ] + }, + { + "name": "godot_packed_vector2i_array_push_back", + "return_type": "void", + "arguments": [ + ["godot_packed_vector2i_array *", "p_self"], + ["const godot_vector2i *", "p_data"] + ] + }, + { + "name": "godot_packed_vector2i_array_remove", + "return_type": "void", + "arguments": [ + ["godot_packed_vector2i_array *", "p_self"], + ["const godot_int", "p_idx"] + ] + }, + { + "name": "godot_packed_vector2i_array_resize", + "return_type": "void", + "arguments": [ + ["godot_packed_vector2i_array *", "p_self"], + ["const godot_int", "p_size"] + ] + }, + { + "name": "godot_packed_vector2i_array_ptr", + "return_type": "const godot_vector2i *", + "arguments": [ + ["const godot_packed_vector2i_array *", "p_self"] + ] + }, + { + "name": "godot_packed_vector2i_array_ptrw", + "return_type": "godot_vector2i *", + "arguments": [ + ["godot_packed_vector2i_array *", "p_self"] + ] + }, + { + "name": "godot_packed_vector2i_array_set", + "return_type": "void", + "arguments": [ + ["godot_packed_vector2i_array *", "p_self"], + ["const godot_int", "p_idx"], + ["const godot_vector2i *", "p_data"] + ] + }, + { + "name": "godot_packed_vector2i_array_get", + "return_type": "godot_vector2i", + "arguments": [ + ["const godot_packed_vector2i_array *", "p_self"], + ["const godot_int", "p_idx"] + ] + }, + { + "name": "godot_packed_vector2i_array_size", + "return_type": "godot_int", + "arguments": [ + ["const godot_packed_vector2i_array *", "p_self"] + ] + }, + { + "name": "godot_packed_vector2i_array_destroy", + "return_type": "void", + "arguments": [ + ["godot_packed_vector2i_array *", "p_self"] + ] + }, { "name": "godot_packed_vector3_array_new", "return_type": "void", @@ -7615,6 +7769,306 @@ ] } ] + }, + { + "name": "text", + "type": "TEXT", + "version": { + "major": 1, + "minor": 0 + }, + "next": null, + "api": [ + { + "name": "godot_text_register_interface", + "return_type": "void", + "arguments": [ + ["const godot_text_interface_gdnative *", "p_interface"], + ["const godot_string *", "p_name"], + ["uint32_t", "p_features"] + ] + }, + { + "name": "godot_glyph_new", + "return_type": "void", + "arguments": [ + ["godot_glyph *", "r_dest"] + ] + }, + { + "name": "godot_glyph_get_range", + "return_type": "godot_vector2i", + "arguments": [ + ["const godot_glyph *", "p_self"] + ] + }, + { + "name": "godot_glyph_set_range", + "return_type": "void", + "arguments": [ + ["godot_glyph *", "p_self"], + ["const godot_vector2i *", "p_range"] + ] + }, + { + "name": "godot_glyph_get_count", + "return_type": "godot_int", + "arguments": [ + ["const godot_glyph *", "p_self"] + ] + }, + { + "name": "godot_glyph_set_count", + "return_type": "void", + "arguments": [ + ["godot_glyph *", "p_self"], + ["godot_int", "p_count"] + ] + }, + { + "name": "godot_glyph_get_repeat", + "return_type": "godot_int", + "arguments": [ + ["const godot_glyph *", "p_self"] + ] + }, + { + "name": "godot_glyph_set_repeat", + "return_type": "void", + "arguments": [ + ["godot_glyph *", "p_self"], + ["godot_int", "p_repeat"] + ] + }, + { + "name": "godot_glyph_get_flags", + "return_type": "godot_int", + "arguments": [ + ["const godot_glyph *", "p_self"] + ] + }, + { + "name": "godot_glyph_set_flags", + "return_type": "void", + "arguments": [ + ["godot_glyph *", "p_self"], + ["godot_int", "p_flags"] + ] + }, + { + "name": "godot_glyph_get_offset", + "return_type": "godot_vector2", + "arguments": [ + ["const godot_glyph *", "p_self"] + ] + }, + { + "name": "godot_glyph_set_offset", + "return_type": "void", + "arguments": [ + ["godot_glyph *", "p_self"], + ["const godot_vector2 *", "p_offset"] + ] + }, + { + "name": "godot_glyph_get_advance", + "return_type": "godot_real", + "arguments": [ + ["const godot_glyph *", "p_self"] + ] + }, + { + "name": "godot_glyph_set_advance", + "return_type": "void", + "arguments": [ + ["godot_glyph *", "p_self"], + ["godot_real", "p_advance"] + ] + }, + { + "name": "godot_glyph_get_font", + "return_type": "godot_rid", + "arguments": [ + ["const godot_glyph *", "p_self"] + ] + }, + { + "name": "godot_glyph_set_font", + "return_type": "void ", + "arguments": [ + ["godot_glyph *", "p_self"], + ["godot_rid *", "p_font"] + ] + }, + { + "name": "godot_glyph_get_font_size", + "return_type": "godot_int", + "arguments": [ + ["const godot_glyph *", "p_self"] + ] + }, + { + "name": "godot_glyph_set_font_size", + "return_type": "void", + "arguments": [ + ["godot_glyph *", "p_self"], + ["godot_int", "p_size"] + ] + }, + { + "name": "godot_glyph_get_index", + "return_type": "godot_int", + "arguments": [ + ["const godot_glyph *", "p_self"] + ] + }, + { + "name": "godot_glyph_set_index", + "return_type": "void", + "arguments": [ + ["godot_glyph *", "p_self"], + ["godot_int", "p_index"] + ] + }, + { + "name": "godot_packed_glyph_array_new", + "return_type": "void", + "arguments": [ + ["godot_packed_glyph_array *", "r_dest"] + ] + }, + { + "name": "godot_packed_glyph_array_new_copy", + "return_type": "void", + "arguments": [ + ["godot_packed_glyph_array *", "r_dest"], + ["const godot_packed_glyph_array *", "p_src"] + ] + }, + { + "name": "godot_packed_glyph_array_empty", + "return_type": "godot_bool", + "arguments": [ + ["const godot_packed_glyph_array *", "p_self"] + ] + }, + { + "name": "godot_packed_glyph_array_append", + "return_type": "void", + "arguments": [ + ["godot_packed_glyph_array *", "p_self"], + ["const godot_glyph *", "p_data"] + ] + }, + { + "name": "godot_packed_glyph_array_append_array", + "return_type": "void", + "arguments": [ + ["godot_packed_glyph_array *", "p_self"], + ["const godot_packed_glyph_array *", "p_array"] + ] + }, + { + "name": "godot_packed_glyph_array_insert", + "return_type": "godot_error", + "arguments": [ + ["godot_packed_glyph_array *", "p_self"], + ["const godot_int", "p_idx"], + ["const godot_glyph *", "p_data"] + ] + }, + { + "name": "godot_packed_glyph_array_has", + "return_type": "godot_bool", + "arguments": [ + ["godot_packed_glyph_array *", "p_self"], + ["const godot_glyph *", "p_value"] + ] + }, + { + "name": "godot_packed_glyph_array_sort", + "return_type": "void", + "arguments": [ + ["godot_packed_glyph_array *", "p_self"] + ] + }, + { + "name": "godot_packed_glyph_array_invert", + "return_type": "void", + "arguments": [ + ["godot_packed_glyph_array *", "p_self"] + ] + }, + { + "name": "godot_packed_glyph_array_push_back", + "return_type": "void", + "arguments": [ + ["godot_packed_glyph_array *", "p_self"], + ["const godot_glyph *", "p_data"] + ] + }, + { + "name": "godot_packed_glyph_array_remove", + "return_type": "void", + "arguments": [ + ["godot_packed_glyph_array *", "p_self"], + ["const godot_int", "p_idx"] + ] + }, + { + "name": "godot_packed_glyph_array_resize", + "return_type": "void", + "arguments": [ + ["godot_packed_glyph_array *", "p_self"], + ["const godot_int", "p_size"] + ] + }, + { + "name": "godot_packed_glyph_array_ptr", + "return_type": "const godot_glyph *", + "arguments": [ + ["const godot_packed_glyph_array *", "p_self"] + ] + }, + { + "name": "godot_packed_glyph_array_ptrw", + "return_type": "godot_glyph *", + "arguments": [ + ["godot_packed_glyph_array *", "p_self"] + ] + }, + { + "name": "godot_packed_glyph_array_set", + "return_type": "void", + "arguments": [ + ["godot_packed_glyph_array *", "p_self"], + ["const godot_int", "p_idx"], + ["const godot_glyph *", "p_data"] + ] + }, + { + "name": "godot_packed_glyph_array_get", + "return_type": "godot_glyph", + "arguments": [ + ["const godot_packed_glyph_array *", "p_self"], + ["const godot_int", "p_idx"] + ] + }, + { + "name": "godot_packed_glyph_array_size", + "return_type": "godot_int", + "arguments": [ + ["const godot_packed_glyph_array *", "p_self"] + ] + }, + { + "name": "godot_packed_glyph_array_destroy", + "return_type": "void", + "arguments": [ + ["godot_packed_glyph_array *", "p_self"] + ] + } + ] } ] } diff --git a/modules/gdnative/gdnative_builders.py b/modules/gdnative/gdnative_builders.py index 28e4957b2f8a..d03298d7a9af 100644 --- a/modules/gdnative/gdnative_builders.py +++ b/modules/gdnative/gdnative_builders.py @@ -24,6 +24,7 @@ def _build_gdnative_api_struct_header(api): "#include ", "#include ", "#include ", + "#include ", "", "#ifdef __cplusplus", 'extern "C" {', diff --git a/modules/gdnative/include/gdnative/array.h b/modules/gdnative/include/gdnative/array.h index 4db685873f56..7a59493b7d0e 100644 --- a/modules/gdnative/include/gdnative/array.h +++ b/modules/gdnative/include/gdnative/array.h @@ -65,6 +65,7 @@ void GDAPI godot_array_new_copy(godot_array *r_dest, const godot_array *p_src); void GDAPI godot_array_new_packed_color_array(godot_array *r_dest, const godot_packed_color_array *p_pca); void GDAPI godot_array_new_packed_vector3_array(godot_array *r_dest, const godot_packed_vector3_array *p_pv3a); void GDAPI godot_array_new_packed_vector2_array(godot_array *r_dest, const godot_packed_vector2_array *p_pv2a); +void GDAPI godot_array_new_packed_vector2i_array(godot_array *r_dest, const godot_packed_vector2i_array *p_pv2a); void GDAPI godot_array_new_packed_string_array(godot_array *r_dest, const godot_packed_string_array *p_psa); void GDAPI godot_array_new_packed_float32_array(godot_array *r_dest, const godot_packed_float32_array *p_pra); void GDAPI godot_array_new_packed_float64_array(godot_array *r_dest, const godot_packed_float64_array *p_pra); diff --git a/modules/gdnative/include/gdnative/packed_arrays.h b/modules/gdnative/include/gdnative/packed_arrays.h index 6a1727d76ff3..ce9579f30724 100644 --- a/modules/gdnative/include/gdnative/packed_arrays.h +++ b/modules/gdnative/include/gdnative/packed_arrays.h @@ -114,6 +114,17 @@ typedef struct { } godot_packed_vector2_array; #endif +/////// PackedVector2iArray + +#define GODOT_PACKED_VECTOR2I_ARRAY_SIZE (2 * sizeof(void *)) + +#ifndef GODOT_CORE_API_GODOT_PACKED_VECTOR2I_ARRAY_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_PACKED_VECTOR2I_ARRAY_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_PACKED_VECTOR2I_ARRAY_SIZE]; +} godot_packed_vector2i_array; +#endif + /////// PackedVector3Array #define GODOT_PACKED_VECTOR3_ARRAY_SIZE (2 * sizeof(void *)) @@ -404,6 +415,42 @@ godot_bool GDAPI godot_packed_vector2_array_empty(const godot_packed_vector2_arr void GDAPI godot_packed_vector2_array_destroy(godot_packed_vector2_array *p_self); +// vector2i + +void GDAPI godot_packed_vector2i_array_new(godot_packed_vector2i_array *r_dest); +void GDAPI godot_packed_vector2i_array_new_copy(godot_packed_vector2i_array *r_dest, const godot_packed_vector2i_array *p_src); +void GDAPI godot_packed_vector2i_array_new_with_array(godot_packed_vector2i_array *r_dest, const godot_array *p_a); + +const godot_vector2i GDAPI *godot_packed_vector2i_array_ptr(const godot_packed_vector2i_array *p_self); +godot_vector2i GDAPI *godot_packed_vector2i_array_ptrw(godot_packed_vector2i_array *p_self); + +void GDAPI godot_packed_vector2i_array_append(godot_packed_vector2i_array *p_self, const godot_vector2i *p_data); + +void GDAPI godot_packed_vector2i_array_append_array(godot_packed_vector2i_array *p_self, const godot_packed_vector2i_array *p_array); + +godot_error GDAPI godot_packed_vector2i_array_insert(godot_packed_vector2i_array *p_self, const godot_int p_idx, const godot_vector2i *p_data); + +godot_bool GDAPI godot_packed_vector2i_array_has(godot_packed_vector2i_array *p_self, const godot_vector2i *p_value); + +void GDAPI godot_packed_vector2i_array_sort(godot_packed_vector2i_array *p_self); + +void GDAPI godot_packed_vector2i_array_invert(godot_packed_vector2i_array *p_self); + +void GDAPI godot_packed_vector2i_array_push_back(godot_packed_vector2i_array *p_self, const godot_vector2i *p_data); + +void GDAPI godot_packed_vector2i_array_remove(godot_packed_vector2i_array *p_self, const godot_int p_idx); + +void GDAPI godot_packed_vector2i_array_resize(godot_packed_vector2i_array *p_self, const godot_int p_size); + +void GDAPI godot_packed_vector2i_array_set(godot_packed_vector2i_array *p_self, const godot_int p_idx, const godot_vector2i *p_data); +godot_vector2i GDAPI godot_packed_vector2i_array_get(const godot_packed_vector2i_array *p_self, const godot_int p_idx); + +godot_int GDAPI godot_packed_vector2i_array_size(const godot_packed_vector2i_array *p_self); + +godot_bool GDAPI godot_packed_vector2i_array_empty(const godot_packed_vector2i_array *p_self); + +void GDAPI godot_packed_vector2i_array_destroy(godot_packed_vector2i_array *p_self); + // vector3 void GDAPI godot_packed_vector3_array_new(godot_packed_vector3_array *r_dest); diff --git a/modules/gdnative/include/text/godot_text.h b/modules/gdnative/include/text/godot_text.h new file mode 100644 index 000000000000..2eac6adfb503 --- /dev/null +++ b/modules/gdnative/include/text/godot_text.h @@ -0,0 +1,228 @@ +/*************************************************************************/ +/* godot_text.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef GODOT_NATIVETEXT_H +#define GODOT_NATIVETEXT_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define GODOT_TEXT_API_MAJOR 1 +#define GODOT_TEXT_API_MINOR 0 + +#define GODOT_GLYPH_SIZE 40 + +#ifndef GODOT_TEXT_API_GODOT_GLYPH_TYPE_DEFINED +#define GODOT_TEXT_API_GODOT_GLYPH_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_GLYPH_SIZE]; +} godot_glyph; +#endif + +#define GODOT_PACKED_GLYPH_ARRAY_SIZE (2 * sizeof(void *)) + +#ifndef GODOT_TEXT_API_GODOT_PACKED_GLYPH_ARRAY_TYPE_DEFINED +#define GODOT_TEXT_API_GODOT_PACKED_GLYPH_ARRAY_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_PACKED_GLYPH_ARRAY_SIZE]; +} godot_packed_glyph_array; +#endif + +typedef struct { + godot_gdnative_api_version version; + void *(*constructor)(godot_object *); + void (*destructor)(void *); + godot_string (*get_name)(const void *); + godot_bool (*has_feature)(const void *, godot_int); + bool (*load_support_data)(void *, const godot_string *); + godot_string (*get_support_data_filename)(const void *); + godot_string (*get_support_data_info)(const void *); + bool (*save_support_data)(void *, const godot_string *); + bool (*is_locale_right_to_left)(void *, const godot_string *); + void (*free)(void *, godot_rid *); + bool (*has)(void *, godot_rid *); + godot_rid (*create_font_system)(void *, const godot_string *, int); + godot_rid (*create_font_resource)(void *, const godot_string *, int); + godot_rid (*create_font_memory)(void *, const uint8_t *, size_t, godot_string *, int); + float (*font_get_height)(void *, godot_rid *, int); + float (*font_get_ascent)(void *, godot_rid *, int); + float (*font_get_descent)(void *, godot_rid *, int); + float (*font_get_underline_position)(void *, godot_rid *, int); + float (*font_get_underline_thickness)(void *, godot_rid *, int); + void (*font_set_antialiased)(void *, godot_rid *, bool); + bool (*font_get_antialiased)(void *, godot_rid *); + godot_dictionary (*font_get_feature_list)(void *, godot_rid *); + void (*font_set_distance_field_hint)(void *, godot_rid *, bool); + bool (*font_get_distance_field_hint)(void *, godot_rid *); + void (*font_set_hinting)(void *, godot_rid *, godot_int); + godot_int (*font_get_hinting)(void *, godot_rid *); + void (*font_set_force_autohinter)(void *, godot_rid *, bool); + bool (*font_get_force_autohinter)(void *, godot_rid *); + bool (*font_has_char)(void *, godot_rid *, char32_t); + godot_string (*font_get_supported_chars)(void *, godot_rid *); + bool (*font_has_outline)(void *, godot_rid *); + int (*font_get_base_size)(void *, godot_rid *); + bool (*font_is_language_supported)(void *, godot_rid *, const godot_string *); + void (*font_set_language_support_override)(void *, godot_rid *, const godot_string *, bool); + bool (*font_get_language_support_override)(void *, godot_rid *, const godot_string *); + void (*font_remove_language_support_override)(void *, godot_rid *, const godot_string *); + godot_packed_string_array (*font_get_language_support_overrides)(void *, godot_rid *); + bool (*font_is_script_supported)(void *, godot_rid *, const godot_string *); + void (*font_set_script_support_override)(void *, godot_rid *, const godot_string *, bool); + bool (*font_get_script_support_override)(void *, godot_rid *, const godot_string *); + void (*font_remove_script_support_override)(void *, godot_rid *, const godot_string *); + godot_packed_string_array (*font_get_script_support_overrides)(void *, godot_rid *); + uint32_t (*font_get_glyph_index)(void *, godot_rid *, char32_t, char32_t); + godot_vector2 (*font_get_glyph_advance)(void *, godot_rid *, uint32_t, int); + godot_vector2 (*font_get_glyph_kerning)(void *, godot_rid *, uint32_t, uint32_t, int); + godot_vector2 (*font_draw_glyph)(void *, godot_rid *, godot_rid *, int, const godot_vector2 *, uint32_t, const godot_color *); + godot_vector2 (*font_draw_glyph_outline)(void *, godot_rid *, godot_rid *, int, int, const godot_vector2 *, uint32_t, const godot_color *); + float (*font_get_oversampling)(void *); + void (*font_set_oversampling)(void *, float); + godot_packed_string_array (*get_system_fonts)(void *); + godot_rid (*create_shaped_text)(void *, godot_int, godot_int); + void (*shaped_text_clear)(void *, godot_rid *); + void (*shaped_text_set_direction)(void *, godot_rid *, godot_int); + godot_int (*shaped_text_get_direction)(void *, godot_rid *); + void (*shaped_text_set_bidi_override)(void *, godot_rid *, const godot_packed_vector2i_array *); + void (*shaped_text_set_orientation)(void *, godot_rid *, godot_int); + godot_int (*shaped_text_get_orientation)(void *, godot_rid *); + void (*shaped_text_set_preserve_invalid)(void *, godot_rid *, bool); + bool (*shaped_text_get_preserve_invalid)(void *, godot_rid *); + void (*shaped_text_set_preserve_control)(void *, godot_rid *, bool); + bool (*shaped_text_get_preserve_control)(void *, godot_rid *); + bool (*shaped_text_add_string)(void *, godot_rid *, const godot_string *, const godot_rid **, int, const godot_dictionary *, const godot_string *); + bool (*shaped_text_add_object)(void *, godot_rid *, const godot_variant *, const godot_vector2 *, godot_int, godot_int); + bool (*shaped_text_resize_object)(void *, godot_rid *, const godot_variant *, const godot_vector2 *, godot_int); + godot_rid (*shaped_text_substr)(void *, godot_rid *, godot_int, godot_int); + godot_rid (*shaped_text_get_parent)(void *, godot_rid *); + float (*shaped_text_fit_to_width)(void *, godot_rid *, float, uint8_t); + float (*shaped_text_tab_align)(void *, godot_rid *, godot_packed_float32_array *); + bool (*shaped_text_shape)(void *, godot_rid *); + bool (*shaped_text_update_breaks)(void *, godot_rid *); + bool (*shaped_text_update_justification_ops)(void *, godot_rid *); + bool (*shaped_text_is_ready)(void *, godot_rid *); + godot_packed_glyph_array (*shaped_text_get_glyphs)(void *, godot_rid *); + godot_vector2i (*shaped_text_get_range)(void *, godot_rid *); + godot_packed_glyph_array (*shaped_text_sort_logical)(void *, godot_rid *); + godot_packed_vector2i_array (*shaped_text_get_line_breaks_adv)(void *, godot_rid *, godot_packed_float32_array *, int, bool, uint8_t); + godot_packed_vector2i_array (*shaped_text_get_line_breaks)(void *, godot_rid *, float, int, uint8_t); + godot_packed_vector2i_array (*shaped_text_get_word_breaks)(void *, godot_rid *); + godot_array (*shaped_text_get_objects)(void *, godot_rid *); + godot_rect2 (*shaped_text_get_object_rect)(void *, godot_rid *, const godot_variant *); + godot_vector2 (*shaped_text_get_size)(void *, godot_rid *); + float (*shaped_text_get_ascent)(void *, godot_rid *); + float (*shaped_text_get_descent)(void *, godot_rid *); + float (*shaped_text_get_width)(void *, godot_rid *); + float (*shaped_text_get_underline_position)(void *, godot_rid *); + float (*shaped_text_get_underline_thickness)(void *, godot_rid *); + godot_string (*format_number)(void *, const godot_string *, const godot_string *); + godot_string (*parse_number)(void *, const godot_string *, const godot_string *); + godot_string (*percent_sign)(void *, const godot_string *); +} godot_text_interface_gdnative; + +void GDAPI godot_text_register_interface(const godot_text_interface_gdnative *p_interface, const godot_string *p_name, uint32_t p_features); + +// Glyph + +void GDAPI godot_glyph_new(godot_glyph *r_dest); + +godot_vector2i GDAPI godot_glyph_get_range(const godot_glyph *p_self); +void GDAPI godot_glyph_set_range(godot_glyph *p_self, const godot_vector2i *p_range); + +godot_int GDAPI godot_glyph_get_count(const godot_glyph *p_self); +void GDAPI godot_glyph_set_count(godot_glyph *p_self, godot_int p_count); + +godot_int GDAPI godot_glyph_get_repeat(const godot_glyph *p_self); +void GDAPI godot_glyph_set_repeat(godot_glyph *p_self, godot_int p_repeat); + +godot_int GDAPI godot_glyph_get_flags(const godot_glyph *p_self); +void GDAPI godot_glyph_set_flags(godot_glyph *p_self, godot_int p_flags); + +godot_vector2 GDAPI godot_glyph_get_offset(const godot_glyph *p_self); +void GDAPI godot_glyph_set_offset(godot_glyph *p_self, const godot_vector2 *p_offset); + +godot_real GDAPI godot_glyph_get_advance(const godot_glyph *p_self); +void GDAPI godot_glyph_set_advance(godot_glyph *p_self, godot_real p_advance); + +godot_rid GDAPI godot_glyph_get_font(const godot_glyph *p_self); +void GDAPI godot_glyph_set_font(godot_glyph *p_self, godot_rid *p_font); + +godot_int GDAPI godot_glyph_get_font_size(const godot_glyph *p_self); +void GDAPI godot_glyph_set_font_size(godot_glyph *p_self, godot_int p_size); + +godot_int GDAPI godot_glyph_get_index(const godot_glyph *p_self); +void GDAPI godot_glyph_set_index(godot_glyph *p_self, godot_int p_index); + +// GlyphArray + +void GDAPI godot_packed_glyph_array_new(godot_packed_glyph_array *r_dest); +void GDAPI godot_packed_glyph_array_new_copy(godot_packed_glyph_array *r_dest, const godot_packed_glyph_array *p_src); + +const godot_glyph GDAPI *godot_packed_glyph_array_ptr(const godot_packed_glyph_array *p_self); +godot_glyph GDAPI *godot_packed_glyph_array_ptrw(godot_packed_glyph_array *p_self); + +void GDAPI godot_packed_glyph_array_append(godot_packed_glyph_array *p_self, const godot_glyph *p_data); + +void GDAPI godot_packed_glyph_array_append_array(godot_packed_glyph_array *p_self, const godot_packed_glyph_array *p_array); + +godot_error GDAPI godot_packed_glyph_array_insert(godot_packed_glyph_array *p_self, const godot_int p_idx, const godot_glyph *p_data); + +godot_bool GDAPI godot_packed_glyph_array_has(godot_packed_glyph_array *p_self, const godot_glyph *p_value); + +void GDAPI godot_packed_glyph_array_sort(godot_packed_glyph_array *p_self); + +void GDAPI godot_packed_glyph_array_invert(godot_packed_glyph_array *p_self); + +void GDAPI godot_packed_glyph_array_push_back(godot_packed_glyph_array *p_self, const godot_glyph *p_data); + +void GDAPI godot_packed_glyph_array_remove(godot_packed_glyph_array *p_self, godot_int p_idx); + +void GDAPI godot_packed_glyph_array_resize(godot_packed_glyph_array *p_self, godot_int p_size); + +void GDAPI godot_packed_glyph_array_set(godot_packed_glyph_array *p_self, godot_int p_idx, const godot_glyph *p_data); +godot_glyph GDAPI godot_packed_glyph_array_get(const godot_packed_glyph_array *p_self, godot_int p_idx); + +godot_int GDAPI godot_packed_glyph_array_size(const godot_packed_glyph_array *p_self); + +godot_bool GDAPI godot_packed_glyph_array_empty(const godot_packed_glyph_array *p_self); + +void GDAPI godot_packed_glyph_array_destroy(godot_packed_glyph_array *p_self); + +// Grapheme + +#ifdef __cplusplus +} +#endif + +#endif /* !GODOT_NATIVETEXT_H */ diff --git a/modules/gdnative/text/SCsub b/modules/gdnative/text/SCsub new file mode 100644 index 000000000000..0b2db3b50454 --- /dev/null +++ b/modules/gdnative/text/SCsub @@ -0,0 +1,6 @@ +#!/usr/bin/env python + +Import("env") +Import("env_gdnative") + +env_gdnative.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/gdnative/text/config.py b/modules/gdnative/text/config.py new file mode 100644 index 000000000000..d22f9454ed25 --- /dev/null +++ b/modules/gdnative/text/config.py @@ -0,0 +1,6 @@ +def can_build(env, platform): + return True + + +def configure(env): + pass diff --git a/modules/gdnative/text/register_types.cpp b/modules/gdnative/text/register_types.cpp new file mode 100644 index 000000000000..e1d4547aa0dd --- /dev/null +++ b/modules/gdnative/text/register_types.cpp @@ -0,0 +1,36 @@ +/*************************************************************************/ +/* register_types.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "register_types.h" +#include "text_server_gdnative.h" + +void register_text_server_gdn_types() {} + +void unregister_text_server_gdn_types() {} diff --git a/modules/gdnative/text/register_types.h b/modules/gdnative/text/register_types.h new file mode 100644 index 000000000000..027653e58e9f --- /dev/null +++ b/modules/gdnative/text/register_types.h @@ -0,0 +1,37 @@ +/*************************************************************************/ +/* register_types.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef TEXT_REGISTER_TYPES_H +#define TEXT_REGISTER_TYPES_H + +void register_text_server_gdn_types(); +void unregister_text_server_gdn_types(); + +#endif // TEXT_REGISTER_TYPES_H diff --git a/modules/gdnative/text/text_server_gdnative.cpp b/modules/gdnative/text/text_server_gdnative.cpp new file mode 100644 index 000000000000..68624260a6b9 --- /dev/null +++ b/modules/gdnative/text/text_server_gdnative.cpp @@ -0,0 +1,835 @@ +/*************************************************************************/ +/* text_server_gdnative.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "text_server_gdnative.h" + +bool TextServerGDNative::has_feature(Feature p_feature) { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->has_feature(data, (godot_int)p_feature); +} + +String TextServerGDNative::get_name() const { + ERR_FAIL_COND_V(interface == nullptr, String()); + godot_string result = interface->get_name(data); + String name = *(String *)&result; + godot_string_destroy(&result); + return name; +} + +void TextServerGDNative::free(RID p_rid) { + ERR_FAIL_COND(interface == nullptr); + interface->free(data, (godot_rid *)&p_rid); +} + +bool TextServerGDNative::has(RID p_rid) { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->has(data, (godot_rid *)&p_rid); +} + +bool TextServerGDNative::load_support_data(const String &p_filename) { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->load_support_data(data, (godot_string *)&p_filename); +} + +#ifdef TOOLS_ENABLED + +String TextServerGDNative::get_support_data_filename() { + ERR_FAIL_COND_V(interface == nullptr, String()); + godot_string result = interface->get_support_data_filename(data); + String name = *(String *)&result; + godot_string_destroy(&result); + return name; +} + +String TextServerGDNative::get_support_data_info() { + ERR_FAIL_COND_V(interface == nullptr, String()); + godot_string result = interface->get_support_data_info(data); + String info = *(String *)&result; + godot_string_destroy(&result); + return info; +} + +bool TextServerGDNative::save_support_data(const String &p_filename) { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->save_support_data(data, (godot_string *)&p_filename); +} + +#endif + +bool TextServerGDNative::is_locale_right_to_left(const String &p_locale) { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->is_locale_right_to_left(data, (godot_string *)&p_locale); +} + +/*************************************************************************/ +/* Font interface */ +/*************************************************************************/ + +RID TextServerGDNative::create_font_system(const String &p_name, int p_base_size) { + ERR_FAIL_COND_V(interface == nullptr, RID()); + godot_rid result = interface->create_font_system(data, (const godot_string *)&p_name, p_base_size); + RID rid = *(RID *)&result; + return rid; +} + +RID TextServerGDNative::create_font_resource(const String &p_filename, int p_base_size) { + ERR_FAIL_COND_V(interface == nullptr, RID()); + godot_rid result = interface->create_font_resource(data, (const godot_string *)&p_filename, p_base_size); + RID rid = *(RID *)&result; + return rid; +} + +RID TextServerGDNative::create_font_memory(const uint8_t *p_data, size_t p_size, const String &p_type, int p_base_size) { + ERR_FAIL_COND_V(interface == nullptr, RID()); + godot_rid result = interface->create_font_memory(data, p_data, p_size, (godot_string *)&p_type, p_base_size); + RID rid = *(RID *)&result; + return rid; +} + +float TextServerGDNative::font_get_height(RID p_font, int p_size) const { + ERR_FAIL_COND_V(interface == nullptr, 0.f); + return interface->font_get_height(data, (godot_rid *)&p_font, p_size); +} + +float TextServerGDNative::font_get_ascent(RID p_font, int p_size) const { + ERR_FAIL_COND_V(interface == nullptr, 0.f); + return interface->font_get_ascent(data, (godot_rid *)&p_font, p_size); +} + +float TextServerGDNative::font_get_descent(RID p_font, int p_size) const { + ERR_FAIL_COND_V(interface == nullptr, 0.f); + return interface->font_get_descent(data, (godot_rid *)&p_font, p_size); +} + +float TextServerGDNative::font_get_underline_position(RID p_font, int p_size) const { + ERR_FAIL_COND_V(interface == nullptr, 0.f); + return interface->font_get_underline_position(data, (godot_rid *)&p_font, p_size); +} + +float TextServerGDNative::font_get_underline_thickness(RID p_font, int p_size) const { + ERR_FAIL_COND_V(interface == nullptr, 0.f); + return interface->font_get_underline_thickness(data, (godot_rid *)&p_font, p_size); +} + +void TextServerGDNative::font_set_antialiased(RID p_font, bool p_antialiased) { + ERR_FAIL_COND(interface == nullptr); + interface->font_set_antialiased(data, (godot_rid *)&p_font, p_antialiased); +} + +bool TextServerGDNative::font_get_antialiased(RID p_font) const { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->font_get_antialiased(data, (godot_rid *)&p_font); +} + +void TextServerGDNative::font_set_hinting(RID p_font, TextServer::Hinting p_hinting) { + ERR_FAIL_COND(interface == nullptr); + interface->font_set_hinting(data, (godot_rid *)&p_font, (godot_int)p_hinting); +} + +TextServer::Hinting TextServerGDNative::font_get_hinting(RID p_font) const { + ERR_FAIL_COND_V(interface == nullptr, TextServer::HINTING_NONE); + return (TextServer::Hinting)interface->font_get_hinting(data, (godot_rid *)&p_font); +} + +Dictionary TextServerGDNative::font_get_feature_list(RID p_font) const { + ERR_FAIL_COND_V(interface == nullptr, Dictionary()); + godot_dictionary result = interface->font_get_feature_list(data, (godot_rid *)&p_font); + Dictionary info = *(Dictionary *)&result; + godot_dictionary_destroy(&result); + + return info; +} + +void TextServerGDNative::font_set_distance_field_hint(RID p_font, bool p_distance_field) { + ERR_FAIL_COND(interface == nullptr); + interface->font_set_distance_field_hint(data, (godot_rid *)&p_font, p_distance_field); +} + +bool TextServerGDNative::font_get_distance_field_hint(RID p_font) const { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->font_get_distance_field_hint(data, (godot_rid *)&p_font); +} + +void TextServerGDNative::font_set_force_autohinter(RID p_font, bool p_enabeld) { + ERR_FAIL_COND(interface == nullptr); + interface->font_set_force_autohinter(data, (godot_rid *)&p_font, p_enabeld); +} + +bool TextServerGDNative::font_get_force_autohinter(RID p_font) const { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->font_get_force_autohinter(data, (godot_rid *)&p_font); +} + +bool TextServerGDNative::font_has_char(RID p_font, char32_t p_char) const { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->font_has_char(data, (godot_rid *)&p_font, p_char); +} + +String TextServerGDNative::font_get_supported_chars(RID p_font) const { + ERR_FAIL_COND_V(interface == nullptr, String()); + godot_string result = interface->font_get_supported_chars(data, (godot_rid *)&p_font); + String ret = *(String *)&result; + godot_string_destroy(&result); + return ret; +} + +bool TextServerGDNative::font_has_outline(RID p_font) const { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->font_has_outline(data, (godot_rid *)&p_font); +} + +float TextServerGDNative::font_get_base_size(RID p_font) const { + ERR_FAIL_COND_V(interface == nullptr, 0.f); + return interface->font_get_base_size(data, (godot_rid *)&p_font); +} + +bool TextServerGDNative::font_is_language_supported(RID p_font, const String &p_language) const { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->font_is_language_supported(data, (godot_rid *)&p_font, (godot_string *)&p_language); +} + +void TextServerGDNative::font_set_language_support_override(RID p_font, const String &p_language, bool p_supported) { + ERR_FAIL_COND(interface == nullptr); + return interface->font_set_language_support_override(data, (godot_rid *)&p_font, (godot_string *)&p_language, p_supported); +} + +bool TextServerGDNative::font_get_language_support_override(RID p_font, const String &p_language) { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->font_get_language_support_override(data, (godot_rid *)&p_font, (godot_string *)&p_language); +} + +void TextServerGDNative::font_remove_language_support_override(RID p_font, const String &p_language) { + ERR_FAIL_COND(interface == nullptr); + interface->font_remove_language_support_override(data, (godot_rid *)&p_font, (godot_string *)&p_language); +} + +Vector TextServerGDNative::font_get_language_support_overrides(RID p_font) { + ERR_FAIL_COND_V(interface == nullptr, Vector()); + godot_packed_string_array result = interface->font_get_language_support_overrides(data, (godot_rid *)&p_font); + Vector ret = *(Vector *)&result; + godot_packed_string_array_destroy(&result); + return ret; +} + +bool TextServerGDNative::font_is_script_supported(RID p_font, const String &p_script) const { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->font_is_script_supported(data, (godot_rid *)&p_font, (godot_string *)&p_script); +} + +void TextServerGDNative::font_set_script_support_override(RID p_font, const String &p_script, bool p_supported) { + ERR_FAIL_COND(interface == nullptr); + return interface->font_set_script_support_override(data, (godot_rid *)&p_font, (godot_string *)&p_script, p_supported); +} + +bool TextServerGDNative::font_get_script_support_override(RID p_font, const String &p_script) { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->font_get_script_support_override(data, (godot_rid *)&p_font, (godot_string *)&p_script); +} + +void TextServerGDNative::font_remove_script_support_override(RID p_font, const String &p_script) { + ERR_FAIL_COND(interface == nullptr); + interface->font_remove_script_support_override(data, (godot_rid *)&p_font, (godot_string *)&p_script); +} + +Vector TextServerGDNative::font_get_script_support_overrides(RID p_font) { + ERR_FAIL_COND_V(interface == nullptr, Vector()); + godot_packed_string_array result = interface->font_get_script_support_overrides(data, (godot_rid *)&p_font); + Vector ret = *(Vector *)&result; + godot_packed_string_array_destroy(&result); + return ret; +} + +uint32_t TextServerGDNative::font_get_glyph_index(RID p_font, char32_t p_char, char32_t p_variation_selector) const { + ERR_FAIL_COND_V(interface == nullptr, 0); + return interface->font_get_glyph_index(data, (godot_rid *)&p_font, p_char, p_variation_selector); +} + +Vector2 TextServerGDNative::font_get_glyph_advance(RID p_font, uint32_t p_index, int p_size) const { + ERR_FAIL_COND_V(interface == nullptr, Vector2()); + godot_vector2 result = interface->font_get_glyph_advance(data, (godot_rid *)&p_font, p_index, p_size); + Vector2 advance = *(Vector2 *)&result; + return advance; +} + +Vector2 TextServerGDNative::font_get_glyph_kerning(RID p_font, uint32_t p_index_a, uint32_t p_index_b, int p_size) const { + ERR_FAIL_COND_V(interface == nullptr, Vector2()); + godot_vector2 result = interface->font_get_glyph_kerning(data, (godot_rid *)&p_font, p_index_a, p_index_b, p_size); + Vector2 kerning = *(Vector2 *)&result; + return kerning; +} + +Vector2 TextServerGDNative::font_draw_glyph(RID p_font, RID p_canvas, int p_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color) const { + ERR_FAIL_COND_V(interface == nullptr, Vector2()); + godot_vector2 result = interface->font_draw_glyph(data, (godot_rid *)&p_font, (godot_rid *)&p_canvas, p_size, (const godot_vector2 *)&p_pos, p_index, (const godot_color *)&p_color); + Vector2 advance = *(Vector2 *)&result; + return advance; +} + +Vector2 TextServerGDNative::font_draw_glyph_outline(RID p_font, RID p_canvas, int p_size, int p_outline_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color) const { + ERR_FAIL_COND_V(interface == nullptr, Vector2()); + godot_vector2 result = interface->font_draw_glyph_outline(data, (godot_rid *)&p_font, (godot_rid *)&p_canvas, p_size, p_outline_size, (const godot_vector2 *)&p_pos, p_index, (const godot_color *)&p_color); + Vector2 advance = *(Vector2 *)&result; + return advance; +} + +float TextServerGDNative::font_get_oversampling() const { + ERR_FAIL_COND_V(interface == nullptr, 1.f); + return interface->font_get_oversampling(data); +} + +void TextServerGDNative::font_set_oversampling(float p_oversampling) { + ERR_FAIL_COND(interface == nullptr); + return interface->font_set_oversampling(data, p_oversampling); +} + +Vector TextServerGDNative::get_system_fonts() const { + ERR_FAIL_COND_V(interface == nullptr, Vector()); + godot_packed_string_array result = interface->get_system_fonts(data); + Vector fonts = *(Vector *)&result; + godot_packed_string_array_destroy(&result); + return fonts; +} + +/*************************************************************************/ +/* Shaped text buffer interface */ +/*************************************************************************/ + +RID TextServerGDNative::create_shaped_text(TextServer::Direction p_direction, TextServer::Orientation p_orientation) { + ERR_FAIL_COND_V(interface == nullptr, RID()); + godot_rid result = interface->create_shaped_text(data, (godot_int)p_direction, (godot_int)p_orientation); + RID rid = *(RID *)&result; + return rid; +} + +void TextServerGDNative::shaped_text_clear(RID p_shaped) { + ERR_FAIL_COND(interface == nullptr); + interface->shaped_text_clear(data, (godot_rid *)&p_shaped); +} + +void TextServerGDNative::shaped_text_set_direction(RID p_shaped, TextServer::Direction p_direction) { + ERR_FAIL_COND(interface == nullptr); + interface->shaped_text_set_direction(data, (godot_rid *)&p_shaped, (godot_int)p_direction); +} + +TextServer::Direction TextServerGDNative::shaped_text_get_direction(RID p_shaped) const { + ERR_FAIL_COND_V(interface == nullptr, TextServer::DIRECTION_LTR); + return (TextServer::Direction)interface->shaped_text_get_direction(data, (godot_rid *)&p_shaped); +} + +void TextServerGDNative::shaped_text_set_orientation(RID p_shaped, TextServer::Orientation p_orientation) { + ERR_FAIL_COND(interface == nullptr); + interface->shaped_text_set_orientation(data, (godot_rid *)&p_shaped, (godot_int)p_orientation); +} + +TextServer::Orientation TextServerGDNative::shaped_text_get_orientation(RID p_shaped) const { + ERR_FAIL_COND_V(interface == nullptr, TextServer::ORIENTATION_HORIZONTAL); + return (TextServer::Orientation)interface->shaped_text_get_orientation(data, (godot_rid *)&p_shaped); +} + +void TextServerGDNative::shaped_text_set_bidi_override(RID p_shaped, const Vector &p_override) { + ERR_FAIL_COND(interface == nullptr); + interface->shaped_text_set_bidi_override(data, (godot_rid *)&p_shaped, (const godot_packed_vector2i_array *)&p_override); +} + +void TextServerGDNative::shaped_text_set_preserve_invalid(RID p_shaped, bool p_enabled) { + ERR_FAIL_COND(interface == nullptr); + interface->shaped_text_set_preserve_invalid(data, (godot_rid *)&p_shaped, p_enabled); +} + +bool TextServerGDNative::shaped_text_get_preserve_invalid(RID p_shaped) const { + ERR_FAIL_COND_V(interface == nullptr, false); + return (TextServer::Orientation)interface->shaped_text_get_preserve_invalid(data, (godot_rid *)&p_shaped); +} + +void TextServerGDNative::shaped_text_set_preserve_control(RID p_shaped, bool p_enabled) { + ERR_FAIL_COND(interface == nullptr); + interface->shaped_text_set_preserve_control(data, (godot_rid *)&p_shaped, p_enabled); +} + +bool TextServerGDNative::shaped_text_get_preserve_control(RID p_shaped) const { + ERR_FAIL_COND_V(interface == nullptr, false); + return (TextServer::Orientation)interface->shaped_text_get_preserve_control(data, (godot_rid *)&p_shaped); +} + +bool TextServerGDNative::shaped_text_add_string(RID p_shaped, const String &p_text, const Vector &p_fonts, int p_size, const Dictionary &p_opentype_features, const String &p_language) { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->shaped_text_add_string(data, (godot_rid *)&p_shaped, (const godot_string *)&p_text, (const godot_rid **)p_fonts.ptr(), p_size, (const godot_dictionary *)&p_opentype_features, (const godot_string *)&p_language); +} + +bool TextServerGDNative::shaped_text_add_object(RID p_shaped, Variant p_key, const Size2 &p_size, VAlign p_inline_align, int p_length) { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->shaped_text_add_object(data, (godot_rid *)&p_shaped, (const godot_variant *)&p_key, (const godot_vector2 *)&p_size, (godot_int)p_inline_align, p_length); +} + +bool TextServerGDNative::shaped_text_resize_object(RID p_shaped, Variant p_key, const Size2 &p_size, VAlign p_inline_align) { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->shaped_text_resize_object(data, (godot_rid *)&p_shaped, (const godot_variant *)&p_key, (const godot_vector2 *)&p_size, (godot_int)p_inline_align); +} + +RID TextServerGDNative::shaped_text_substr(RID p_shaped, int p_start, int p_length) const { + ERR_FAIL_COND_V(interface == nullptr, RID()); + godot_rid result = interface->shaped_text_substr(data, (godot_rid *)&p_shaped, (godot_int)p_start, (godot_int)p_length); + RID rid = *(RID *)&result; + return rid; +} + +RID TextServerGDNative::shaped_text_get_parent(RID p_shaped) const { + ERR_FAIL_COND_V(interface == nullptr, RID()); + godot_rid result = interface->shaped_text_get_parent(data, (godot_rid *)&p_shaped); + RID rid = *(RID *)&result; + return rid; +} + +float TextServerGDNative::shaped_text_fit_to_width(RID p_shaped, float p_width, uint8_t p_jst_flags) { + ERR_FAIL_COND_V(interface == nullptr, 0.f); + return interface->shaped_text_fit_to_width(data, (godot_rid *)&p_shaped, p_width, p_jst_flags); +} + +float TextServerGDNative::shaped_text_tab_align(RID p_shaped, const Vector &p_tab_stops) { + ERR_FAIL_COND_V(interface == nullptr, 0.f); + return interface->shaped_text_tab_align(data, (godot_rid *)&p_shaped, (godot_packed_float32_array *)&p_tab_stops); +} + +bool TextServerGDNative::shaped_text_shape(RID p_shaped) { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->shaped_text_shape(data, (godot_rid *)&p_shaped); +} + +bool TextServerGDNative::shaped_text_update_breaks(RID p_shaped) { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->shaped_text_update_breaks(data, (godot_rid *)&p_shaped); +} + +bool TextServerGDNative::shaped_text_update_justification_ops(RID p_shaped) { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->shaped_text_update_justification_ops(data, (godot_rid *)&p_shaped); +} + +bool TextServerGDNative::shaped_text_is_ready(RID p_shaped) const { + ERR_FAIL_COND_V(interface == nullptr, false); + return interface->shaped_text_is_ready(data, (godot_rid *)&p_shaped); +} + +Vector TextServerGDNative::shaped_text_get_glyphs(RID p_shaped) const { + ERR_FAIL_COND_V(interface == nullptr, Vector()); + godot_packed_glyph_array result = interface->shaped_text_get_glyphs(data, (godot_rid *)&p_shaped); + Vector glyphs = *(Vector *)&result; + godot_packed_glyph_array_destroy(&result); + return glyphs; +} + +Vector2i TextServerGDNative::shaped_text_get_range(RID p_shaped) const { + ERR_FAIL_COND_V(interface == nullptr, Vector2i()); + godot_vector2i result = interface->shaped_text_get_range(data, (godot_rid *)&p_shaped); + Vector2i range = *(Vector2i *)&result; + return range; +} + +Vector TextServerGDNative::shaped_text_sort_logical(RID p_shaped) { + ERR_FAIL_COND_V(interface == nullptr, Vector()); + godot_packed_glyph_array result = interface->shaped_text_sort_logical(data, (godot_rid *)&p_shaped); + Vector glyphs = *(Vector *)&result; + godot_packed_glyph_array_destroy(&result); + return glyphs; +} + +Vector TextServerGDNative::shaped_text_get_line_breaks_adv(RID p_shaped, const Vector &p_width, int p_start, bool p_once, uint8_t p_break_flags) const { + ERR_FAIL_COND_V(interface == nullptr, Vector()); + if (interface->shaped_text_get_line_breaks_adv != nullptr) { + godot_packed_vector2i_array result = interface->shaped_text_get_line_breaks_adv(data, (godot_rid *)&p_shaped, (godot_packed_float32_array *)&p_width, p_start, p_once, p_break_flags); + Vector breaks = *(Vector *)&result; + godot_packed_vector2i_array_destroy(&result); + return breaks; + } else { + return TextServer::shaped_text_get_line_breaks_adv(p_shaped, p_width, p_break_flags); + } +} + +Vector TextServerGDNative::shaped_text_get_line_breaks(RID p_shaped, float p_width, int p_start, uint8_t p_break_flags) const { + ERR_FAIL_COND_V(interface == nullptr, Vector()); + if (interface->shaped_text_get_line_breaks != nullptr) { + godot_packed_vector2i_array result = interface->shaped_text_get_line_breaks(data, (godot_rid *)&p_shaped, p_width, p_start, p_break_flags); + Vector breaks = *(Vector *)&result; + godot_packed_vector2i_array_destroy(&result); + return breaks; + } else { + return TextServer::shaped_text_get_line_breaks(p_shaped, p_width, p_break_flags); + } +} + +Vector TextServerGDNative::shaped_text_get_word_breaks(RID p_shaped) const { + ERR_FAIL_COND_V(interface == nullptr, Vector()); + if (interface->shaped_text_get_word_breaks != nullptr) { + godot_packed_vector2i_array result = interface->shaped_text_get_word_breaks(data, (godot_rid *)&p_shaped); + Vector breaks = *(Vector *)&result; + godot_packed_vector2i_array_destroy(&result); + return breaks; + } else { + return TextServer::shaped_text_get_word_breaks(p_shaped); + } +} + +Array TextServerGDNative::shaped_text_get_objects(RID p_shaped) const { + ERR_FAIL_COND_V(interface == nullptr, Array()); + godot_array result = interface->shaped_text_get_objects(data, (godot_rid *)&p_shaped); + Array rect = *(Array *)&result; + return rect; +} + +Rect2 TextServerGDNative::shaped_text_get_object_rect(RID p_shaped, Variant p_key) const { + ERR_FAIL_COND_V(interface == nullptr, Rect2()); + godot_rect2 result = interface->shaped_text_get_object_rect(data, (godot_rid *)&p_shaped, (const godot_variant *)&p_key); + Rect2 rect = *(Rect2 *)&result; + return rect; +} + +Size2 TextServerGDNative::shaped_text_get_size(RID p_shaped) const { + ERR_FAIL_COND_V(interface == nullptr, Size2()); + godot_vector2 result = interface->shaped_text_get_size(data, (godot_rid *)&p_shaped); + Size2 size = *(Size2 *)&result; + return size; +} + +float TextServerGDNative::shaped_text_get_ascent(RID p_shaped) const { + ERR_FAIL_COND_V(interface == nullptr, 0.f); + return interface->shaped_text_get_ascent(data, (godot_rid *)&p_shaped); +} + +float TextServerGDNative::shaped_text_get_descent(RID p_shaped) const { + ERR_FAIL_COND_V(interface == nullptr, 0.f); + return interface->shaped_text_get_descent(data, (godot_rid *)&p_shaped); +} + +float TextServerGDNative::shaped_text_get_width(RID p_shaped) const { + ERR_FAIL_COND_V(interface == nullptr, 0.f); + return interface->shaped_text_get_width(data, (godot_rid *)&p_shaped); +} + +float TextServerGDNative::shaped_text_get_underline_position(RID p_shaped) const { + ERR_FAIL_COND_V(interface == nullptr, 0.f); + return interface->shaped_text_get_underline_position(data, (godot_rid *)&p_shaped); +} + +float TextServerGDNative::shaped_text_get_underline_thickness(RID p_shaped) const { + ERR_FAIL_COND_V(interface == nullptr, 0.f); + return interface->shaped_text_get_underline_thickness(data, (godot_rid *)&p_shaped); +} + +String TextServerGDNative::format_number(const String &p_string, const String &p_language) const { + ERR_FAIL_COND_V(interface == nullptr, String()); + godot_string result = interface->format_number(data, (const godot_string *)&p_string, (const godot_string *)&p_language); + if (interface->format_number == nullptr) { + return p_string; + } + String ret = *(String *)&result; + godot_string_destroy(&result); + return ret; +} + +String TextServerGDNative::parse_number(const String &p_string, const String &p_language) const { + ERR_FAIL_COND_V(interface == nullptr, String()); + if (interface->parse_number == nullptr) { + return p_string; + } + godot_string result = interface->parse_number(data, (const godot_string *)&p_string, (const godot_string *)&p_language); + String ret = *(String *)&result; + godot_string_destroy(&result); + return ret; +} + +String TextServerGDNative::percent_sign(const String &p_language) const { + ERR_FAIL_COND_V(interface == nullptr, String()); + if (interface->percent_sign == nullptr) { + return "%"; + } + godot_string result = interface->percent_sign(data, (const godot_string *)&p_language); + String ret = *(String *)&result; + godot_string_destroy(&result); + return ret; +} + +TextServer *TextServerGDNative::create_func(Error &r_error, void *p_user_data) { + const godot_text_interface_gdnative *interface = (const godot_text_interface_gdnative *)p_user_data; + r_error = OK; + + TextServerGDNative *server = memnew(TextServerGDNative()); + server->interface = interface; + server->data = interface->constructor((godot_object *)server); + + return server; +} + +TextServerGDNative::TextServerGDNative() { + data = nullptr; + interface = nullptr; +} + +TextServerGDNative::~TextServerGDNative() { + if (interface != nullptr) { + interface->destructor(data); + data = nullptr; + interface = nullptr; + } +} + +/*************************************************************************/ +/* GDNative functions */ +/*************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif + +static_assert(sizeof(godot_glyph) == sizeof(TextServer::Glyph), "Glyph size mismatch"); +static_assert(sizeof(godot_packed_glyph_array) == sizeof(Vector), "Vector size mismatch"); + +void GDAPI godot_text_register_interface(const godot_text_interface_gdnative *p_interface, const godot_string *p_name, uint32_t p_features) { + ERR_FAIL_COND(p_interface->version.major != 1); + String name = *(String *)p_name; + TextServerManager::register_create_function(name + "(GDNative)", p_features, TextServerGDNative::create_func, (void *)p_interface); +} + +// Glyph + +void GDAPI godot_glyph_new(godot_glyph *r_dest) { + TextServer::Glyph *dest = (TextServer::Glyph *)r_dest; + *dest = TextServer::Glyph(); +} + +godot_vector2i GDAPI godot_glyph_get_range(const godot_glyph *p_self) { + godot_vector2i dest; + Vector2i *d = (Vector2i *)&dest; + const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; + d->x = self->start; + d->y = self->end; + return dest; +} + +void GDAPI godot_glyph_set_range(godot_glyph *p_self, const godot_vector2i *p_range) { + TextServer::Glyph *self = (TextServer::Glyph *)p_self; + const Vector2i *range = (const Vector2i *)p_range; + self->start = range->x; + self->end = range->y; +} + +godot_int GDAPI godot_glyph_get_count(const godot_glyph *p_self) { + const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; + return self->count; +} + +void GDAPI godot_glyph_set_count(godot_glyph *p_self, godot_int p_count) { + TextServer::Glyph *self = (TextServer::Glyph *)p_self; + self->count = p_count; +} + +godot_int GDAPI godot_glyph_get_repeat(const godot_glyph *p_self) { + const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; + return self->repeat; +} + +void GDAPI godot_glyph_set_repeat(godot_glyph *p_self, godot_int p_repeat) { + TextServer::Glyph *self = (TextServer::Glyph *)p_self; + self->repeat = p_repeat; +} + +godot_int GDAPI godot_glyph_get_flags(const godot_glyph *p_self) { + const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; + return self->flags; +} + +void GDAPI godot_glyph_set_flags(godot_glyph *p_self, godot_int p_flags) { + TextServer::Glyph *self = (TextServer::Glyph *)p_self; + self->flags = p_flags; +} + +godot_vector2 GDAPI godot_glyph_get_offset(const godot_glyph *p_self) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; + d->x = self->x_off; + d->y = self->y_off; + return dest; +} + +void GDAPI godot_glyph_set_offset(godot_glyph *p_self, const godot_vector2 *p_offset) { + TextServer::Glyph *self = (TextServer::Glyph *)p_self; + const Vector2 *offset = (const Vector2 *)p_offset; + self->x_off = offset->x; + self->y_off = offset->y; +} + +godot_real GDAPI godot_glyph_get_advance(const godot_glyph *p_self) { + const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; + return self->advance; +} + +void GDAPI godot_glyph_set_advance(godot_glyph *p_self, godot_real p_advance) { + TextServer::Glyph *self = (TextServer::Glyph *)p_self; + self->advance = p_advance; +} + +godot_rid GDAPI godot_glyph_get_font(const godot_glyph *p_self) { + godot_rid dest; + RID *d = (RID *)&dest; + const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; + *d = self->font_rid; + return dest; +} + +void GDAPI godot_glyph_set_font(godot_glyph *p_self, godot_rid *p_font) { + TextServer::Glyph *self = (TextServer::Glyph *)p_self; + const RID *font = (const RID *)p_font; + self->font_rid = *font; +} + +godot_int GDAPI godot_glyph_get_font_size(const godot_glyph *p_self) { + const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; + return self->font_size; +} + +void GDAPI godot_glyph_set_font_size(godot_glyph *p_self, godot_int p_size) { + TextServer::Glyph *self = (TextServer::Glyph *)p_self; + self->font_size = p_size; +} + +godot_int GDAPI godot_glyph_get_index(const godot_glyph *p_self) { + const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; + return self->index; +} + +void GDAPI godot_glyph_set_index(godot_glyph *p_self, godot_int p_index) { + TextServer::Glyph *self = (TextServer::Glyph *)p_self; + self->index = p_index; +} + +// GlyphArray + +void GDAPI godot_packed_glyph_array_new(godot_packed_glyph_array *r_dest) { + Vector *dest = (Vector *)r_dest; + memnew_placement(dest, Vector); +} + +void GDAPI godot_packed_glyph_array_new_copy(godot_packed_glyph_array *r_dest, const godot_packed_glyph_array *p_src) { + Vector *dest = (Vector *)r_dest; + const Vector *src = (const Vector *)p_src; + memnew_placement(dest, Vector(*src)); +} + +const godot_glyph GDAPI *godot_packed_glyph_array_ptr(const godot_packed_glyph_array *p_self) { + const Vector *self = (const Vector *)p_self; + return (const godot_glyph *)self->ptr(); +} + +godot_glyph GDAPI *godot_packed_glyph_array_ptrw(godot_packed_glyph_array *p_self) { + Vector *self = (Vector *)p_self; + return (godot_glyph *)self->ptrw(); +} + +void GDAPI godot_packed_glyph_array_append(godot_packed_glyph_array *p_self, const godot_glyph *p_data) { + Vector *self = (Vector *)p_self; + TextServer::Glyph &s = *(TextServer::Glyph *)p_data; + self->push_back(s); +} + +void GDAPI godot_packed_glyph_array_append_array(godot_packed_glyph_array *p_self, const godot_packed_glyph_array *p_array) { + Vector *self = (Vector *)p_self; + Vector *array = (Vector *)p_array; + self->append_array(*array); +} + +godot_error GDAPI godot_packed_glyph_array_insert(godot_packed_glyph_array *p_self, const godot_int p_idx, const godot_glyph *p_data) { + Vector *self = (Vector *)p_self; + TextServer::Glyph &s = *(TextServer::Glyph *)p_data; + return (godot_error)self->insert(p_idx, s); +} + +godot_bool GDAPI godot_packed_glyph_array_has(godot_packed_glyph_array *p_self, const godot_glyph *p_value) { + Vector *self = (Vector *)p_self; + TextServer::Glyph &v = *(TextServer::Glyph *)p_value; + return (godot_bool)self->has(v); +} + +void GDAPI godot_packed_glyph_array_sort(godot_packed_glyph_array *p_self) { + Vector *self = (Vector *)p_self; + self->sort(); +} + +void GDAPI godot_packed_glyph_array_invert(godot_packed_glyph_array *p_self) { + Vector *self = (Vector *)p_self; + self->invert(); +} + +void GDAPI godot_packed_glyph_array_push_back(godot_packed_glyph_array *p_self, const godot_glyph *p_data) { + Vector *self = (Vector *)p_self; + TextServer::Glyph &s = *(TextServer::Glyph *)p_data; + self->push_back(s); +} + +void GDAPI godot_packed_glyph_array_remove(godot_packed_glyph_array *p_self, const godot_int p_idx) { + Vector *self = (Vector *)p_self; + self->remove(p_idx); +} + +void GDAPI godot_packed_glyph_array_resize(godot_packed_glyph_array *p_self, const godot_int p_size) { + Vector *self = (Vector *)p_self; + self->resize(p_size); +} + +void GDAPI godot_packed_glyph_array_set(godot_packed_glyph_array *p_self, const godot_int p_idx, const godot_glyph *p_data) { + Vector *self = (Vector *)p_self; + TextServer::Glyph &s = *(TextServer::Glyph *)p_data; + self->set(p_idx, s); +} + +godot_glyph GDAPI godot_packed_glyph_array_get(const godot_packed_glyph_array *p_self, const godot_int p_idx) { + const Vector *self = (const Vector *)p_self; + godot_glyph v; + TextServer::Glyph *s = (TextServer::Glyph *)&v; + *s = self->get(p_idx); + return v; +} + +godot_int GDAPI godot_packed_glyph_array_size(const godot_packed_glyph_array *p_self) { + const Vector *self = (const Vector *)p_self; + return self->size(); +} + +godot_bool GDAPI godot_packed_glyph_array_empty(const godot_packed_glyph_array *p_self) { + const Vector *self = (const Vector *)p_self; + return self->empty(); +} + +void GDAPI godot_packed_glyph_array_destroy(godot_packed_glyph_array *p_self) { + ((Vector *)p_self)->~Vector(); +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/text/text_server_gdnative.h b/modules/gdnative/text/text_server_gdnative.h new file mode 100644 index 000000000000..0196120c0079 --- /dev/null +++ b/modules/gdnative/text/text_server_gdnative.h @@ -0,0 +1,183 @@ +/*************************************************************************/ +/* text_server_gdnative.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef TEXT_SERVER_GDNATIVE_H +#define TEXT_SERVER_GDNATIVE_H + +#include "modules/gdnative/gdnative.h" + +#include "servers/text_server.h" + +class TextServerGDNative : public TextServer { + GDCLASS(TextServerGDNative, TextServer); + + const godot_text_interface_gdnative *interface = nullptr; + void *data = nullptr; + +protected: + static void _bind_methods(){}; + +public: + virtual bool has_feature(Feature p_feature) override; + virtual String get_name() const override; + + virtual void free(RID p_rid) override; + virtual bool has(RID p_rid) override; + virtual bool load_support_data(const String &p_filename) override; + +#ifdef TOOLS_ENABLED + virtual String get_support_data_filename() override; + virtual String get_support_data_info() override; + virtual bool save_support_data(const String &p_filename) override; +#endif + + virtual bool is_locale_right_to_left(const String &p_locale) override; + + /* Font interface */ + virtual RID create_font_system(const String &p_name, int p_base_size = 16) override; + virtual RID create_font_resource(const String &p_filename, int p_base_size = 16) override; + virtual RID create_font_memory(const uint8_t *p_data, size_t p_size, const String &p_type, int p_base_size = 16) override; + + virtual float font_get_height(RID p_font, int p_size) const override; + virtual float font_get_ascent(RID p_font, int p_size) const override; + virtual float font_get_descent(RID p_font, int p_size) const override; + + virtual float font_get_underline_position(RID p_font, int p_size) const override; + virtual float font_get_underline_thickness(RID p_font, int p_size) const override; + + virtual void font_set_antialiased(RID p_font, bool p_antialiased) override; + virtual bool font_get_antialiased(RID p_font) const override; + + virtual Dictionary font_get_feature_list(RID p_font) const override; + + virtual void font_set_hinting(RID p_font, Hinting p_hinting) override; + virtual Hinting font_get_hinting(RID p_font) const override; + + virtual void font_set_distance_field_hint(RID p_font, bool p_distance_field) override; + virtual bool font_get_distance_field_hint(RID p_font) const override; + + virtual void font_set_force_autohinter(RID p_font, bool p_enabeld) override; + virtual bool font_get_force_autohinter(RID p_font) const override; + + virtual bool font_has_char(RID p_font, char32_t p_char) const override; + virtual String font_get_supported_chars(RID p_font) const override; + + virtual bool font_has_outline(RID p_font) const override; + virtual float font_get_base_size(RID p_font) const override; + + virtual bool font_is_language_supported(RID p_font, const String &p_language) const override; + virtual void font_set_language_support_override(RID p_font, const String &p_language, bool p_supported) override; + virtual bool font_get_language_support_override(RID p_font, const String &p_language) override; + virtual void font_remove_language_support_override(RID p_font, const String &p_language) override; + Vector font_get_language_support_overrides(RID p_font) override; + + virtual bool font_is_script_supported(RID p_font, const String &p_script) const override; + virtual void font_set_script_support_override(RID p_font, const String &p_script, bool p_supported) override; + virtual bool font_get_script_support_override(RID p_font, const String &p_script) override; + virtual void font_remove_script_support_override(RID p_font, const String &p_script) override; + Vector font_get_script_support_overrides(RID p_font) override; + + virtual uint32_t font_get_glyph_index(RID p_font, char32_t p_char, char32_t p_variation_selector = 0x0000) const override; + virtual Vector2 font_get_glyph_advance(RID p_font, uint32_t p_index, int p_size) const override; + virtual Vector2 font_get_glyph_kerning(RID p_font, uint32_t p_index_a, uint32_t p_index_b, int p_size) const override; + + virtual Vector2 font_draw_glyph(RID p_font, RID p_canvas, int p_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color = Color(1, 1, 1)) const override; + virtual Vector2 font_draw_glyph_outline(RID p_font, RID p_canvas, int p_size, int p_outline_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color = Color(1, 1, 1)) const override; + + virtual float font_get_oversampling() const override; + virtual void font_set_oversampling(float p_oversampling) override; + + virtual Vector get_system_fonts() const override; + + /* Shaped text buffer interface */ + + virtual RID create_shaped_text(Direction p_direction = DIRECTION_AUTO, Orientation p_orientation = ORIENTATION_HORIZONTAL) override; + + virtual void shaped_text_clear(RID p_shaped) override; + + virtual void shaped_text_set_direction(RID p_shaped, Direction p_direction = DIRECTION_AUTO) override; + virtual Direction shaped_text_get_direction(RID p_shaped) const override; + + virtual void shaped_text_set_bidi_override(RID p_shaped, const Vector &p_override) override; + + virtual void shaped_text_set_orientation(RID p_shaped, Orientation p_orientation = ORIENTATION_HORIZONTAL) override; + virtual Orientation shaped_text_get_orientation(RID p_shaped) const override; + + virtual void shaped_text_set_preserve_invalid(RID p_shaped, bool p_enabled) override; + virtual bool shaped_text_get_preserve_invalid(RID p_shaped) const override; + + virtual void shaped_text_set_preserve_control(RID p_shaped, bool p_enabled) override; + virtual bool shaped_text_get_preserve_control(RID p_shaped) const override; + + virtual bool shaped_text_add_string(RID p_shaped, const String &p_text, const Vector &p_fonts, int p_size, const Dictionary &p_opentype_features = Dictionary(), const String &p_language = "") override; + virtual bool shaped_text_add_object(RID p_shaped, Variant p_key, const Size2 &p_size, VAlign p_inline_align = VALIGN_CENTER, int p_length = 1) override; + virtual bool shaped_text_resize_object(RID p_shaped, Variant p_key, const Size2 &p_size, VAlign p_inline_align = VALIGN_CENTER) override; + + virtual RID shaped_text_substr(RID p_shaped, int p_start, int p_length) const override; + virtual RID shaped_text_get_parent(RID p_shaped) const override; + + virtual float shaped_text_fit_to_width(RID p_shaped, float p_width, uint8_t /*JustificationFlag*/ p_jst_flags = JUSTIFICATION_WORD_BOUND | JUSTIFICATION_KASHIDA) override; + virtual float shaped_text_tab_align(RID p_shaped, const Vector &p_tab_stops) override; + + virtual bool shaped_text_shape(RID p_shaped) override; + virtual bool shaped_text_update_breaks(RID p_shaped) override; + virtual bool shaped_text_update_justification_ops(RID p_shaped) override; + + virtual bool shaped_text_is_ready(RID p_shaped) const override; + + virtual Vector shaped_text_get_glyphs(RID p_shaped) const override; + + virtual Vector2i shaped_text_get_range(RID p_shaped) const override; + + virtual Vector shaped_text_sort_logical(RID p_shaped) override; + virtual Vector shaped_text_get_line_breaks_adv(RID p_shaped, const Vector &p_width, int p_start = 0, bool p_once = true, uint8_t /*TextBreakFlag*/ p_break_flags = BREAK_MANDATORY | BREAK_WORD_BOUND) const override; + virtual Vector shaped_text_get_line_breaks(RID p_shaped, float p_width, int p_start = 0, uint8_t p_break_flags = BREAK_MANDATORY | BREAK_WORD_BOUND) const override; + virtual Vector shaped_text_get_word_breaks(RID p_shaped) const override; + virtual Array shaped_text_get_objects(RID p_shaped) const override; + virtual Rect2 shaped_text_get_object_rect(RID p_shaped, Variant p_key) const override; + + virtual Size2 shaped_text_get_size(RID p_shaped) const override; + virtual float shaped_text_get_ascent(RID p_shaped) const override; + virtual float shaped_text_get_descent(RID p_shaped) const override; + virtual float shaped_text_get_width(RID p_shaped) const override; + virtual float shaped_text_get_underline_position(RID p_shaped) const override; + virtual float shaped_text_get_underline_thickness(RID p_shaped) const override; + + virtual String format_number(const String &p_string, const String &p_language = "") const override; + virtual String parse_number(const String &p_string, const String &p_language = "") const override; + virtual String percent_sign(const String &p_language = "") const override; + + static TextServer *create_func(Error &r_error, void *p_user_data); + + TextServerGDNative(); + ~TextServerGDNative(); +}; + +#endif // TEXT_SERVER_GDNATIVE_H diff --git a/modules/mono/editor/code_completion.cpp b/modules/mono/editor/code_completion.cpp index f1919c2501e4..2d37b1306cc5 100644 --- a/modules/mono/editor/code_completion.cpp +++ b/modules/mono/editor/code_completion.cpp @@ -228,6 +228,18 @@ PackedStringArray get_code_completion(CompletionKind p_kind, const String &p_scr } } } break; + case CompletionKind::THEME_FONT_SIZES: { + Ref