connecting rewritten with vector view, mousewheel + ctrl changes notes
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
CXX = g++
|
CXX = g++
|
||||||
CXXFLAGS = -std=c++20 -Wall -g -fno-omit-frame-pointer -gdwarf-4 -Og -Wnarrowing
|
CXXFLAGS = -std=c++20 -Wall -g -fno-omit-frame-pointer -gdwarf-4 -Og -Wnarrowing -DLIBREMIDI_ALSA=1
|
||||||
CXXINC = -I/usr/lib/gcc/x86_64-pc-linux-gnu/13.3.0/include -Iinclude
|
CXXINC = -Iinclude
|
||||||
|
|
||||||
LDLIBS = -lraylib
|
LDLIBS = -lraylib -lasound -pthread
|
||||||
LDFLAGS = -Llib -L/usr/lib -L/usr/local/lib
|
LDFLAGS = -Llib -L/usr/lib -L/usr/local/lib
|
||||||
|
|
||||||
hdr_files = ${wildcard src/*.h}
|
hdr_files = ${wildcard src/*.h}
|
||||||
|
|||||||
+85
-47
@@ -19,6 +19,7 @@
|
|||||||
#include "datatypes.h"
|
#include "datatypes.h"
|
||||||
#include "signal-manager.h"
|
#include "signal-manager.h"
|
||||||
#include <format>
|
#include <format>
|
||||||
|
#include <iterator>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
#include <raymath.h>
|
#include <raymath.h>
|
||||||
@@ -101,13 +102,13 @@ int main(){
|
|||||||
|
|
||||||
SetTargetFPS(app.fps);
|
SetTargetFPS(app.fps);
|
||||||
|
|
||||||
ToggleFullscreen();
|
nodes.reserve(1000);
|
||||||
|
|
||||||
for(int i = 0; i < 4; ++i){
|
for(int i = 0; i < 4; ++i){
|
||||||
nodes.emplace(nodes.end(), Node((float)i * app.grid + 10 * app.grid, 5 * app.grid, 15.0f));
|
nodes.emplace_back((float)i * app.grid + 10 * app.grid, 5 * app.grid, 15.0f);
|
||||||
}
|
}
|
||||||
for(int i = 3; i >= 0; --i){
|
for(int i = 3; i >= 0; --i){
|
||||||
nodes.emplace(nodes.end(), Node((float)i * app.grid + 10 * app.grid, 6 * app.grid, 15.0f));
|
nodes.emplace_back((float)i * app.grid + 10 * app.grid, 6 * app.grid, 15.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 8; ++i){
|
for(int i = 0; i < 8; ++i){
|
||||||
@@ -130,6 +131,8 @@ int main(){
|
|||||||
Vec2D<float> select_start;
|
Vec2D<float> select_start;
|
||||||
Rectangle selection;
|
Rectangle selection;
|
||||||
|
|
||||||
|
ToggleFullscreen();
|
||||||
|
|
||||||
while(!WindowShouldClose()){
|
while(!WindowShouldClose()){
|
||||||
|
|
||||||
//app.grid = round(((app.fps / (app.bpm / 60.0f)) * app.speed) / 4.0f); // from quarter notes to 16th notes = div by 4
|
//app.grid = round(((app.fps / (app.bpm / 60.0f)) * app.speed) / 4.0f); // from quarter notes to 16th notes = div by 4
|
||||||
@@ -143,6 +146,16 @@ int main(){
|
|||||||
bool mouse_clicked = IsMouseButtonPressed(MOUSE_BUTTON_LEFT);
|
bool mouse_clicked = IsMouseButtonPressed(MOUSE_BUTTON_LEFT);
|
||||||
bool mouse_released = IsMouseButtonReleased(MOUSE_BUTTON_LEFT);
|
bool mouse_released = IsMouseButtonReleased(MOUSE_BUTTON_LEFT);
|
||||||
|
|
||||||
|
for(auto &n : nodes){
|
||||||
|
n.hovering = false;
|
||||||
|
n.hover_connect = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto dragging_nodes = nodes | std::ranges::views::filter([](Node n) { return n.dragging;});
|
||||||
|
auto connecting_nodes = nodes | std::ranges::views::filter([](Node n) { return n.connecting;});
|
||||||
|
auto hovering_nodes = nodes | std::ranges::views::filter([&mouse_pos](Node n) { return CheckCollisionPointCircle(mouse_pos, n.position, n.radius);});
|
||||||
|
auto hovering_connectors = nodes | std::ranges::views::filter([&mouse_pos](Node n) { return CheckCollisionPointCircle(mouse_pos, (n.position - ((n.position - mouse_pos)).norm() * (n.radius + 14.0f)), 8.0f);});
|
||||||
|
|
||||||
if(IsMouseButtonDown(MOUSE_BUTTON_RIGHT)){
|
if(IsMouseButtonDown(MOUSE_BUTTON_RIGHT)){
|
||||||
Vector2 delta = GetMouseDelta();
|
Vector2 delta = GetMouseDelta();
|
||||||
delta = Vector2Scale(delta, -1.0f/camera.zoom);
|
delta = Vector2Scale(delta, -1.0f/camera.zoom);
|
||||||
@@ -151,12 +164,16 @@ int main(){
|
|||||||
|
|
||||||
float wheel = GetMouseWheelMove();
|
float wheel = GetMouseWheelMove();
|
||||||
if(wheel != 0){
|
if(wheel != 0){
|
||||||
Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera);
|
if(!hovering_nodes.empty() && IsKeyDown(KEY_LEFT_CONTROL)){
|
||||||
camera.offset = GetMousePosition();
|
hovering_nodes.front().midi_note = (hovering_nodes.front().midi_note + 1) % midi.midiNotes.size();
|
||||||
camera.target = mouseWorldPos;
|
} else {
|
||||||
float scaleFactor = 1.0f + (0.25f*fabsf(wheel));
|
Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera);
|
||||||
if (wheel < 0) scaleFactor = 1.0f/scaleFactor;
|
camera.offset = GetMousePosition();
|
||||||
camera.zoom = Clamp(camera.zoom*scaleFactor, 0.125f, 64.0f);
|
camera.target = mouseWorldPos;
|
||||||
|
float scaleFactor = 1.0f + (0.25f*fabsf(wheel));
|
||||||
|
if (wheel < 0) scaleFactor = 1.0f/scaleFactor;
|
||||||
|
camera.zoom = Clamp(camera.zoom*scaleFactor, 0.125f, 64.0f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mouse_clicked){
|
if(mouse_clicked){
|
||||||
@@ -176,14 +193,17 @@ int main(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto &n : nodes){
|
|
||||||
n.hovering = false;
|
for(auto &h : hovering_connectors){
|
||||||
|
h.hover_connect = true;
|
||||||
}
|
}
|
||||||
|
if(dragging_nodes.empty() && connecting_nodes.empty()) {
|
||||||
|
|
||||||
auto dragging_nodes = nodes | std::ranges::views::filter([](Node n) { return n.dragging;});
|
if(!hovering_connectors.empty()){
|
||||||
|
if(mouse_clicked){
|
||||||
if(dragging_nodes.empty()) {
|
hovering_connectors.front().connecting = true;
|
||||||
auto hovering_nodes = nodes | std::ranges::views::filter([&mouse_pos](Node n) { return CheckCollisionPointCircle(mouse_pos, n.position, n.radius);});
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(hovering_nodes.empty() || selection.width > 0){
|
if(hovering_nodes.empty() || selection.width > 0){
|
||||||
if(mouse_clicked){
|
if(mouse_clicked){
|
||||||
@@ -216,7 +236,9 @@ int main(){
|
|||||||
}
|
}
|
||||||
selection = (Rectangle){0,0,0,0};
|
selection = (Rectangle){0,0,0,0};
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if(!hovering_nodes.empty()){
|
||||||
hovering_nodes.front().hovering = true;
|
hovering_nodes.front().hovering = true;
|
||||||
if(selection.width == 0.0f){
|
if(selection.width == 0.0f){
|
||||||
if(mouse_clicked){
|
if(mouse_clicked){
|
||||||
@@ -232,7 +254,7 @@ int main(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else if(!dragging_nodes.empty()){
|
||||||
|
|
||||||
if(mouse_down){
|
if(mouse_down){
|
||||||
if(IsKeyDown(KEY_LEFT_CONTROL)) {
|
if(IsKeyDown(KEY_LEFT_CONTROL)) {
|
||||||
@@ -260,42 +282,58 @@ int main(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} else if(!connecting_nodes.empty() || connecting){
|
||||||
|
|
||||||
for(auto& n : nodes){
|
Vec2D<float> connector_position = connecting_nodes.front().position - ((connecting_nodes.front().position - mouse_pos)).norm() * (connecting_nodes.front().radius + 14.0f);
|
||||||
Vec2D<float> 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();
|
if(connecting_nodes.front().connecting && mouse_down){
|
||||||
|
|
||||||
// connect nodes
|
|
||||||
if( (dist <= n.radius + 25.0f && dist > n.radius) || n.connecting){
|
|
||||||
n.hover_connect = true;
|
|
||||||
} else {
|
|
||||||
n.hover_connect = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(dist_connector <= 8.0f && mouse_clicked && !connecting) {
|
|
||||||
connecting_from = &n;
|
|
||||||
n.connecting = true;
|
|
||||||
connecting = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(n.connecting && mouse_down){
|
|
||||||
DrawLine(connector_position.x, connector_position.y, mouse_pos.x, mouse_pos.y, (Color){229, 181, 103, 255});
|
DrawLine(connector_position.x, connector_position.y, mouse_pos.x, mouse_pos.y, (Color){229, 181, 103, 255});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mouse_released && n.connecting) {
|
if(mouse_released) {
|
||||||
n.connecting = false;
|
if(!hovering_nodes.empty()){
|
||||||
//connecting_from = nullptr;
|
cm.addConnection(&connecting_nodes.front(), &hovering_nodes.front());
|
||||||
}
|
} else if(!hovering_connectors.empty()){
|
||||||
|
cm.addConnection(&connecting_nodes.front(), &hovering_connectors.front());
|
||||||
if(mouse_released && (n.hover_connect || n.dragging)) {
|
|
||||||
if(&n != connecting_from && connecting_from != nullptr){
|
|
||||||
cm.addConnection(connecting_from, &n);
|
|
||||||
connecting_from = nullptr;
|
|
||||||
}
|
}
|
||||||
|
connecting_nodes.front().connecting = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto& n : nodes){
|
||||||
|
/*Vec2D<float> 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();*/
|
||||||
|
/**/
|
||||||
|
/*// connect nodes*/
|
||||||
|
/*if( (dist <= n.radius + 25.0f && dist > n.radius) || n.connecting){*/
|
||||||
|
/* n.hover_connect = true;*/
|
||||||
|
/*} else {*/
|
||||||
|
/* n.hover_connect = false;*/
|
||||||
|
/*}*/
|
||||||
|
/**/
|
||||||
|
/*if(dist_connector <= 8.0f && mouse_clicked && !connecting) {*/
|
||||||
|
/* connecting_from = &n;*/
|
||||||
|
/* n.connecting = true;*/
|
||||||
|
/* connecting = true;*/
|
||||||
|
/*}*/
|
||||||
|
/**/
|
||||||
|
/*if(n.connecting && mouse_down){*/
|
||||||
|
/* DrawLine(connector_position.x, connector_position.y, mouse_pos.x, mouse_pos.y, (Color){229, 181, 103, 255});*/
|
||||||
|
/*}*/
|
||||||
|
/**/
|
||||||
|
/*if(mouse_released && n.connecting) {*/
|
||||||
|
/* n.connecting = false;*/
|
||||||
|
/* //connecting_from = nullptr;*/
|
||||||
|
/*}*/
|
||||||
|
/**/
|
||||||
|
/*if(mouse_released && (n.hover_connect || n.dragging)) {*/
|
||||||
|
/* if(&n != connecting_from && connecting_from != nullptr){*/
|
||||||
|
/* cm.addConnection(connecting_from, &n);*/
|
||||||
|
/* connecting_from = nullptr;*/
|
||||||
|
/* }*/
|
||||||
|
/*}*/
|
||||||
n.draw(&mouse_pos, &camera);
|
n.draw(&mouse_pos, &camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,7 +392,7 @@ int main(){
|
|||||||
int s_nodes = s_signal + 60 + signal_configs*20;
|
int s_nodes = s_signal + 60 + signal_configs*20;
|
||||||
GuiLabel((Rectangle){20, (float)s_nodes + 30, 240, 20}, "NODES");
|
GuiLabel((Rectangle){20, (float)s_nodes + 30, 240, 20}, "NODES");
|
||||||
if(GuiButton((Rectangle){20, (float)s_nodes + 60, 240, 20}, "ADD RANDOM NODE")){
|
if(GuiButton((Rectangle){20, (float)s_nodes + 60, 240, 20}, "ADD RANDOM NODE")){
|
||||||
nodes.emplace_back(Node(200.0f, 200.0f, 15.0f));
|
nodes.emplace_back(200.0f, 200.0f, 15.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user