Skip to content

Commit

Permalink
#6131: Convert TransformDialog to a dockable control
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Oct 21, 2022
1 parent a6e78c9 commit 90638f7
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 152 deletions.
1 change: 1 addition & 0 deletions include/ui/iusercontrol.h
Expand Up @@ -50,6 +50,7 @@ struct UserControl
constexpr static const char* LightInspector = "LightInspector";
constexpr static const char* LayerControlPanel = "LayerControlPanel";
constexpr static const char* TextureTool = "TextureTool";
constexpr static const char* TransformPanel = "TransformPanel";
};

}
5 changes: 2 additions & 3 deletions install/user.xml
Expand Up @@ -72,15 +72,14 @@
<offsetClonedObjects value="1" />
<manipulatorFontSize value="14" />
<manipulatorFontStyle value="Sans" />
<transformDialog>
<window xPosition="150" yPosition="200" width="260" height="314" />
<transformPanel>
<rotXStep value="45" />
<rotYStep value="45" />
<rotZStep value="45" />
<scaleXStep value="1.1" />
<scaleYStep value="1.1" />
<scaleZStep value="1.1" />
</transformDialog>
</transformPanel>
<layers>
<controlDialog>
<window xPosition="57" yPosition="449" width="164" height="299" />
Expand Down
6 changes: 4 additions & 2 deletions radiant/ui/UserInterfaceModule.cpp
Expand Up @@ -42,7 +42,6 @@
#include "ui/console/Console.h"
#include "ui/lightinspector/LightInspector.h"
#include "ui/patch/PatchInspector.h"
#include "ui/transform/TransformDialog.h"
#include "ui/findshader/FindShader.h"
#include "ui/mapinfo/MapInfoDialog.h"
#include "ui/commandlist/CommandList.h"
Expand Down Expand Up @@ -79,6 +78,7 @@
#include "patch/PatchInspectorControl.h"
#include "surfaceinspector/SurfaceInspectorControl.h"
#include "textool/TextureToolControl.h"
#include "transform/TransformPanelControl.h"

namespace ui
{
Expand Down Expand Up @@ -257,6 +257,7 @@ void UserInterfaceModule::initialiseModule(const IApplicationContext& ctx)
registerControl(std::make_shared<TextureToolControl>());
registerControl(std::make_shared<PatchInspectorControl>());
registerControl(std::make_shared<LightInspectorControl>());
registerControl(std::make_shared<TransformPanelControl>());

GlobalMainFrame().signal_MainFrameConstructed().connect([&]()
{
Expand All @@ -266,6 +267,7 @@ void UserInterfaceModule::initialiseModule(const IApplicationContext& ctx)
GlobalMainFrame().addControl(UserControl::TextureTool, { IMainFrame::Location::FloatingWindow, false });
GlobalMainFrame().addControl(UserControl::PatchInspector, { IMainFrame::Location::FloatingWindow, false });
GlobalMainFrame().addControl(UserControl::LightInspector, { IMainFrame::Location::FloatingWindow, false });
GlobalMainFrame().addControl(UserControl::TransformPanel, { IMainFrame::Location::FloatingWindow, false });
});
}

Expand Down Expand Up @@ -430,10 +432,10 @@ void UserInterfaceModule::registerUICommands()
GlobalCommandSystem().addStatement("SurfaceInspector", fmt::format("ToggleControl {0}", UserControl::SurfaceInspector), false);
GlobalCommandSystem().addStatement("ToggleLayerControlDialog", fmt::format("ToggleControl {0}", UserControl::LayerControlPanel), false);
GlobalCommandSystem().addStatement("PatchInspector", fmt::format("ToggleControl {0}", UserControl::PatchInspector), false);
GlobalCommandSystem().addStatement("TransformDialog", fmt::format("ToggleControl {0}", UserControl::TransformPanel), false);

GlobalCommandSystem().addCommand("MergeControlDialog", MergeControlDialog::ShowDialog);
GlobalCommandSystem().addCommand("OverlayDialog", OverlayDialog::toggle);
GlobalCommandSystem().addCommand("TransformDialog", TransformDialog::toggle);
GlobalCommandSystem().addCommand("ChooseAndTogglePointfile",
[](const cmd::ArgumentList&)
{ PointFileChooser::chooseAndToggle(); });
Expand Down
@@ -1,11 +1,8 @@
#include "TransformDialog.h"
#include "TransformPanel.h"

#include "i18n.h"
#include "icommandsystem.h"
#include "ui/imainframe.h"
#include "itextstream.h"
#include "selectionlib.h"
#include "string/string.h"
#include "registry/Widgets.h"

#include "wxutil/ControlButton.h"
Expand All @@ -22,22 +19,20 @@ namespace ui

namespace
{
const char* const WINDOW_TITLE = N_("Arbitrary Transformation");
const char* const LABEL_ROTATION = N_("Rotation");
const char* const LABEL_SCALE = N_("Scale");
constexpr const char* const LABEL_ROTATION = N_("Rotation");
constexpr const char* const LABEL_SCALE = N_("Scale");

const char* const LABEL_ROTX = N_("X-Axis Rotate:");
const char* const LABEL_ROTY = N_("Y-Axis Rotate:");
const char* const LABEL_ROTZ = N_("Z-Axis Rotate:");
constexpr const char* const LABEL_ROTX = N_("X-Axis Rotate:");
constexpr const char* const LABEL_ROTY = N_("Y-Axis Rotate:");
constexpr const char* const LABEL_ROTZ = N_("Z-Axis Rotate:");

const char* const LABEL_SCALEX = N_("X-Axis Scale:");
const char* const LABEL_SCALEY = N_("Y-Axis Scale:");
const char* const LABEL_SCALEZ = N_("Z-Axis Scale:");
constexpr const char* const LABEL_SCALEX = N_("X-Axis Scale:");
constexpr const char* const LABEL_SCALEY = N_("Y-Axis Scale:");
constexpr const char* const LABEL_SCALEZ = N_("Z-Axis Scale:");

const char* const LABEL_STEP = N_("Step:");
constexpr const char* const LABEL_STEP = N_("Step:");

const std::string RKEY_ROOT = "user/ui/transformDialog/";
const std::string RKEY_WINDOW_STATE = RKEY_ROOT + "window";
const std::string RKEY_ROOT = "user/ui/transformPanel/";
const std::string RKEY_ROTX_STEP = RKEY_ROOT + "rotXStep";
const std::string RKEY_ROTY_STEP = RKEY_ROOT + "rotYStep";
const std::string RKEY_ROTZ_STEP = RKEY_ROOT + "rotZStep";
Expand All @@ -47,72 +42,32 @@ namespace
const std::string RKEY_SCALEZ_STEP = RKEY_ROOT + "scaleZStep";
}

TransformDialog::TransformDialog()
: TransientWindow(_(WINDOW_TITLE), GlobalMainFrame().getWxTopLevelWindow(), true),
_selectionInfo(GlobalSelectionSystem().getSelectionInfo())
TransformPanel::TransformPanel(wxWindow* parent) :
wxPanel(parent),
_selectionInfo(GlobalSelectionSystem().getSelectionInfo())
{
// Create all the widgets and pack them into the window
populateWindow();

// Update the widget sensitivity
update();
_selectionChanged.disconnect();

InitialiseWindowPosition(260, 314, RKEY_WINDOW_STATE);
}

void TransformDialog::onMainFrameShuttingDown()
{
rMessage() << "TransformDialog shutting down." << std::endl;
// Register self to the SelSystem to get notified upon selection changes.
_selectionChanged = GlobalSelectionSystem().signal_selectionChanged().connect(
[this](const ISelectable&) { update(); });

if (IsShownOnScreen())
{
Hide();
}

// Destroy the window
SendDestroyEvent();
InstancePtr().reset();
}

TransformDialogPtr& TransformDialog::InstancePtr()
{
static TransformDialogPtr _instancePtr;

if (_instancePtr == NULL)
{
// Not yet instantiated, do it now
_instancePtr = TransformDialogPtr(new TransformDialog);

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

return _instancePtr;
}

TransformDialog& TransformDialog::Instance()
{
return *InstancePtr();
}

// The command target
void TransformDialog::toggle(const cmd::ArgumentList& args)
{
Instance().ToggleVisibility();
// Update the widget sensitivity
update();
}

void TransformDialog::populateWindow()
void TransformPanel::populateWindow()
{
wxPanel* dialogPanel = new wxPanel(this, wxID_ANY);
dialogPanel->SetSizer(new wxBoxSizer(wxVERTICAL));
SetSizer(new wxBoxSizer(wxVERTICAL));

wxBoxSizer* overallVBox = new wxBoxSizer(wxVERTICAL);
dialogPanel->GetSizer()->Add(overallVBox, 1, wxEXPAND | wxALL, 12);
GetSizer()->Add(overallVBox, 1, wxEXPAND | wxALL, 12);

_rotatePanel = new wxPanel(dialogPanel, wxID_ANY);
_scalePanel = new wxPanel(dialogPanel, wxID_ANY);
_rotatePanel = new wxPanel(this, wxID_ANY);
_scalePanel = new wxPanel(this, wxID_ANY);

overallVBox->Add(_rotatePanel, 0, wxEXPAND);
overallVBox->Add(_scalePanel, 1, wxEXPAND);
Expand Down Expand Up @@ -161,12 +116,12 @@ void TransformDialog::populateWindow()
EntryRow& row = i->second;

// Pass a EntryRow pointer to the callback, that's all it will need to update
row.smaller->Bind(wxEVT_BUTTON, std::bind(&TransformDialog::onClickSmaller, this, std::placeholders::_1, &row));
row.larger->Bind(wxEVT_BUTTON, std::bind(&TransformDialog::onClickLarger, this, std::placeholders::_1, &row));
row.smaller->Bind(wxEVT_BUTTON, std::bind(&TransformPanel::onClickSmaller, this, std::placeholders::_1, &row));
row.larger->Bind(wxEVT_BUTTON, std::bind(&TransformPanel::onClickLarger, this, std::placeholders::_1, &row));
}
}

TransformDialog::EntryRow TransformDialog::createEntryRow(
TransformPanel::EntryRow TransformPanel::createEntryRow(
const std::string& label, wxSizer* table, bool isRotator, int axis)
{
EntryRow entryRow;
Expand Down Expand Up @@ -218,30 +173,12 @@ TransformDialog::EntryRow TransformDialog::createEntryRow(
return entryRow;
}

// Pre-hide callback
void TransformDialog::_preHide()
{
TransientWindow::_preHide();

_selectionChanged.disconnect();
}

// Pre-show callback
void TransformDialog::_preShow()
TransformPanel::~TransformPanel()
{
TransientWindow::_preShow();

_selectionChanged.disconnect();

// Register self to the SelSystem to get notified upon selection changes.
_selectionChanged = GlobalSelectionSystem().signal_selectionChanged().connect(
[this](const ISelectable&) { update(); });

// Update the widget values
update();
}

void TransformDialog::update()
void TransformPanel::update()
{
// Check if there is anything selected
bool rotSensitive = (_selectionInfo.totalCount > 0);
Expand All @@ -255,7 +192,7 @@ void TransformDialog::update()
_scalePanel->Enable(scaleSensitive);
}

void TransformDialog::onClickLarger(wxCommandEvent& ev, EntryRow* row)
void TransformPanel::onClickLarger(wxCommandEvent& ev, EntryRow* row)
{
// Get the current step increment
float step = string::convert<float>(row->stepEntry->GetValue().ToStdString());
Expand Down Expand Up @@ -285,7 +222,7 @@ void TransformDialog::onClickLarger(wxCommandEvent& ev, EntryRow* row)
}
}

void TransformDialog::onClickSmaller(wxCommandEvent& ev, EntryRow* row)
void TransformPanel::onClickSmaller(wxCommandEvent& ev, EntryRow* row)
{
// Get the current value and the step increment
float step = string::convert<float>(row->stepEntry->GetValue().ToStdString());
Expand Down Expand Up @@ -321,4 +258,4 @@ void TransformDialog::onClickSmaller(wxCommandEvent& ev, EntryRow* row)
}
}

} // namespace ui
} // namespace
Expand Up @@ -2,32 +2,25 @@

#include <string>
#include <map>
#include "icommandsystem.h"
#include "iradiant.h"
#include "iselection.h"
#include "wxutil/window/TransientWindow.h"
#include <wx/panel.h>
#include <sigc++/connection.h>

namespace wxutil { class ControlButton; }

class wxTextCtrl;

/* greebo: The dialog providing the Free Transform functionality.
/**
* The panel providing the Free Transform functionality.
*
* The Dialog gets notified upon selection change and updates the widget
* sensitivity accordingly.
*
* If any entity is part of the selection, the scale widgets get disabled.
* Gets notified upon selection change and updates the widget sensitivity accordingly.
* E.g. if any entity is part of the selection, the scale widgets get disabled.
*/
namespace ui
{

class TransformDialog;
typedef std::shared_ptr<TransformDialog> TransformDialogPtr;

class TransformDialog :
public wxutil::TransientWindow
class TransformPanel :
public wxPanel
{
private:
// The entry fields
Expand All @@ -52,12 +45,11 @@ class TransformDialog :

sigc::connection _selectionChanged;

private:

// TransientWindow callbacks
virtual void _preShow();
virtual void _preHide();
public:
TransformPanel(wxWindow* parent);
~TransformPanel() override;

private:
/** greebo: Updates the sensitivity of the widgets according to
* the current selection.
*/
Expand All @@ -78,30 +70,7 @@ class TransformDialog :
// Callbacks to catch the scale/rotation button clicks
void onClickSmaller(wxCommandEvent& ev, EntryRow* row);
void onClickLarger(wxCommandEvent& ev, EntryRow* row);
};

/**
* greebo: Safely disconnects this dialog from all systems
* and saves the window state to the registry.
*/
void onMainFrameShuttingDown();

public:
// Constructor
TransformDialog();

/** greebo: Contains the static instance of this dialog.
* Constructs the instance and calls toggle() when invoked.
*/
static TransformDialog& Instance();

/** greebo: The command target to connect to the EventManager.
*/
static void toggle(const cmd::ArgumentList& args);

private:
static TransformDialogPtr& InstancePtr();

}; // class TransformDialog

} // namespace ui
} // namespace

0 comments on commit 90638f7

Please sign in to comment.