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 <fcntl.h>
#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 "state.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
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;
virtual bool hovering() override {
return STATE != IState::DRAW_SELECTION && 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();
}
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) {};
2024-11-03 03:48:49 +01:00
virtual void trigger() {};
void update() override{
BASE::Draggable::update();
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();
/*is_hovering = hovering();*/
}
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
}