Files
viseq/src/node.h
T

89 lines
1.9 KiB
C++
Raw Normal View History

2024-10-09 02:01:23 +02:00
#pragma once
#include <memory>
#include <raylib.h>
2024-10-09 02:01:23 +02:00
#include "connector.h"
2024-10-09 02:01:23 +02:00
#include "datatypes.h"
#include "draggable.h"
2024-10-30 14:55:24 +01:00
#include "graph-item.h"
#include "vmath.h"
2024-10-20 01:17:18 +02:00
2024-11-03 03:48:49 +01:00
namespace VISEQ::GRAPH::EDGES{
class Edge;
}
2024-10-09 02:01:23 +02:00
2024-11-03 03:48:49 +01:00
namespace VISEQ::GRAPH::NODES {
class Node : public BASE::Draggable, public GraphItem{
2024-11-03 03:48:49 +01:00
public:
using GraphItem::state;
Node() {}
Node(float x, float y) : Draggable(Vec2Df(x, y)) {}
Node(Vec2Df p) : Draggable(p) {}
2024-11-12 01:42:05 +01:00
void addConnector() {
connectors.emplace_back(std::make_shared<Connector>(std::make_shared<GraphItem>(this), position, radius + 5.0f));
connectors.back()->init();
2024-11-12 01:42:05 +01:00
}
void init() {
addConnector();
}
2024-10-27 00:40:57 +02:00
2024-11-03 03:48:49 +01:00
NodeType nodeType;
2024-11-06 02:28:37 +01:00
std::vector<std::shared_ptr<Node>> neighbors;
2024-11-03 03:48:49 +01:00
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;
2024-11-03 03:48:49 +01:00
Distribution distributionMode = Distribution::GEOMETRIC;
2024-11-03 03:48:49 +01:00
float radius = 15.0f;
bool config = false;
2024-11-03 03:48:49 +01:00
virtual NodeType getNodeType() const {return nodeType;}
2024-11-03 03:48:49 +01:00
virtual void SMode(int mode) {};
virtual int GGate() {return 0;};
virtual int GActive() {return 0;};
virtual void trigger() {};
virtual bool hovering() override {
2024-11-14 23:21:04 +01:00
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);
2024-11-11 02:11:54 +01:00
c->update();
}
if(free_connectors == 0) addConnector();
}
2024-11-12 01:42:05 +01:00
void draw(Vec2Df mp, Camera2D cam) override {}
void draw() override{
for(auto c : connectors){
c->draw();
}
}
2024-11-03 03:48:49 +01:00
};
2024-11-03 03:48:49 +01:00
typedef std::shared_ptr<VISEQ::GRAPH::NODES::Node> SPTR_Node;
typedef std::vector<SPTR_Node> VEC_SPTR_Node;
2024-11-03 03:48:49 +01:00
}