connecting does weird things!
This commit is contained in:
+30
-1
@@ -1,17 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "draggable.h"
|
||||
#include <memory>
|
||||
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<std::shared_ptr<Connectable>> connectables;
|
||||
|
||||
std::shared_ptr<Connectable> 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<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
@@ -1,18 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "connectable.h"
|
||||
#include "interactable.h"
|
||||
#include "moveable.h"
|
||||
#include "graph-item.h"
|
||||
#include "raymath.h"
|
||||
#include "vmath.h"
|
||||
#include <memory>
|
||||
|
||||
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);
|
||||
|
||||
+1
-2
@@ -2,8 +2,6 @@
|
||||
|
||||
#include "raylib.h"
|
||||
#include "datatypes.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
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;
|
||||
|
||||
+9
-8
@@ -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);
|
||||
}
|
||||
|
||||
+15
-3
@@ -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<Connector>(position, radius + 5.0f));
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user