better states
This commit is contained in:
+22
-42
@@ -124,10 +124,10 @@ int main(){
|
|||||||
Vec2D<float> cam_drag_offset;
|
Vec2D<float> cam_drag_offset;
|
||||||
Vec2D<float> cam_mouse_drag_offset;
|
Vec2D<float> cam_mouse_drag_offset;
|
||||||
|
|
||||||
Node* connecting_from = nullptr;
|
|
||||||
|
|
||||||
double drag_timer = GetTime();
|
double drag_timer = GetTime();
|
||||||
|
|
||||||
|
enum InteractionState {HOVER_CANVAS, HOVER_NODE, HOVER_CONNECTOR, DRAG_NODE, CONNECT_NODE};
|
||||||
|
|
||||||
Vec2D<float> select_start;
|
Vec2D<float> select_start;
|
||||||
Rectangle selection;
|
Rectangle selection;
|
||||||
|
|
||||||
@@ -145,6 +145,10 @@ int main(){
|
|||||||
bool mouse_down = IsMouseButtonDown(MOUSE_BUTTON_LEFT);
|
bool mouse_down = IsMouseButtonDown(MOUSE_BUTTON_LEFT);
|
||||||
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);
|
||||||
|
|
||||||
|
bool mouse_right_down = IsMouseButtonDown(MOUSE_BUTTON_RIGHT);
|
||||||
|
bool mouse_right_clicked = IsMouseButtonPressed(MOUSE_BUTTON_RIGHT);
|
||||||
|
bool mouse_right_released = IsMouseButtonReleased(MOUSE_BUTTON_RIGHT);
|
||||||
|
|
||||||
for(auto &n : nodes){
|
for(auto &n : nodes){
|
||||||
n.hovering = false;
|
n.hovering = false;
|
||||||
@@ -156,7 +160,11 @@ int main(){
|
|||||||
auto hovering_nodes = nodes | std::ranges::views::filter([&mouse_pos](Node n) { return CheckCollisionPointCircle(mouse_pos, n.position, n.radius);});
|
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);});
|
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(hovering_nodes.empty() && IsMouseButtonDown(MOUSE_BUTTON_RIGHT)){
|
||||||
Vector2 delta = GetMouseDelta();
|
Vector2 delta = GetMouseDelta();
|
||||||
delta = Vector2Scale(delta, -1.0f/camera.zoom);
|
delta = Vector2Scale(delta, -1.0f/camera.zoom);
|
||||||
camera.target = Vector2Add(camera.target, delta);
|
camera.target = Vector2Add(camera.target, delta);
|
||||||
@@ -165,7 +173,9 @@ int main(){
|
|||||||
float wheel = GetMouseWheelMove();
|
float wheel = GetMouseWheelMove();
|
||||||
if(wheel != 0){
|
if(wheel != 0){
|
||||||
if(!hovering_nodes.empty() && IsKeyDown(KEY_LEFT_CONTROL)){
|
if(!hovering_nodes.empty() && IsKeyDown(KEY_LEFT_CONTROL)){
|
||||||
hovering_nodes.front().midi_note = (hovering_nodes.front().midi_note + 1) % midi.midiNotes.size();
|
hovering_nodes.front().midi_note += wheel;
|
||||||
|
if(hovering_nodes.front().midi_note < 0 ) hovering_nodes.front().midi_note = midi.midiNotes.size()-1;
|
||||||
|
if(hovering_nodes.front().midi_note >= midi.midiNotes.size() ) hovering_nodes.front().midi_note = 0;
|
||||||
} else {
|
} else {
|
||||||
Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera);
|
Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera);
|
||||||
camera.offset = GetMousePosition();
|
camera.offset = GetMousePosition();
|
||||||
@@ -181,7 +191,7 @@ int main(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
DrawFPS(app.width - 300, 50);
|
DrawFPS(20, app.height - 100);
|
||||||
ClearBackground((Color){46,46,46});
|
ClearBackground((Color){46,46,46});
|
||||||
|
|
||||||
BeginMode2D(camera);
|
BeginMode2D(camera);
|
||||||
@@ -193,10 +203,10 @@ int main(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for(auto &h : hovering_connectors){
|
for(auto &h : hovering_connectors){
|
||||||
h.hover_connect = true;
|
h.hover_connect = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dragging_nodes.empty() && connecting_nodes.empty()) {
|
if(dragging_nodes.empty() && connecting_nodes.empty()) {
|
||||||
|
|
||||||
if(!hovering_connectors.empty()){
|
if(!hovering_connectors.empty()){
|
||||||
@@ -244,11 +254,11 @@ int main(){
|
|||||||
if(mouse_clicked){
|
if(mouse_clicked){
|
||||||
drag_timer = GetTime();
|
drag_timer = GetTime();
|
||||||
}
|
}
|
||||||
if(mouse_down && GetTime() - drag_timer > 0.07){
|
if(mouse_right_down && GetTime() - drag_timer > 0.1){
|
||||||
hovering_nodes.front().drag_offset = hovering_nodes.front().position - mouse_pos;
|
hovering_nodes.front().drag_offset = hovering_nodes.front().position - mouse_pos;
|
||||||
hovering_nodes.front().dragging = true;
|
hovering_nodes.front().dragging = true;
|
||||||
}
|
}
|
||||||
if(mouse_released && GetTime() - drag_timer <= 0.07){
|
if(mouse_right_released && GetTime() - drag_timer <= 0.1){
|
||||||
hovering_nodes.front().config = true;
|
hovering_nodes.front().config = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -295,52 +305,22 @@ int main(){
|
|||||||
cm.addConnection(&connecting_nodes.front(), &hovering_nodes.front());
|
cm.addConnection(&connecting_nodes.front(), &hovering_nodes.front());
|
||||||
} else if(!hovering_connectors.empty()){
|
} else if(!hovering_connectors.empty()){
|
||||||
cm.addConnection(&connecting_nodes.front(), &hovering_connectors.front());
|
cm.addConnection(&connecting_nodes.front(), &hovering_connectors.front());
|
||||||
|
} else {
|
||||||
|
nodes.emplace_back(mouse_pos.x, mouse_pos.y, 15.0f);
|
||||||
|
cm.addConnection(&connecting_nodes.front(), &nodes.back());
|
||||||
}
|
}
|
||||||
connecting_nodes.front().connecting = false;
|
connecting_nodes.front().connecting = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto& n : nodes){
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
cm.drawConnections(&mouse_pos, &camera);
|
cm.drawConnections(&mouse_pos, &camera);
|
||||||
sm.drawSignals(&mouse_pos, &camera);
|
sm.drawSignals(&mouse_pos, &camera);
|
||||||
|
|
||||||
midi.update();
|
midi.update();
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
|
|
||||||
// Main Config Window
|
// Main Config Window
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ class Signal : public Movable{
|
|||||||
Node *next;
|
Node *next;
|
||||||
Node *last;
|
Node *last;
|
||||||
|
|
||||||
|
Node *start;
|
||||||
|
|
||||||
bool at_target = false;
|
bool at_target = false;
|
||||||
int target_node_id = 1;
|
int target_node_id = 1;
|
||||||
int source_node_id = 0;
|
int source_node_id = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user