2024-11-10 01:56:33 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-11-11 02:11:54 +01:00
|
|
|
#include "draggable.h"
|
2024-11-12 01:42:05 +01:00
|
|
|
#include <memory>
|
2024-11-13 01:58:44 +01:00
|
|
|
|
2024-11-10 01:56:33 +01:00
|
|
|
namespace VISEQ::BASE {
|
2024-11-11 02:11:54 +01:00
|
|
|
class Connectable : public Draggable{
|
2024-11-10 01:56:33 +01:00
|
|
|
public:
|
2024-11-13 01:58:44 +01:00
|
|
|
Connectable() {}
|
|
|
|
|
Connectable(Vec2Df position) : Draggable(position) {}
|
2024-11-10 01:56:33 +01:00
|
|
|
virtual ~Connectable() {}
|
2024-11-13 01:58:44 +01:00
|
|
|
|
2024-11-12 01:42:05 +01:00
|
|
|
inline static std::vector<std::shared_ptr<Connectable>> connectables;
|
|
|
|
|
|
2024-11-11 02:11:54 +01:00
|
|
|
std::shared_ptr<Connectable> partner;
|
2024-11-10 01:56:33 +01:00
|
|
|
|
2024-11-13 01:58:44 +01:00
|
|
|
virtual void init() {
|
|
|
|
|
connectables.emplace_back(this);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-12 01:42:05 +01:00
|
|
|
virtual bool hovering() override {
|
2024-11-14 01:37:16 +01:00
|
|
|
return CheckCollisionPointCircle(state->screen_mouse, position, 5);
|
2024-11-12 01:42:05 +01:00
|
|
|
}
|
|
|
|
|
|
2024-11-11 02:11:54 +01:00
|
|
|
virtual void drag() override {
|
2024-11-14 00:55:09 +01:00
|
|
|
DrawLineV(position, state->mod_mouse, (Color){229, 181, 103, 255});
|
2024-11-10 01:56:33 +01:00
|
|
|
}
|
2024-11-13 01:58:44 +01:00
|
|
|
|
|
|
|
|
void update() override{
|
|
|
|
|
if(pickedUp()) drag();
|
|
|
|
|
if(released()) putDown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void putDown() override {
|
|
|
|
|
connect();
|
|
|
|
|
Draggable::putDown();
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-12 01:42:05 +01:00
|
|
|
virtual void connect() {
|
|
|
|
|
if(picked_up){
|
2024-11-13 01:58:44 +01:00
|
|
|
for(auto c : connectables){
|
|
|
|
|
if(c.get() != this && c->hovering()) {
|
|
|
|
|
partner = c;
|
2024-11-13 14:39:46 +01:00
|
|
|
c->partner.reset(this);
|
2024-11-13 01:58:44 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-12 01:42:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2024-11-10 01:56:33 +01:00
|
|
|
};
|
|
|
|
|
}
|