connectors fixed

This commit is contained in:
Sebastian
2026-07-02 08:28:21 +02:00
parent 30408393e7
commit 585e5e1167
8 changed files with 135 additions and 97 deletions
+87
View File
@@ -0,0 +1,87 @@
#include "connector.h"
#include "helper.h"
#include "raymath.h"
#include "state.h"
#include "button.h"
#include <execution>
#include <memory>
namespace VISEQ::GRAPH {
GraphItemType Connector::getType() {
return GraphItemType::CONNECTOR;
}
std::shared_ptr<Connector> Connector::getPtr(){
return shared_from_this();
}
bool Connector::hovering() {
return partner.expired() && CheckCollisionPointCircle(SCREEN_MOUSE, position, radius);
}
void Connector::setParent(std::shared_ptr<GraphItem> _parent){
parent = _parent;
}
void Connector::setPosition(Vec2Df pos) {
center_position = pos;
parent_position = pos;
}
void Connector::setOrbit(float r) {
orbit = r;
}
void Connector::update() {
if(hovering()) state->pushEvent({getPtr(), APP::Interaction::HOVER});
if(hovering() && clicked()) state->pushEvent({getPtr(), APP::Interaction::PICKUP});
if(pickedUp()) state->pushEvent({getPtr(), APP::Interaction::DRAG});
if(picked_up && released()) state->pushEvent({getPtr(), APP::Interaction::PUTDOWN});
if(connected) {
state->pushEvent({getPtr(), APP::Interaction::CONNECT});
connected = false;
}
if(partner.expired()) {
position = center_position.orbitAlongVector(SCREEN_MOUSE, orbit);
position_text = center_position.orbitAlongVector(SCREEN_MOUSE, orbit+10);
}
if(!partner.expired()) {
position = center_position .orbitAlongVector(partner.lock()->position, orbit);
position_text = center_position.orbitAlongVector(partner.lock()->position, orbit+10);
}
if(new_partner) {
new_partner = false;
state->pushEvent({getPtr(), APP::Interaction::CONNECT});
}
}
void Connector::draw() {
BASE::Connectable::draw();
float opacity = Clamp((400.0f - Clamp(position.dist(SCREEN_MOUSE), 0.0f, 400.0f)) / 400.0f, 0.0f, 1.0f);
float rotation = 0.0f;
if(partner.expired()) rotation = HELPER::GetRotation(parent_position, SCREEN_MOUSE) + 90.0f;
if(!partner.expired()) {
rotation = HELPER::GetRotation(parent_position, partner.lock()->position) + 90.0f;
opacity = 1.0f;
}
if(connecting) opacity = 1.0f;
if(partner.expired() && !connecting) ViTexButton(SCREEN_MOUSE, position, rotation, 8.0f,
TEXTURES::tex_connector, TEXTURES::tex_connector_hover, TEXTURES::tex_connector_pressed,
ColorLerp(Fade(VS_COLOR_WHITE, .0f), Fade(VS_COLOR_WHITE, 1.0f), opacity));
if(!partner.expired() || connecting) ViTexButton(SCREEN_MOUSE, position, rotation, 8.0f,
TEXTURES::tex_connector_connected, TEXTURES::tex_connector_hover,
ColorLerp(Fade(VS_COLOR_WHITE, .0f), Fade(VS_COLOR_WHITE, 1.0f), opacity));
//int partner_id = -1;
//if(!partner.expired()) partner_id = std::dynamic_pointer_cast<Connector>(partner.lock())->id;
//DrawTextPro(GetFontDefault(), std::format("{} {}", id, partner_id).c_str(), position_text, (Vector2){0,0}, rotation, 10.0f, 2.0f, VS_COLOR_PINK);
//DrawText(std::format("{}", id), position + Vec2Df(100.0f,100.0f), 8.0f, Color(255, 0, 0));
}
}
+14 -66
View File
@@ -3,14 +3,10 @@
#include "connectable.h" #include "connectable.h"
#include "datatypes.h" #include "datatypes.h"
#include "graph-item.h" #include "graph-item.h"
#include "helper.h"
//#include "interaction-event.h"
#include "raymath.h"
#include "state.h"
#include "vmath.h" #include "vmath.h"
#include "button.h"
#include <fcntl.h> #include <fcntl.h>
#include <memory> #include <memory>
#include <raylib.h>
namespace VISEQ::GRAPH { namespace VISEQ::GRAPH {
class Connector : public BASE::Connectable, public GraphItem, public std::enable_shared_from_this<Connector> { class Connector : public BASE::Connectable, public GraphItem, public std::enable_shared_from_this<Connector> {
@@ -20,6 +16,8 @@ namespace VISEQ::GRAPH {
Connector(std::shared_ptr<GraphItem> parent, Vec2Df center_position, float orbit) : orbit(orbit) { Connector(std::shared_ptr<GraphItem> parent, Vec2Df center_position, float orbit) : orbit(orbit) {
setPosition(center_position); setPosition(center_position);
setParent(parent); setParent(parent);
_id++;
id = _id;
} }
std::weak_ptr<GraphItem> parent; std::weak_ptr<GraphItem> parent;
@@ -30,69 +28,19 @@ namespace VISEQ::GRAPH {
float orbit = 20.0f; float orbit = 20.0f;
Vec2Df center_position; Vec2Df center_position;
Vec2Df parent_position; Vec2Df parent_position;
Vec2Df position_text;
inline static int _id = 0;
int id = 0;
GraphItemType getType() override{ GraphItemType getType() override;
return GraphItemType::CONNECTOR;
}
std::shared_ptr<Connector> getPtr(){ std::shared_ptr<Connector> getPtr();
return shared_from_this();
}
virtual bool hovering() override { virtual bool hovering() override;
return partner.expired() && CheckCollisionPointCircle(SCREEN_MOUSE, position, radius); void setParent(std::shared_ptr<GraphItem> _parent);
} void setPosition(Vec2Df pos) override;
void setOrbit(float r);
void setParent(std::shared_ptr<GraphItem> _parent){ void update() override;
parent = _parent; void draw() override;
}
void setPosition(Vec2Df pos) override {
center_position = pos;
parent_position = pos;
}
void setOrbit(float r) {
orbit = r;
}
void update() override {
if(hovering()) state->pushEvent({getPtr(), APP::Interaction::HOVER});
if(hovering() && clicked()) state->pushEvent({getPtr(), APP::Interaction::PICKUP});
if(pickedUp()) state->pushEvent({getPtr(), APP::Interaction::DRAG});
if(picked_up && released()) state->pushEvent({getPtr(), APP::Interaction::PUTDOWN});
if(connected) {
state->pushEvent({getPtr(), APP::Interaction::CONNECT});
connected = false;
}
if(partner.expired()) position = center_position.orbitAlongVector(SCREEN_MOUSE, orbit);
if(!partner.expired()) position = center_position .orbitAlongVector(partner.lock()->position, orbit);
if(new_partner) {
new_partner = false;
state->pushEvent({getPtr(), APP::Interaction::CONNECT});
}
}
void draw() override {
BASE::Connectable::draw();
float opacity = Clamp((400.0f - Clamp(position.dist(SCREEN_MOUSE), 0.0f, 400.0f)) / 400.0f, 0.0f, 1.0f);
float rotation;
if(partner.expired()) rotation = HELPER::GetRotation(parent_position, SCREEN_MOUSE) + 90.0f;
if(!partner.expired()) {
rotation = HELPER::GetRotation(position, partner.lock()->position) + 90.0f;
opacity = 1.0f;
}
if(connecting) opacity = 1.0f;
if(partner.expired() && !connecting) ViTexButton(SCREEN_MOUSE, position, rotation, 8.0f,
TEXTURES::tex_connector, TEXTURES::tex_connector_hover, TEXTURES::tex_connector_pressed,
ColorLerp(Fade(VS_COLOR_WHITE, .0f), Fade(VS_COLOR_WHITE, 1.0f), opacity));
if(!partner.expired() || connecting) ViTexButton(SCREEN_MOUSE, position, rotation, 8.0f,
TEXTURES::tex_connector_connected, TEXTURES::tex_connector_hover,
ColorLerp(Fade(VS_COLOR_WHITE, .0f), Fade(VS_COLOR_WHITE, 1.0f), opacity));
}
}; };
} }
+15 -16
View File
@@ -64,23 +64,17 @@ namespace VISEQ::GRAPH{
edges.back()->edgeType = et; edges.back()->edgeType = et;
edges.back()->start = from; edges.back()->start = from;
edges.back()->end = to; edges.back()->end = to;
from.lock()->update();
to.lock()->update(); from.lock()->connectors.back()->partner = to.lock()->getConnector();
to.lock()->connectors.back()->partner = from.lock()->getConnector();
edges.back()->start_conn = from.lock()->connectors.back(); edges.back()->start_conn = from.lock()->connectors.back();
edges.back()->end_conn = to.lock()->connectors.back(); edges.back()->end_conn = to.lock()->connectors.back();
from.lock()->connections.push_back(edges.back()); from.lock()->connections.push_back(edges.back());
to.lock()->connections.push_back(edges.back()); to.lock()->connections.push_back(edges.back());
from.lock()->connectors.back()->partner = to.lock()->getConnector();
to.lock()->connectors.back()->partner = from.lock()->getConnector();
if(to.lock()->connectors.back()->partner.expired()) std::cout << "expired" << std::endl;
else std::cout << "not expired" << std::endl;
} }
std::cout << "add connection" << std::endl;
} }
void GraphManager::addToSelection(){ void GraphManager::addToSelection(){
@@ -210,10 +204,15 @@ namespace VISEQ::GRAPH{
return edges.back(); return edges.back();
} }
WPTR_Node GraphManager::next(WPTR_Node current, WPTR_Node last){ VEC_WPTR_Edge GraphManager::getPassableConnections(WPTR_Node node){
VEC_WPTR_Edge possible_connections = current.lock()->connections | RANGE_FILTER([current](WPTR_Edge c){ VEC_WPTR_Edge passable_connections = node.lock()->connections | RANGE_FILTER([node](WPTR_Edge c){
return (c.lock()->getEdgeType() == EdgeType::MIDIEDGE) && ((c.lock()->start.lock() == current.lock() && c.lock()->pass_forward) || (c.lock()->end.lock() == current.lock() && c.lock()->pass_backward)); return (c.lock()->getEdgeType() == EdgeType::MIDIEDGE) && ((c.lock()->start.lock() == node.lock() && c.lock()->pass_forward) || (c.lock()->end.lock() == node.lock() && c.lock()->pass_backward));
}) | std::ranges::to<VEC_WPTR_Edge>(); }) | std::ranges::to<VEC_WPTR_Edge>();
return passable_connections;
}
WPTR_Node GraphManager::next(WPTR_Node current, WPTR_Node last){
VEC_WPTR_Edge possible_connections = getPassableConnections(current);
if(possible_connections.empty()) return SPTR_Node(nullptr); if(possible_connections.empty()) return SPTR_Node(nullptr);
@@ -368,8 +367,8 @@ namespace VISEQ::GRAPH{
if(v1_v2_distance < 100) c->switches_offset = v1_v2_distance/2.3f; if(v1_v2_distance < 100) c->switches_offset = v1_v2_distance/2.3f;
Vec2Df from_to_handle = c->start.lock()->position - ((c->start.lock()->position - c->end.lock()->position)).norm()*45.0f; Vec2Df from_to_handle = c->start.lock()->position - ((c->start.lock()->position - c->end.lock()->position)).norm()*45.0f;
Vec2Df to_from_handle = c->end.lock()->position - ((c->end.lock()->position - c->start.lock()->position)).norm()*45.0f; Vec2Df to_from_handle = c->end.lock()->position - ((c->end.lock()->position - c->start.lock()->position)).norm()*45.0f;
Vec2Df middle_handle_2 = c->end.lock()->position - ((c->end.lock()->position - c->start.lock()->position)).norm()*65.0f; //Vec2Df middle_handle_2 = c->end.lock()->position - ((c->end.lock()->position - c->start.lock()->position)).norm()*65.0f;
Vec2Df middle_handle = c->start.lock()->position - ((c->start.lock()->position - c->end.lock()->position)).norm()*65.0f; //Vec2Df middle_handle = c->start.lock()->position - ((c->start.lock()->position - c->end.lock()->position)).norm()*65.0f;
Vec2Df center_handle = c->end.lock()->position - ((c->end.lock()->position - c->start.lock()->position))*0.5f; Vec2Df center_handle = c->end.lock()->position - ((c->end.lock()->position - c->start.lock()->position))*0.5f;
Vec2Df delete_position = center_handle + (c->start.lock()->position - c->end.lock()->position).norm().orth() * 12.0f; Vec2Df delete_position = center_handle + (c->start.lock()->position - c->end.lock()->position).norm().orth() * 12.0f;
@@ -390,7 +389,7 @@ namespace VISEQ::GRAPH{
Color col = {229, 181, 103, 255}; Color col = {229, 181, 103, 255};
if(c->GActive()) col = {108, 153, 187, 255}; if(c->GActive()) col = {108, 153, 187, 255};
DrawLine(v1_position.x, v1_position.y, v2_position.x, v2_position.y, col); DrawLine(v1_position.x, v1_position.y, v2_position.x, v2_position.y, col);
{ if(state->draw_edge_lengths){
float d = c->start.lock()->position.dist(c->end.lock()->position); float d = c->start.lock()->position.dist(c->end.lock()->position);
std::string frac = MIDI::Fractions.at(std::clamp<int>(round(d/60) - 1, 0, 31)); std::string frac = MIDI::Fractions.at(std::clamp<int>(round(d/60) - 1, 0, 31));
Vector2 text_length = MeasureTextEx(GetFontDefault(), std::format("{:.1f}",d).c_str(), 10.0f, 2.0f); Vector2 text_length = MeasureTextEx(GetFontDefault(), std::format("{:.1f}",d).c_str(), 10.0f, 2.0f);
+1
View File
@@ -67,6 +67,7 @@ namespace VISEQ::GRAPH {
SPTR_Node getClosestNode(Vec2Df position); SPTR_Node getClosestNode(Vec2Df position);
VEC_WPTR_Node getNodesByID(int _id); VEC_WPTR_Node getNodesByID(int _id);
WPTR_Edge lastEdge(); WPTR_Edge lastEdge();
VEC_WPTR_Edge getPassableConnections(WPTR_Node node);
WPTR_Node next(WPTR_Node current, WPTR_Node last); WPTR_Node next(WPTR_Node current, WPTR_Node last);
void splitEdge(SPTR_Edge edge); void splitEdge(SPTR_Edge edge);
void splitEdges(); void splitEdges();
+4 -1
View File
@@ -32,7 +32,10 @@ namespace VISEQ::INTERACTION{
if(KEYS_DOWN.shift && IsKeyPressed(KEY_TAB)) { if(KEYS_DOWN.shift && IsKeyPressed(KEY_TAB)) {
gm->cycleModeOfSelectedNodes(false); gm->cycleModeOfSelectedNodes(false);
} }
if(IsKeyPressed(KEY_V)){
state->draw_edge_lengths = !state->draw_edge_lengths;
}
} }
void InteractionManager::draw(){ void InteractionManager::draw(){
+13 -13
View File
@@ -274,23 +274,23 @@ namespace VISEQ::GRAPH::NODES {
VMATH::Vec2D<float> desc_position = position + VMATH::Vec2D<float>(radius + 7.0f, radius + 7.0f); VMATH::Vec2D<float> desc_position = position + VMATH::Vec2D<float>(radius + 7.0f, radius + 7.0f);
switch(mode){ switch(mode){
case NOTE:{ case NOTE:{
if(!KEYS_DOWN.shift && !KEYS_DOWN.alt) DrawCenteredText(MIDI::Notes[getNotes().note], position, 12, WHITE); if(!KEYS_DOWN.shift && !KEYS_DOWN.alt) DrawCenteredText(MIDI::Notes[getNotes().note], position, 12, VS_COLOR_BLACK);
if(!KEYS_DOWN.ctrl && KEYS_DOWN.shift && !KEYS_DOWN.alt) DrawCenteredText(std::format("{}", getNotes().velocity), position, 12, WHITE); if(!KEYS_DOWN.ctrl && KEYS_DOWN.shift && !KEYS_DOWN.alt) DrawCenteredText(std::format("{}", getNotes().velocity), position, 12, VS_COLOR_BLACK);
if(!KEYS_DOWN.ctrl && !KEYS_DOWN.shift && KEYS_DOWN.alt) DrawCenteredText(std::format("{:.1f}s", (float)getNotes().gate / 1000.f), position, 12, WHITE); if(!KEYS_DOWN.ctrl && !KEYS_DOWN.shift && KEYS_DOWN.alt) DrawCenteredText(std::format("{:.1f}s", (float)getNotes().gate / 1000.f), position, 12, VS_COLOR_BLACK);
if(KEYS_DOWN.ctrl && !KEYS_DOWN.shift && KEYS_DOWN.alt) DrawCenteredText(std::format("{:.2f}s", (float)getNotes().gate / 1000.f), position, 12, WHITE); if(KEYS_DOWN.ctrl && !KEYS_DOWN.shift && KEYS_DOWN.alt) DrawCenteredText(std::format("{:.2f}s", (float)getNotes().gate / 1000.f), position, 12, VS_COLOR_BLACK);
if(!KEYS_DOWN.ctrl && KEYS_DOWN.shift && KEYS_DOWN.alt) DrawCenteredText(std::format("{:.2f}s", (float)getNotes().gate / 1000.f), position, 12, WHITE); if(!KEYS_DOWN.ctrl && KEYS_DOWN.shift && KEYS_DOWN.alt) DrawCenteredText(std::format("{:.2f}s", (float)getNotes().gate / 1000.f), position, 12, VS_COLOR_BLACK);
if(KEYS_DOWN.ctrl && KEYS_DOWN.shift && KEYS_DOWN.alt) DrawCenteredText(std::format("{:.3f}s", (float)getNotes().gate / 1000.f), position, 12, WHITE); if(KEYS_DOWN.ctrl && KEYS_DOWN.shift && KEYS_DOWN.alt) DrawCenteredText(std::format("{:.3f}s", (float)getNotes().gate / 1000.f), position, 12, VS_COLOR_BLACK);
if(selected){ if(selected){
if(!KEYS_DOWN.ctrl && !KEYS_DOWN.shift && !KEYS_DOWN.alt) DrawText("NOTE", desc_position, 8, WHITE); if(!KEYS_DOWN.ctrl && !KEYS_DOWN.shift && !KEYS_DOWN.alt) DrawText("NOTE", desc_position, 8, VS_COLOR_BLACK);
if(KEYS_DOWN.ctrl && !KEYS_DOWN.shift && !KEYS_DOWN.alt) DrawText("VALUE", desc_position, 8, WHITE); if(KEYS_DOWN.ctrl && !KEYS_DOWN.shift && !KEYS_DOWN.alt) DrawText("VALUE", desc_position, 8, VS_COLOR_BLACK);
if(!KEYS_DOWN.ctrl && KEYS_DOWN.shift && !KEYS_DOWN.alt) DrawText("VELOCITY", desc_position, 8, WHITE); if(!KEYS_DOWN.ctrl && KEYS_DOWN.shift && !KEYS_DOWN.alt) DrawText("VELOCITY", desc_position, 8, VS_COLOR_BLACK);
if(!KEYS_DOWN.ctrl && !KEYS_DOWN.shift && KEYS_DOWN.alt) DrawText("GATE 0.1s", desc_position, 8, WHITE); if(!KEYS_DOWN.ctrl && !KEYS_DOWN.shift && KEYS_DOWN.alt) DrawText("GATE 0.1s", desc_position, 8, VS_COLOR_BLACK);
if(KEYS_DOWN.ctrl && !KEYS_DOWN.shift && KEYS_DOWN.alt) DrawText("GATE 1.0s", desc_position, 8, WHITE); if(KEYS_DOWN.ctrl && !KEYS_DOWN.shift && KEYS_DOWN.alt) DrawText("GATE 1.0s", desc_position, 8, VS_COLOR_BLACK);
if(!KEYS_DOWN.ctrl && KEYS_DOWN.shift && KEYS_DOWN.alt) DrawText("GATE 0.01s", desc_position, 8, WHITE); if(!KEYS_DOWN.ctrl && KEYS_DOWN.shift && KEYS_DOWN.alt) DrawText("GATE 0.01s", desc_position, 8, VS_COLOR_BLACK);
if(KEYS_DOWN.ctrl && KEYS_DOWN.shift && KEYS_DOWN.alt) DrawText("GATE 0.001s", desc_position, 8, WHITE); if(KEYS_DOWN.ctrl && KEYS_DOWN.shift && KEYS_DOWN.alt) DrawText("GATE 0.001s", desc_position, 8, VS_COLOR_BLACK);
} }
break;} break;}
case CC:{ case CC:{
-1
View File
@@ -72,7 +72,6 @@ namespace VISEQ::GRAPH::NODES {
return c; return c;
} }
} }
addConnector();
return connectors.back(); return connectors.back();
} }
+1
View File
@@ -66,6 +66,7 @@ namespace VISEQ::APP{
int node_mode = 0; int node_mode = 0;
bool context_menu = false; bool context_menu = false;
bool draw_edge_lengths = false;
bool hovering = false; bool hovering = false;