connecting works, but position is off. addConnector is the problem
This commit is contained in:
+28
-14
@@ -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};
|
||||
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});
|
||||
for(auto c : connectables){
|
||||
if(c.get() != this && c->hovering()) {
|
||||
partner = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+9
-14
@@ -9,34 +9,29 @@ namespace VISEQ::GRAPH {
|
||||
class Connector : public BASE::Connectable, public GraphItem{
|
||||
public:
|
||||
Connector() {}
|
||||
Connector(Vec2Df position, float orbit) : BASE::Connectable(position), orbit(orbit) {}
|
||||
Connector(Vec2Df center_position, float orbit) : orbit(orbit) {setPosition(center_position);}
|
||||
|
||||
float radius = 5.0f;
|
||||
float orbit = 14.0f;
|
||||
|
||||
virtual bool hovering() override {
|
||||
void setPosition(Vec2Df pos) override {
|
||||
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
|
||||
return CheckCollisionPointCircle(mp, position, radius);
|
||||
}
|
||||
|
||||
void updatePosition(Vec2Df pos){
|
||||
position = pos;
|
||||
}
|
||||
|
||||
void update() override{
|
||||
connect();
|
||||
position = pos - ((pos - mp)).norm() * (radius + orbit);
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
|
||||
|
||||
Vec2Df connector = position - ((position - mp)).norm() * (radius + orbit);
|
||||
float opacity = 150.0f - Clamp(position.dist(mp), 0.0f, 150.0f);
|
||||
|
||||
if(partner){
|
||||
DrawLineV(position, partner->position, VS_COLOR_RED);
|
||||
}
|
||||
|
||||
if(hover_connect){
|
||||
DrawCircle(connector.x, connector.y, 8.0f, (Color){108, 153, 187, 255});
|
||||
DrawCircle(position.x, position.y, 8.0f, (Color){108, 153, 187, 255});
|
||||
} else {
|
||||
DrawCircle(connector.x, connector.y, 8.0f, (Color){108, 153, 187, (unsigned char)opacity});
|
||||
DrawCircle(position.x, position.y, 8.0f, (Color){108, 153, 187, (unsigned char)opacity});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ namespace VISEQ::BASE {
|
||||
virtual Vec2Df getPosition() {return position;};
|
||||
virtual void update(double frametime) {};
|
||||
virtual void update() {};
|
||||
|
||||
virtual void update(Vec2Df pos) {};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+2
-1
@@ -24,6 +24,7 @@ namespace VISEQ::GRAPH::NODES {
|
||||
|
||||
void addConnector() {
|
||||
connectors.emplace_back(std::make_shared<Connector>(position, radius + 5.0f));
|
||||
connectors.back()->init();
|
||||
}
|
||||
|
||||
NodeType nodeType;
|
||||
@@ -55,7 +56,7 @@ namespace VISEQ::GRAPH::NODES {
|
||||
if(pickedUp()) drag();
|
||||
if(released()) putDown();
|
||||
for(auto c : connectors){
|
||||
c->updatePosition(position);
|
||||
c->setPosition(position);
|
||||
c->update();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user