various node UI improvements

This commit is contained in:
itsmattkc
2019-07-16 13:25:38 -04:00
parent ea4e142e0c
commit a78cc3950a
26 changed files with 279 additions and 154 deletions
+7 -3
View File
@@ -1,11 +1,15 @@
#include "solid.h"
SolidGenerator::SolidGenerator(QObject *parent) :
Node(parent),
SolidGenerator::SolidGenerator() :
texture_(nullptr)
{
texture_output_ = new NodeOutput(this);
color_input_ = new NodeInput();
color_input_->add_data_input(NodeParam::kColor);
AddParameter(color_input_);
texture_output_ = new NodeOutput();
texture_output_->set_data_type(NodeOutput::kTexture);
AddParameter(texture_output_);
}
QString SolidGenerator::Name()
+3 -1
View File
@@ -9,7 +9,7 @@ class SolidGenerator : public Node
{
Q_OBJECT
public:
SolidGenerator(QObject* parent = nullptr);
SolidGenerator();
virtual QString Name() override;
virtual QString Category() override;
@@ -21,6 +21,8 @@ public slots:
virtual void Process(const rational &time) override;
private:
NodeInput* color_input_;
NodeOutput* texture_output_;
QOpenGLTexture* texture_;
+8
View File
@@ -27,6 +27,14 @@ NodeGraph::NodeGraph()
}
void NodeGraph::AddNode(Node *node)
{
node->setParent(this);
connect(node, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SIGNAL(EdgeAdded(NodeEdgePtr)));
connect(node, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SIGNAL(EdgeRemoved(NodeEdgePtr)));
}
const QString &NodeGraph::name()
{
return name_;
+7
View File
@@ -27,14 +27,21 @@
class NodeGraph : public QObject
{
Q_OBJECT
public:
NodeGraph();
void AddNode(Node* node);
const QString& name();
void set_name(const QString& name);
QList<Node*> nodes();
signals:
void EdgeAdded(NodeEdgePtr edge);
void EdgeRemoved(NodeEdgePtr edge);
private:
QString name_;
};
+6 -2
View File
@@ -22,8 +22,7 @@
#include "output.h"
NodeInput::NodeInput(Node* parent) :
NodeParam(parent),
NodeInput::NodeInput() :
can_accept_multiple_inputs_(false)
{
// Have at least one keyframe/value active at any time
@@ -97,3 +96,8 @@ void NodeInput::set_keyframing(bool k)
{
keyframing_ = k;
}
const QList<NodeParam::DataType> &NodeInput::inputs()
{
return inputs_;
}
+3 -1
View File
@@ -27,7 +27,7 @@
class NodeInput : public NodeParam
{
public:
NodeInput(Node *parent);
NodeInput();
virtual Type type() override;
@@ -43,6 +43,8 @@ public:
bool keyframing();
void set_keyframing(bool k);
const QList<DataType>& inputs();
private:
QList<DataType> inputs_;
+9 -2
View File
@@ -22,8 +22,7 @@
#include "common/qobjectlistcast.h"
Node::Node(QObject *parent) :
QObject(parent)
Node::Node()
{
}
@@ -39,6 +38,14 @@ QString Node::Description()
return QString();
}
void Node::AddParameter(NodeParam *param)
{
param->setParent(this);
connect(param, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SIGNAL(EdgeAdded(NodeEdgePtr)));
connect(param, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SIGNAL(EdgeRemoved(NodeEdgePtr)));
}
void Node::InvalidateCache(const rational &start_range, const rational &end_range)
{
QList<NodeParam *> params = parameters();
+7 -1
View File
@@ -31,12 +31,14 @@ class Node : public QObject
{
Q_OBJECT
public:
Node(QObject* parent = nullptr);
Node();
virtual QString Name() = 0;
virtual QString Category();
virtual QString Description();
void AddParameter(NodeParam* param);
/**
* @brief Signal all dependent Nodes that anything cached between start_range and end_range is now invalid and
* requires re-rendering
@@ -71,6 +73,10 @@ public:
public slots:
virtual void Process(const rational& time) = 0;
signals:
void EdgeAdded(NodeEdgePtr edge);
void EdgeRemoved(NodeEdgePtr edge);
};
#endif // NODE_H
+1 -2
View File
@@ -22,8 +22,7 @@
#include "node/node.h"
NodeOutput::NodeOutput(Node *parent) :
NodeParam(parent)
NodeOutput::NodeOutput()
{
}
+1 -1
View File
@@ -26,7 +26,7 @@
class NodeOutput : public NodeParam
{
public:
NodeOutput(Node* parent);
NodeOutput();
virtual Type type() override;
+3 -3
View File
@@ -2,12 +2,12 @@
#include "panel/panelfocusmanager.h"
ViewerOutput::ViewerOutput(QObject* parent) :
Node(parent),
ViewerOutput::ViewerOutput() :
attached_viewer_(nullptr)
{
texture_input_ = new NodeInput(this);
texture_input_ = new NodeInput();
texture_input_->add_data_input(NodeInput::kTexture);
AddParameter(texture_input_);
}
QString ViewerOutput::Name()
+1 -1
View File
@@ -8,7 +8,7 @@ class ViewerOutput : public Node
{
Q_OBJECT
public:
ViewerOutput(QObject* parent = nullptr);
ViewerOutput();
virtual QString Name() override;
virtual QString Category() override;
+37 -2
View File
@@ -20,12 +20,13 @@
#include "param.h"
#include <QDebug>
#include "node/node.h"
#include "node/input.h"
#include "node/output.h"
NodeParam::NodeParam(Node *parent) :
QObject(parent)
NodeParam::NodeParam()
{
}
@@ -54,6 +55,28 @@ const QVector<NodeEdgePtr> &NodeParam::edges()
return edges_;
}
bool NodeParam::AreDataTypesCompatible(NodeParam *a, NodeParam *b)
{
// Make sure one is an input and one is an output
if (a->type() == b->type()) {
return false;
}
NodeInput* input;
NodeOutput* output;
// Work out which parameter is which
if (a->type() == NodeParam::kInput) {
input = static_cast<NodeInput*>(a);
output = static_cast<NodeOutput*>(b);
} else {
input = static_cast<NodeInput*>(b);
output = static_cast<NodeOutput*>(a);
}
return AreDataTypesCompatible(output->data_type(), input->inputs());
}
bool NodeParam::AreDataTypesCompatible(const NodeParam::DataType &output_type, const NodeParam::DataType &input_type)
{
if (input_type == output_type) {
@@ -94,11 +117,21 @@ NodeEdgePtr NodeParam::ConnectEdge(NodeOutput *output, NodeInput *input)
DisconnectEdge(input->edges_.first());
}
// Make sure it's not a duplicate of an edge that already exists
foreach (NodeEdgePtr existing, input->edges()) {
if (existing->output() == output) {
return nullptr;
}
}
NodeEdgePtr edge = std::make_shared<NodeEdge>(output, input);
output->edges_.append(edge);
input->edges_.append(edge);
// Emit a signal than an edge was added (only one signal needs emitting)
emit output->EdgeAdded(edge);
return edge;
}
@@ -109,6 +142,8 @@ void NodeParam::DisconnectEdge(NodeEdgePtr edge)
output->edges_.removeAll(edge);
input->edges_.removeAll(edge);
emit output->EdgeRemoved(edge);
}
QString NodeParam::GetDefaultDataTypeName(const DataType& type)
+7 -1
View File
@@ -31,6 +31,7 @@ class Node;
class NodeParam : public QObject
{
Q_OBJECT
public:
enum Type {
kInput,
@@ -52,7 +53,7 @@ public:
kAny
};
NodeParam(Node* parent);
NodeParam();
virtual Type type() = 0;
@@ -65,6 +66,7 @@ public:
const QVector<NodeEdgePtr>& edges();
static bool AreDataTypesCompatible(NodeParam* a, NodeParam* b);
static bool AreDataTypesCompatible(const DataType& output_type, const DataType& input_type);
static bool AreDataTypesCompatible(const DataType& output_type, const QList<DataType>& input_types);
@@ -73,6 +75,10 @@ public:
static QString GetDefaultDataTypeName(const DataType &type);
signals:
void EdgeAdded(NodeEdgePtr edge);
void EdgeRemoved(NodeEdgePtr edge);
protected:
QVector<NodeEdgePtr> edges_;
+1 -2
View File
@@ -20,8 +20,7 @@
#include "renderer.h"
RendererProcessor::RendererProcessor(QObject *parent) :
Node(parent),
RendererProcessor::RendererProcessor() :
started_(false)
{
+1 -1
View File
@@ -34,7 +34,7 @@ public:
* Constructing a Renderer object will not start any threads/backend on its own. Use Start() to do this and Stop()
* when the Renderer is about to be destroyed.
*/
RendererProcessor(QObject* parent = nullptr);
RendererProcessor();
virtual QString Name() override;
virtual QString Category() override;