dynamic_font_import_settings.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /**************************************************************************/
  2. /* dynamic_font_import_settings.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 DYNAMIC_FONT_IMPORT_SETTINGS_H
  31. #define DYNAMIC_FONT_IMPORT_SETTINGS_H
  32. #include "editor/import/resource_importer_dynamic_font.h"
  33. #include "core/templates/rb_set.h"
  34. #include "scene/gui/dialogs.h"
  35. #include "scene/gui/item_list.h"
  36. #include "scene/gui/option_button.h"
  37. #include "scene/gui/split_container.h"
  38. #include "scene/gui/subviewport_container.h"
  39. #include "scene/gui/tab_container.h"
  40. #include "scene/gui/text_edit.h"
  41. #include "scene/gui/tree.h"
  42. #include "scene/resources/font.h"
  43. #include "servers/text_server.h"
  44. class DynamicFontImportSettingsDialog;
  45. class DynamicFontImportSettingsData : public RefCounted {
  46. GDCLASS(DynamicFontImportSettingsData, RefCounted)
  47. friend class DynamicFontImportSettingsDialog;
  48. HashMap<StringName, Variant> settings;
  49. HashMap<StringName, Variant> defaults;
  50. List<ResourceImporter::ImportOption> options;
  51. DynamicFontImportSettingsDialog *owner = nullptr;
  52. HashSet<char32_t> selected_chars;
  53. HashSet<int32_t> selected_glyphs;
  54. Ref<FontFile> fd;
  55. public:
  56. bool _set(const StringName &p_name, const Variant &p_value);
  57. bool _get(const StringName &p_name, Variant &r_ret) const;
  58. void _get_property_list(List<PropertyInfo> *p_list) const;
  59. Ref<FontFile> get_font() const;
  60. };
  61. class EditorFileDialog;
  62. class EditorInspector;
  63. class EditorLocaleDialog;
  64. class DynamicFontImportSettingsDialog : public ConfirmationDialog {
  65. GDCLASS(DynamicFontImportSettingsDialog, ConfirmationDialog)
  66. friend class DynamicFontImportSettingsData;
  67. enum ItemButton {
  68. BUTTON_ADD_VAR,
  69. BUTTON_REMOVE_VAR,
  70. };
  71. static DynamicFontImportSettingsDialog *singleton;
  72. String base_path;
  73. Ref<DynamicFontImportSettingsData> import_settings_data;
  74. List<ResourceImporter::ImportOption> options_variations;
  75. List<ResourceImporter::ImportOption> options_general;
  76. // Root layout
  77. Label *label_warn = nullptr;
  78. TabContainer *main_pages = nullptr;
  79. // Page 1 layout: Rendering Options
  80. Label *page1_description = nullptr;
  81. Label *font_name_label = nullptr;
  82. Label *font_preview_label = nullptr;
  83. EditorInspector *inspector_general = nullptr;
  84. void _main_prop_changed(const String &p_edited_property);
  85. // Page 2 layout: Preload Configurations
  86. Label *page2_description = nullptr;
  87. Label *label_vars = nullptr;
  88. Button *add_var = nullptr;
  89. Tree *vars_list = nullptr;
  90. TreeItem *vars_list_root = nullptr;
  91. EditorInspector *inspector_vars = nullptr;
  92. void _variation_add();
  93. void _variation_selected();
  94. void _variation_remove(Object *p_item, int p_column, int p_id, MouseButton p_button);
  95. void _variation_changed(const String &p_edited_property);
  96. void _variations_validate();
  97. TabContainer *preload_pages = nullptr;
  98. Label *label_glyphs = nullptr;
  99. void _glyph_clear();
  100. void _glyph_update_lbl();
  101. // Page 2.0 layout: Translations
  102. Label *page2_0_description = nullptr;
  103. Tree *locale_tree = nullptr;
  104. TreeItem *locale_root = nullptr;
  105. Button *btn_fill_locales = nullptr;
  106. void _locale_edited();
  107. void _process_locales();
  108. // Page 2.1 layout: Text to select glyphs
  109. Label *page2_1_description = nullptr;
  110. TextEdit *text_edit = nullptr;
  111. EditorInspector *inspector_text = nullptr;
  112. Button *btn_fill = nullptr;
  113. List<ResourceImporter::ImportOption> options_text;
  114. Ref<DynamicFontImportSettingsData> text_settings_data;
  115. void _change_text_opts();
  116. void _glyph_text_selected();
  117. // Page 2.2 layout: Character map
  118. Label *page2_2_description = nullptr;
  119. Tree *glyph_table = nullptr;
  120. Tree *glyph_tree = nullptr;
  121. TreeItem *glyph_root = nullptr;
  122. void _glyph_selected();
  123. void _range_edited();
  124. void _range_selected();
  125. void _edit_range(int32_t p_start, int32_t p_end);
  126. bool _char_update(int32_t p_char);
  127. void _range_update(int32_t p_start, int32_t p_end);
  128. // Common
  129. void _add_glyph_range_item(int32_t p_start, int32_t p_end, const String &p_name);
  130. Ref<FontFile> font_preview;
  131. Ref<FontFile> font_main;
  132. void _re_import();
  133. String _pad_zeros(const String &p_hex) const;
  134. protected:
  135. void _notification(int p_what);
  136. public:
  137. void open_settings(const String &p_path);
  138. static DynamicFontImportSettingsDialog *get_singleton();
  139. DynamicFontImportSettingsDialog();
  140. };
  141. #endif // DYNAMIC_FONT_IMPORT_SETTINGS_H