connecting works, but position is off. addConnector is the problem
This commit is contained in:
+28
-14
@@ -1,44 +1,58 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "datatypes.h"
|
||||||
#include "draggable.h"
|
#include "draggable.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace VISEQ::BASE {
|
namespace VISEQ::BASE {
|
||||||
class Connectable : public Draggable{
|
class Connectable : public Draggable{
|
||||||
public:
|
public:
|
||||||
Connectable() {VISEQ::BASE::Connectable::connectables.emplace_back(this);}
|
Connectable() {}
|
||||||
Connectable(Vec2Df position) : Draggable(position) {VISEQ::BASE::Connectable::connectables.emplace_back(this);}
|
/*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() {}
|
virtual ~Connectable() {}
|
||||||
|
|
||||||
inline static std::vector<std::shared_ptr<Connectable>> connectables;
|
inline static std::vector<std::shared_ptr<Connectable>> connectables;
|
||||||
|
|
||||||
std::shared_ptr<Connectable> partner;
|
std::shared_ptr<Connectable> partner;
|
||||||
|
|
||||||
|
virtual void init() {
|
||||||
|
connectables.emplace_back(this);
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool hovering() override {
|
virtual bool hovering() override {
|
||||||
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
|
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
|
||||||
|
std::cout << "hovering" << std::endl;
|
||||||
return CheckCollisionPointCircle(mp, position, 5);
|
return CheckCollisionPointCircle(mp, position, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void drag() override {
|
virtual void drag() override {
|
||||||
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
|
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() {
|
virtual void connect() {
|
||||||
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
|
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
|
||||||
|
|
||||||
if(picked_up){
|
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{
|
class Connector : public BASE::Connectable, public GraphItem{
|
||||||
public:
|
public:
|
||||||
Connector() {}
|
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 radius = 5.0f;
|
||||||
float orbit = 14.0f;
|
float orbit = 14.0f;
|
||||||
|
|
||||||
virtual bool hovering() override {
|
void setPosition(Vec2Df pos) override {
|
||||||
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
|
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
|
||||||
return CheckCollisionPointCircle(mp, position, radius);
|
position = pos - ((pos - mp)).norm() * (radius + orbit);
|
||||||
}
|
|
||||||
|
|
||||||
void updatePosition(Vec2Df pos){
|
|
||||||
position = pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
void update() override{
|
|
||||||
connect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw() override {
|
void draw() override {
|
||||||
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
|
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);
|
float opacity = 150.0f - Clamp(position.dist(mp), 0.0f, 150.0f);
|
||||||
|
|
||||||
|
if(partner){
|
||||||
|
DrawLineV(position, partner->position, VS_COLOR_RED);
|
||||||
|
}
|
||||||
|
|
||||||
if(hover_connect){
|
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 {
|
} 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 Vec2Df getPosition() {return position;};
|
||||||
virtual void update(double frametime) {};
|
virtual void update(double frametime) {};
|
||||||
virtual void update() {};
|
virtual void update() {};
|
||||||
|
virtual void update(Vec2Df pos) {};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -24,6 +24,7 @@ namespace VISEQ::GRAPH::NODES {
|
|||||||
|
|
||||||
void addConnector() {
|
void addConnector() {
|
||||||
connectors.emplace_back(std::make_shared<Connector>(position, radius + 5.0f));
|
connectors.emplace_back(std::make_shared<Connector>(position, radius + 5.0f));
|
||||||
|
connectors.back()->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeType nodeType;
|
NodeType nodeType;
|
||||||
@@ -55,7 +56,7 @@ namespace VISEQ::GRAPH::NODES {
|
|||||||
if(pickedUp()) drag();
|
if(pickedUp()) drag();
|
||||||
if(released()) putDown();
|
if(released()) putDown();
|
||||||
for(auto c : connectors){
|
for(auto c : connectors){
|
||||||
c->updatePosition(position);
|
c->setPosition(position);
|
||||||
c->update();
|
c->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user