From 284b2b9d4d68ddb56bd4c46446da96aadf1eb099 Mon Sep 17 00:00:00 2001 From: codereader Date: Sat, 25 Sep 2021 07:03:10 +0200 Subject: [PATCH] #5128: Intercept the component mode toggle requests in the Texture Tool to allow switching between Surface and Vertex modes. --- radiant/textool/TexTool.cpp | 43 +++++++++++++++++-- radiant/textool/TexTool.h | 6 +++ .../selection/RadiantSelectionSystem.cpp | 30 ++++++++++--- 3 files changed, 69 insertions(+), 10 deletions(-) diff --git a/radiant/textool/TexTool.cpp b/radiant/textool/TexTool.cpp index 2e47e93f4d..35a49db412 100644 --- a/radiant/textool/TexTool.cpp +++ b/radiant/textool/TexTool.cpp @@ -3,6 +3,7 @@ #include #include "i18n.h" #include "ieventmanager.h" +#include "icommandsystem.h" #include "itexturetoolmodel.h" #include "imainframe.h" #include "igl.h" @@ -51,7 +52,8 @@ TexTool::TexTool() : _gridActive(registry::getValue(RKEY_GRID_STATE)), _updateNeeded(false), _selectionRescanNeeded(false), - _manipulatorModeToggleRequestHandler(std::numeric_limits::max()) + _manipulatorModeToggleRequestHandler(std::numeric_limits::max()), + _componentSelectionModeToggleRequestHandler(std::numeric_limits::max()) { Bind(wxEVT_IDLE, &TexTool::onIdle, this); @@ -128,6 +130,9 @@ void TexTool::_preHide() GlobalRadiantCore().getMessageBus().removeListener(_manipulatorModeToggleRequestHandler); _manipulatorModeToggleRequestHandler = std::numeric_limits::max(); + + GlobalRadiantCore().getMessageBus().removeListener(_componentSelectionModeToggleRequestHandler); + _componentSelectionModeToggleRequestHandler = std::numeric_limits::max(); } // Pre-show callback @@ -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( sigc::mem_fun(this, &TexTool::handleManipulatorModeToggleRequest))); + _componentSelectionModeToggleRequestHandler = GlobalRadiantCore().getMessageBus().addListener( + radiant::IMessage::ComponentSelectionModeToggleRequest, + radiant::TypeListener( + sigc::mem_fun(this, &TexTool::handleComponentSelectionModeToggleRequest))); + _undoHandler = GlobalUndoSystem().signal_postUndo().connect( sigc::mem_fun(this, &TexTool::onUndoRedoOperation)); _redoHandler = GlobalUndoSystem().signal_postRedo().connect( @@ -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; } @@ -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(); diff --git a/radiant/textool/TexTool.h b/radiant/textool/TexTool.h index c37b84d0bc..8e9209822f 100644 --- a/radiant/textool/TexTool.h +++ b/radiant/textool/TexTool.h @@ -20,6 +20,7 @@ #include "tools/TextureToolMouseEvent.h" #include "render/TextureToolView.h" #include "messages/ManipulatorModeToggleRequest.h" +#include "messages/ComponentSelectionModeToggleRequest.h" class Winding; class Patch; @@ -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. @@ -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(); diff --git a/radiantcore/selection/RadiantSelectionSystem.cpp b/radiantcore/selection/RadiantSelectionSystem.cpp index bbef6843c2..835a831125 100644 --- a/radiantcore/selection/RadiantSelectionSystem.cpp +++ b/radiantcore/selection/RadiantSelectionSystem.cpp @@ -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" @@ -1249,25 +1250,40 @@ void RadiantSelectionSystem::toggleComponentModeCmd(const cmd::ArgumentList& arg { rWarning() << "Usage: ToggleComponentSelectionMode " << std::endl; rWarning() << " with 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); } }