1 | /**************************************************************************/ |
2 | /* theme_editor_preview.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 THEME_EDITOR_PREVIEW_H |
32 | #define THEME_EDITOR_PREVIEW_H |
33 | |
34 | #include "scene/gui/box_container.h" |
35 | #include "scene/resources/theme.h" |
36 | |
37 | class Button; |
38 | class ColorPickerButton; |
39 | class ColorRect; |
40 | class MarginContainer; |
41 | class ScrollContainer; |
42 | |
43 | class ThemeEditorPreview : public VBoxContainer { |
44 | GDCLASS(ThemeEditorPreview, VBoxContainer); |
45 | |
46 | ScrollContainer *preview_container = nullptr; |
47 | MarginContainer *preview_root = nullptr; |
48 | ColorRect *preview_bg = nullptr; |
49 | MarginContainer *preview_overlay = nullptr; |
50 | Control *picker_overlay = nullptr; |
51 | Control *hovered_control = nullptr; |
52 | |
53 | struct ThemeCache { |
54 | Ref<StyleBox> preview_picker_overlay; |
55 | Color preview_picker_overlay_color; |
56 | Ref<StyleBox> preview_picker_label; |
57 | Ref<Font> preview_picker_font; |
58 | int font_size = 16; |
59 | } theme_cache; |
60 | |
61 | double time_left = 0; |
62 | |
63 | void _propagate_redraw(Control *p_at); |
64 | void _refresh_interval(); |
65 | void _preview_visibility_changed(); |
66 | |
67 | void _picker_button_cbk(); |
68 | Control *_find_hovered_control(Control *p_parent, Vector2 p_mouse_position); |
69 | |
70 | void _draw_picker_overlay(); |
71 | void _gui_input_picker_overlay(const Ref<InputEvent> &p_event); |
72 | void _reset_picker_overlay(); |
73 | |
74 | protected: |
75 | HBoxContainer *preview_toolbar = nullptr; |
76 | MarginContainer *preview_content = nullptr; |
77 | Button *picker_button = nullptr; |
78 | |
79 | void add_preview_overlay(Control *p_overlay); |
80 | |
81 | void _notification(int p_what); |
82 | static void _bind_methods(); |
83 | |
84 | public: |
85 | void set_preview_theme(const Ref<Theme> &p_theme); |
86 | |
87 | ThemeEditorPreview(); |
88 | }; |
89 | |
90 | class DefaultThemeEditorPreview : public ThemeEditorPreview { |
91 | GDCLASS(DefaultThemeEditorPreview, ThemeEditorPreview); |
92 | |
93 | ColorPickerButton *test_color_picker_button = nullptr; |
94 | |
95 | protected: |
96 | void _notification(int p_what); |
97 | |
98 | public: |
99 | DefaultThemeEditorPreview(); |
100 | }; |
101 | |
102 | class SceneThemeEditorPreview : public ThemeEditorPreview { |
103 | GDCLASS(SceneThemeEditorPreview, ThemeEditorPreview); |
104 | |
105 | Ref<PackedScene> loaded_scene; |
106 | |
107 | Button *reload_scene_button = nullptr; |
108 | |
109 | void _reload_scene(); |
110 | |
111 | protected: |
112 | void _notification(int p_what); |
113 | static void _bind_methods(); |
114 | |
115 | public: |
116 | bool set_preview_scene(const String &p_path); |
117 | String get_preview_scene_path() const; |
118 | |
119 | SceneThemeEditorPreview(); |
120 | }; |
121 | |
122 | #endif // THEME_EDITOR_PREVIEW_H |
123 | |