Skip to content

Commit

Permalink
#5128: Intercept the component mode toggle requests in the Texture To…
Browse files Browse the repository at this point in the history
…ol to allow switching between Surface and Vertex modes.
  • Loading branch information
codereader committed Sep 25, 2021
1 parent b1d91be commit 284b2b9
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 10 deletions.
43 changes: 40 additions & 3 deletions radiant/textool/TexTool.cpp
Expand Up @@ -3,6 +3,7 @@
#include <limits>
#include "i18n.h"
#include "ieventmanager.h"
#include "icommandsystem.h"
#include "itexturetoolmodel.h"
#include "imainframe.h"
#include "igl.h"
Expand Down Expand Up @@ -51,7 +52,8 @@ TexTool::TexTool() :
_gridActive(registry::getValue<bool>(RKEY_GRID_STATE)),
_updateNeeded(false),
_selectionRescanNeeded(false),
_manipulatorModeToggleRequestHandler(std::numeric_limits<std::size_t>::max())
_manipulatorModeToggleRequestHandler(std::numeric_limits<std::size_t>::max()),
_componentSelectionModeToggleRequestHandler(std::numeric_limits<std::size_t>::max())
{
Bind(wxEVT_IDLE, &TexTool::onIdle, this);

Expand Down Expand Up @@ -128,6 +130,9 @@ void TexTool::_preHide()

GlobalRadiantCore().getMessageBus().removeListener(_manipulatorModeToggleRequestHandler);
_manipulatorModeToggleRequestHandler = std::numeric_limits<std::size_t>::max();

GlobalRadiantCore().getMessageBus().removeListener(_componentSelectionModeToggleRequestHandler);
_componentSelectionModeToggleRequestHandler = std::numeric_limits<std::size_t>::max();
}

// Pre-show callback
Expand All @@ -146,10 +151,16 @@ void TexTool::_preShow()
_sceneSelectionChanged = GlobalSelectionSystem().signal_selectionChanged().connect(
[this](const ISelectable&) { _selectionRescanNeeded = true; });

_manipulatorModeToggleRequestHandler = GlobalRadiantCore().getMessageBus().addListener(radiant::IMessage::ManipulatorModeToggleRequest,
_manipulatorModeToggleRequestHandler = GlobalRadiantCore().getMessageBus().addListener(
radiant::IMessage::ManipulatorModeToggleRequest,
radiant::TypeListener<selection::ManipulatorModeToggleRequest>(
sigc::mem_fun(this, &TexTool::handleManipulatorModeToggleRequest)));

_componentSelectionModeToggleRequestHandler = GlobalRadiantCore().getMessageBus().addListener(
radiant::IMessage::ComponentSelectionModeToggleRequest,
radiant::TypeListener<selection::ComponentSelectionModeToggleRequest>(
sigc::mem_fun(this, &TexTool::handleComponentSelectionModeToggleRequest)));

_undoHandler = GlobalUndoSystem().signal_postUndo().connect(
sigc::mem_fun(this, &TexTool::onUndoRedoOperation));
_redoHandler = GlobalUndoSystem().signal_postRedo().connect(
Expand All @@ -170,9 +181,14 @@ void TexTool::_preShow()
queueDraw();
}

bool TexTool::textureToolHasFocus()
{
return HasFocus() || _glWidget->HasFocus();
}

void TexTool::handleManipulatorModeToggleRequest(selection::ManipulatorModeToggleRequest& request)
{
if (!HasFocus() && !_glWidget->HasFocus())
if (!textureToolHasFocus())
{
return;
}
Expand All @@ -188,6 +204,27 @@ void TexTool::handleManipulatorModeToggleRequest(selection::ManipulatorModeToggl
};
}

void TexTool::handleComponentSelectionModeToggleRequest(selection::ComponentSelectionModeToggleRequest& request)
{
if (!textureToolHasFocus())
{
return;
}

// Catch specific mode types, let the others slip through
switch (request.getMode())
{
case selection::ComponentSelectionMode::Default:
GlobalCommandSystem().executeCommand("ToggleTextureToolSelectionMode", { "Surface" });
request.setHandled(true);
break;
case selection::ComponentSelectionMode::Vertex:
GlobalCommandSystem().executeCommand("ToggleTextureToolSelectionMode", { "Vertex" });
request.setHandled(true);
break;
};
}

void TexTool::onUndoRedoOperation()
{
queueDraw();
Expand Down
6 changes: 6 additions & 0 deletions radiant/textool/TexTool.h
Expand Up @@ -20,6 +20,7 @@
#include "tools/TextureToolMouseEvent.h"
#include "render/TextureToolView.h"
#include "messages/ManipulatorModeToggleRequest.h"
#include "messages/ComponentSelectionModeToggleRequest.h"

class Winding;
class Patch;
Expand Down Expand Up @@ -78,6 +79,7 @@ class TexTool :
sigc::connection _selectionModeChanged;
sigc::connection _selectionChanged;
std::size_t _manipulatorModeToggleRequestHandler;
std::size_t _componentSelectionModeToggleRequestHandler;

private:
// This is where the static shared_ptr of the singleton instance is held.
Expand Down Expand Up @@ -154,6 +156,10 @@ class TexTool :
void onMainFrameShuttingDown();

void handleManipulatorModeToggleRequest(selection::ManipulatorModeToggleRequest& request);
void handleComponentSelectionModeToggleRequest(selection::ComponentSelectionModeToggleRequest& request);

// Returns true if the texture tool window or the GL widget has focus
bool textureToolHasFocus();

public:
TexTool();
Expand Down
30 changes: 23 additions & 7 deletions radiantcore/selection/RadiantSelectionSystem.cpp
Expand Up @@ -20,6 +20,7 @@
#include "string/case_conv.h"
#include "messages/UnselectSelectionRequest.h"
#include "messages/ManipulatorModeToggleRequest.h"
#include "messages/ComponentSelectionModeToggleRequest.h"

#include "manipulators/DragManipulator.h"
#include "manipulators/ClipManipulator.h"
Expand Down Expand Up @@ -1249,25 +1250,40 @@ void RadiantSelectionSystem::toggleComponentModeCmd(const cmd::ArgumentList& arg
{
rWarning() << "Usage: ToggleComponentSelectionMode <mode>" << std::endl;
rWarning() << " with <mode> being one of the following: " << std::endl;
rWarning() << " Default" << std::endl;
rWarning() << " Vertex" << std::endl;
rWarning() << " Edge" << std::endl;
rWarning() << " Face" << std::endl;
return;
}

auto mode = string::to_lower_copy(args[0].getString());
auto modeStr = string::to_lower_copy(args[0].getString());
ComponentSelectionMode mode;

if (mode == "vertex")
if (modeStr == "vertex")
{
toggleComponentMode(ComponentSelectionMode::Vertex);
mode = ComponentSelectionMode::Vertex;
}
else if (mode == "edge")
else if (modeStr == "edge")
{
toggleComponentMode(ComponentSelectionMode::Edge);
mode = ComponentSelectionMode::Edge;
}
else if (mode == "face")
else if (modeStr == "face")
{
toggleComponentMode(ComponentSelectionMode::Face);
mode = ComponentSelectionMode::Face;
}
else if (modeStr == "default")
{
mode = ComponentSelectionMode::Default;
}

ComponentSelectionModeToggleRequest request(mode);
GlobalRadiantCore().getMessageBus().sendMessage(request);

if (!request.isHandled())
{
// Handle it ourselves
toggleComponentMode(mode);
}
}

Expand Down

0 comments on commit 284b2b9

Please sign in to comment.