font_config_plugin.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /**************************************************************************/
  2. /* font_config_plugin.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #pragma once
  31. #include "editor/editor_properties.h"
  32. #include "editor/editor_properties_array_dict.h"
  33. #include "editor/plugins/editor_plugin.h"
  34. /*************************************************************************/
  35. class EditorPropertyFontMetaObject : public RefCounted {
  36. GDCLASS(EditorPropertyFontMetaObject, RefCounted);
  37. Dictionary dict;
  38. protected:
  39. bool _set(const StringName &p_name, const Variant &p_value);
  40. bool _get(const StringName &p_name, Variant &r_ret) const;
  41. public:
  42. void set_dict(const Dictionary &p_dict);
  43. Dictionary get_dict();
  44. };
  45. /*************************************************************************/
  46. class EditorPropertyFontOTObject : public RefCounted {
  47. GDCLASS(EditorPropertyFontOTObject, RefCounted);
  48. Dictionary dict;
  49. Dictionary defaults_dict;
  50. protected:
  51. bool _set(const StringName &p_name, const Variant &p_value);
  52. bool _get(const StringName &p_name, Variant &r_ret) const;
  53. bool _property_can_revert(const StringName &p_name) const;
  54. bool _property_get_revert(const StringName &p_name, Variant &r_property) const;
  55. public:
  56. void set_dict(const Dictionary &p_dict);
  57. Dictionary get_dict();
  58. void set_defaults(const Dictionary &p_dict);
  59. Dictionary get_defaults();
  60. };
  61. /*************************************************************************/
  62. class EditorPropertyFontMetaOverride : public EditorProperty {
  63. GDCLASS(EditorPropertyFontMetaOverride, EditorProperty);
  64. Ref<EditorPropertyFontMetaObject> object;
  65. MarginContainer *container = nullptr;
  66. VBoxContainer *property_vbox = nullptr;
  67. Button *button_add = nullptr;
  68. Button *edit = nullptr;
  69. PopupMenu *menu = nullptr;
  70. EditorLocaleDialog *locale_select = nullptr;
  71. Vector<String> script_codes;
  72. bool script_editor = false;
  73. bool updating = false;
  74. int page_length = 20;
  75. int page_index = 0;
  76. EditorPaginator *paginator = nullptr;
  77. protected:
  78. void _notification(int p_what);
  79. static void _bind_methods() {}
  80. void _edit_pressed();
  81. void _page_changed(int p_page);
  82. void _property_changed(const String &p_property, const Variant &p_value, const String &p_name = "", bool p_changing = false);
  83. void _remove(Object *p_button, const String &p_key);
  84. void _add_menu();
  85. void _add_script(int p_option);
  86. void _add_lang(const String &p_locale);
  87. void _object_id_selected(const StringName &p_property, ObjectID p_id);
  88. public:
  89. virtual void update_property() override;
  90. EditorPropertyFontMetaOverride(bool p_script);
  91. };
  92. /*************************************************************************/
  93. class EditorPropertyOTVariation : public EditorProperty {
  94. GDCLASS(EditorPropertyOTVariation, EditorProperty);
  95. Ref<EditorPropertyFontOTObject> object;
  96. MarginContainer *container = nullptr;
  97. VBoxContainer *property_vbox = nullptr;
  98. Button *edit = nullptr;
  99. bool updating = false;
  100. int page_length = 20;
  101. int page_index = 0;
  102. EditorPaginator *paginator = nullptr;
  103. protected:
  104. static void _bind_methods() {}
  105. void _edit_pressed();
  106. void _page_changed(int p_page);
  107. void _property_changed(const String &p_property, const Variant &p_value, const String &p_name = "", bool p_changing = false);
  108. void _object_id_selected(const StringName &p_property, ObjectID p_id);
  109. public:
  110. virtual void update_property() override;
  111. EditorPropertyOTVariation();
  112. };
  113. /*************************************************************************/
  114. class EditorPropertyOTFeatures : public EditorProperty {
  115. GDCLASS(EditorPropertyOTFeatures, EditorProperty);
  116. enum FeatureGroups {
  117. FGRP_STYLISTIC_SET,
  118. FGRP_CHARACTER_VARIANT,
  119. FGRP_CAPITLS,
  120. FGRP_LIGATURES,
  121. FGRP_ALTERNATES,
  122. FGRP_EAL,
  123. FGRP_EAW,
  124. FGRP_NUMAL,
  125. FGRP_CUSTOM,
  126. FGRP_MAX,
  127. };
  128. Ref<EditorPropertyFontOTObject> object;
  129. MarginContainer *container = nullptr;
  130. VBoxContainer *property_vbox = nullptr;
  131. Button *button_add = nullptr;
  132. Button *edit = nullptr;
  133. PopupMenu *menu = nullptr;
  134. PopupMenu *menu_sub[FGRP_MAX];
  135. String group_names[FGRP_MAX];
  136. bool updating = false;
  137. int page_length = 20;
  138. int page_index = 0;
  139. EditorPaginator *paginator = nullptr;
  140. protected:
  141. void _notification(int p_what);
  142. static void _bind_methods() {}
  143. void _edit_pressed();
  144. void _page_changed(int p_page);
  145. void _property_changed(const String &p_property, const Variant &p_value, const String &p_name = "", bool p_changing = false);
  146. void _remove(Object *p_button, int p_key);
  147. void _add_menu();
  148. void _add_feature(int p_option);
  149. void _object_id_selected(const StringName &p_property, ObjectID p_id);
  150. public:
  151. virtual void update_property() override;
  152. EditorPropertyOTFeatures();
  153. };
  154. /*************************************************************************/
  155. class EditorInspectorPluginFontVariation : public EditorInspectorPlugin {
  156. GDCLASS(EditorInspectorPluginFontVariation, EditorInspectorPlugin);
  157. public:
  158. virtual bool can_handle(Object *p_object) override;
  159. virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide = false) override;
  160. };
  161. /*************************************************************************/
  162. class FontPreview : public Control {
  163. GDCLASS(FontPreview, Control);
  164. protected:
  165. void _notification(int p_what);
  166. static void _bind_methods();
  167. Ref<Font> prev_font;
  168. void _preview_changed();
  169. public:
  170. virtual Size2 get_minimum_size() const override;
  171. void set_data(const Ref<Font> &p_f);
  172. };
  173. /*************************************************************************/
  174. class EditorInspectorPluginFontPreview : public EditorInspectorPlugin {
  175. GDCLASS(EditorInspectorPluginFontPreview, EditorInspectorPlugin);
  176. public:
  177. virtual bool can_handle(Object *p_object) override;
  178. virtual void parse_begin(Object *p_object) override;
  179. virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide = false) override;
  180. };
  181. /*************************************************************************/
  182. class EditorPropertyFontNamesArray : public EditorPropertyArray {
  183. GDCLASS(EditorPropertyFontNamesArray, EditorPropertyArray);
  184. PopupMenu *menu = nullptr;
  185. protected:
  186. virtual void _add_element() override;
  187. void _add_font(int p_option);
  188. static void _bind_methods() {}
  189. public:
  190. EditorPropertyFontNamesArray();
  191. };
  192. /*************************************************************************/
  193. class EditorInspectorPluginSystemFont : public EditorInspectorPlugin {
  194. GDCLASS(EditorInspectorPluginSystemFont, EditorInspectorPlugin);
  195. public:
  196. virtual bool can_handle(Object *p_object) override;
  197. virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide = false) override;
  198. };
  199. /*************************************************************************/
  200. class FontEditorPlugin : public EditorPlugin {
  201. GDCLASS(FontEditorPlugin, EditorPlugin);
  202. public:
  203. FontEditorPlugin();
  204. virtual String get_plugin_name() const override { return "Font"; }
  205. };