Connectables working now. On to more refactoring!

This commit is contained in:
Sebastian
2024-11-13 14:39:46 +01:00
parent 1e0a131169
commit e6f370ba4f
5 changed files with 22 additions and 10 deletions
+1 -5
View File
@@ -1,6 +1,5 @@
#pragma once
#include "datatypes.h"
#include "draggable.h"
#include <memory>
@@ -8,9 +7,7 @@ namespace VISEQ::BASE {
class Connectable : public Draggable{
public:
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;
@@ -23,7 +20,6 @@ namespace VISEQ::BASE {
virtual bool hovering() override {
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
std::cout << "hovering" << std::endl;
return CheckCollisionPointCircle(mp, position, 5);
}
@@ -42,7 +38,6 @@ namespace VISEQ::BASE {
Draggable::putDown();
}
virtual void connect() {
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
@@ -50,6 +45,7 @@ namespace VISEQ::BASE {
for(auto c : connectables){
if(c.get() != this && c->hovering()) {
partner = c;
c->partner.reset(this);
break;
}
}
+4 -1
View File
@@ -13,10 +13,13 @@ namespace VISEQ::GRAPH {
float radius = 5.0f;
float orbit = 14.0f;
Vec2Df center_position;
void setPosition(Vec2Df pos) override {
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
position = pos - ((pos - mp)).norm() * (radius + orbit);
center_position = pos;
if(!partner) position = center_position - ((center_position - mp)).norm() * (radius + orbit);
if(partner) position = center_position - ((center_position - partner->position)).norm() * (radius + orbit);
}
void draw() override {
+5
View File
@@ -56,6 +56,11 @@ namespace VISEQ::GRAPH {
std::ranges::sample(edges, std::back_inserter(o), 1, std::mt19937{std::random_device{}()});
return std::dynamic_pointer_cast<VISEQ::GRAPH::EDGES::Edge>(o.front());
}
void addNode(SPTR_Node node){
nodes.insert(nodes.end(), node);
nodes.back()->init();
}
void copyNodes(VEC_SPTR_Node _nodes, Vec2Df position){
for(auto n: _nodes){
+2 -1
View File
@@ -101,7 +101,8 @@ int main(){
for(auto n : graph.at("graphmanager").at("nodes")){
std::shared_ptr<MidiNode> mn = n;
app.gm.nodes.push_back(mn);
app.gm.addNode(mn);
//app.gm.nodes.push_back(mn);
std::cout << std::format("adding node {}", mn->id) << std::endl;
}
+10 -3
View File
@@ -18,14 +18,18 @@ namespace VISEQ::GRAPH::NODES {
class Node : public BASE::Draggable, public GraphItem{
public:
Node() {addConnector();}
Node(float x, float y) : Draggable(Vec2Df(x, y)) {addConnector();}
Node(Vec2Df p) : Draggable(p) {addConnector();}
Node() {}
Node(float x, float y) : Draggable(Vec2Df(x, y)) {}
Node(Vec2Df p) : Draggable(p) {}
void addConnector() {
connectors.emplace_back(std::make_shared<Connector>(position, radius + 5.0f));
connectors.back()->init();
}
void init() {
addConnector();
}
NodeType nodeType;
@@ -55,10 +59,13 @@ namespace VISEQ::GRAPH::NODES {
void update() override{
if(pickedUp()) drag();
if(released()) putDown();
int free_connectors = 0;
for(auto c : connectors){
if(!c->partner) free_connectors++;
c->setPosition(position);
c->update();
}
if(free_connectors == 0) addConnector();
}
void draw(Vec2Df mp, Camera2D cam) override {}