Skip to content

Commit

Permalink
Add an experimental AUI-based layout
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Matthew Mott committed Feb 17, 2021
1 parent d8f98d9 commit 50b4ac0
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
1 change: 1 addition & 0 deletions radiant/CMakeLists.txt
Expand Up @@ -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
Expand Down
133 changes: 133 additions & 0 deletions 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 <wx/sizer.h>
#include <wx/splitter.h>
#include <functional>

#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
44 changes: 44 additions & 0 deletions radiant/ui/mainframe/AuiLayout.h
@@ -0,0 +1,44 @@
#pragma once

#include <memory>
#include "wxutil/PanedPosition.h"
#include "imainframelayout.h"

#include "camera/CamWnd.h"
#include "wxutil/Splitter.h"

#include <wx/aui/aui.h>

namespace ui
{

#define AUI_LAYOUT_NAME "Dockable"

class AuiLayout;
typedef std::shared_ptr<AuiLayout> 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
5 changes: 3 additions & 2 deletions radiant/ui/mainframe/MainFrameLayoutManager.cpp
Expand Up @@ -8,6 +8,7 @@

#include "module/StaticModule.h"

#include "AuiLayout.h"
#include "FloatingLayout.h"
#include "SplitPaneLayout.h"
#include "RegularLayout.h"
Expand Down Expand Up @@ -45,7 +46,7 @@ void MainFrameLayoutManager::registerLayout(
}
}

void MainFrameLayoutManager::registerCommands()
void MainFrameLayoutManager::registerCommands()
{
// remove all commands beforehand
_commands.clear();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 50b4ac0

Please sign in to comment.