connecting works, but position is off. addConnector is the problem

This commit is contained in:
Sebastian
2024-11-13 01:58:44 +01:00
parent 96082e1190
commit 1e0a131169
4 changed files with 46 additions and 36 deletions
+33 -19
View File
@@ -1,44 +1,58 @@
#pragma once
#include "datatypes.h"
#include "draggable.h"
#include <memory>
namespace VISEQ::BASE {
class Connectable : public Draggable{
public:
Connectable() {VISEQ::BASE::Connectable::connectables.emplace_back(this);}
Connectable(Vec2Df position) : Draggable(position) {VISEQ::BASE::Connectable::connectables.emplace_back(this);}
Connectable() {}
/*Connectable() {VISEQ::BASE::Connectable::connectables.emplace_back(this);}*/
Connectable(Vec2Df position) : Draggable(position) {}
/*virtual ~Connectable() { connectables.erase(std::remove(connectables.begin(), connectables.end(), std::shared_ptr<Connectable>(this)), connectables.end()); }*/
virtual ~Connectable() {}
inline static std::vector<std::shared_ptr<Connectable>> connectables;
std::shared_ptr<Connectable> partner;
virtual void init() {
connectables.emplace_back(this);
}
virtual bool hovering() override {
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
return CheckCollisionPointCircle(mp, position, 5);
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
std::cout << "hovering" << std::endl;
return CheckCollisionPointCircle(mp, position, 5);
}
virtual void drag() override {
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
DrawLineV(position, mp, (Color){229, 181, 103, 255});
}
void update() override{
if(pickedUp()) drag();
if(released()) putDown();
}
void putDown() override {
connect();
Draggable::putDown();
}
virtual void connect() {
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
if(picked_up){
DrawLineV(position, mp, (Color){229, 181, 103, 255});
}
if(released()){
std::cout << connectables.size() << std::endl;
// static auto hover_partner = VISEQ::BASE::Connectable::connectables | std::ranges::views::filter([](std::shared_ptr<Connectable> c){ return c->hovering();}) | std::ranges::to<std::vector<std::shared_ptr<Connectable>>>();
// if(hover_partner.empty()){
/*SPTR_Node new_node = app.gm.copyNode(std::dynamic_pointer_cast<MidiNode>(connecting_nodes.front()), target_position);*/
/*new_node->connecting = false;*/
/*app.gm.addConnection(connecting_nodes.front(), new_node);*/
// } else {
// partner = hover_partner.front();
// }
for(auto c : connectables){
if(c.get() != this && c->hovering()) {
partner = c;
break;
}
}
}
}