2024-10-09 02:01:23 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-11-19 01:04:06 +01:00
|
|
|
#include <fcntl.h>
|
2024-11-02 23:12:38 +01:00
|
|
|
#include <memory>
|
2024-10-13 04:22:09 +02:00
|
|
|
#include <raylib.h>
|
2024-10-09 02:01:23 +02:00
|
|
|
|
2024-11-10 01:56:33 +01:00
|
|
|
#include "connector.h"
|
2024-10-09 02:01:23 +02:00
|
|
|
#include "datatypes.h"
|
2024-11-10 01:56:33 +01:00
|
|
|
#include "draggable.h"
|
2024-10-30 14:55:24 +01:00
|
|
|
#include "graph-item.h"
|
2024-11-24 03:08:06 +01:00
|
|
|
#include "interaction-event.h"
|
2024-11-17 02:40:31 +01:00
|
|
|
#include "state.h"
|
2024-11-10 01:56:33 +01:00
|
|
|
#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 {
|
2024-11-01 02:38:47 +01:00
|
|
|
|
2024-11-24 03:08:06 +01:00
|
|
|
class Node : public BASE::Draggable, public GraphItem {
|
2024-11-01 02:38:47 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
public:
|
2024-11-14 01:37:16 +01:00
|
|
|
|
2024-11-13 14:39:46 +01:00
|
|
|
Node() {}
|
|
|
|
|
Node(float x, float y) : Draggable(Vec2Df(x, y)) {}
|
|
|
|
|
Node(Vec2Df p) : Draggable(p) {}
|
2024-11-28 01:08:04 +01:00
|
|
|
|
|
|
|
|
/*Node(const Node& n){*/
|
|
|
|
|
/* distributionMode = n.distributionMode;*/
|
|
|
|
|
/* radius = n.radius;*/
|
|
|
|
|
/* config = n.config;*/
|
|
|
|
|
/* position = n.position;*/
|
|
|
|
|
/* for(auto c : n.connectors){*/
|
|
|
|
|
/* connectors.emplace_back(std::make_shared<Connector>(*c));*/
|
|
|
|
|
/* }*/
|
|
|
|
|
/*}*/
|
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;
|
2024-10-19 04:08:46 +02:00
|
|
|
|
2024-11-10 01:56:33 +01:00
|
|
|
std::vector<std::shared_ptr<Connector>> connectors;
|
|
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
Distribution distributionMode = Distribution::GEOMETRIC;
|
2024-11-01 02:38:47 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
float radius = 15.0f;
|
|
|
|
|
bool config = false;
|
2024-11-02 15:52:16 +01:00
|
|
|
|
2024-11-21 02:03:32 +01:00
|
|
|
virtual bool hovering() override {
|
2024-11-24 03:08:06 +01:00
|
|
|
return CheckCollisionPointCircle(SCREEN_MOUSE, position, radius);
|
2024-11-21 02:03:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addConnector() {
|
|
|
|
|
connectors.emplace_back(std::make_shared<Connector>(GraphItem::getptr(), position, radius + 5.0f));
|
|
|
|
|
connectors.back()->init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void init() {
|
|
|
|
|
addConnector();
|
|
|
|
|
}
|
2024-11-10 01:56:33 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
virtual NodeType getNodeType() const {return nodeType;}
|
2024-11-02 23:12:38 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
virtual void SMode(int mode) {};
|
2024-11-21 02:03:32 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
virtual void trigger() {};
|
2024-11-10 01:56:33 +01:00
|
|
|
|
2024-11-24 03:08:06 +01:00
|
|
|
GraphItemType getType() override{
|
|
|
|
|
return GraphItemType::NODE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<Node> getPtr(){
|
|
|
|
|
return std::static_pointer_cast<Node>(shared_from_this());
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-10 01:56:33 +01:00
|
|
|
void update() override{
|
2024-11-28 01:08:04 +01:00
|
|
|
if(hovering()) state->pushEvent({getPtr(), APP::Interaction::HOVER});
|
2024-11-24 03:08:06 +01:00
|
|
|
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});
|
2024-11-17 02:40:31 +01:00
|
|
|
|
2024-11-13 14:39:46 +01:00
|
|
|
int free_connectors = 0;
|
2024-11-10 01:56:33 +01:00
|
|
|
for(auto c : connectors){
|
2024-11-13 14:39:46 +01:00
|
|
|
if(!c->partner) free_connectors++;
|
2024-11-13 01:58:44 +01:00
|
|
|
c->setPosition(position);
|
2024-11-11 02:11:54 +01:00
|
|
|
c->update();
|
2024-11-10 01:56:33 +01:00
|
|
|
}
|
2024-11-13 14:39:46 +01:00
|
|
|
if(free_connectors == 0) addConnector();
|
2024-11-10 01:56:33 +01:00
|
|
|
}
|
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-02 23:12:38 +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-02 15:52:16 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
}
|