Skip to content

Commit

Permalink
#6131: Migrate LayerControlPanel to derive from wxPanel, create adapt…
Browse files Browse the repository at this point in the history
…er for docking
  • Loading branch information
codereader committed Oct 18, 2022
1 parent e81fe4d commit 2bc1a60
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 74 deletions.
8 changes: 4 additions & 4 deletions radiant/ui/UserInterfaceModule.cpp
Expand Up @@ -36,7 +36,6 @@
#include "ui/prefdialog/GameSetupDialog.h"
#include "ui/modelselector/ModelSelector.h"
#include "ui/layers/LayerOrthoContextMenuItem.h"
#include "ui/layers/LayerControlPanel.h"
#include "ui/overlay/OverlayDialog.h"
#include "ui/prefdialog/PrefDialog.h"
#include "ui/Documentation.h"
Expand Down Expand Up @@ -75,6 +74,7 @@
#include <wx/version.h>

#include "console/ConsoleControl.h"
#include "layers/LayerControl.h"
#include "surfaceinspector/SurfaceInspectorControl.h"

namespace ui
Expand Down Expand Up @@ -164,9 +164,6 @@ void UserInterfaceModule::initialiseModule(const IApplicationContext& ctx)
IOrthoContextMenu::SECTION_LAYER
);

GlobalMainFrame().signal_MainFrameConstructed().connect(
sigc::ptr_fun(LayerControlPanel::onMainFrameConstructed));

// Pre-load models
module::GlobalModuleRegistry().signal_allModulesInitialised().connect(
sigc::ptr_fun(ModelSelector::Populate)
Expand Down Expand Up @@ -253,10 +250,13 @@ void UserInterfaceModule::initialiseModule(const IApplicationContext& ctx)

registerControl(std::make_shared<ConsoleControl>());
registerControl(std::make_shared<SurfaceInspectorControl>());
registerControl(std::make_shared<LayerControl>());

GlobalMainFrame().signal_MainFrameConstructed().connect([&]()
{
// Set default locations of some controls
GlobalMainFrame().addControl(UserControl::SurfaceInspector, { IMainFrame::Location::FloatingWindow, false });
GlobalMainFrame().addControl(UserControl::LayerControlPanel, { IMainFrame::Location::FloatingWindow, false });
});
}

Expand Down
34 changes: 34 additions & 0 deletions radiant/ui/layers/LayerControl.h
@@ -0,0 +1,34 @@
#pragma once

#include "ui/iusercontrol.h"
#include "LayerControlPanel.h"

namespace ui
{

class LayerControl :
public IUserControl
{
public:
std::string getControlName() override
{
return UserControl::LayerControlPanel;
}

std::string getDisplayName() override
{
return _("Layers");
}

std::string getIcon() override
{
return "layers.png";
}

wxWindow* createWidget(wxWindow* parent) override
{
return new LayerControlPanel(parent);
}
};

}
58 changes: 2 additions & 56 deletions radiant/ui/layers/LayerControlPanel.cpp
@@ -1,10 +1,8 @@
#include "LayerControlPanel.h"

#include "i18n.h"
#include "iregistry.h"
#include "itextstream.h"
#include "ilayer.h"
#include "ui/imainframe.h"
#include "iselection.h"

#include <wx/bmpbuttn.h>
Expand All @@ -29,14 +27,8 @@
namespace ui
{

namespace
{
const std::string RKEY_ROOT = "user/ui/layers/controlDialog/";
const std::string RKEY_WINDOW_STATE = RKEY_ROOT + "window";
}

LayerControlPanel::LayerControlPanel() :
TransientWindow(_("Layers"), GlobalMainFrame().getWxTopLevelWindow(), true),
LayerControlPanel::LayerControlPanel(wxWindow* parent) :
wxPanel(parent),
_layersView(nullptr),
_showAllLayers(nullptr),
_hideAllLayers(nullptr),
Expand All @@ -47,9 +39,6 @@ LayerControlPanel::LayerControlPanel() :
populateWindow();

Bind(wxEVT_IDLE, [&](wxIdleEvent&) { onIdle(); });

InitialiseWindowPosition(230, 400, RKEY_WINDOW_STATE);
SetMinClientSize(wxSize(230, 200));
}

void LayerControlPanel::populateWindow()
Expand Down Expand Up @@ -383,23 +372,8 @@ void LayerControlPanel::onIdle()
}
}

void LayerControlPanel::onMainFrameConstructed()
{
// Lookup the stored window information in the registry
if (GlobalRegistry().getAttribute(RKEY_WINDOW_STATE, "visible") == "1")
{
// Show dialog
Instance().Show();
}
}

void LayerControlPanel::onMainFrameShuttingDown()
{
rMessage() << "LayerControlPanel shutting down." << std::endl;

// Write the visibility status to the registry
GlobalRegistry().setAttribute(RKEY_WINDOW_STATE, "visible", IsShownOnScreen() ? "1" : "0");

// Hide the window and save its state
if (IsShownOnScreen())
{
Expand All @@ -408,38 +382,10 @@ void LayerControlPanel::onMainFrameShuttingDown()

// Destroy the window
SendDestroyEvent();

// Final step: clear the instance pointer
InstancePtr().reset();
}

std::shared_ptr<LayerControlPanel>& LayerControlPanel::InstancePtr()
{
static std::shared_ptr<LayerControlPanel> _instancePtr;
return _instancePtr;
}

LayerControlPanel& LayerControlPanel::Instance()
{
auto& instancePtr = InstancePtr();

if (!instancePtr)
{
// Not yet instantiated, do it now
instancePtr.reset(new LayerControlPanel);

// Pre-destruction cleanup
GlobalMainFrame().signal_MainFrameShuttingDown().connect(
sigc::mem_fun(*instancePtr, &LayerControlPanel::onMainFrameShuttingDown));
}

return *instancePtr;
}

void LayerControlPanel::_preShow()
{
TransientWindow::_preShow();

_selectionChangedSignal = GlobalSelectionSystem().signal_selectionChanged().connect([this](const ISelectable&)
{
_rescanSelectionOnIdle = true;
Expand Down
17 changes: 4 additions & 13 deletions radiant/ui/layers/LayerControlPanel.h
Expand Up @@ -2,8 +2,6 @@

#include <map>
#include "imap.h"
#include "icommandsystem.h"
#include "wxutil/window/TransientWindow.h"

#include <wx/panel.h>
#include <sigc++/connection.h>
Expand All @@ -24,7 +22,7 @@ namespace ui
{

class LayerControlPanel :
public wxutil::TransientWindow
public wxPanel
{
private:
struct TreeColumns :
Expand Down Expand Up @@ -68,21 +66,14 @@ class LayerControlPanel :
sigc::connection _mapEventSignal;

public:
LayerControlPanel();

// Checks if dialog should be shown after startup
static void onMainFrameConstructed();

static LayerControlPanel& Instance();
LayerControlPanel(wxWindow* parent);

private:
static std::shared_ptr<LayerControlPanel>& InstancePtr();

void onMainFrameShuttingDown();

// TransientWindow events
void _preShow() override;
void _postHide() override;
void _preShow();
void _postHide();

// Calls refresh() on the next idle event
void queueRefresh();
Expand Down
2 changes: 1 addition & 1 deletion radiant/ui/mainframe/AuiLayout.cpp
Expand Up @@ -41,7 +41,7 @@ namespace

void setupFloatingPane(wxAuiPaneInfo& pane)
{
pane.Float().CloseButton(true).MinSize(300, 450);
pane.Float().CloseButton(true).MinSize(128, 128);
}
}

Expand Down
1 change: 1 addition & 0 deletions tools/msvc/DarkRadiant.vcxproj
Expand Up @@ -462,6 +462,7 @@
<ClInclude Include="..\..\radiant\ui\groupdialog\GroupDialog.h" />
<ClInclude Include="..\..\radiant\ui\groupdialog\GroupDialogManager.h" />
<ClInclude Include="..\..\radiant\ui\layers\CreateLayerDialog.h" />
<ClInclude Include="..\..\radiant\ui\layers\LayerControl.h" />
<ClInclude Include="..\..\radiant\ui\layers\LayerControlPanel.h" />
<ClInclude Include="..\..\radiant\ui\LongRunningOperationHandler.h" />
<ClInclude Include="..\..\radiant\ui\mainframe\AuiLayout.h" />
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/DarkRadiant.vcxproj.filters
Expand Up @@ -1410,6 +1410,9 @@
<ClInclude Include="..\..\radiant\ui\layers\LayerControlPanel.h">
<Filter>src\ui\layers</Filter>
</ClInclude>
<ClInclude Include="..\..\radiant\ui\layers\LayerControl.h">
<Filter>src\ui\layers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\radiant\darkradiant.rc" />
Expand Down

0 comments on commit 2bc1a60

Please sign in to comment.