editor_dock_manager.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. #ifndef EDITOR_DOCK_MANAGER_H
  31. #define EDITOR_DOCK_MANAGER_H
  32. #include "scene/gui/popup.h"
  33. #include "scene/gui/split_container.h"
  34. class Button;
  35. class ConfigFile;
  36. class Control;
  37. class PopupMenu;
  38. class TabContainer;
  39. class VBoxContainer;
  40. class WindowWrapper;
  41. class DockSplitContainer : public SplitContainer {
  42. GDCLASS(DockSplitContainer, SplitContainer);
  43. private:
  44. bool is_updating = false;
  45. protected:
  46. void _update_visibility();
  47. virtual void add_child_notify(Node *p_child) override;
  48. virtual void remove_child_notify(Node *p_child) override;
  49. };
  50. class DockContextPopup;
  51. class EditorDockManager : public Object {
  52. GDCLASS(EditorDockManager, Object);
  53. public:
  54. enum DockSlot {
  55. DOCK_SLOT_NONE = -1,
  56. DOCK_SLOT_LEFT_UL,
  57. DOCK_SLOT_LEFT_BL,
  58. DOCK_SLOT_LEFT_UR,
  59. DOCK_SLOT_LEFT_BR,
  60. DOCK_SLOT_RIGHT_UL,
  61. DOCK_SLOT_RIGHT_BL,
  62. DOCK_SLOT_RIGHT_UR,
  63. DOCK_SLOT_RIGHT_BR,
  64. DOCK_SLOT_MAX
  65. };
  66. private:
  67. friend class DockContextPopup;
  68. struct DockInfo {
  69. String title;
  70. bool open = false;
  71. bool enabled = true;
  72. bool at_bottom = false;
  73. int previous_tab_index = -1;
  74. bool previous_at_bottom = false;
  75. WindowWrapper *dock_window = nullptr;
  76. int dock_slot_index = DOCK_SLOT_NONE;
  77. Ref<Shortcut> shortcut;
  78. Ref<Texture2D> icon; // Only used when `icon_name` is empty.
  79. StringName icon_name;
  80. };
  81. static EditorDockManager *singleton;
  82. // To access splits easily by index.
  83. Vector<DockSplitContainer *> vsplits;
  84. Vector<DockSplitContainer *> hsplits;
  85. Vector<WindowWrapper *> dock_windows;
  86. TabContainer *dock_slot[DOCK_SLOT_MAX];
  87. HashMap<Control *, DockInfo> all_docks;
  88. bool docks_visible = true;
  89. DockContextPopup *dock_context_popup = nullptr;
  90. PopupMenu *docks_menu = nullptr;
  91. Vector<Control *> docks_menu_docks;
  92. Control *closed_dock_parent = nullptr;
  93. void _dock_split_dragged(int p_offset);
  94. void _dock_container_gui_input(const Ref<InputEvent> &p_input, TabContainer *p_dock_container);
  95. void _bottom_dock_button_gui_input(const Ref<InputEvent> &p_input, Control *p_dock, Button *p_bottom_button);
  96. void _dock_container_update_visibility(TabContainer *p_dock_container);
  97. void _update_layout();
  98. void _update_docks_menu();
  99. void _docks_menu_option(int p_id);
  100. void _window_close_request(WindowWrapper *p_wrapper);
  101. Control *_close_window(WindowWrapper *p_wrapper);
  102. void _open_dock_in_window(Control *p_dock, bool p_show_window = true, bool p_reset_size = false);
  103. void _restore_dock_to_saved_window(Control *p_dock, const Dictionary &p_window_dump);
  104. void _dock_move_to_bottom(Control *p_dock);
  105. void _dock_remove_from_bottom(Control *p_dock);
  106. bool _is_dock_at_bottom(Control *p_dock);
  107. void _move_dock_tab_index(Control *p_dock, int p_tab_index, bool p_set_current);
  108. void _move_dock(Control *p_dock, Control *p_target, int p_tab_index = -1, bool p_set_current = true);
  109. void _update_tab_style(Control *p_dock);
  110. public:
  111. static EditorDockManager *get_singleton() { return singleton; }
  112. void update_tab_styles();
  113. void set_tab_icon_max_width(int p_max_width);
  114. void add_vsplit(DockSplitContainer *p_split);
  115. void add_hsplit(DockSplitContainer *p_split);
  116. void register_dock_slot(DockSlot p_dock_slot, TabContainer *p_tab_container);
  117. int get_vsplit_count() const;
  118. PopupMenu *get_docks_menu();
  119. void save_docks_to_config(Ref<ConfigFile> p_layout, const String &p_section) const;
  120. void load_docks_from_config(Ref<ConfigFile> p_layout, const String &p_section);
  121. void set_dock_enabled(Control *p_dock, bool p_enabled);
  122. void close_dock(Control *p_dock);
  123. void open_dock(Control *p_dock, bool p_set_current = true);
  124. void focus_dock(Control *p_dock);
  125. TabContainer *get_dock_tab_container(Control *p_dock) const;
  126. void bottom_dock_show_placement_popup(const Rect2i &p_position, Control *p_dock);
  127. void set_docks_visible(bool p_show);
  128. bool are_docks_visible() const;
  129. 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());
  130. void remove_dock(Control *p_dock);
  131. void set_dock_tab_icon(Control *p_dock, const Ref<Texture2D> &p_icon);
  132. EditorDockManager();
  133. };
  134. class DockContextPopup : public PopupPanel {
  135. GDCLASS(DockContextPopup, PopupPanel);
  136. VBoxContainer *dock_select_popup_vb = nullptr;
  137. Button *make_float_button = nullptr;
  138. Button *tab_move_left_button = nullptr;
  139. Button *tab_move_right_button = nullptr;
  140. Button *close_button = nullptr;
  141. Button *dock_to_bottom_button = nullptr;
  142. Control *dock_select = nullptr;
  143. Rect2 dock_select_rects[EditorDockManager::DOCK_SLOT_MAX];
  144. int dock_select_rect_over_idx = -1;
  145. Control *context_dock = nullptr;
  146. EditorDockManager *dock_manager = nullptr;
  147. void _tab_move_left();
  148. void _tab_move_right();
  149. void _close_dock();
  150. void _float_dock();
  151. void _move_dock_to_bottom();
  152. void _dock_select_input(const Ref<InputEvent> &p_input);
  153. void _dock_select_mouse_exited();
  154. void _dock_select_draw();
  155. void _update_buttons();
  156. protected:
  157. void _notification(int p_what);
  158. public:
  159. void select_current_dock_in_dock_slot(int p_dock_slot);
  160. void set_dock(Control *p_dock);
  161. Control *get_dock() const;
  162. void docks_updated();
  163. DockContextPopup();
  164. };
  165. #endif // EDITOR_DOCK_MANAGER_H