From 78c41d3eee7f9d7a00f2be0cd5dc7cdd5d116871 Mon Sep 17 00:00:00 2001 From: Dave Corley Date: Fri, 22 Dec 2023 18:59:16 -0600 Subject: [PATCH] Feat(instancemode.cpp): Implement keybinds for axis locking & switching submodes Cleanup(instancemode): Make the axis shortcut using std::string instead of format --- apps/opencs/view/render/instancemode.cpp | 55 ++++++++++++++++++++++++ apps/opencs/view/render/instancemode.hpp | 1 + 2 files changed, 56 insertions(+) diff --git a/apps/opencs/view/render/instancemode.cpp b/apps/opencs/view/render/instancemode.cpp index bc821ee25a..5851311035 100644 --- a/apps/opencs/view/render/instancemode.cpp +++ b/apps/opencs/view/render/instancemode.cpp @@ -252,6 +252,48 @@ void CSVRender::InstanceMode::getSelectionGroup(const int group) getWorldspaceWidget().selectGroup(targets); } +void CSVRender::InstanceMode::setDragAxis(const char axis) +{ + int newDragAxis; + + const std::vector> selection = getWorldspaceWidget().getSelection(Mask_Reference); + + if (selection.empty()) + return; + + switch (axis) + { + case 'x': + newDragAxis = 0; + break; + case 'y': + newDragAxis = 1; + break; + case 'z': + newDragAxis = 2; + break; + default: + return; + } + + if (newDragAxis == mDragAxis) + newDragAxis = -1; + + if (mSubModeId == "move") + { + mObjectsAtDragStart.clear(); + + for (const auto& object : selection) + if (CSVRender::ObjectTag* objectTag = dynamic_cast(object.get())) + { + const osg::Vec3f thisPoint = objectTag->mObject->getPosition().asVec3(); + mDragStart = thisPoint; + mObjectsAtDragStart.emplace_back(thisPoint); + } + } + mDragAxis = newDragAxis; +} + CSVRender::InstanceMode::InstanceMode( WorldspaceWidget* worldspaceWidget, osg::ref_ptr parentNode, QWidget* parent) : EditMode(worldspaceWidget, Misc::ScalableIcon::load(":scenetoolbar/editing-instance"), @@ -306,6 +348,19 @@ CSVRender::InstanceMode::InstanceMode( connect(new CSMPrefs::Shortcut("scene-save-" + std::to_string(i), worldspaceWidget), qOverload<>(&CSMPrefs::Shortcut::activated), this, [this, i] { this->saveSelectionGroup(i); }); } + + connect(new CSMPrefs::Shortcut("scene-submode-move", worldspaceWidget), qOverload<>(&CSMPrefs::Shortcut::activated), + this, [this] { mSubMode->setButton("move"); }); + + connect(new CSMPrefs::Shortcut("scene-submode-scale", worldspaceWidget), + qOverload<>(&CSMPrefs::Shortcut::activated), this, [this] { mSubMode->setButton("scale"); }); + + connect(new CSMPrefs::Shortcut("scene-submode-rotate", worldspaceWidget), + qOverload<>(&CSMPrefs::Shortcut::activated), this, [this] { mSubMode->setButton("rotate"); }); + + for (const char axis : "xyz") + connect(new CSMPrefs::Shortcut(std::string("scene-axis-") + axis, worldspaceWidget), + qOverload<>(&CSMPrefs::Shortcut::activated), this, [this, axis] { this->setDragAxis(axis); }); } void CSVRender::InstanceMode::activate(CSVWidget::SceneToolbar* toolbar) diff --git a/apps/opencs/view/render/instancemode.hpp b/apps/opencs/view/render/instancemode.hpp index 9267823e22..45d7c2b6fd 100644 --- a/apps/opencs/view/render/instancemode.hpp +++ b/apps/opencs/view/render/instancemode.hpp @@ -133,6 +133,7 @@ namespace CSVRender private slots: + void setDragAxis(const char axis); void subModeChanged(const std::string& id); void deleteSelectedInstances(); void cloneSelectedInstances();