editor_dock_manager.h 7.2 KB

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