Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions engine/includes/editor/viewport/handletools.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ENGINE_EXPORT HandleTools {

static float distanceToMesh(const Matrix4 &matrix, const IndexVector &indices, const Vector3Vector &vertices, const Vector2 &screen);

static bool pointInRect(const Matrix4 &matrix, const Vector3 &tl, const Vector3 &br, const Vector2 &screen);
};

#endif // HANDLETOOLS_H
2 changes: 1 addition & 1 deletion engine/src/editor/editortool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void EditorTool::cancelControl() {

}
/*!
Returns the icon identifier for the tool.
Returns a cursor shape for the active tool action.
*/
Qt::CursorShape EditorTool::cursor() const {
return m_cursor;
Expand Down
8 changes: 2 additions & 6 deletions engine/src/editor/viewport/handles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,12 +662,8 @@ Vector3 Handles::rectTool(const Vector3 &center, const Vector3 &box, int &axis,
} else if((side ? HandleTools::distanceToPoint(model, l, s_Mouse) :
HandleTools::distanceToPath(model, {tl, bl}, s_Mouse)) <= sence) {
Handles::s_Axes = Handles::LEFT;
} else {
Ray ray = camera->castRay(Handles::s_Mouse.x, Handles::s_Mouse.y);
if(ray.intersect(model * tr, model * tl, model * bl, nullptr, true) ||
ray.intersect(model * bl, model * br, model * tr, nullptr, true)) {
Handles::s_Axes = Handles::BOTTOM | Handles::TOP | Handles::LEFT | Handles::RIGHT;
}
} else if(HandleTools::pointInRect(model, tl, br, s_Mouse)) {
Handles::s_Axes = Handles::BOTTOM | Handles::TOP | Handles::LEFT | Handles::RIGHT;
}
}

Expand Down
7 changes: 7 additions & 0 deletions engine/src/editor/viewport/handletools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ float HandleTools::distanceToMesh(const Matrix4 &matrix, const IndexVector &indi
}
return sqrtf(result);
}

bool HandleTools::pointInRect(const Matrix4 &matrix, const Vector3 &tl, const Vector3 &br, const Vector2 &screen) {
Vector3 sstl = Camera::current()->project(matrix * tl);
Vector3 ssbr = Camera::current()->project(matrix * br);

return screen.x > sstl.x && screen.x < ssbr.x && screen.y < sstl.y && screen.y > ssbr.y;
}
2 changes: 2 additions & 0 deletions modules/uikit/includes/components/recttransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class UIKIT_EXPORT RectTransform : public Transform {
SizePolicy horizontalPolicy() const;
void setHorizontalPolicy(SizePolicy policy);

Vector2 sizeHint() const;

private:
friend class Layout;

Expand Down
2 changes: 1 addition & 1 deletion modules/uikit/includes/editor/tools/widgettool.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class WidgetTool : public EditorTool {

Vector3 objectPosition();

protected:
void update(bool pivot, bool local, bool snap) override;

void beginControl() override;
void endControl() override;
void cancelControl() override;

protected:
Vector3 recalcPosition(RectTransform *rect, RectTransform *root) const;

std::string icon() const override;
Expand Down
2 changes: 1 addition & 1 deletion modules/uikit/includes/editor/widgetcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public slots:

Widget *m_rootObject;

EditorTool *m_widgetTool;
WidgetTool *m_widgetTool;

uint32_t m_selected;

Expand Down
8 changes: 8 additions & 0 deletions modules/uikit/src/components/recttransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ void RectTransform::recalcChilds() const {
m_dirty = true;
}

Vector2 RectTransform::sizeHint() const {
if(m_layout) {
return m_layout->sizeHint();
}

return Vector2();
}

void RectTransform::recalcParent() {
if(m_layout) {
Vector2 hint(m_layout->sizeHint());
Expand Down
33 changes: 27 additions & 6 deletions modules/uikit/src/editor/tools/widgettool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void WidgetTool::update(bool pivot, bool local, bool snap) {
bool isDrag = m_controller->isDrag();

int axis;
m_world = Handles::rectTool(boxCenter, boxSize, axis, true, isDrag);
m_world = Handles::rectTool(boxCenter, boxSize, axis, false, isDrag);

if(isDrag) {
Vector3 delta(m_world - m_savedWorld);
Expand All @@ -195,24 +195,45 @@ void WidgetTool::update(bool pivot, bool local, bool snap) {
Vector2 position(p.x, p.y);
Vector2 size(rect->size());
Vector2 pivot(rect->pivot());
Vector2 hint(rect->sizeHint());

Vector2 min(position - (size * pivot));
Vector2 max(position + (size * (Vector2(1.0f) - pivot)));
Vector2 localMin(size * pivot);
Vector2 localMax(size * (Vector2(1.0f) - pivot));
Vector2 min(position - localMin);
Vector2 max(position + localMax);

bool moveAll = Handles::s_Axes == (Handles::TOP | Handles::BOTTOM | Handles::LEFT | Handles::RIGHT);

if(Handles::s_Axes & Handles::TOP) {
max.y += delta.y;
float limit = min.y + hint.y;
if(!moveAll && max.y < limit) {
max.y = limit;
}
}
if(Handles::s_Axes & Handles::BOTTOM) {
min.y += delta.y;
float limit = max.y - hint.y;
if(!moveAll && min.y > limit) {
min.y = limit;
}
}
if(Handles::s_Axes & Handles::LEFT) {
min.x += delta.x;
float limit = max.x - hint.x;
if(!moveAll && min.x > limit) {
min.x = limit;
}
}
if(Handles::s_Axes & Handles::RIGHT) {
max.x += delta.x;
float limit = min.x + hint.x;
if(!moveAll && max.x < limit) {
max.x = limit;
}
}

size = Vector2(MAX(max.x - min.x, 0.0f), MAX(max.y - min.y, 0.0f));
size = Vector2(max.x - min.x, max.y - min.y);
rect->setSize(size);

if(rect->parentTransform()) {
Expand All @@ -236,9 +257,9 @@ void WidgetTool::update(bool pivot, bool local, bool snap) {
shape = Qt::SizeFDiagCursor;
} else if(Handles::s_Axes == (Handles::BOTTOM | Handles::LEFT)) {
shape = Qt::SizeBDiagCursor;
} else if((Handles::s_Axes == Handles::TOP) | (Handles::s_Axes == Handles::BOTTOM)) {
} else if(Handles::s_Axes == Handles::TOP || Handles::s_Axes == Handles::BOTTOM) {
shape = Qt::SizeVerCursor;
} else if((Handles::s_Axes == Handles::LEFT) | (Handles::s_Axes == Handles::RIGHT)) {
} else if(Handles::s_Axes == Handles::LEFT || Handles::s_Axes == Handles::RIGHT) {
shape = Qt::SizeHorCursor;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/uikit/src/editor/widgetcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void WidgetController::onSelectActor(uint32_t object) {
}

void WidgetController::onSelectActor(const QList<Object *> &list) {
onSelectActor(list.front()->uuid());
onSelectActor(list.size() > 0 ? list.front()->uuid() : 0);
}

void WidgetController::drawHandles() {
Expand Down
Loading