Connectables working now. On to more refactoring!
This commit is contained in:
+1
-5
@@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "datatypes.h"
|
|
||||||
#include "draggable.h"
|
#include "draggable.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@@ -8,9 +7,7 @@ namespace VISEQ::BASE {
|
|||||||
class Connectable : public Draggable{
|
class Connectable : public Draggable{
|
||||||
public:
|
public:
|
||||||
Connectable() {}
|
Connectable() {}
|
||||||
/*Connectable() {VISEQ::BASE::Connectable::connectables.emplace_back(this);}*/
|
|
||||||
Connectable(Vec2Df position) : Draggable(position) {}
|
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;
|
||||||
@@ -23,7 +20,6 @@ namespace VISEQ::BASE {
|
|||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +38,6 @@ namespace VISEQ::BASE {
|
|||||||
Draggable::putDown();
|
Draggable::putDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual void connect() {
|
virtual void connect() {
|
||||||
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
|
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
|
||||||
|
|
||||||
@@ -50,6 +45,7 @@ namespace VISEQ::BASE {
|
|||||||
for(auto c : connectables){
|
for(auto c : connectables){
|
||||||
if(c.get() != this && c->hovering()) {
|
if(c.get() != this && c->hovering()) {
|
||||||
partner = c;
|
partner = c;
|
||||||
|
c->partner.reset(this);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -13,10 +13,13 @@ namespace VISEQ::GRAPH {
|
|||||||
|
|
||||||
float radius = 5.0f;
|
float radius = 5.0f;
|
||||||
float orbit = 14.0f;
|
float orbit = 14.0f;
|
||||||
|
Vec2Df center_position;
|
||||||
|
|
||||||
void setPosition(Vec2Df pos) override {
|
void setPosition(Vec2Df pos) override {
|
||||||
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
|
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 {
|
void draw() override {
|
||||||
|
|||||||
@@ -57,6 +57,11 @@ namespace VISEQ::GRAPH {
|
|||||||
return std::dynamic_pointer_cast<VISEQ::GRAPH::EDGES::Edge>(o.front());
|
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){
|
void copyNodes(VEC_SPTR_Node _nodes, Vec2Df position){
|
||||||
for(auto n: _nodes){
|
for(auto n: _nodes){
|
||||||
nodes.insert(nodes.end(), std::make_shared<Node>(*n));
|
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")){
|
for(auto n : graph.at("graphmanager").at("nodes")){
|
||||||
std::shared_ptr<MidiNode> mn = n;
|
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;
|
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{
|
class Node : public BASE::Draggable, public GraphItem{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Node() {addConnector();}
|
Node() {}
|
||||||
Node(float x, float y) : Draggable(Vec2Df(x, y)) {addConnector();}
|
Node(float x, float y) : Draggable(Vec2Df(x, y)) {}
|
||||||
Node(Vec2Df p) : Draggable(p) {addConnector();}
|
Node(Vec2Df p) : Draggable(p) {}
|
||||||
|
|
||||||
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();
|
connectors.back()->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void init() {
|
||||||
|
addConnector();
|
||||||
|
}
|
||||||
|
|
||||||
NodeType nodeType;
|
NodeType nodeType;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Node>> neighbors;
|
std::vector<std::shared_ptr<Node>> neighbors;
|
||||||
@@ -55,10 +59,13 @@ namespace VISEQ::GRAPH::NODES {
|
|||||||
void update() override{
|
void update() override{
|
||||||
if(pickedUp()) drag();
|
if(pickedUp()) drag();
|
||||||
if(released()) putDown();
|
if(released()) putDown();
|
||||||
|
int free_connectors = 0;
|
||||||
for(auto c : connectors){
|
for(auto c : connectors){
|
||||||
|
if(!c->partner) free_connectors++;
|
||||||
c->setPosition(position);
|
c->setPosition(position);
|
||||||
c->update();
|
c->update();
|
||||||
}
|
}
|
||||||
|
if(free_connectors == 0) addConnector();
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw(Vec2Df mp, Camera2D cam) override {}
|
void draw(Vec2Df mp, Camera2D cam) override {}
|
||||||
|
|||||||
Reference in New Issue
Block a user