Connectables working now. On to more refactoring!
This commit is contained in:
+1
-5
@@ -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
@@ -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 {
|
||||
|
||||
@@ -57,6 +57,11 @@ namespace VISEQ::GRAPH {
|
||||
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){
|
||||
nodes.insert(nodes.end(), std::make_shared<Node>(*n));
|
||||
|
||||
+2
-1
@@ -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
@@ -18,15 +18,19 @@ 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;
|
||||
|
||||
std::vector<std::shared_ptr<Node>> neighbors;
|
||||
@@ -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 {}
|
||||
|
||||
Reference in New Issue
Block a user