From 96082e11905c1fb621466e5461a971f1ca0e8b4b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 12 Nov 2024 01:42:05 +0100 Subject: [PATCH] connecting does weird things! --- src/connectable.h | 33 +++++++++++++++++++++++++++++++-- src/connector.h | 13 +++++-------- src/graph-item.h | 3 +-- src/midi-node.h | 17 +++++++++-------- src/node.h | 20 ++++++++++++++++---- 5 files changed, 62 insertions(+), 24 deletions(-) diff --git a/src/connectable.h b/src/connectable.h index a72f123..d1c0fcd 100644 --- a/src/connectable.h +++ b/src/connectable.h @@ -1,17 +1,46 @@ #pragma once #include "draggable.h" +#include namespace VISEQ::BASE { class Connectable : public Draggable{ public: - Connectable() {} + Connectable() {VISEQ::BASE::Connectable::connectables.emplace_back(this);} + Connectable(Vec2Df position) : Draggable(position) {VISEQ::BASE::Connectable::connectables.emplace_back(this);} virtual ~Connectable() {} + inline static std::vector> connectables; + std::shared_ptr partner; + virtual bool hovering() override { + Vec2Df mp = {GetMousePosition().x, GetMousePosition().y}; + return CheckCollisionPointCircle(mp, position, 5); + } + virtual void drag() override { 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 c){ return c->hovering();}) | std::ranges::to>>(); +// if(hover_partner.empty()){ + /*SPTR_Node new_node = app.gm.copyNode(std::dynamic_pointer_cast(connecting_nodes.front()), target_position);*/ + /*new_node->connecting = false;*/ + /*app.gm.addConnection(connecting_nodes.front(), new_node);*/ +// } else { +// partner = hover_partner.front(); +// } + } + + } }; } diff --git a/src/connector.h b/src/connector.h index 75dcbef..d3ae339 100644 --- a/src/connector.h +++ b/src/connector.h @@ -1,19 +1,16 @@ #pragma once #include "connectable.h" -#include "interactable.h" -#include "moveable.h" +#include "graph-item.h" #include "raymath.h" #include "vmath.h" -#include namespace VISEQ::GRAPH { - class Connector : public BASE::Connectable{ + class Connector : public BASE::Connectable, public GraphItem{ public: 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 orbit = 14.0f; @@ -27,10 +24,10 @@ namespace VISEQ::GRAPH { } void update() override{ - + connect(); } - void draw() { + void draw() override { Vec2Df mp = {GetMousePosition().x, GetMousePosition().y}; Vec2Df connector = position - ((position - mp)).norm() * (radius + orbit); diff --git a/src/graph-item.h b/src/graph-item.h index 6baf3c3..e0c208e 100644 --- a/src/graph-item.h +++ b/src/graph-item.h @@ -2,8 +2,6 @@ #include "raylib.h" #include "datatypes.h" -#include -#include namespace VISEQ::GRAPH { class GraphItem{ @@ -25,6 +23,7 @@ namespace VISEQ::GRAPH { _id++; } + virtual void draw() {}; virtual void draw(Vec2Df mouse, Camera2D cam) {}; virtual GraphItemType getType() {return graphItemType;} virtual ~GraphItem() = default; diff --git a/src/midi-node.h b/src/midi-node.h index 438dee7..eb0bc70 100644 --- a/src/midi-node.h +++ b/src/midi-node.h @@ -84,6 +84,7 @@ namespace VISEQ::GRAPH::NODES { } void draw(Vec2Df mouse, Camera2D cam) override { + Node::draw(); last = time; time = GetTime(); if(time - start >= (float)midi_gate / 1000.0f){ @@ -157,14 +158,14 @@ namespace VISEQ::GRAPH::NODES { } } - Vec2Df connector = position - ((position - mouse)).norm() * (radius + RADIUS); - float opacity = 150.0f - Clamp(position.dist(mouse), 0.0f, 150.0f); - - if(hover_connect){ - DrawCircle(connector.x, connector.y, 8.0f, (Color){108, 153, 187, 255}); - } else { - DrawCircle(connector.x, connector.y, 8.0f, (Color){108, 153, 187, (unsigned char)opacity}); - } + /*Vec2Df connector = position - ((position - mouse)).norm() * (radius + RADIUS);*/ + /*float opacity = 150.0f - Clamp(position.dist(mouse), 0.0f, 150.0f);*/ + /**/ + /*if(hover_connect){*/ + /* DrawCircle(connector.x, connector.y, 8.0f, (Color){108, 153, 187, 255});*/ + /*} else {*/ + /* 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}); DrawText(std::format("{}", id).c_str(), position.x + 20.0f, position.y + 20.0f, 10, WHITE); } diff --git a/src/node.h b/src/node.h index 0477e41..af79bf6 100644 --- a/src/node.h +++ b/src/node.h @@ -18,9 +18,13 @@ namespace VISEQ::GRAPH::NODES { class Node : public BASE::Draggable, public GraphItem{ public: - Node() {} - Node(float x, float y) : Draggable(Vec2Df(x, y)) {} - Node(Vec2Df p) : Draggable(p) {} + Node() {addConnector();} + Node(float x, float y) : Draggable(Vec2Df(x, y)) {addConnector();} + Node(Vec2Df p) : Draggable(p) {addConnector();} + + void addConnector() { + connectors.emplace_back(std::make_shared(position, radius + 5.0f)); + } NodeType nodeType; @@ -55,7 +59,15 @@ namespace VISEQ::GRAPH::NODES { c->update(); } } - + + void draw(Vec2Df mp, Camera2D cam) override {} + + void draw() override{ + for(auto c : connectors){ + c->draw(); + } + } + }; typedef std::shared_ptr SPTR_Node;