Skip to content

Commit

Permalink
#5200: Move UI-related toggle state code from RadiantSelectionSystem …
Browse files Browse the repository at this point in the history
…to the UI module.

Fix a bug in RadiantSelectionSystem::getManipulatorIdForType.
  • Loading branch information
codereader committed Sep 13, 2020
1 parent 60ebd0b commit 8d17221
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 21 deletions.
2 changes: 2 additions & 0 deletions include/iselection.h
Expand Up @@ -184,6 +184,8 @@ class SelectionSystem :
virtual void setActiveManipulator(std::size_t manipulatorId) = 0;
virtual void setActiveManipulator(selection::Manipulator::Type manipulatorType) = 0;

virtual sigc::signal<void, selection::Manipulator::Type>& signal_activeManipulatorChanged() = 0;

virtual const SelectionInfo& getSelectionInfo() = 0;

virtual void SetMode(EMode mode) = 0;
Expand Down
67 changes: 67 additions & 0 deletions radiant/ui/ManipulatorToggle.h
@@ -0,0 +1,67 @@
#pragma once

#include "iselection.h"
#include <sigc++/connection.h>

namespace ui
{

// Adaptor class connecting the EventSystem toggles covering the
// various SelectionSystem manipulator mode to the actual state
// of the backend RadiantSelectionSystem.
class ManipulatorToggle
{
private:
sigc::connection _activeManipulatorChanged;

public:
ManipulatorToggle()
{
_activeManipulatorChanged = GlobalSelectionSystem().signal_activeManipulatorChanged()
.connect(sigc::mem_fun(this, &ManipulatorToggle::onActiveManipulatorChanged));

GlobalEventManager().addToggle("ToggleClipper", [this](bool)
{
GlobalCommandSystem().executeCommand("ToggleManipulatorMode", { "Clip" });
});

GlobalEventManager().addToggle("MouseTranslate", [this](bool)
{
GlobalCommandSystem().executeCommand("ToggleManipulatorMode", { "Translate" });
});

GlobalEventManager().addToggle("MouseRotate", [this](bool)
{
GlobalCommandSystem().executeCommand("ToggleManipulatorMode", { "Rotate" });
});

GlobalEventManager().addToggle("MouseDrag", [this](bool)
{
GlobalCommandSystem().executeCommand("ToggleManipulatorMode", { "Drag" });
});

GlobalEventManager().addToggle("ToggleModelScaleManipulator", [this](bool)
{
GlobalCommandSystem().executeCommand("ToggleManipulatorMode", { "ModelScale" });
});

onActiveManipulatorChanged(GlobalSelectionSystem().getActiveManipulatorType());
}

~ManipulatorToggle()
{
_activeManipulatorChanged.disconnect();
}

private:
void onActiveManipulatorChanged(selection::Manipulator::Type type)
{
GlobalEventManager().setToggled("ToggleClipper", GlobalClipper().clipMode());
GlobalEventManager().setToggled("MouseTranslate", type == selection::Manipulator::Translate);
GlobalEventManager().setToggled("MouseRotate", type == selection::Manipulator::Rotate);
GlobalEventManager().setToggled("MouseDrag", type == selection::Manipulator::Drag);
GlobalEventManager().setToggled("ToggleModelScaleManipulator", type == selection::Manipulator::ModelScale);
}
};

}
2 changes: 2 additions & 0 deletions radiant/ui/UserInterfaceModule.cpp
Expand Up @@ -210,6 +210,7 @@ void UserInterfaceModule::initialiseModule(const IApplicationContext& ctx)
_mruMenu.reset(new MRUMenu);
_shaderClipboardStatus.reset(new ShaderClipboardStatus);
_editStopwatchStatus.reset(new EditingStopwatchStatus);
_manipulatorToggle.reset(new ManipulatorToggle);

MouseToolRegistrationHelper::RegisterTools();

Expand All @@ -234,6 +235,7 @@ void UserInterfaceModule::shutdownModule()
_autoSaveRequestHandler.reset();
_shaderClipboardStatus.reset();
_editStopwatchStatus.reset();
_manipulatorToggle.reset();

_mruMenu.reset();
}
Expand Down
2 changes: 2 additions & 0 deletions radiant/ui/UserInterfaceModule.h
Expand Up @@ -12,6 +12,7 @@
#include "FileSelectionRequestHandler.h"
#include "AutoSaveRequestHandler.h"
#include "MapFileProgressHandler.h"
#include "ManipulatorToggle.h"
#include "shaderclipboard/ShaderClipboardStatus.h"
#include "statusbar/EditingStopwatchStatus.h"
#include "messages/CommandExecutionFailed.h"
Expand Down Expand Up @@ -42,6 +43,7 @@ class UserInterfaceModule :
std::unique_ptr<FileSelectionRequestHandler> _fileSelectionRequestHandler;
std::unique_ptr<ShaderClipboardStatus> _shaderClipboardStatus;
std::unique_ptr<EditingStopwatchStatus> _editStopwatchStatus;
std::unique_ptr<ManipulatorToggle> _manipulatorToggle;

sigc::connection _entitySettingsConn;
sigc::connection _coloursUpdatedConn;
Expand Down
76 changes: 57 additions & 19 deletions radiantcore/selection/RadiantSelectionSystem.cpp
Expand Up @@ -295,6 +295,11 @@ void RadiantSelectionSystem::setActiveManipulator(Manipulator::Type manipulatorT
rError() << "Cannot activate non-existent manipulator by type " << manipulatorType << std::endl;
}

sigc::signal<void, selection::Manipulator::Type>& RadiantSelectionSystem::signal_activeManipulatorChanged()
{
return _sigActiveManipulatorChanged;
}

// return the number of selected primitives
std::size_t RadiantSelectionSystem::countSelected() const {
return _countPrimitive;
Expand Down Expand Up @@ -1090,12 +1095,8 @@ void RadiantSelectionSystem::initialiseModule(const IApplicationContext& ctx)
sigc::mem_fun(this, &RadiantSelectionSystem::pivotChanged)
);

GlobalEventManager().addToggle("ToggleClipper", std::bind(&RadiantSelectionSystem::toggleManipulatorMode, this, Manipulator::Clip, std::placeholders::_1));
GlobalEventManager().addToggle("MouseTranslate", std::bind(&RadiantSelectionSystem::toggleManipulatorMode, this, Manipulator::Translate, std::placeholders::_1));
GlobalEventManager().addToggle("MouseRotate", std::bind(&RadiantSelectionSystem::toggleManipulatorMode, this, Manipulator::Rotate, std::placeholders::_1));
GlobalEventManager().addToggle("MouseDrag", std::bind(&RadiantSelectionSystem::toggleManipulatorMode, this, Manipulator::Drag, std::placeholders::_1));
GlobalEventManager().addToggle("ToggleModelScaleManipulator", std::bind(&RadiantSelectionSystem::toggleManipulatorMode, this, Manipulator::ModelScale, std::placeholders::_1));
GlobalEventManager().setToggled("MouseDrag", true);
GlobalCommandSystem().addCommand("ToggleManipulatorMode",
std::bind(&RadiantSelectionSystem::toggleManipulatorModeCmd, this, std::placeholders::_1), { cmd::ARGTYPE_STRING });

GlobalEventManager().addToggle("DragVertices", std::bind(&RadiantSelectionSystem::toggleComponentMode, this, eVertex, std::placeholders::_1));
GlobalEventManager().addToggle("DragEdges", std::bind(&RadiantSelectionSystem::toggleComponentMode, this, eEdge, std::placeholders::_1));
Expand Down Expand Up @@ -1166,7 +1167,7 @@ std::size_t RadiantSelectionSystem::getManipulatorIdForType(Manipulator::Type ty
{
for (const Manipulators::value_type& pair : _manipulators)
{
if (pair.second->getType() == _defaultManipulatorType)
if (pair.second->getType() == type)
{
return pair.first;
}
Expand All @@ -1175,7 +1176,7 @@ std::size_t RadiantSelectionSystem::getManipulatorIdForType(Manipulator::Type ty
return 0;
}

void RadiantSelectionSystem::toggleManipulatorModeById(std::size_t manipId, bool newState)
void RadiantSelectionSystem::toggleManipulatorModeById(std::size_t manipId)
{
std::size_t defaultManipId = getManipulatorIdForType(_defaultManipulatorType);

Expand All @@ -1187,7 +1188,7 @@ void RadiantSelectionSystem::toggleManipulatorModeById(std::size_t manipId, bool
// Switch back to the default mode if we're already in <mode>
if (_activeManipulator->getId() == manipId && defaultManipId != manipId)
{
toggleManipulatorModeById(defaultManipId, true);
toggleManipulatorModeById(defaultManipId);
}
else // we're not in <mode> yet
{
Expand All @@ -1209,12 +1210,55 @@ void RadiantSelectionSystem::toggleManipulatorModeById(std::size_t manipId, bool
}
}

void RadiantSelectionSystem::toggleManipulatorMode(Manipulator::Type type, bool newState)
void RadiantSelectionSystem::toggleManipulatorModeCmd(const cmd::ArgumentList& args)
{
if (args.size() != 1)
{
rWarning() << "Usage: ToggleManipulatorMode <manipulator>" << std::endl;
rWarning() << " with <manipulator> being one of the following: " << std::endl;
rWarning() << " Drag" << std::endl;
rWarning() << " Translate" << std::endl;
rWarning() << " Rotate" << std::endl;
rWarning() << " Scale" << std::endl;
rWarning() << " Clip" << std::endl;
rWarning() << " ModelScale" << std::endl;
return;
}

auto manip = args[0].getString();

if (manip == "Drag")
{
toggleManipulatorModeById(getManipulatorIdForType(Manipulator::Drag));
}
else if (manip == "Translate")
{
toggleManipulatorModeById(getManipulatorIdForType(Manipulator::Translate));
}
else if (manip == "Rotate")
{
toggleManipulatorModeById(getManipulatorIdForType(Manipulator::Rotate));
}
else if (manip == "Scale")
{
toggleManipulatorModeById(getManipulatorIdForType(Manipulator::Drag));
}
else if (manip == "Clip")
{
toggleManipulatorModeById(getManipulatorIdForType(Manipulator::Clip));
}
else if (manip == "ModelScale")
{
toggleManipulatorModeById(getManipulatorIdForType(Manipulator::ModelScale));
}
}

void RadiantSelectionSystem::toggleManipulatorMode(Manipulator::Type type)
{
// Switch back to the default mode if we're already in <mode>
if (_activeManipulator->getType() == type && _defaultManipulatorType != type)
{
toggleManipulatorMode(_defaultManipulatorType, true);
toggleManipulatorMode(_defaultManipulatorType);
}
else // we're not in <mode> yet
{
Expand Down Expand Up @@ -1254,7 +1298,7 @@ void RadiantSelectionSystem::toggleComponentMode(EComponentMode mode, bool newSt
{
if (!_activeManipulator->supportsComponentManipulation())
{
toggleManipulatorMode(_defaultManipulatorType, true);
toggleManipulatorMode(_defaultManipulatorType);
}

SetMode(eComponent);
Expand Down Expand Up @@ -1326,13 +1370,7 @@ void RadiantSelectionSystem::toggleGroupPartMode(bool newState)

void RadiantSelectionSystem::onManipulatorModeChanged()
{
GlobalEventManager().setToggled("ToggleClipper", GlobalClipper().clipMode());

GlobalEventManager().setToggled("MouseTranslate", _activeManipulator->getType() == Manipulator::Translate);
GlobalEventManager().setToggled("MouseRotate", _activeManipulator->getType() == Manipulator::Rotate);
GlobalEventManager().setToggled("MouseDrag", _activeManipulator->getType() == Manipulator::Drag);
GlobalEventManager().setToggled("ToggleModelScaleManipulator", _activeManipulator->getType() == Manipulator::ModelScale);

_sigActiveManipulatorChanged.emit(getActiveManipulatorType());
SceneChangeNotify();
}

Expand Down
8 changes: 6 additions & 2 deletions radiantcore/selection/RadiantSelectionSystem.h
Expand Up @@ -68,6 +68,8 @@ class RadiantSelectionSystem :

bool nothingSelected() const;

sigc::signal<void, selection::Manipulator::Type> _sigActiveManipulatorChanged;

public:

RadiantSelectionSystem();
Expand Down Expand Up @@ -101,6 +103,7 @@ class RadiantSelectionSystem :
const ManipulatorPtr& getActiveManipulator() override;
void setActiveManipulator(std::size_t manipulatorId) override;
void setActiveManipulator(Manipulator::Type manipulatorType) override;
sigc::signal<void, selection::Manipulator::Type>& signal_activeManipulatorChanged() override;

std::size_t countSelected() const override;
std::size_t countSelectedComponents() const override;
Expand Down Expand Up @@ -181,8 +184,9 @@ class RadiantSelectionSystem :
std::size_t getManipulatorIdForType(Manipulator::Type type);

// Command targets used to connect to the event system
void toggleManipulatorMode(Manipulator::Type type, bool newState);
void toggleManipulatorModeById(std::size_t manipId, bool newState);
void toggleManipulatorModeCmd(const cmd::ArgumentList& args);
void toggleManipulatorMode(Manipulator::Type type);
void toggleManipulatorModeById(std::size_t manipId);

void activateDefaultMode();

Expand Down
1 change: 1 addition & 0 deletions tools/msvc/DarkRadiant.vcxproj
Expand Up @@ -448,6 +448,7 @@
<ClInclude Include="..\..\radiant\ui\layers\CreateLayerDialog.h" />
<ClInclude Include="..\..\radiant\ui\LongRunningOperationHandler.h" />
<ClInclude Include="..\..\radiant\ui\mainframe\TopLevelFrame.h" />
<ClInclude Include="..\..\radiant\ui\ManipulatorToggle.h" />
<ClInclude Include="..\..\radiant\ui\MapCommands.h" />
<ClInclude Include="..\..\radiant\ui\MapFileProgressHandler.h" />
<ClInclude Include="..\..\radiant\ui\mapinfo\LayerInfoTab.h" />
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/DarkRadiant.vcxproj.filters
Expand Up @@ -1290,6 +1290,9 @@
<ClInclude Include="..\..\radiant\ApplicationContext.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\..\radiant\ui\ManipulatorToggle.h">
<Filter>src\ui</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\radiant\darkradiant.rc" />
Expand Down

0 comments on commit 8d17221

Please sign in to comment.