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