Feat(instancemode.cpp): Implement keybinds for axis locking & switching submodes

Cleanup(instancemode): Make the axis shortcut using std::string instead
of format
pull/3236/head
Dave Corley 1 year ago
parent 98750a122d
commit 78c41d3eee

@ -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<osg::ref_ptr<TagBase>> 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<CSVRender::ObjectTag*>(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<osg::Group> 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)

@ -133,6 +133,7 @@ namespace CSVRender
private slots:
void setDragAxis(const char axis);
void subModeChanged(const std::string& id);
void deleteSelectedInstances();
void cloneSelectedInstances();

Loading…
Cancel
Save