Files
viseq/src/node.h
T

99 lines
2.1 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 "state.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>(GraphItem::getptr(), 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<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 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 STATE != APP::InteractionState::DRAW_SELECTION && CheckCollisionPointCircle(SCREEN_MOUSE, position, radius);
}
virtual bool entered() override {
return !is_hovering && hovering();
}
virtual bool exited() override {
return is_hovering && !hovering();
}
void update() override{
BASE::Draggable::update();
int free_connectors = 0;
for(auto c : connectors){
if(!c->partner) free_connectors++;
c->setPosition(position);
c->update();
}
if(free_connectors == 0) addConnector();
is_hovering = hovering();
}
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;
}