/
AuiLayout.cpp
177 lines (139 loc) · 5.15 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
#include "AuiLayout.h"
#include "i18n.h"
#include "itextstream.h"
#include "ieventmanager.h"
#include "imenumanager.h"
#include "igroupdialog.h"
#include "imainframe.h"
#include "ientityinspector.h"
#include <wx/sizer.h>
#include <wx/splitter.h>
#include <functional>
#include "camera/CameraWndManager.h"
#include "ui/texturebrowser/TextureBrowser.h"
#include "xyview/GlobalXYWnd.h"
#include "registry/registry.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).Layer(1).CloseButton(false)
.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()
{
wxFrame* topLevelParent = GlobalMainFrame().getWxTopLevelWindow();
// AUI manager can't manage a Sizer, we need to create an actual wxWindow
// container
wxWindow* managedArea = new wxWindow(topLevelParent, wxID_ANY);
_auiMgr.SetManagedWindow(managedArea);
GlobalMainFrame().getWxMainContainer()->Add(managedArea, 1, wxEXPAND);
// Allocate a new OrthoView and set its ViewType to XY
XYWndPtr xywnd = GlobalXYWnd().createEmbeddedOrthoView(XY, managedArea);
// Create a new camera window and parent it
_camWnd = GlobalCamera().createCamWnd(managedArea);
wxPanel* 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
wxWindow* textureBrowser = new TextureBrowser(notebookPanel);
// Texture Page
{
IGroupDialog::PagePtr page(new IGroupDialog::Page);
page->name = "textures";
page->windowLabel = _("Texture Browser");
page->page = textureBrowser;
page->tabIcon = "icon_texture.png";
page->tabLabel = _("Textures");
page->position = IGroupDialog::Page::Position::TextureBrowser;
GlobalGroupDialog().addPage(page);
}
// 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(xywnd->getGLWidget(),
DEFAULT_PANE_INFO(_("2D View"), size).Right());
addPane(_camWnd->getMainWidget(),
DEFAULT_PANE_INFO(_("Camera"), size).Left().Position(0));
addPane(notebookPanel,
DEFAULT_PANE_INFO(_("Properties"), size).Left().Position(1));
_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);
}
void AuiLayout::deactivate()
{
// 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();
// Delete the CamWnd
_camWnd.reset();
// Give the notebook back to the GroupDialog
GlobalGroupDialog().reparentNotebookToSelf();
// Hide the group dialog
GlobalGroupDialog().hideDialogWindow();
GlobalGroupDialog().removePage("textures"); // do this after destroyWindow()
}
void AuiLayout::restoreStateFromRegistry()
{
}
void AuiLayout::toggleFullscreenCameraView()
{
}
// The creation function, needed by the mainframe layout manager
AuiLayoutPtr AuiLayout::CreateInstance()
{
return AuiLayoutPtr(new AuiLayout);
}
} // namespace ui