/
AuiLayout.cpp
186 lines (146 loc) · 5.64 KB
/
AuiLayout.cpp
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
#include "AuiLayout.h"
#include "i18n.h"
#include "ui/imenumanager.h"
#include "ui/igroupdialog.h"
#include "ui/imainframe.h"
#include "ui/iuserinterface.h"
#include <wx/sizer.h>
#include "camera/CameraWndManager.h"
#include "ui/texturebrowser/TextureBrowser.h"
#include "xyview/GlobalXYWnd.h"
namespace ui
{
namespace
{
const std::string RKEY_ROOT = "user/ui/mainFrame/aui";
// Minimum size of docked panels
const wxSize MIN_SIZE(128, 128);
// Return a pane info with default options
wxAuiPaneInfo DEFAULT_PANE_INFO(const std::string& caption,
const wxSize& minSize)
{
return wxAuiPaneInfo().Caption(caption).CloseButton(false)
.BestSize(minSize).MinSize(minSize);
}
}
AuiLayout::AuiLayout()
: _auiMgr(nullptr, wxAUI_MGR_ALLOW_FLOATING | wxAUI_MGR_VENETIAN_BLINDS_HINT |
wxAUI_MGR_LIVE_RESIZE)
{
}
void AuiLayout::addPane(wxWindow* window, const wxAuiPaneInfo& info)
{
// Give the pane a deterministic name so we can restore perspective
wxAuiPaneInfo nameInfo = info;
nameInfo.Name(std::to_string(_panes.size()));
// Add and store the pane
_auiMgr.AddPane(window, nameInfo);
_panes.push_back(window);
}
std::string AuiLayout::getName()
{
return AUI_LAYOUT_NAME;
}
void AuiLayout::activate()
{
auto topLevelParent = GlobalMainFrame().getWxTopLevelWindow();
// AUI manager can't manage a Sizer, we need to create an actual wxWindow
// container
auto managedArea = new wxWindow(topLevelParent, wxID_ANY);
_auiMgr.SetManagedWindow(managedArea);
GlobalMainFrame().getWxMainContainer()->Add(managedArea, 1, wxEXPAND);
auto notebookPanel = new wxPanel(managedArea, wxID_ANY);
notebookPanel->SetSizer(new wxBoxSizer(wxVERTICAL));
GlobalGroupDialog().reparentNotebook(notebookPanel);
// Hide the floating window
GlobalGroupDialog().hideDialogWindow();
// Add a new texture browser to the group dialog pages
auto textureBrowserControl = GlobalUserInterface().findControl(UserControl::TextureBrowser);
assert(textureBrowserControl);
GlobalGroupDialog().addControl(UserControl::TextureBrowser);
#if 0
// Texture Page
{
IGroupDialog::PagePtr page(new IGroupDialog::Page);
page->name = "textures";
page->windowLabel = _("Texture Browser");
page->page = textureBrowserControl->createWidget(notebookPanel);
page->tabIcon = "icon_texture.png";
page->tabLabel = _("Textures");
page->position = IGroupDialog::Page::Position::TextureBrowser;
GlobalGroupDialog().addPage(page);
}
#endif
auto orthoViewControl = GlobalUserInterface().findControl(UserControl::OrthoView);
auto cameraControl = GlobalUserInterface().findControl(UserControl::Camera);
assert(cameraControl);
assert(orthoViewControl);
// Add the camera and notebook to the left, as with the Embedded layout, and
// the 2D view on the right
wxSize size = topLevelParent->GetSize();
size.Scale(0.5, 1.0);
addPane(cameraControl->createWidget(managedArea),
DEFAULT_PANE_INFO(_("Camera"), size).Left().Position(0));
addPane(notebookPanel,
DEFAULT_PANE_INFO(_("Properties"), size).Left().Position(1));
addPane(orthoViewControl->createWidget(managedArea),
DEFAULT_PANE_INFO(_("2D View"), size).CenterPane());
_auiMgr.Update();
// Nasty hack to get the panes sized properly. Since BestSize() is
// completely ignored (at least on Linux), we have to add the panes with a
// large *minimum* size and then reset this size after the initial addition.
for (wxWindow* w: _panes)
{
_auiMgr.GetPane(w).MinSize(MIN_SIZE);
}
_auiMgr.Update();
// If we have a stored perspective, load it
std::string storedPersp = GlobalRegistry().get(RKEY_ROOT);
if (!storedPersp.empty())
{
_auiMgr.LoadPerspective(storedPersp);
}
// Hide the camera toggle option for non-floating views
GlobalMenuManager().setVisibility("main/view/cameraview", false);
// Hide the console/texture browser toggles for non-floating/non-split views
GlobalMenuManager().setVisibility("main/view/textureBrowser", false);
// Restore all floating XY views
GlobalXYWnd().restoreState();
}
void AuiLayout::deactivate()
{
// Save all floating XYWnd states
GlobalXYWnd().saveState();
// Store perspective
GlobalRegistry().set(RKEY_ROOT, _auiMgr.SavePerspective().ToStdString());
// Show the camera toggle option again
GlobalMenuManager().setVisibility("main/view/cameraview", true);
GlobalMenuManager().setVisibility("main/view/textureBrowser", true);
// Remove all previously stored pane information
// GlobalRegistry().deleteXPath(RKEY_ROOT + "//pane");
// Delete all active views
GlobalXYWndManager().destroyViews();
// Give the notebook back to the GroupDialog
GlobalGroupDialog().reparentNotebookToSelf();
// Hide the group dialog
GlobalGroupDialog().hideDialogWindow();
GlobalGroupDialog().removePage("textures"); // do this after destroyWindow()
// Get a reference to the managed window, it might be cleared by UnInit()
auto managedWindow = _auiMgr.GetManagedWindow();
// Unregister the AuiMgr from the event handlers of the managed window
// otherwise we run into crashes during shutdown (#5586)
_auiMgr.UnInit();
managedWindow->Destroy();
}
void AuiLayout::restoreStateFromRegistry()
{
}
void AuiLayout::toggleFullscreenCameraView()
{
}
// The creation function, needed by the mainframe layout manager
AuiLayoutPtr AuiLayout::CreateInstance()
{
return AuiLayoutPtr(new AuiLayout);
}
} // namespace ui