Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/docks/editor_dock_manager.h
9903 views
1
/**************************************************************************/
2
/* editor_dock_manager.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
#pragma once
32
33
#include "scene/gui/popup.h"
34
#include "scene/gui/split_container.h"
35
36
class Button;
37
class ConfigFile;
38
class Control;
39
class PopupMenu;
40
class TabBar;
41
class TabContainer;
42
class VBoxContainer;
43
class WindowWrapper;
44
class StyleBoxFlat;
45
46
class DockSplitContainer : public SplitContainer {
47
GDCLASS(DockSplitContainer, SplitContainer);
48
49
private:
50
bool is_updating = false;
51
52
protected:
53
void _update_visibility();
54
55
virtual void add_child_notify(Node *p_child) override;
56
virtual void remove_child_notify(Node *p_child) override;
57
58
public:
59
DockSplitContainer();
60
};
61
62
class DockContextPopup;
63
class EditorDockDragHint;
64
65
class EditorDockManager : public Object {
66
GDCLASS(EditorDockManager, Object);
67
68
public:
69
enum DockSlot {
70
DOCK_SLOT_NONE = -1,
71
DOCK_SLOT_LEFT_UL,
72
DOCK_SLOT_LEFT_BL,
73
DOCK_SLOT_LEFT_UR,
74
DOCK_SLOT_LEFT_BR,
75
DOCK_SLOT_RIGHT_UL,
76
DOCK_SLOT_RIGHT_BL,
77
DOCK_SLOT_RIGHT_UR,
78
DOCK_SLOT_RIGHT_BR,
79
DOCK_SLOT_MAX
80
};
81
82
private:
83
friend class DockContextPopup;
84
friend class EditorDockDragHint;
85
86
struct DockInfo {
87
String title;
88
bool open = false;
89
bool enabled = true;
90
bool at_bottom = false;
91
int previous_tab_index = -1;
92
bool previous_at_bottom = false;
93
WindowWrapper *dock_window = nullptr;
94
int dock_slot_index = DOCK_SLOT_NONE;
95
Ref<Shortcut> shortcut;
96
Ref<Texture2D> icon; // Only used when `icon_name` is empty.
97
StringName icon_name;
98
};
99
100
static EditorDockManager *singleton;
101
102
// To access splits easily by index.
103
Vector<DockSplitContainer *> vsplits;
104
Vector<DockSplitContainer *> hsplits;
105
106
Vector<WindowWrapper *> dock_windows;
107
TabContainer *dock_slot[DOCK_SLOT_MAX];
108
EditorDockDragHint *dock_drag_rects[DOCK_SLOT_MAX];
109
HashMap<Control *, DockInfo> all_docks;
110
Control *dock_tab_dragged = nullptr;
111
bool docks_visible = true;
112
113
DockContextPopup *dock_context_popup = nullptr;
114
PopupMenu *docks_menu = nullptr;
115
Vector<Control *> docks_menu_docks;
116
Control *closed_dock_parent = nullptr;
117
118
Control *_get_dock_tab_dragged();
119
void _dock_drag_stopped();
120
void _dock_split_dragged(int p_offset);
121
void _dock_container_gui_input(const Ref<InputEvent> &p_input, TabContainer *p_dock_container);
122
void _bottom_dock_button_gui_input(const Ref<InputEvent> &p_input, Control *p_dock, Button *p_bottom_button);
123
void _dock_container_update_visibility(TabContainer *p_dock_container);
124
void _update_layout();
125
126
void _docks_menu_option(int p_id);
127
128
void _window_close_request(WindowWrapper *p_wrapper);
129
Control *_close_window(WindowWrapper *p_wrapper);
130
void _open_dock_in_window(Control *p_dock, bool p_show_window = true, bool p_reset_size = false);
131
void _restore_dock_to_saved_window(Control *p_dock, const Dictionary &p_window_dump);
132
133
void _dock_move_to_bottom(Control *p_dock, bool p_visible);
134
void _dock_remove_from_bottom(Control *p_dock);
135
bool _is_dock_at_bottom(Control *p_dock);
136
137
void _move_dock_tab_index(Control *p_dock, int p_tab_index, bool p_set_current);
138
void _move_dock(Control *p_dock, Control *p_target, int p_tab_index = -1, bool p_set_current = true);
139
140
void _update_tab_style(Control *p_dock);
141
142
public:
143
static EditorDockManager *get_singleton() { return singleton; }
144
145
void update_docks_menu();
146
void update_tab_styles();
147
void set_tab_icon_max_width(int p_max_width);
148
149
void add_vsplit(DockSplitContainer *p_split);
150
void add_hsplit(DockSplitContainer *p_split);
151
void register_dock_slot(DockSlot p_dock_slot, TabContainer *p_tab_container);
152
int get_vsplit_count() const;
153
PopupMenu *get_docks_menu();
154
155
void save_docks_to_config(Ref<ConfigFile> p_layout, const String &p_section) const;
156
void load_docks_from_config(Ref<ConfigFile> p_layout, const String &p_section, bool p_first_load = false);
157
158
void set_dock_enabled(Control *p_dock, bool p_enabled);
159
void close_dock(Control *p_dock);
160
void open_dock(Control *p_dock, bool p_set_current = true);
161
void focus_dock(Control *p_dock);
162
163
TabContainer *get_dock_tab_container(Control *p_dock) const;
164
165
void bottom_dock_show_placement_popup(const Rect2i &p_position, Control *p_dock);
166
167
void set_docks_visible(bool p_show);
168
bool are_docks_visible() const;
169
170
void add_dock(Control *p_dock, const String &p_title = "", DockSlot p_slot = DOCK_SLOT_NONE, const Ref<Shortcut> &p_shortcut = nullptr, const StringName &p_icon_name = StringName());
171
void remove_dock(Control *p_dock);
172
173
void set_dock_tab_icon(Control *p_dock, const Ref<Texture2D> &p_icon);
174
175
EditorDockManager();
176
};
177
178
class EditorDockDragHint : public Control {
179
GDCLASS(EditorDockDragHint, Control);
180
181
private:
182
EditorDockManager *dock_manager = nullptr;
183
EditorDockManager::DockSlot occupied_slot = EditorDockManager::DOCK_SLOT_MAX;
184
TabBar *drop_tabbar = nullptr;
185
186
Color valid_drop_color;
187
Ref<StyleBoxFlat> dock_drop_highlight;
188
bool can_drop_dock = false;
189
bool mouse_inside = false;
190
bool mouse_inside_tabbar = false;
191
192
void _drag_move_tab(int p_from_index, int p_to_index);
193
void _drag_move_tab_from(TabBar *p_from_tabbar, int p_from_index, int p_to_index);
194
195
protected:
196
virtual void gui_input(const Ref<InputEvent> &p_event) override;
197
198
void _notification(int p_what);
199
bool can_drop_data(const Point2 &p_point, const Variant &p_data) const override;
200
void drop_data(const Point2 &p_point, const Variant &p_data) override;
201
202
public:
203
void set_slot(EditorDockManager::DockSlot p_slot);
204
205
EditorDockDragHint();
206
};
207
208
class DockContextPopup : public PopupPanel {
209
GDCLASS(DockContextPopup, PopupPanel);
210
211
private:
212
VBoxContainer *dock_select_popup_vb = nullptr;
213
214
Button *make_float_button = nullptr;
215
Button *tab_move_left_button = nullptr;
216
Button *tab_move_right_button = nullptr;
217
Button *close_button = nullptr;
218
Button *dock_to_bottom_button = nullptr;
219
220
Control *dock_select = nullptr;
221
Rect2 dock_select_rects[EditorDockManager::DOCK_SLOT_MAX];
222
int dock_select_rect_over_idx = -1;
223
224
Control *context_dock = nullptr;
225
226
EditorDockManager *dock_manager = nullptr;
227
228
void _tab_move_left();
229
void _tab_move_right();
230
void _close_dock();
231
void _float_dock();
232
void _move_dock_to_bottom();
233
234
void _dock_select_input(const Ref<InputEvent> &p_input);
235
void _dock_select_mouse_exited();
236
void _dock_select_draw();
237
238
void _update_buttons();
239
240
protected:
241
void _notification(int p_what);
242
243
public:
244
void select_current_dock_in_dock_slot(int p_dock_slot);
245
void set_dock(Control *p_dock);
246
Control *get_dock() const;
247
void docks_updated();
248
249
DockContextPopup();
250
};
251
252