98 lines
2.2 KiB
C++
98 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#include <fcntl.h>
|
|
#include <memory>
|
|
#include <raylib.h>
|
|
|
|
#include "connector.h"
|
|
#include "datatypes.h"
|
|
#include "draggable.h"
|
|
#include "graph-item.h"
|
|
#include "interaction-event.h"
|
|
#include "state.h"
|
|
#include "vmath.h"
|
|
|
|
namespace VISEQ::GRAPH::EDGES{
|
|
class Edge;
|
|
}
|
|
|
|
namespace VISEQ::GRAPH::NODES {
|
|
|
|
class Node : public BASE::Draggable, public GraphItem {
|
|
|
|
public:
|
|
|
|
Node() {}
|
|
Node(float x, float y) : Draggable(Vec2Df(x, y)) {}
|
|
Node(Vec2Df p) : Draggable(p) {}
|
|
|
|
NodeType nodeType;
|
|
|
|
std::vector<std::shared_ptr<Node>> neighbors;
|
|
std::vector<std::shared_ptr<VISEQ::GRAPH::EDGES::Edge>> connections;
|
|
|
|
std::vector<std::shared_ptr<Node>> connected_nodes; //TODO: change from node->edge->node to node->node with edge being edge[node->node]
|
|
|
|
std::vector<std::shared_ptr<Connector>> connectors;
|
|
|
|
Distribution distributionMode = Distribution::GEOMETRIC;
|
|
|
|
float radius = 15.0f;
|
|
bool config = false;
|
|
|
|
virtual bool hovering() override {
|
|
return CheckCollisionPointCircle(SCREEN_MOUSE, position, radius);
|
|
}
|
|
|
|
void addConnector() {
|
|
connectors.emplace_back(std::make_shared<Connector>(GraphItem::getptr(), position, radius + 5.0f));
|
|
connectors.back()->init();
|
|
}
|
|
|
|
void init() {
|
|
addConnector();
|
|
}
|
|
|
|
virtual NodeType getNodeType() const {return nodeType;}
|
|
|
|
virtual void SMode(int mode) {};
|
|
|
|
virtual void trigger() {};
|
|
|
|
GraphItemType getType() override{
|
|
return GraphItemType::NODE;
|
|
}
|
|
|
|
std::shared_ptr<Node> getPtr(){
|
|
return std::static_pointer_cast<Node>(shared_from_this());
|
|
}
|
|
|
|
void update() override{
|
|
if(hovering() && clicked()) state->pushEvent({getPtr(), APP::Interaction::PICKUP});
|
|
if(pickedUp()) state->pushEvent({getPtr(), APP::Interaction::DRAG});
|
|
if(picked_up && released()) state->pushEvent({getPtr(), APP::Interaction::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;
|
|
|
|
}
|