From 50b4ac0d6eb55399f21afb065766732741d14077 Mon Sep 17 00:00:00 2001 From: Matthew Mott Date: Wed, 17 Feb 2021 20:19:57 +0000 Subject: [PATCH] Add an experimental AUI-based layout This layout approximates the Embedded layout but uses the wxWidgets AUI system to manage the components, allowing for panels to be moved, docked and floated as required by the user. Currently the basic layout works and the panels are in approximately the right positions, but the panels are very thin and have to be dragged out to fill the whole window, and there is no way to get them back if the close button is clicked. --- CMakeLists.txt | 4 +- radiant/CMakeLists.txt | 1 + radiant/ui/mainframe/AuiLayout.cpp | 133 ++++++++++++++++++ radiant/ui/mainframe/AuiLayout.h | 44 ++++++ .../ui/mainframe/MainFrameLayoutManager.cpp | 5 +- 5 files changed, 183 insertions(+), 4 deletions(-) create mode 100644 radiant/ui/mainframe/AuiLayout.cpp create mode 100644 radiant/ui/mainframe/AuiLayout.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a4fc3beeac..b7580c64b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,7 @@ pkg_check_modules(GLIB glib-2.0 REQUIRED) # Locate wxWidgets find_package(wxWidgets REQUIRED - COMPONENTS base core stc adv gl xrc) + COMPONENTS base core stc adv gl xrc aui) include(${wxWidgets_USE_FILE}) # Locate Python @@ -163,7 +163,7 @@ if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14") install(DIRECTORY install/i18n/de TYPE LOCALE FILES_MATCHING PATTERN "*.mo") else() -install(DIRECTORY install/i18n/de DESTINATION ${CMAKE_INSTALL_LOCALEDIR} +install(DIRECTORY install/i18n/de DESTINATION ${CMAKE_INSTALL_LOCALEDIR} FILES_MATCHING PATTERN "*.mo") endif() diff --git a/radiant/CMakeLists.txt b/radiant/CMakeLists.txt index cb8439a897..729e9db79b 100644 --- a/radiant/CMakeLists.txt +++ b/radiant/CMakeLists.txt @@ -91,6 +91,7 @@ add_executable(darkradiant ui/layers/LayerOrthoContextMenuItem.cpp ui/lightinspector/LightInspector.cpp ui/LongRunningOperationHandler.cpp + ui/mainframe/AuiLayout.cpp ui/mainframe/EmbeddedLayout.cpp ui/mainframe/FloatingLayout.cpp ui/mainframe/MainFrame.cpp diff --git a/radiant/ui/mainframe/AuiLayout.cpp b/radiant/ui/mainframe/AuiLayout.cpp new file mode 100644 index 0000000000..76909d6a3b --- /dev/null +++ b/radiant/ui/mainframe/AuiLayout.cpp @@ -0,0 +1,133 @@ +#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 +#include +#include + +#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"; +} + +AuiLayout::AuiLayout() +: _auiMgr(nullptr, wxAUI_MGR_ALLOW_FLOATING | wxAUI_MGR_VENETIAN_BLINDS_HINT | + wxAUI_MGR_LIVE_RESIZE) +{ +} + +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 + _auiMgr.AddPane(_camWnd->getMainWidget(), wxAuiPaneInfo().Left().Dockable().Dock()); + _auiMgr.AddPane(notebookPanel, wxAuiPaneInfo().Left().Dockable().Dock()); + _auiMgr.AddPane(xywnd->getGLWidget(), wxAuiPaneInfo().Right().Dockable().Dock()); + _auiMgr.Update(); + + topLevelParent->Layout(); + + // 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() +{ + // 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 diff --git a/radiant/ui/mainframe/AuiLayout.h b/radiant/ui/mainframe/AuiLayout.h new file mode 100644 index 0000000000..b83c9cf85a --- /dev/null +++ b/radiant/ui/mainframe/AuiLayout.h @@ -0,0 +1,44 @@ +#pragma once + +#include +#include "wxutil/PanedPosition.h" +#include "imainframelayout.h" + +#include "camera/CamWnd.h" +#include "wxutil/Splitter.h" + +#include + +namespace ui +{ + +#define AUI_LAYOUT_NAME "Dockable" + +class AuiLayout; +typedef std::shared_ptr AuiLayoutPtr; + +/// Layout based on wxWidgets AUI (dock widget interface) +class AuiLayout: public IMainFrameLayout +{ + // The camera view + CamWndPtr _camWnd; + + // Main AUI manager + wxAuiManager _auiMgr; + + // Main constructor + AuiLayout(); + +public: + // IMainFrameLayout implementation + std::string getName() override; + void activate() override; + void deactivate() override; + void toggleFullscreenCameraView() override; + void restoreStateFromRegistry() override; + + // The creation function, needed by the mainframe layout manager + static AuiLayoutPtr CreateInstance(); +}; + +} // namespace ui diff --git a/radiant/ui/mainframe/MainFrameLayoutManager.cpp b/radiant/ui/mainframe/MainFrameLayoutManager.cpp index b1d5050e12..ef4493f1bd 100644 --- a/radiant/ui/mainframe/MainFrameLayoutManager.cpp +++ b/radiant/ui/mainframe/MainFrameLayoutManager.cpp @@ -8,6 +8,7 @@ #include "module/StaticModule.h" +#include "AuiLayout.h" #include "FloatingLayout.h" #include "SplitPaneLayout.h" #include "RegularLayout.h" @@ -45,7 +46,7 @@ void MainFrameLayoutManager::registerLayout( } } -void MainFrameLayoutManager::registerCommands() +void MainFrameLayoutManager::registerCommands() { // remove all commands beforehand _commands.clear(); @@ -83,7 +84,7 @@ void MainFrameLayoutManager::initialiseModule(const IApplicationContext& ctx) // Register the default layouts registerLayout(EMBEDDED_LAYOUT_NAME, EmbeddedLayout::CreateInstance); - + registerLayout(AUI_LAYOUT_NAME, AuiLayout::CreateInstance); registerLayout(FLOATING_LAYOUT_NAME, FloatingLayout::CreateInstance); registerLayout(SPLITPANE_LAYOUT_NAME, SplitPaneLayout::CreateInstance); registerLayout(REGULAR_LAYOUT_NAME, RegularLayout::CreateRegularInstance);