font_config_plugin.h 9.4 KB

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