Path: blob/master/editor/docks/editor_dock_manager.h
10277 views
/**************************************************************************/1/* editor_dock_manager.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "scene/gui/popup.h"33#include "scene/gui/split_container.h"3435class Button;36class ConfigFile;37class Control;38class PopupMenu;39class TabBar;40class TabContainer;41class VBoxContainer;42class WindowWrapper;43class StyleBoxFlat;4445class DockSplitContainer : public SplitContainer {46GDCLASS(DockSplitContainer, SplitContainer);4748private:49bool is_updating = false;5051protected:52void _update_visibility();5354virtual void add_child_notify(Node *p_child) override;55virtual void remove_child_notify(Node *p_child) override;5657public:58DockSplitContainer();59};6061class DockContextPopup;62class EditorDockDragHint;6364class EditorDockManager : public Object {65GDCLASS(EditorDockManager, Object);6667public:68enum DockSlot {69DOCK_SLOT_NONE = -1,70DOCK_SLOT_LEFT_UL,71DOCK_SLOT_LEFT_BL,72DOCK_SLOT_LEFT_UR,73DOCK_SLOT_LEFT_BR,74DOCK_SLOT_RIGHT_UL,75DOCK_SLOT_RIGHT_BL,76DOCK_SLOT_RIGHT_UR,77DOCK_SLOT_RIGHT_BR,78DOCK_SLOT_MAX79};8081private:82friend class DockContextPopup;83friend class EditorDockDragHint;8485struct DockInfo {86String title;87bool open = false;88bool enabled = true;89bool at_bottom = false;90int previous_tab_index = -1;91bool previous_at_bottom = false;92WindowWrapper *dock_window = nullptr;93int dock_slot_index = DOCK_SLOT_NONE;94Ref<Shortcut> shortcut;95Ref<Texture2D> icon; // Only used when `icon_name` is empty.96StringName icon_name;97};9899static EditorDockManager *singleton;100101// To access splits easily by index.102Vector<DockSplitContainer *> vsplits;103Vector<DockSplitContainer *> hsplits;104105Vector<WindowWrapper *> dock_windows;106TabContainer *dock_slot[DOCK_SLOT_MAX];107EditorDockDragHint *dock_drag_rects[DOCK_SLOT_MAX];108HashMap<Control *, DockInfo> all_docks;109Control *dock_tab_dragged = nullptr;110bool docks_visible = true;111112DockContextPopup *dock_context_popup = nullptr;113PopupMenu *docks_menu = nullptr;114Vector<Control *> docks_menu_docks;115Control *closed_dock_parent = nullptr;116117Control *_get_dock_tab_dragged();118void _dock_drag_stopped();119void _dock_split_dragged(int p_offset);120void _dock_container_gui_input(const Ref<InputEvent> &p_input, TabContainer *p_dock_container);121void _bottom_dock_button_gui_input(const Ref<InputEvent> &p_input, Control *p_dock, Button *p_bottom_button);122void _dock_container_update_visibility(TabContainer *p_dock_container);123void _update_layout();124125void _docks_menu_option(int p_id);126127void _window_close_request(WindowWrapper *p_wrapper);128Control *_close_window(WindowWrapper *p_wrapper);129void _open_dock_in_window(Control *p_dock, bool p_show_window = true, bool p_reset_size = false);130void _restore_dock_to_saved_window(Control *p_dock, const Dictionary &p_window_dump);131132void _dock_move_to_bottom(Control *p_dock, bool p_visible);133void _dock_remove_from_bottom(Control *p_dock);134bool _is_dock_at_bottom(Control *p_dock);135136void _move_dock_tab_index(Control *p_dock, int p_tab_index, bool p_set_current);137void _move_dock(Control *p_dock, Control *p_target, int p_tab_index = -1, bool p_set_current = true);138139void _update_tab_style(Control *p_dock);140141public:142static EditorDockManager *get_singleton() { return singleton; }143144void update_docks_menu();145void update_tab_styles();146void set_tab_icon_max_width(int p_max_width);147148void add_vsplit(DockSplitContainer *p_split);149void add_hsplit(DockSplitContainer *p_split);150void register_dock_slot(DockSlot p_dock_slot, TabContainer *p_tab_container);151int get_vsplit_count() const;152PopupMenu *get_docks_menu();153154void save_docks_to_config(Ref<ConfigFile> p_layout, const String &p_section) const;155void load_docks_from_config(Ref<ConfigFile> p_layout, const String &p_section, bool p_first_load = false);156157void set_dock_enabled(Control *p_dock, bool p_enabled);158void close_dock(Control *p_dock);159void open_dock(Control *p_dock, bool p_set_current = true);160void focus_dock(Control *p_dock);161162TabContainer *get_dock_tab_container(Control *p_dock) const;163164void bottom_dock_show_placement_popup(const Rect2i &p_position, Control *p_dock);165166void set_docks_visible(bool p_show);167bool are_docks_visible() const;168169void 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());170void remove_dock(Control *p_dock);171172void set_dock_tab_icon(Control *p_dock, const Ref<Texture2D> &p_icon);173174EditorDockManager();175};176177class EditorDockDragHint : public Control {178GDCLASS(EditorDockDragHint, Control);179180private:181EditorDockManager *dock_manager = nullptr;182EditorDockManager::DockSlot occupied_slot = EditorDockManager::DOCK_SLOT_MAX;183TabBar *drop_tabbar = nullptr;184185Color valid_drop_color;186Ref<StyleBoxFlat> dock_drop_highlight;187bool can_drop_dock = false;188bool mouse_inside = false;189bool mouse_inside_tabbar = false;190191void _drag_move_tab(int p_from_index, int p_to_index);192void _drag_move_tab_from(TabBar *p_from_tabbar, int p_from_index, int p_to_index);193194protected:195virtual void gui_input(const Ref<InputEvent> &p_event) override;196197void _notification(int p_what);198bool can_drop_data(const Point2 &p_point, const Variant &p_data) const override;199void drop_data(const Point2 &p_point, const Variant &p_data) override;200201public:202void set_slot(EditorDockManager::DockSlot p_slot);203204EditorDockDragHint();205};206207class DockContextPopup : public PopupPanel {208GDCLASS(DockContextPopup, PopupPanel);209210private:211VBoxContainer *dock_select_popup_vb = nullptr;212213Button *make_float_button = nullptr;214Button *tab_move_left_button = nullptr;215Button *tab_move_right_button = nullptr;216Button *close_button = nullptr;217Button *dock_to_bottom_button = nullptr;218219Control *dock_select = nullptr;220Rect2 dock_select_rects[EditorDockManager::DOCK_SLOT_MAX];221int dock_select_rect_over_idx = -1;222223Control *context_dock = nullptr;224225EditorDockManager *dock_manager = nullptr;226227void _tab_move_left();228void _tab_move_right();229void _close_dock();230void _float_dock();231void _move_dock_to_bottom();232233void _dock_select_input(const Ref<InputEvent> &p_input);234void _dock_select_mouse_exited();235void _dock_select_draw();236237void _update_buttons();238239protected:240void _notification(int p_what);241242public:243void select_current_dock_in_dock_slot(int p_dock_slot);244void set_dock(Control *p_dock);245Control *get_dock() const;246void docks_updated();247248DockContextPopup();249};250251252