2024-11-10 01:56:33 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-11-11 02:11:54 +01:00
|
|
|
#include "draggable.h"
|
2024-11-28 01:08:04 +01:00
|
|
|
#include "vmath.h"
|
2024-11-12 01:42:05 +01:00
|
|
|
#include <memory>
|
2024-12-01 00:55:59 +01:00
|
|
|
#include <vector>
|
2024-11-13 01:58:44 +01:00
|
|
|
|
2024-11-10 01:56:33 +01:00
|
|
|
namespace VISEQ::BASE {
|
2024-12-01 01:45:36 +01:00
|
|
|
class Connectable : public Draggable, public std::enable_shared_from_this<Connectable> {
|
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-28 08:49:35 +01:00
|
|
|
bool new_partner = false;
|
2024-11-30 12:47:33 +01:00
|
|
|
bool connecting = false;
|
|
|
|
|
Vec2Df connecting_position;
|
2024-11-10 01:56:33 +01:00
|
|
|
|
2024-12-01 01:45:36 +01:00
|
|
|
std::shared_ptr<Connectable> getPtr(){
|
|
|
|
|
return shared_from_this();
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-13 01:58:44 +01:00
|
|
|
virtual void init() {
|
|
|
|
|
connectables.emplace_back(this);
|
|
|
|
|
}
|
2024-12-01 00:55:59 +01:00
|
|
|
|
2024-11-28 01:08:04 +01:00
|
|
|
virtual void drag(Vec2Df new_position) override {
|
2024-11-30 12:47:33 +01:00
|
|
|
connecting = true;
|
|
|
|
|
connecting_position = new_position;
|
2024-11-10 01:56:33 +01:00
|
|
|
}
|
2024-11-13 01:58:44 +01:00
|
|
|
|
|
|
|
|
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){
|
2024-12-01 01:45:36 +01:00
|
|
|
if(c != getPtr() && c->hovering()) {
|
2024-11-13 01:58:44 +01:00
|
|
|
partner = c;
|
2024-12-01 01:45:36 +01:00
|
|
|
c->partner = getPtr();
|
2024-11-28 08:49:35 +01:00
|
|
|
new_partner = true;
|
|
|
|
|
partner->new_partner = true;
|
2024-12-01 01:45:36 +01:00
|
|
|
std::cout << "connect use count: " << getPtr().use_count() << std::endl;
|
2024-11-13 01:58:44 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-30 12:47:33 +01:00
|
|
|
connecting = false;
|
2024-11-12 01:42:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2024-11-30 12:47:33 +01:00
|
|
|
|
|
|
|
|
virtual void draw(){
|
|
|
|
|
if(connecting) DrawLineV(position, connecting_position, (Color){229, 181, 103, 255});
|
|
|
|
|
}
|
2024-11-10 01:56:33 +01:00
|
|
|
};
|
|
|
|
|
}
|