Files
viseq/src/connectable.h
T

56 lines
1.1 KiB
C++
Raw Normal View History

#pragma once
2024-11-11 02:11:54 +01:00
#include "draggable.h"
#include "vmath.h"
2024-11-12 01:42:05 +01:00
#include <memory>
namespace VISEQ::BASE {
2024-11-11 02:11:54 +01:00
class Connectable : public Draggable{
public:
Connectable() {}
Connectable(Vec2Df position) : Draggable(position) {}
virtual ~Connectable() {}
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;
bool new_partner = false;
2024-11-30 12:47:33 +01:00
bool connecting = false;
Vec2Df connecting_position;
virtual void init() {
connectables.emplace_back(this);
}
virtual void drag(Vec2Df new_position) override {
2024-11-30 12:47:33 +01:00
connecting = true;
connecting_position = new_position;
}
void putDown() override {
connect();
Draggable::putDown();
}
2024-11-12 01:42:05 +01:00
virtual void connect() {
if(picked_up){
for(auto c : connectables){
if(c.get() != this && c->hovering()) {
partner = c;
c->partner.reset(this);
new_partner = true;
partner->new_partner = true;
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});
}
};
}