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