refactor: handle inactive when select tool is selected
This commit is contained in:
parent
4bfca68fb0
commit
a346b1d9a8
|
@ -28,6 +28,7 @@ class Handles : public Instance {
|
||||||
public:
|
public:
|
||||||
const static InstanceType TYPE;
|
const static InstanceType TYPE;
|
||||||
|
|
||||||
|
bool active;
|
||||||
std::optional<std::weak_ptr<Part>> adornee;
|
std::optional<std::weak_ptr<Part>> adornee;
|
||||||
// inline std::optional<std::weak_ptr<Part>> GetAdornee() { return adornee; }
|
// inline std::optional<std::weak_ptr<Part>> GetAdornee() { return adornee; }
|
||||||
// inline void SetAdornee(std::optional<std::weak_ptr<Part>> newAdornee) { this->adornee = newAdornee; updateAdornee(); };
|
// inline void SetAdornee(std::optional<std::weak_ptr<Part>> newAdornee) { this->adornee = newAdornee; updateAdornee(); };
|
||||||
|
|
|
@ -152,7 +152,7 @@ void renderSkyBox() {
|
||||||
void renderHandles() {
|
void renderHandles() {
|
||||||
// if (getSelection().size() == 0) return;
|
// if (getSelection().size() == 0) return;
|
||||||
// if (getSelection()[0].lock()->GetClass() != &Part::TYPE) return;
|
// if (getSelection()[0].lock()->GetClass() != &Part::TYPE) return;
|
||||||
if (!editorToolHandles->adornee.has_value()) return;
|
if (!editorToolHandles->adornee.has_value() || !editorToolHandles->active) return;
|
||||||
|
|
||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
enum SelectedTool {
|
|
||||||
SELECT,
|
|
||||||
MOVE,
|
|
||||||
SCALE,
|
|
||||||
ROTATE,
|
|
||||||
};
|
|
||||||
|
|
||||||
extern SelectedTool selectedTool;
|
|
|
@ -146,7 +146,7 @@ void MainGLWidget::handleHandleDrag(QMouseEvent* evt) {
|
||||||
QPoint cLastPoint = lastPoint;
|
QPoint cLastPoint = lastPoint;
|
||||||
lastPoint = evt->pos();
|
lastPoint = evt->pos();
|
||||||
|
|
||||||
if (!isMouseDragging || !draggingHandle || !editorToolHandles->adornee) return;
|
if (!isMouseDragging || !draggingHandle || !editorToolHandles->adornee || !editorToolHandles->active) return;
|
||||||
|
|
||||||
QPoint position = evt->pos();
|
QPoint position = evt->pos();
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ void MainGLWidget::handleHandleDrag(QMouseEvent* evt) {
|
||||||
glm::vec3 handlePoint, rb;
|
glm::vec3 handlePoint, rb;
|
||||||
get_closest_points_between_segments(axisSegment0, axisSegment1, mouseSegment0, mouseSegment1, handlePoint, rb);
|
get_closest_points_between_segments(axisSegment0, axisSegment1, mouseSegment0, mouseSegment1, handlePoint, rb);
|
||||||
|
|
||||||
if (selectedTool == SelectedTool::MOVE) {
|
if (mainWindow()->selectedTool == SelectedTool::MOVE) {
|
||||||
glm::vec3 newPos = editorToolHandles->PartCFrameFromHandlePos(draggingHandle.value(), handlePoint).Position();
|
glm::vec3 newPos = editorToolHandles->PartCFrameFromHandlePos(draggingHandle.value(), handlePoint).Position();
|
||||||
glm::vec3 oldPos = editorToolHandles->adornee->lock()->cframe.Position();
|
glm::vec3 oldPos = editorToolHandles->adornee->lock()->cframe.Position();
|
||||||
glm::vec3 diff = newPos - oldPos;
|
glm::vec3 diff = newPos - oldPos;
|
||||||
|
@ -179,7 +179,7 @@ void MainGLWidget::handleHandleDrag(QMouseEvent* evt) {
|
||||||
newPos = diff + oldPos;
|
newPos = diff + oldPos;
|
||||||
|
|
||||||
editorToolHandles->adornee->lock()->cframe = editorToolHandles->adornee->lock()->cframe.Rotation() + newPos;
|
editorToolHandles->adornee->lock()->cframe = editorToolHandles->adornee->lock()->cframe.Rotation() + newPos;
|
||||||
} else if (selectedTool == SelectedTool::SCALE) {
|
} else if (mainWindow()->selectedTool == SelectedTool::SCALE) {
|
||||||
glm::vec3 handlePos = editorToolHandles->PartCFrameFromHandlePos(draggingHandle.value(), handlePoint).Position();
|
glm::vec3 handlePos = editorToolHandles->PartCFrameFromHandlePos(draggingHandle.value(), handlePoint).Position();
|
||||||
|
|
||||||
// Find change in handles, and negate difference in sign between axes
|
// Find change in handles, and negate difference in sign between axes
|
||||||
|
@ -199,7 +199,7 @@ void MainGLWidget::handleHandleDrag(QMouseEvent* evt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<HandleFace> MainGLWidget::raycastHandle(glm::vec3 pointDir) {
|
std::optional<HandleFace> MainGLWidget::raycastHandle(glm::vec3 pointDir) {
|
||||||
if (!editorToolHandles->adornee.has_value()) return std::nullopt;
|
if (!editorToolHandles->adornee.has_value() || !editorToolHandles->active) return std::nullopt;
|
||||||
return editorToolHandles->RaycastHandle(rp3d::Ray(glmToRp(camera.cameraPos), glmToRp(glm::normalize(pointDir)) * 50000));
|
return editorToolHandles->RaycastHandle(rp3d::Ray(glmToRp(camera.cameraPos), glmToRp(glm::normalize(pointDir)) * 50000));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,6 @@
|
||||||
#include "qobject.h"
|
#include "qobject.h"
|
||||||
#include "qsysinfo.h"
|
#include "qsysinfo.h"
|
||||||
|
|
||||||
SelectedTool selectedTool;
|
|
||||||
|
|
||||||
bool simulationPlaying = false;
|
bool simulationPlaying = false;
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
|
@ -87,7 +85,12 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
});
|
});
|
||||||
|
|
||||||
addSelectionListener([&](auto oldSelection, auto newSelection, bool fromExplorer) {
|
addSelectionListener([&](auto oldSelection, auto newSelection, bool fromExplorer) {
|
||||||
updateToolbars();
|
editorToolHandles->adornee = std::nullopt;
|
||||||
|
if (newSelection.size() == 0) return;
|
||||||
|
InstanceRef inst = newSelection[0].lock();
|
||||||
|
if (inst->GetClass() != &Part::TYPE) return;
|
||||||
|
|
||||||
|
editorToolHandles->adornee = std::dynamic_pointer_cast<Part>(inst);
|
||||||
});
|
});
|
||||||
|
|
||||||
// ui->explorerView->Init(ui);
|
// ui->explorerView->Init(ui);
|
||||||
|
@ -153,16 +156,7 @@ void MainWindow::updateToolbars() {
|
||||||
|
|
||||||
if (selectedTool == SelectedTool::MOVE) editorToolHandles->worldMode = true;
|
if (selectedTool == SelectedTool::MOVE) editorToolHandles->worldMode = true;
|
||||||
if (selectedTool == SelectedTool::SCALE) editorToolHandles->worldMode = false;
|
if (selectedTool == SelectedTool::SCALE) editorToolHandles->worldMode = false;
|
||||||
|
editorToolHandles->active = selectedTool != SelectedTool::SELECT;
|
||||||
// This code sucks. A lot
|
|
||||||
if (selectedTool == SelectedTool::SELECT) return;
|
|
||||||
if (getSelection().size() == 0) { editorToolHandles->adornee = std::nullopt; return; };
|
|
||||||
InstanceRef inst = getSelection()[0].lock();
|
|
||||||
if (inst->GetClass() != &Part::TYPE) { editorToolHandles->adornee = std::nullopt; return; };
|
|
||||||
|
|
||||||
editorToolHandles->adornee = std::dynamic_pointer_cast<Part>(inst);
|
|
||||||
|
|
||||||
// editorToolHandles->adornee = std::nullopt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
|
|
@ -8,6 +8,13 @@
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
|
||||||
|
enum SelectedTool {
|
||||||
|
SELECT,
|
||||||
|
MOVE,
|
||||||
|
SCALE,
|
||||||
|
ROTATE,
|
||||||
|
};
|
||||||
|
|
||||||
enum GridSnappingMode {
|
enum GridSnappingMode {
|
||||||
SNAP_1_STUD,
|
SNAP_1_STUD,
|
||||||
SNAP_05_STUDS,
|
SNAP_05_STUDS,
|
||||||
|
@ -28,6 +35,7 @@ public:
|
||||||
MainWindow(QWidget *parent = nullptr);
|
MainWindow(QWidget *parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
SelectedTool selectedTool;
|
||||||
GridSnappingMode snappingMode;
|
GridSnappingMode snappingMode;
|
||||||
|
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
|
Loading…
Reference in a new issue