minimal gui functional
This commit is contained in:
+63
-30
@@ -16,6 +16,8 @@
|
||||
/*Pink: (176, 82, 121); #b05279*/
|
||||
/*Blue: (108, 153, 187); #6c99bb*/
|
||||
|
||||
#include "datatypes.h"
|
||||
#include <iostream>
|
||||
#include <raylib.h>
|
||||
#include <raymath.h>
|
||||
|
||||
@@ -30,11 +32,9 @@
|
||||
#include <cstdlib>
|
||||
#include <stdio.h>
|
||||
#include <cmath>
|
||||
#include <map>
|
||||
|
||||
#include "node.h"
|
||||
#include "signal.h"
|
||||
#include "connection.h"
|
||||
|
||||
#include "connection-manager.h"
|
||||
|
||||
@@ -46,7 +46,6 @@ std::vector<libremidi::output_port> midi_out_ports;
|
||||
|
||||
std::vector<Node> nodes;
|
||||
std::vector<Signal> signals;
|
||||
//std::vector<Connection> connections;
|
||||
ConnectionManager cm;
|
||||
|
||||
Vec2D<float> mouse_pos;
|
||||
@@ -98,20 +97,25 @@ int main(){
|
||||
}
|
||||
|
||||
for(int i = 0; i < 10; i++){
|
||||
nodes.emplace(nodes.end(), Node((float)(rand() % 2160 + 200), (float)(rand() % 1040 + 200), 15.0f));
|
||||
nodes.emplace(nodes.end(), Node((float)(rand() % app.width*0.5 + app.width*0.25), (float)(rand() % app.height*0.5 + app.height*0.25), 15.0f));
|
||||
|
||||
std::cout << nodes.back().position.x << " " << nodes.back().position.y << std::endl;
|
||||
}
|
||||
|
||||
for(int i = 0; i < 2; i++){
|
||||
signals.emplace(signals.end(), Signal(1280, 720, 5.0f, 2.0f));
|
||||
signals[i].next = &nodes[0];
|
||||
for(int i = 0; i < 1; i++){
|
||||
signals.emplace(signals.end(), Signal(nodes.front().position.x+1, nodes.front().position.y+1, 5.0f, 2.0f)); // position + 1 or else it does not render. why? no idea!
|
||||
signals[i].next = &nodes.front();
|
||||
signals[i].last = &nodes.front();
|
||||
}
|
||||
|
||||
midi_out.open_port(midi_out_ports[2]);
|
||||
|
||||
Vec2D<float> drag_offset;
|
||||
|
||||
Node* connecting_from;
|
||||
|
||||
Node* connecting_from = nullptr;
|
||||
|
||||
double drag_timer = GetTime();
|
||||
|
||||
while(!WindowShouldClose()){
|
||||
|
||||
Vector2 mp = GetScreenToWorld2D(GetMousePosition(), camera);
|
||||
@@ -130,6 +134,8 @@ int main(){
|
||||
ClearBackground((Color){46,46,46});
|
||||
|
||||
BeginMode2D(camera);
|
||||
bool connecting = false;
|
||||
bool dragging = false;
|
||||
|
||||
for(auto& n : nodes){
|
||||
Vec2D<float> connector_position = n.position - ((n.position - mouse_pos)).norm() * (n.radius + 10.0f);
|
||||
@@ -144,9 +150,10 @@ int main(){
|
||||
n.hover_connect = false;
|
||||
}
|
||||
|
||||
if(dist_connector <= 6.0f && mouse_clicked) {
|
||||
if(dist_connector <= 6.0f && mouse_clicked && !connecting) {
|
||||
connecting_from = &n;
|
||||
n.connecting = true;
|
||||
connecting = true;
|
||||
}
|
||||
|
||||
if(n.connecting && mouse_down){
|
||||
@@ -155,6 +162,7 @@ int main(){
|
||||
|
||||
if(mouse_released && n.connecting) {
|
||||
n.connecting = false;
|
||||
//connecting_from = nullptr;
|
||||
}
|
||||
|
||||
if(mouse_released && (n.hover_connect || n.hover_move)) {
|
||||
@@ -163,24 +171,32 @@ int main(){
|
||||
connecting_from = nullptr;
|
||||
}
|
||||
}
|
||||
if(!connecting){
|
||||
// move node
|
||||
if((n.position - mouse_pos).length() <= n.radius || n.picked_up){
|
||||
n.hover_move = true;
|
||||
} else {
|
||||
n.hover_move = false;
|
||||
}
|
||||
|
||||
// move node
|
||||
if((n.position - mouse_pos).length() <= n.radius || n.picked_up){
|
||||
n.hover_move = true;
|
||||
} else {
|
||||
n.hover_move = false;
|
||||
}
|
||||
if(mouse_clicked && n.hover_move && !dragging){
|
||||
n.picked_up = true;
|
||||
drag_offset = n.position - mouse_pos;
|
||||
dragging = true;
|
||||
drag_timer = GetTime();
|
||||
}
|
||||
if(mouse_down && n.picked_up){
|
||||
if(GetTime() - drag_timer > 0.1) n.position = mouse_pos + drag_offset;
|
||||
}
|
||||
|
||||
if(mouse_clicked && n.hover_move){
|
||||
n.picked_up = true;
|
||||
drag_offset = n.position - mouse_pos;
|
||||
}
|
||||
if(mouse_down && n.picked_up){
|
||||
n.position = mouse_pos + drag_offset;
|
||||
}
|
||||
if(mouse_released && n.picked_up){
|
||||
if(GetTime() - drag_timer < 0.1) n.config = true;
|
||||
}
|
||||
|
||||
if(mouse_released) {
|
||||
n.picked_up = false;
|
||||
}
|
||||
|
||||
if(mouse_released) {
|
||||
n.picked_up = false;
|
||||
}
|
||||
n.draw(&mouse_pos);
|
||||
}
|
||||
@@ -188,11 +204,13 @@ int main(){
|
||||
cm.draw();
|
||||
|
||||
for(auto& s : signals){
|
||||
s.direction = s.next->position - s.position;
|
||||
s.direction = (s.next->position - s.position).norm();
|
||||
if(s.position.dist(&s.next->position) < s.speed * 1.5) {
|
||||
Node* n = cm.next(s.next);
|
||||
Node* n = cm.next(s.next, s.last);
|
||||
if(n != s.next && n != nullptr) {
|
||||
s.last = s.next;
|
||||
s.next = n;
|
||||
std::cout << s.last << " " << s.next << std::endl;
|
||||
midi_out.send_message(libremidi::channel_events::control_change(2, 10, 50));
|
||||
}
|
||||
}
|
||||
@@ -200,9 +218,24 @@ int main(){
|
||||
}
|
||||
|
||||
EndMode2D();
|
||||
GuiWindowBox((Rectangle){16,16,232,400}, "config");
|
||||
|
||||
GuiButton((Rectangle){32, 64, 96, 20}, "button");
|
||||
GuiWindowBox((Rectangle){0,0,280,600}, "config");
|
||||
|
||||
if(GuiButton((Rectangle){20, 60, 240, 20}, "button")){
|
||||
signals.emplace_back(Signal(nodes.front().position.x + 1, nodes.front().position.y + 1, 5.0f, 2.0f)); // position + 1 or else it does not render. why? no idea!
|
||||
signals.back().next = &nodes[0];
|
||||
signals.back().last = &nodes[0];
|
||||
}
|
||||
|
||||
for(auto& n : nodes){
|
||||
if(n.config){
|
||||
int option = n.mode;
|
||||
GuiComboBox((Rectangle){ 20, 100, 240, 20 }, "Round Robin;Random", &option);
|
||||
n.mode = (Distribution)option;
|
||||
if(GuiButton((Rectangle){20, 140, 240, 20 }, "button")){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user