87 lines
1.7 KiB
C++
87 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include <raylib.h>
|
|
|
|
#include "connector.h"
|
|
#include "datatypes.h"
|
|
#include "draggable.h"
|
|
#include "graph-item.h"
|
|
#include "vmath.h"
|
|
|
|
namespace VISEQ::GRAPH::EDGES{
|
|
class Edge;
|
|
}
|
|
|
|
namespace VISEQ::GRAPH::NODES {
|
|
|
|
class Node : public BASE::Draggable, public GraphItem{
|
|
|
|
public:
|
|
using GraphItem::state;
|
|
|
|
Node() {}
|
|
Node(float x, float y) : Draggable(Vec2Df(x, y)) {}
|
|
Node(Vec2Df p) : Draggable(p) {}
|
|
|
|
void addConnector() {
|
|
connectors.emplace_back(std::make_shared<Connector>(position, radius + 5.0f));
|
|
connectors.back()->init();
|
|
}
|
|
|
|
void init() {
|
|
addConnector();
|
|
}
|
|
|
|
NodeType nodeType;
|
|
|
|
std::vector<std::shared_ptr<Node>> neighbors;
|
|
std::vector<std::shared_ptr<VISEQ::GRAPH::EDGES::Edge>> connections;
|
|
|
|
std::vector<std::shared_ptr<Connector>> connectors;
|
|
|
|
Distribution distributionMode = Distribution::GEOMETRIC;
|
|
|
|
float radius = 15.0f;
|
|
bool config = false;
|
|
|
|
|
|
virtual NodeType getNodeType() const {return nodeType;}
|
|
|
|
virtual void SMode(int mode) {};
|
|
virtual int GGate() {return 0;};
|
|
virtual int GActive() {return 0;};
|
|
virtual void trigger() {};
|
|
|
|
virtual bool hovering() override {
|
|
return CheckCollisionPointCircle(state->screen_mouse, position, radius);
|
|
}
|
|
|
|
void update() override{
|
|
|
|
if(pickedUp()) drag();
|
|
if(released()) putDown();
|
|
int free_connectors = 0;
|
|
for(auto c : connectors){
|
|
if(!c->partner) free_connectors++;
|
|
c->setPosition(position);
|
|
c->update();
|
|
}
|
|
if(free_connectors == 0) addConnector();
|
|
}
|
|
|
|
void draw(Vec2Df mp, Camera2D cam) override {}
|
|
|
|
void draw() override{
|
|
for(auto c : connectors){
|
|
c->draw();
|
|
}
|
|
}
|
|
|
|
};
|
|
|
|
typedef std::shared_ptr<VISEQ::GRAPH::NODES::Node> SPTR_Node;
|
|
typedef std::vector<SPTR_Node> VEC_SPTR_Node;
|
|
|
|
}
|