1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
/*************************************************************************/
/* control_editor_plugin.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef CONTROL_EDITOR_PLUGIN_H
#define CONTROL_EDITOR_PLUGIN_H
#include "editor/editor_node.h"
#include "editor/editor_plugin.h"
#include "scene/gui/box_container.h"
#include "scene/gui/check_box.h"
#include "scene/gui/control.h"
#include "scene/gui/label.h"
#include "scene/gui/margin_container.h"
#include "scene/gui/option_button.h"
#include "scene/gui/panel_container.h"
#include "scene/gui/texture_rect.h"
class ControlPositioningWarning : public MarginContainer {
GDCLASS(ControlPositioningWarning, MarginContainer);
Control *control_node = nullptr;
PanelContainer *bg_panel = nullptr;
GridContainer *grid = nullptr;
TextureRect *title_icon = nullptr;
TextureRect *hint_icon = nullptr;
Label *title_label = nullptr;
Label *hint_label = nullptr;
Control *hint_filler_left = nullptr;
Control *hint_filler_right = nullptr;
void _update_warning();
void _update_toggler();
virtual void gui_input(const Ref<InputEvent> &p_event) override;
protected:
void _notification(int p_notification);
public:
void set_control(Control *p_node);
ControlPositioningWarning();
};
class EditorPropertyAnchorsPreset : public EditorProperty {
GDCLASS(EditorPropertyAnchorsPreset, EditorProperty);
OptionButton *options;
void _option_selected(int p_which);
protected:
virtual void _set_read_only(bool p_read_only) override;
public:
void setup(const Vector<String> &p_options);
virtual void update_property() override;
EditorPropertyAnchorsPreset();
};
class EditorPropertySizeFlags : public EditorProperty {
GDCLASS(EditorPropertySizeFlags, EditorProperty);
enum FlagPreset {
SIZE_FLAGS_PRESET_FILL,
SIZE_FLAGS_PRESET_SHRINK_BEGIN,
SIZE_FLAGS_PRESET_SHRINK_CENTER,
SIZE_FLAGS_PRESET_SHRINK_END,
SIZE_FLAGS_PRESET_CUSTOM,
};
OptionButton *flag_presets;
CheckBox *flag_expand;
VBoxContainer *flag_options;
Vector<CheckBox *> flag_checks;
bool vertical = false;
bool keep_selected_preset = false;
void _preset_selected(int p_which);
void _expand_toggled();
void _flag_toggled();
protected:
virtual void _set_read_only(bool p_read_only) override;
public:
void setup(const Vector<String> &p_options, bool p_vertical);
virtual void update_property() override;
EditorPropertySizeFlags();
};
class EditorInspectorPluginControl : public EditorInspectorPlugin {
GDCLASS(EditorInspectorPluginControl, EditorInspectorPlugin);
public:
virtual bool can_handle(Object *p_object) override;
virtual void parse_group(Object *p_object, const String &p_group) override;
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 uint32_t p_usage, const bool p_wide = false) override;
};
class ControlEditorToolbar : public HBoxContainer {
GDCLASS(ControlEditorToolbar, HBoxContainer);
UndoRedo *undo_redo;
EditorSelection *editor_selection;
enum MenuOption {
ANCHORS_AND_OFFSETS_PRESET_TOP_LEFT,
ANCHORS_AND_OFFSETS_PRESET_TOP_RIGHT,
ANCHORS_AND_OFFSETS_PRESET_BOTTOM_LEFT,
ANCHORS_AND_OFFSETS_PRESET_BOTTOM_RIGHT,
ANCHORS_AND_OFFSETS_PRESET_CENTER_LEFT,
ANCHORS_AND_OFFSETS_PRESET_CENTER_RIGHT,
ANCHORS_AND_OFFSETS_PRESET_CENTER_TOP,
ANCHORS_AND_OFFSETS_PRESET_CENTER_BOTTOM,
ANCHORS_AND_OFFSETS_PRESET_CENTER,
ANCHORS_AND_OFFSETS_PRESET_TOP_WIDE,
ANCHORS_AND_OFFSETS_PRESET_LEFT_WIDE,
ANCHORS_AND_OFFSETS_PRESET_RIGHT_WIDE,
ANCHORS_AND_OFFSETS_PRESET_BOTTOM_WIDE,
ANCHORS_AND_OFFSETS_PRESET_VCENTER_WIDE,
ANCHORS_AND_OFFSETS_PRESET_HCENTER_WIDE,
ANCHORS_AND_OFFSETS_PRESET_WIDE,
ANCHORS_AND_OFFSETS_PRESET_KEEP_RATIO,
ANCHORS_PRESET_TOP_LEFT,
ANCHORS_PRESET_TOP_RIGHT,
ANCHORS_PRESET_BOTTOM_LEFT,
ANCHORS_PRESET_BOTTOM_RIGHT,
ANCHORS_PRESET_CENTER_LEFT,
ANCHORS_PRESET_CENTER_RIGHT,
ANCHORS_PRESET_CENTER_TOP,
ANCHORS_PRESET_CENTER_BOTTOM,
ANCHORS_PRESET_CENTER,
ANCHORS_PRESET_TOP_WIDE,
ANCHORS_PRESET_LEFT_WIDE,
ANCHORS_PRESET_RIGHT_WIDE,
ANCHORS_PRESET_BOTTOM_WIDE,
ANCHORS_PRESET_VCENTER_WIDE,
ANCHORS_PRESET_HCENTER_WIDE,
ANCHORS_PRESET_WIDE,
// Offsets Presets are not currently in use.
OFFSETS_PRESET_TOP_LEFT,
OFFSETS_PRESET_TOP_RIGHT,
OFFSETS_PRESET_BOTTOM_LEFT,
OFFSETS_PRESET_BOTTOM_RIGHT,
OFFSETS_PRESET_CENTER_LEFT,
OFFSETS_PRESET_CENTER_RIGHT,
OFFSETS_PRESET_CENTER_TOP,
OFFSETS_PRESET_CENTER_BOTTOM,
OFFSETS_PRESET_CENTER,
OFFSETS_PRESET_TOP_WIDE,
OFFSETS_PRESET_LEFT_WIDE,
OFFSETS_PRESET_RIGHT_WIDE,
OFFSETS_PRESET_BOTTOM_WIDE,
OFFSETS_PRESET_VCENTER_WIDE,
OFFSETS_PRESET_HCENTER_WIDE,
OFFSETS_PRESET_WIDE,
CONTAINERS_H_PRESET_FILL,
CONTAINERS_H_PRESET_FILL_EXPAND,
CONTAINERS_H_PRESET_SHRINK_BEGIN,
CONTAINERS_H_PRESET_SHRINK_CENTER,
CONTAINERS_H_PRESET_SHRINK_END,
CONTAINERS_V_PRESET_FILL,
CONTAINERS_V_PRESET_FILL_EXPAND,
CONTAINERS_V_PRESET_SHRINK_BEGIN,
CONTAINERS_V_PRESET_SHRINK_CENTER,
CONTAINERS_V_PRESET_SHRINK_END,
};
TextureRect *anchor_layouts_icon;
MenuButton *anchor_presets_menu;
PopupMenu *anchors_popup;
TextureRect *container_layouts_icon;
MenuButton *container_h_presets_menu;
MenuButton *container_v_presets_menu;
Button *anchor_mode_button;
bool anchors_mode = false;
void _set_anchors_preset(Control::LayoutPreset p_preset);
void _set_anchors_and_offsets_preset(Control::LayoutPreset p_preset);
void _set_anchors_and_offsets_to_keep_ratio();
void _set_container_h_preset(Control::SizeFlags p_preset);
void _set_container_v_preset(Control::SizeFlags p_preset);
Vector2 _anchor_to_position(const Control *p_control, Vector2 anchor);
Vector2 _position_to_anchor(const Control *p_control, Vector2 position);
void _button_toggle_anchor_mode(bool p_status);
bool _is_node_locked(const Node *p_node);
List<Control *> _get_edited_controls(bool retrieve_locked = false, bool remove_controls_if_parent_in_selection = true);
void _popup_callback(int p_op);
void _selection_changed();
protected:
void _notification(int p_notification);
static ControlEditorToolbar *singleton;
public:
bool is_anchors_mode_enabled() { return anchors_mode; };
static ControlEditorToolbar *get_singleton() { return singleton; }
ControlEditorToolbar();
};
class ControlEditorPlugin : public EditorPlugin {
GDCLASS(ControlEditorPlugin, EditorPlugin);
ControlEditorToolbar *toolbar;
public:
virtual String get_name() const override { return "Control"; }
ControlEditorPlugin();
};
#endif //CONTROL_EDITOR_PLUGIN_H
|