Files
viseq/src/node.h
T
2026-06-28 23:45:54 +02:00

70 lines
1.8 KiB
C++

#pragma once
#include <memory>
#include <raylib.h>
#include "connector.h"
#include "datatypes.h"
#include "draggable.h"
#include "graph-item.h"
#include "vmath.h"
namespace VISEQ::GRAPH::EDGES{
class Edge;
}
namespace VISEQ::GRAPH::NODES {
class Node : public BASE::Draggable, public GraphItem, public std::enable_shared_from_this<Node> {
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<Connector>> connectors;
Distribution distributionMode = Distribution::GEOMETRIC;
float radius = 15.0f;
float node_radius = 15.0f;
float hover_radius = 32.0f;
bool config = false;
bool triggered = false;
int mode = 0;
virtual void trigger() {}
virtual void setMode(int _mode);
std::shared_ptr<Node> getPtr();
virtual bool hovering() override;
void addConnector();
std::weak_ptr<Connector> getConnector();
void removeConnector(std::weak_ptr<Connector> connector);
virtual NodeType getNodeType() const;
void deselect() override;
GraphItemType getType() override;
void clearConnectors();
void update() override;
void draw(Vec2Df mp, Camera2D cam) override;
void draw() override;
virtual void cycleMode(bool direction);
friend void to_json(json& j, const Node& N);
friend void from_json(const json& j, Node& N);
friend void to_json(json& j, const std::shared_ptr<Node>& N);
friend void from_json(const json& j, std::shared_ptr<Node>& N);
};
typedef std::shared_ptr<VISEQ::GRAPH::NODES::Node> SPTR_Node;
typedef std::weak_ptr<VISEQ::GRAPH::NODES::Node> WPTR_Node;
typedef std::vector<SPTR_Node> VEC_SPTR_Node;
typedef std::vector<WPTR_Node> VEC_WPTR_Node;
}