connecting does weird things!

This commit is contained in:
Sebastian
2024-11-12 01:42:05 +01:00
parent 31a1a264d4
commit 96082e1190
5 changed files with 62 additions and 24 deletions
+30 -1
View File
@@ -1,17 +1,46 @@
#pragma once #pragma once
#include "draggable.h" #include "draggable.h"
#include <memory>
namespace VISEQ::BASE { namespace VISEQ::BASE {
class Connectable : public Draggable{ class Connectable : public Draggable{
public: public:
Connectable() {} Connectable() {VISEQ::BASE::Connectable::connectables.emplace_back(this);}
Connectable(Vec2Df position) : Draggable(position) {VISEQ::BASE::Connectable::connectables.emplace_back(this);}
virtual ~Connectable() {} virtual ~Connectable() {}
inline static std::vector<std::shared_ptr<Connectable>> connectables;
std::shared_ptr<Connectable> partner; std::shared_ptr<Connectable> partner;
virtual bool hovering() override {
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
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};
} }
virtual void connect() {
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
if(picked_up){
DrawLineV(position, mp, (Color){229, 181, 103, 255});
}
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();
// }
}
}
}; };
} }
+5 -8
View File
@@ -1,18 +1,15 @@
#pragma once #pragma once
#include "connectable.h" #include "connectable.h"
#include "interactable.h" #include "graph-item.h"
#include "moveable.h"
#include "raymath.h" #include "raymath.h"
#include "vmath.h" #include "vmath.h"
#include <memory>
namespace VISEQ::GRAPH { namespace VISEQ::GRAPH {
class Connector : public BASE::Connectable{ class Connector : public BASE::Connectable, public GraphItem{
public: public:
Connector() {} Connector() {}
Connector(Vec2Df position, float orbit) : Movable(position, 0.0f), orbit(orbit) {} Connector(Vec2Df position, float orbit) : BASE::Connectable(position), orbit(orbit) {}
float radius = 5.0f; float radius = 5.0f;
float orbit = 14.0f; float orbit = 14.0f;
@@ -27,10 +24,10 @@ namespace VISEQ::GRAPH {
} }
void update() override{ void update() override{
connect();
} }
void draw() { void draw() override {
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y}; Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
Vec2Df connector = position - ((position - mp)).norm() * (radius + orbit); Vec2Df connector = position - ((position - mp)).norm() * (radius + orbit);
+1 -2
View File
@@ -2,8 +2,6 @@
#include "raylib.h" #include "raylib.h"
#include "datatypes.h" #include "datatypes.h"
#include <memory>
#include <vector>
namespace VISEQ::GRAPH { namespace VISEQ::GRAPH {
class GraphItem{ class GraphItem{
@@ -25,6 +23,7 @@ namespace VISEQ::GRAPH {
_id++; _id++;
} }
virtual void draw() {};
virtual void draw(Vec2Df mouse, Camera2D cam) {}; virtual void draw(Vec2Df mouse, Camera2D cam) {};
virtual GraphItemType getType() {return graphItemType;} virtual GraphItemType getType() {return graphItemType;}
virtual ~GraphItem() = default; virtual ~GraphItem() = default;
+9 -8
View File
@@ -84,6 +84,7 @@ namespace VISEQ::GRAPH::NODES {
} }
void draw(Vec2Df mouse, Camera2D cam) override { void draw(Vec2Df mouse, Camera2D cam) override {
Node::draw();
last = time; last = time;
time = GetTime(); time = GetTime();
if(time - start >= (float)midi_gate / 1000.0f){ if(time - start >= (float)midi_gate / 1000.0f){
@@ -157,14 +158,14 @@ namespace VISEQ::GRAPH::NODES {
} }
} }
Vec2Df connector = position - ((position - mouse)).norm() * (radius + RADIUS); /*Vec2Df connector = position - ((position - mouse)).norm() * (radius + RADIUS);*/
float opacity = 150.0f - Clamp(position.dist(mouse), 0.0f, 150.0f); /*float opacity = 150.0f - Clamp(position.dist(mouse), 0.0f, 150.0f);*/
/**/
if(hover_connect){ /*if(hover_connect){*/
DrawCircle(connector.x, connector.y, 8.0f, (Color){108, 153, 187, 255}); /* DrawCircle(connector.x, connector.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(connector.x, connector.y, 8.0f, (Color){108, 153, 187, (unsigned char)opacity});*/
} /*}*/
if(highlighted) DrawCircleLinesV(position, radius+2, (Color){255, 0, 0, 200}); if(highlighted) DrawCircleLinesV(position, radius+2, (Color){255, 0, 0, 200});
DrawText(std::format("{}", id).c_str(), position.x + 20.0f, position.y + 20.0f, 10, WHITE); DrawText(std::format("{}", id).c_str(), position.x + 20.0f, position.y + 20.0f, 10, WHITE);
} }
+15 -3
View File
@@ -18,9 +18,13 @@ namespace VISEQ::GRAPH::NODES {
class Node : public BASE::Draggable, public GraphItem{ class Node : public BASE::Draggable, public GraphItem{
public: public:
Node() {} Node() {addConnector();}
Node(float x, float y) : Draggable(Vec2Df(x, y)) {} Node(float x, float y) : Draggable(Vec2Df(x, y)) {addConnector();}
Node(Vec2Df p) : Draggable(p) {} Node(Vec2Df p) : Draggable(p) {addConnector();}
void addConnector() {
connectors.emplace_back(std::make_shared<Connector>(position, radius + 5.0f));
}
NodeType nodeType; NodeType nodeType;
@@ -56,6 +60,14 @@ namespace VISEQ::GRAPH::NODES {
} }
} }
void draw(Vec2Df mp, Camera2D cam) override {}
void draw() override{
for(auto c : connectors){
c->draw();
}
}
}; };
typedef std::shared_ptr<VISEQ::GRAPH::NODES::Node> SPTR_Node; typedef std::shared_ptr<VISEQ::GRAPH::NODES::Node> SPTR_Node;