dynamic_font_import_settings.h 6.0 KB

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