font_config_plugin.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. #ifndef FONT_CONFIG_PLUGIN_H
  31. #define FONT_CONFIG_PLUGIN_H
  32. #include "editor/editor_properties.h"
  33. #include "editor/editor_properties_array_dict.h"
  34. #include "editor/plugins/editor_plugin.h"
  35. /*************************************************************************/
  36. class EditorPropertyFontMetaObject : public RefCounted {
  37. GDCLASS(EditorPropertyFontMetaObject, RefCounted);
  38. Dictionary dict;
  39. protected:
  40. bool _set(const StringName &p_name, const Variant &p_value);
  41. bool _get(const StringName &p_name, Variant &r_ret) const;
  42. public:
  43. void set_dict(const Dictionary &p_dict);
  44. Dictionary get_dict();
  45. EditorPropertyFontMetaObject() {}
  46. };
  47. /*************************************************************************/
  48. class EditorPropertyFontOTObject : public RefCounted {
  49. GDCLASS(EditorPropertyFontOTObject, RefCounted);
  50. Dictionary dict;
  51. Dictionary defaults_dict;
  52. protected:
  53. bool _set(const StringName &p_name, const Variant &p_value);
  54. bool _get(const StringName &p_name, Variant &r_ret) const;
  55. bool _property_can_revert(const StringName &p_name) const;
  56. bool _property_get_revert(const StringName &p_name, Variant &r_property) const;
  57. public:
  58. void set_dict(const Dictionary &p_dict);
  59. Dictionary get_dict();
  60. void set_defaults(const Dictionary &p_dict);
  61. Dictionary get_defaults();
  62. EditorPropertyFontOTObject() {}
  63. };
  64. /*************************************************************************/
  65. class EditorPropertyFontMetaOverride : public EditorProperty {
  66. GDCLASS(EditorPropertyFontMetaOverride, EditorProperty);
  67. Ref<EditorPropertyFontMetaObject> object;
  68. MarginContainer *container = nullptr;
  69. VBoxContainer *property_vbox = nullptr;
  70. Button *button_add = nullptr;
  71. Button *edit = nullptr;
  72. PopupMenu *menu = nullptr;
  73. EditorLocaleDialog *locale_select = nullptr;
  74. Vector<String> script_codes;
  75. bool script_editor = false;
  76. bool updating = false;
  77. int page_length = 20;
  78. int page_index = 0;
  79. EditorPaginator *paginator = nullptr;
  80. protected:
  81. void _notification(int p_what);
  82. static void _bind_methods() {}
  83. void _edit_pressed();
  84. void _page_changed(int p_page);
  85. void _property_changed(const String &p_property, const Variant &p_value, const String &p_name = "", bool p_changing = false);
  86. void _remove(Object *p_button, const String &p_key);
  87. void _add_menu();
  88. void _add_script(int p_option);
  89. void _add_lang(const String &p_locale);
  90. void _object_id_selected(const StringName &p_property, ObjectID p_id);
  91. public:
  92. virtual void update_property() override;
  93. EditorPropertyFontMetaOverride(bool p_script);
  94. };
  95. /*************************************************************************/
  96. class EditorPropertyOTVariation : public EditorProperty {
  97. GDCLASS(EditorPropertyOTVariation, EditorProperty);
  98. Ref<EditorPropertyFontOTObject> object;
  99. MarginContainer *container = nullptr;
  100. VBoxContainer *property_vbox = nullptr;
  101. Button *edit = nullptr;
  102. bool updating = false;
  103. int page_length = 20;
  104. int page_index = 0;
  105. EditorPaginator *paginator = nullptr;
  106. protected:
  107. static void _bind_methods() {}
  108. void _edit_pressed();
  109. void _page_changed(int p_page);
  110. void _property_changed(const String &p_property, const Variant &p_value, const String &p_name = "", bool p_changing = false);
  111. void _object_id_selected(const StringName &p_property, ObjectID p_id);
  112. public:
  113. virtual void update_property() override;
  114. EditorPropertyOTVariation();
  115. };
  116. /*************************************************************************/
  117. class EditorPropertyOTFeatures : public EditorProperty {
  118. GDCLASS(EditorPropertyOTFeatures, EditorProperty);
  119. enum FeatureGroups {
  120. FGRP_STYLISTIC_SET,
  121. FGRP_CHARACTER_VARIANT,
  122. FGRP_CAPITLS,
  123. FGRP_LIGATURES,
  124. FGRP_ALTERNATES,
  125. FGRP_EAL,
  126. FGRP_EAW,
  127. FGRP_NUMAL,
  128. FGRP_CUSTOM,
  129. FGRP_MAX,
  130. };
  131. Ref<EditorPropertyFontOTObject> object;
  132. MarginContainer *container = nullptr;
  133. VBoxContainer *property_vbox = nullptr;
  134. Button *button_add = nullptr;
  135. Button *edit = nullptr;
  136. PopupMenu *menu = nullptr;
  137. PopupMenu *menu_sub[FGRP_MAX];
  138. String group_names[FGRP_MAX];
  139. bool updating = false;
  140. int page_length = 20;
  141. int page_index = 0;
  142. EditorPaginator *paginator = nullptr;
  143. protected:
  144. void _notification(int p_what);
  145. static void _bind_methods() {}
  146. void _edit_pressed();
  147. void _page_changed(int p_page);
  148. void _property_changed(const String &p_property, const Variant &p_value, const String &p_name = "", bool p_changing = false);
  149. void _remove(Object *p_button, int p_key);
  150. void _add_menu();
  151. void _add_feature(int p_option);
  152. void _object_id_selected(const StringName &p_property, ObjectID p_id);
  153. public:
  154. virtual void update_property() override;
  155. EditorPropertyOTFeatures();
  156. };
  157. /*************************************************************************/
  158. class EditorInspectorPluginFontVariation : public EditorInspectorPlugin {
  159. GDCLASS(EditorInspectorPluginFontVariation, EditorInspectorPlugin);
  160. public:
  161. virtual bool can_handle(Object *p_object) override;
  162. 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;
  163. };
  164. /*************************************************************************/
  165. class FontPreview : public Control {
  166. GDCLASS(FontPreview, Control);
  167. protected:
  168. void _notification(int p_what);
  169. static void _bind_methods();
  170. Ref<Font> prev_font;
  171. void _preview_changed();
  172. public:
  173. virtual Size2 get_minimum_size() const override;
  174. void set_data(const Ref<Font> &p_f);
  175. FontPreview();
  176. };
  177. /*************************************************************************/
  178. class EditorInspectorPluginFontPreview : public EditorInspectorPlugin {
  179. GDCLASS(EditorInspectorPluginFontPreview, EditorInspectorPlugin);
  180. public:
  181. virtual bool can_handle(Object *p_object) override;
  182. virtual void parse_begin(Object *p_object) override;
  183. 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;
  184. };
  185. /*************************************************************************/
  186. class EditorPropertyFontNamesArray : public EditorPropertyArray {
  187. GDCLASS(EditorPropertyFontNamesArray, EditorPropertyArray);
  188. PopupMenu *menu = nullptr;
  189. protected:
  190. virtual void _add_element() override;
  191. void _add_font(int p_option);
  192. static void _bind_methods() {}
  193. public:
  194. EditorPropertyFontNamesArray();
  195. };
  196. /*************************************************************************/
  197. class EditorInspectorPluginSystemFont : public EditorInspectorPlugin {
  198. GDCLASS(EditorInspectorPluginSystemFont, EditorInspectorPlugin);
  199. public:
  200. virtual bool can_handle(Object *p_object) override;
  201. 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;
  202. };
  203. /*************************************************************************/
  204. class FontEditorPlugin : public EditorPlugin {
  205. GDCLASS(FontEditorPlugin, EditorPlugin);
  206. public:
  207. FontEditorPlugin();
  208. virtual String get_plugin_name() const override { return "Font"; }
  209. };
  210. #endif // FONT_CONFIG_PLUGIN_H