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
7 changes: 4 additions & 3 deletions engine/includes/editor/viewport/cameracontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ public slots:
void bottomSide();

protected:
void cameraZoom(float delta);
virtual void cameraZoom(float delta);

void cameraRotate(const Vector3 &delta);
virtual void cameraRotate(const Vector3 &delta);

void cameraMove(const Vector3 &delta);
virtual void cameraMove(const Vector3 &delta);

void drawHelpers(Object &object);

Expand Down Expand Up @@ -124,6 +124,7 @@ public slots:
float m_focalLengthTarget;
float m_transferProgress;

Vector2 m_delta;
Vector2 m_saved;

Actor *m_camera;
Expand Down
1 change: 0 additions & 1 deletion engine/includes/editor/viewport/viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class ENGINE_EXPORT Viewport : public QWidget {
void setLiveUpdate(bool update);

void setGameView(bool enabled);
void setSceneView(bool enabled);

void setGridEnabled(bool enabled);
void setGizmoEnabled(bool enabled);
Expand Down
12 changes: 8 additions & 4 deletions engine/src/editor/viewport/cameracontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ void CameraController::update() {
}

Vector4 pos(Input::mousePosition());

if(Input::isMouseButtonDown(Input::MOUSE_RIGHT) || Input::isMouseButtonDown(Input::MOUSE_MIDDLE)) {
m_saved = Vector2(pos.x, pos.y);
}
Expand All @@ -107,9 +108,9 @@ void CameraController::update() {
}

// Mouse control
Vector2 delta = Vector2(pos.x, pos.y) - m_saved;
m_delta = Vector2(pos.x, pos.y) - m_saved;

Vector3 p(delta.x / m_screenSize.x * m_activeCamera->ratio(), delta.y / m_screenSize.y, 0.0f);
Vector3 p(m_delta.x / m_screenSize.x * m_activeCamera->ratio(), m_delta.y / m_screenSize.y, 0.0f);

Handles::s_Mouse = Vector2(pos.z, pos.w);
Handles::s_Screen = m_screenSize;
Expand All @@ -128,7 +129,7 @@ void CameraController::update() {
m_saved = p;
}
} else if(!m_blockRotation) {
cameraRotate(Vector3(-delta.y, delta.x, 0.0f) * 0.1f);
cameraRotate(Vector3(-m_delta.y, m_delta.x, 0.0f) * 0.1f);
m_saved = Vector2(pos.x, pos.y);
}
} else if(Input::isMouseButton(Input::MOUSE_MIDDLE) && !m_blockMove) {
Expand All @@ -139,7 +140,10 @@ void CameraController::update() {
}

// Camera zoom
cameraZoom(Input::mouseScrollDelta());
float delta = Input::mouseScrollDelta();
if(delta != 0.0f) {
cameraZoom(delta);
}
}

void CameraController::move() {
Expand Down
10 changes: 0 additions & 10 deletions engine/src/editor/viewport/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,6 @@ void Viewport::init() {
PipelineTask *lastLayer = pipelineContext->renderTasks().back();

if(!m_gameView) {
setSceneView(true);

m_gridRender = new GridRender;
m_gridRender->setInput(0, lastLayer->output(0));
m_gridRender->setInput(1, pipelineContext->textureBuffer("depthMap"));
Expand Down Expand Up @@ -671,14 +669,6 @@ void Viewport::setGameView(bool enabled) {
m_gameView = enabled;
}

void Viewport::setSceneView(bool enabled) {
PipelineContext *pipelineContext = m_renderSystem->pipelineContext();

for(auto it : pipelineContext->renderTasks()) {
it->setProperty("sceneView", enabled);
}
}

void Viewport::setGridEnabled(bool enabled) {
m_gridRender->setEnabled(enabled);
}
Expand Down
12 changes: 4 additions & 8 deletions modules/editor/grapheditor/editor/graph/abstractnodegraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ void AbstractNodeGraph::load(const QString &path) {
if(version == 0) {
loadGraphV0(loadXmlMap(document));
} else {
blockSignals(true);

QDomNode p = document.firstChild();
while(!p.isNull()) {
QDomElement element = p.toElement();
Expand All @@ -269,6 +271,8 @@ void AbstractNodeGraph::load(const QString &path) {
p = p.nextSiblingElement();
}

blockSignals(false);

emit graphUpdated();
}

Expand Down Expand Up @@ -300,14 +304,6 @@ QStringList AbstractNodeGraph::nodeList() const {
return QStringList();
}

void AbstractNodeGraph::setPreviewVisible(GraphNode *node, bool visible) {

}

Texture *AbstractNodeGraph::preview(GraphNode *node) {
return nullptr;
}

QVariantMap AbstractNodeGraph::loadXmlMap(const QDomElement &parent) {
QVariantMap result;

Expand Down
3 changes: 0 additions & 3 deletions modules/editor/grapheditor/editor/graph/abstractnodegraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ class NODEGRAPH_EXPORT AbstractNodeGraph : public QObject {

void reportMessage(GraphNode *node, const QString &text);

virtual void setPreviewVisible(GraphNode *node, bool visible);
virtual Texture *preview(GraphNode *node);

signals:
void graphUpdated();

Expand Down
53 changes: 36 additions & 17 deletions modules/editor/grapheditor/editor/graph/graphcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <components/camera.h>
#include <components/recttransform.h>

Vector3 GraphController::s_worldPosition;

GraphController::GraphController(GraphView *view) :
m_focusedWidget(nullptr),
m_graph(nullptr),
Expand Down Expand Up @@ -52,16 +50,12 @@ void GraphController::composeLinks() {
m_view->composeLinks();
}

Vector3 GraphController::worldPosition() {
return s_worldPosition;
}

void GraphController::update() {
Vector4 pos = Input::mousePosition();
s_worldPosition = m_activeCamera->unproject(Vector3(pos.z, pos.w, 0.0f));

if((Input::isMouseButtonUp(Input::MOUSE_RIGHT) && !m_cameraInMove) ||
(Input::isMouseButtonUp(Input::MOUSE_LEFT) && m_view->isCreationLink())) {

m_view->showMenu();
}

Expand All @@ -85,22 +79,30 @@ void GraphController::update() {
emit unsetCursor();
}

RectTransform *parentRect = static_cast<RectTransform *>(m_view->view().transform());
Vector2 parentSize(parentRect->size());
Vector3 localPos = parentRect->worldTransform().inverse() * Vector3(pos.x, pos.y, 0.0f);

float px = localPos.x - parentSize.x * 0.5f;
float py = localPos.y - parentSize.y * 0.5f;

if(Input::isMouseButtonDown(Input::MOUSE_LEFT)) {
if(m_focusedWidget == nullptr &&
shape == Qt::ArrowCursor && !m_view->isCreationLink()) {
m_view->rubberBand()->setEnabled(true);
m_view->rubberBand()->raise();
RectTransform *rect = m_view->rubberBand()->rectTransform();

m_rubberOrigin = Vector2(s_worldPosition.x, s_worldPosition.y);
m_rubberOrigin = Vector2(px, py);

RectTransform *rect = m_view->rubberBand()->rectTransform();
rect->setPosition(Vector3(m_rubberOrigin, 0.0f));
rect->setSize(Vector2());
rect->setSize(Vector2(0.0f));
}
}

if(m_view->rubberBand()->isEnabled()) {
QRect r(QPoint(MIN(m_rubberOrigin.x, s_worldPosition.x), MIN(m_rubberOrigin.y, s_worldPosition.y)),
QPoint(MAX(m_rubberOrigin.x, s_worldPosition.x), MAX(m_rubberOrigin.y, s_worldPosition.y)));
QRect r(QPoint(MIN(m_rubberOrigin.x, px), MIN(m_rubberOrigin.y, py)),
QPoint(MAX(m_rubberOrigin.x, px), MAX(m_rubberOrigin.y, py)));

RectTransform *transform = m_view->rubberBand()->rectTransform();
transform->setPosition(Vector3(r.x(), r.y(), 0.0f));
Expand Down Expand Up @@ -140,11 +142,11 @@ void GraphController::update() {
}

if(m_focusedWidget) {
RectTransform *title = m_focusedWidget->title()->rectTransform();
RectTransform *rect = m_focusedWidget->rectTransform();

if(title->isHovered(s_worldPosition.x, s_worldPosition.y)) {
if(rect->isHovered(pos.x, pos.y)) {
if(Input::isMouseButtonDown(Input::MOUSE_LEFT)) {
m_originMousePos = Vector3(s_worldPosition.x, s_worldPosition.y, 0.0f);
m_originMousePos = Vector3(px, py, 0.0f);
}

if(!m_drag && Input::isMouseButtonUp(Input::MOUSE_LEFT)) {
Expand Down Expand Up @@ -182,7 +184,7 @@ void GraphController::update() {

if(m_drag) {
if(Input::isMouseButton(Input::MOUSE_LEFT)) {
Vector3 newPos = m_originNodePos + Vector3(s_worldPosition.x, s_worldPosition.y, 0.0f) - m_originMousePos;
Vector3 newPos = m_originNodePos + Vector3(px, py, 0.0f) - m_originMousePos;

float snap = m_view->gridCell();
for(int n = 0; n < 3; n++) {
Expand Down Expand Up @@ -225,7 +227,7 @@ void GraphController::update() {
m_drag = false;
}
} else {
if(m_focusedWidget && (Vector3(s_worldPosition.x, s_worldPosition.y, 0.0f) - m_originMousePos).length() > 5.0f) { // Drag sensor = 5.0f
if(m_focusedWidget && (Vector3(pos.x, pos.y, 0.0f) - m_originMousePos).length() > 5.0f) { // Drag sensor = 5.0f
if(m_selectedItems.isEmpty() || !isSelected(m_focusedWidget)) { // Select on drag
for(auto it : qAsConst(m_selectedItems)) {
GraphNode *node = static_cast<GraphNode *>(it);
Expand Down Expand Up @@ -286,6 +288,23 @@ void GraphController::update() {
}
}

void GraphController::cameraMove(const Vector3 &delta) {
CameraController::cameraMove(delta);

Transform *t = m_view->view().transform();
t->setPosition(t->position() + Vector3(m_delta, 0.0f));
}

void GraphController::cameraZoom(float delta) {
CameraController::cameraZoom(delta);

Transform *t = m_view->view().transform();

float scale = CLAMP(t->scale().x * 1000.0f + delta, m_zoomLimit.x, m_zoomLimit.y) * 0.001f;

t->setScale(Vector3(scale, scale, 1.0f));
}

bool GraphController::isSelected(NodeWidget *widget) const {
bool result = false;

Expand Down
7 changes: 4 additions & 3 deletions modules/editor/grapheditor/editor/graph/graphcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ class GraphController : public CameraController {

void composeLinks();

static Vector3 worldPosition();

private:
void update() override;

void cameraMove(const Vector3 &delta) override;

void cameraZoom(float delta) override;

bool isSelected(NodeWidget *widget) const;

private:
QList<QObject *> m_selectedItems;
QList<QObject *> m_softSelectedItems;

static Vector3 s_worldPosition;
Vector3 m_originMousePos;
Vector3 m_originNodePos;
Vector2 m_rubberOrigin;
Expand Down
33 changes: 26 additions & 7 deletions modules/editor/grapheditor/editor/graph/graphnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

#include <QMetaProperty>

#include <components/recttransform.h>

#include <editor/assetconverter.h>
#include "graphwidgets/nodewidget.h"

Q_DECLARE_METATYPE(Vector2)
Q_DECLARE_METATYPE(Vector3)
Q_DECLARE_METATYPE(Vector4)

namespace {
const char *gNodeWidget("NodeWidget");
}

GraphNode::GraphNode() :
m_nodeWidget(nullptr),
m_graph(nullptr) {
Expand Down Expand Up @@ -68,15 +74,28 @@ void GraphNode::setPosition(const Vector2 &position) {
m_pos = position;
}

NodeWidget *GraphNode::widget() const {
Widget *GraphNode::widget() {
if(m_nodeWidget == nullptr) {
Actor *nodeActor = Engine::composeActor(gNodeWidget, qPrintable(objectName()));
if(nodeActor) {
NodeWidget *nodeWidget = static_cast<NodeWidget *>(nodeActor->component(gNodeWidget));

nodeWidget->setGraphNode(this);
nodeWidget->setBorderColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));

m_nodeWidget = nodeWidget;
}
}

return m_nodeWidget;
}
void GraphNode::setWidget(NodeWidget *widget) {
m_nodeWidget = widget;
}

bool GraphNode::isState() const {
return false;
Widget *GraphNode::portWidget(int port) {
NodePort *p = GraphNode::port(port);
if(p) {
return reinterpret_cast<Widget *>(p->m_userData);
}
return nullptr;
}

std::vector<NodePort> &GraphNode::ports() {
Expand All @@ -86,7 +105,7 @@ std::vector<NodePort> &GraphNode::ports() {
void GraphNode::saveUserData(QVariantMap &data) {
const QMetaObject *meta = metaObject();
for(int i = 0; i < meta->propertyCount(); i++) {
QMetaProperty property = meta->property(i);
QMetaProperty property = meta->property(i);
if(property.isUser(this)) {
QVariant value = property.read(this);
switch(value.userType()) {
Expand Down
9 changes: 4 additions & 5 deletions modules/editor/grapheditor/editor/graph/graphnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class AbstractNodeGraph;
class GraphNode;
class NodeWidget;
class Widget;

class NODEGRAPH_EXPORT NodePort {
public:
Expand Down Expand Up @@ -82,10 +82,9 @@ class NODEGRAPH_EXPORT GraphNode : public QObject {

void setPosition(const Vector2 &position);

NodeWidget *widget() const;
void setWidget(NodeWidget *widget);
virtual Widget *widget();

virtual bool isState() const;
virtual Widget *portWidget(int port);

std::vector<NodePort> &ports();

Expand All @@ -102,7 +101,7 @@ class NODEGRAPH_EXPORT GraphNode : public QObject {

Vector2 m_pos;

NodeWidget *m_nodeWidget;
Widget *m_nodeWidget;

AbstractNodeGraph *m_graph;

Expand Down
Loading