From d1542870d5b2ba7813475bbd82f68004e7d98907 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 18 Oct 2024 01:27:14 +0200 Subject: [PATCH] gui work --- src/connection-manager.h | 2 +- src/connection.h | 4 ++++ src/main.cpp | 23 ++++++++++++++++------- src/node.h | 10 ++++++---- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/connection-manager.h b/src/connection-manager.h index 6c31338..4628c13 100644 --- a/src/connection-manager.h +++ b/src/connection-manager.h @@ -23,7 +23,7 @@ class ConnectionManager{ p.active = false; paths.push_back(&p); } - if(p.v1 == last || p.v2 == last) last_ok = true; + if(((p.v1 == last && p.v2_v1) || (p.v2 == last && p.v1_v2))) last_ok = true; } if(paths.empty() && last_ok) return last; diff --git a/src/connection.h b/src/connection.h index e017ca9..85d9e50 100644 --- a/src/connection.h +++ b/src/connection.h @@ -16,6 +16,7 @@ class Connection{ bool v2_v1 = true; bool active = false; bool remove = false; + bool config = false; void draw(){ Vec2D v1_position = v1->position - ((v1->position - v2->position)).norm() * (v1->radius + 10.0f); @@ -28,10 +29,13 @@ class Connection{ Vec2D from_to_handle = v1->position - ((v1->position - v2->position)).norm() * (v1->radius + 35); Vec2D to_from_handle = v2->position - ((v2->position - v1->position)).norm() * (v2->radius + 35); Vec2D middle_handle = v2->position - ((v2->position - v1->position))*0.5f; + Vec2D config_handle = v2->position - ((v2->position - v1->position))*0.66f; if(ViButton(from_to_handle.x, from_to_handle.y, 8.0f, v1_v2 ? (Color){232, 125, 62, 255} : (Color){232, 50, 32, 255} )) v1_v2 = !v1_v2; if(ViButton(to_from_handle.x, to_from_handle.y, 8.0f, v2_v1 ? (Color){232, 125, 62, 255} : (Color){232, 50, 32, 255} )) v2_v1 = !v2_v1; if(ViButton(middle_handle.x, middle_handle.y, 8.0f, (Color){232, 50, 32, 255} )) remove = true; + + if(ViButton(config_handle.x, config_handle.y, 8.0f, (Color){158, 134, 200, 255})) config = !config; } }; diff --git a/src/main.cpp b/src/main.cpp index b11da89..62a8cbb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,6 +39,7 @@ #include "connection-manager.h" libremidi::observer obs; +std::vector midi_outs; libremidi::midi_out midi_out; std::vector midi_in_ports; @@ -107,7 +108,7 @@ int main(){ signals[i].next = &nodes.front(); signals[i].last = &nodes.front(); } - + midi_out.open_port(midi_out_ports[2]); Vec2D drag_offset; @@ -138,7 +139,7 @@ int main(){ bool dragging = false; for(auto& n : nodes){ - Vec2D connector_position = n.position - ((n.position - mouse_pos)).norm() * (n.radius + 10.0f); + Vec2D connector_position = n.position - ((n.position - mouse_pos)).norm() * (n.radius + 14.0f); float dist_connector = (connector_position - mouse_pos).length(); float dist = (n.position - mouse_pos).length(); @@ -150,7 +151,7 @@ int main(){ n.hover_connect = false; } - if(dist_connector <= 6.0f && mouse_clicked && !connecting) { + if(dist_connector <= 8.0f && mouse_clicked && !connecting) { connecting_from = &n; n.connecting = true; connecting = true; @@ -228,12 +229,20 @@ int main(){ for(auto& n : nodes){ if(n.config){ + n.config = !GuiWindowBox((Rectangle){n.position.x + 10, n.position.y + 10,200,300}, "config"); int option = n.mode; - GuiComboBox((Rectangle){ 20, 100, 240, 20 }, "Round Robin;Random", &option); + GuiComboBox((Rectangle){ n.position.x + 20, n.position.y + 40, 200, 20 }, "Round Robin;Random", &option); n.mode = (Distribution)option; - if(GuiButton((Rectangle){20, 140, 240, 20 }, "button")){ - - } + } + } + + for(auto& c : cm.connections){ + if(c.config){ + Vec2D config_handle = c.v2->position - ((c.v2->position - c.v1->position))*0.75f; + c.config = !GuiWindowBox((Rectangle){config_handle.x + 10, config_handle.y + 10, 200, 300}, "connection"); + GuiToggle((Rectangle){config_handle.x + 10, config_handle.y + 50, 80, 20}, "v1v2", &c.v1_v2); + GuiToggle((Rectangle){config_handle.x + 100, config_handle.y + 50, 80, 20}, "v2v1", &c.v2_v1); + } } diff --git a/src/node.h b/src/node.h index 015929f..729b3d0 100644 --- a/src/node.h +++ b/src/node.h @@ -5,7 +5,7 @@ #include "datatypes.h" #include "moveable.h" -#define R 10.0f +#define R 14.0f class Node : public Movable{ @@ -31,15 +31,17 @@ class Node : public Movable{ void draw(Vec2D *mouse) { if(!hover_move) DrawCircle(position.x, position.y, radius, (Color){180, 210, 115, 255}); if(hover_move) DrawCircle(position.x, position.y, radius, (Color){108, 153, 187, 255}); - + + if(mode == Distribution::RANDOM) DrawCircle(position.x, position.y, radius/2.0f, (Color){229, 181, 103, 255}); + Vec2D connector = position - ((position - *mouse)).norm() * (radius + R); if(hover_connect){ DrawCircleLines(position.x, position.y, radius + R, (Color){108, 153, 187, 255}); - DrawCircle(connector.x, connector.y, 6.0f, (Color){108, 153, 187, 255}); + DrawCircle(connector.x, connector.y, 8.0f, (Color){108, 153, 187, 255}); } else { DrawCircleLines(position.x, position.y, radius + R, (Color){108, 153, 187, 50}); - DrawCircle(connector.x, connector.y, 6.0f, (Color){108, 153, 187, 50}); + DrawCircle(connector.x, connector.y, 8.0f, (Color){108, 153, 187, 50}); } } };