2024-11-10 01:56:33 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-11-11 02:11:54 +01:00
|
|
|
#include "connectable.h"
|
2024-11-24 03:08:06 +01:00
|
|
|
#include "datatypes.h"
|
2024-11-12 01:42:05 +01:00
|
|
|
#include "graph-item.h"
|
2024-11-24 03:08:06 +01:00
|
|
|
#include "moveable.h"
|
2024-11-11 02:11:54 +01:00
|
|
|
#include "raymath.h"
|
2024-11-21 02:03:32 +01:00
|
|
|
#include "state.h"
|
2024-11-10 01:56:33 +01:00
|
|
|
#include "vmath.h"
|
|
|
|
|
|
|
|
|
|
namespace VISEQ::GRAPH {
|
2024-11-12 01:42:05 +01:00
|
|
|
class Connector : public BASE::Connectable, public GraphItem{
|
2024-11-10 01:56:33 +01:00
|
|
|
public:
|
2024-11-24 03:08:06 +01:00
|
|
|
using BASE::Movable::state;
|
2024-11-14 01:37:16 +01:00
|
|
|
|
2024-11-10 01:56:33 +01:00
|
|
|
Connector() {}
|
2024-11-15 02:09:06 +01:00
|
|
|
Connector(std::shared_ptr<GraphItem> parent, Vec2Df center_position, float orbit) : orbit(orbit) {
|
|
|
|
|
setPosition(center_position);
|
|
|
|
|
setParent(parent);
|
|
|
|
|
}
|
2024-11-24 03:08:06 +01:00
|
|
|
|
|
|
|
|
GraphItemType getType() override{
|
|
|
|
|
return GraphItemType::CONNECTOR;
|
|
|
|
|
}
|
2024-11-15 02:09:06 +01:00
|
|
|
|
|
|
|
|
std::shared_ptr<GraphItem> parent;
|
2024-11-16 00:29:01 +01:00
|
|
|
|
|
|
|
|
bool hover_connect = false;
|
2024-11-15 02:09:06 +01:00
|
|
|
|
2024-11-10 01:56:33 +01:00
|
|
|
float radius = 5.0f;
|
|
|
|
|
float orbit = 14.0f;
|
2024-11-13 14:39:46 +01:00
|
|
|
Vec2Df center_position;
|
2024-11-24 03:08:06 +01:00
|
|
|
|
|
|
|
|
std::shared_ptr<Connectable> getPtr(){
|
|
|
|
|
return std::static_pointer_cast<Connector>(shared_from_this());
|
|
|
|
|
}
|
2024-11-10 01:56:33 +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
|
|
|
}
|
|
|
|
|
|
2024-11-15 02:09:06 +01:00
|
|
|
void setParent(std::shared_ptr<GraphItem> _parent){
|
|
|
|
|
parent = _parent;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-13 01:58:44 +01:00
|
|
|
void setPosition(Vec2Df pos) override {
|
2024-11-13 14:39:46 +01:00
|
|
|
center_position = pos;
|
2024-11-19 01:04:06 +01:00
|
|
|
if(!partner) position = center_position - ((center_position - SCREEN_MOUSE)).norm() * (radius + orbit);
|
2024-11-13 14:39:46 +01:00
|
|
|
if(partner) position = center_position - ((center_position - partner->position)).norm() * (radius + orbit);
|
2024-11-10 01:56:33 +01:00
|
|
|
}
|
|
|
|
|
|
2024-11-21 02:03:32 +01:00
|
|
|
void update() override {
|
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-21 02:03:32 +01:00
|
|
|
}
|
|
|
|
|
|
2024-11-12 01:42:05 +01:00
|
|
|
void draw() override {
|
2024-11-19 01:04:06 +01:00
|
|
|
float opacity = 150.0f - Clamp(position.dist(SCREEN_MOUSE), 0.0f, 150.0f);
|
2024-11-10 01:56:33 +01:00
|
|
|
|
2024-11-13 01:58:44 +01:00
|
|
|
if(partner){
|
|
|
|
|
DrawLineV(position, partner->position, VS_COLOR_RED);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-10 01:56:33 +01:00
|
|
|
if(hover_connect){
|
2024-11-13 01:58:44 +01:00
|
|
|
DrawCircle(position.x, position.y, 8.0f, (Color){108, 153, 187, 255});
|
2024-11-10 01:56:33 +01:00
|
|
|
} else {
|
2024-11-13 01:58:44 +01:00
|
|
|
DrawCircle(position.x, position.y, 8.0f, (Color){108, 153, 187, (unsigned char)opacity});
|
2024-11-10 01:56:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|