node deletion with connection deletion and signal redistribution implemented
This commit is contained in:
+19
-19
@@ -50,7 +50,7 @@ int main(){
|
||||
|
||||
app.ui.init();
|
||||
|
||||
int monitor = 0; //GetCurrentMonitor();
|
||||
int monitor = 1; //GetCurrentMonitor();
|
||||
|
||||
SetWindowMonitor(monitor);
|
||||
|
||||
@@ -83,10 +83,10 @@ int main(){
|
||||
}
|
||||
|
||||
for(int i = 0; i < 8; ++i){
|
||||
app.cm.addConnection(&app.nm.nodes[i], &app.nm.nodes[(i+1) % 8]);
|
||||
app.cm.addConnection(app.nm.nodes[i].id, app.nm.nodes[(i+1) % 8].id);
|
||||
}
|
||||
|
||||
app.sm.addSignalAtNode(&app.nm.nodes.front());
|
||||
app.sm.addSignalAtNode((app.nm.nodes | std::views::values).front().id);
|
||||
|
||||
app.sm.startSignalThread();
|
||||
|
||||
@@ -110,7 +110,7 @@ int main(){
|
||||
BeginDrawing();
|
||||
ClearBackground((Color){46,46,46});
|
||||
BeginMode2D(camera);
|
||||
//app.settings.mutex.lock();
|
||||
|
||||
app.settings.speed = (app.settings.grid * 8.0f) * (app.settings.bpm / 120.f);
|
||||
|
||||
Vector2 mp = GetScreenToWorld2D(GetMousePosition(), camera);
|
||||
@@ -128,11 +128,11 @@ int main(){
|
||||
Vec2D<float> mouse_delta = {GetMouseDelta().x, GetMouseDelta().y};
|
||||
Vec2D<float> delta = mouse_delta * (-1.0f/camera.zoom);
|
||||
|
||||
auto dragging_nodes = app.nm.nodes | std::ranges::views::filter([](Node n) { return n.dragging;});
|
||||
auto connecting_nodes = app.nm.nodes | std::ranges::views::filter([](Node n) { return n.connecting;});
|
||||
auto selected_nodes = app.nm.nodes | std::ranges::views::filter([](Node n) { return n.selected && !n.dragging;});
|
||||
auto hovering_nodes = app.nm.nodes | std::ranges::views::filter([&mouse_pos](Node n) { return CheckCollisionPointCircle(mouse_pos, n.position, n.radius);});
|
||||
auto hovering_connectors = app.nm.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 dragging_nodes = app.nm.nodes | std::ranges::views::values | std::ranges::views::filter([](Node n) { return n.dragging;});
|
||||
auto connecting_nodes = app.nm.nodes | std::ranges::views::values| std::ranges::views::filter([](Node n) { return n.connecting;});
|
||||
auto selected_nodes = app.nm.nodes | std::ranges::views::values| std::ranges::views::filter([](Node n) { return n.selected && !n.dragging;});
|
||||
auto hovering_nodes = app.nm.nodes | std::ranges::views::values| std::ranges::views::filter([&mouse_pos](Node n) { return CheckCollisionPointCircle(mouse_pos, n.position, n.radius);});
|
||||
auto hovering_connectors = app.nm.nodes | std::ranges::views::values| 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(!mouse_down && !mouse_right_down && dragging_nodes.empty() && connecting_nodes.empty() && hovering_nodes.empty() && hovering_connectors.empty()) istate = InteractionState::HOVER_CANVAS;
|
||||
if((mouse_clicked || mouse_down || mouse_released) && !mouse_right_down && dragging_nodes.empty() && connecting_nodes.empty() && hovering_nodes.empty() && hovering_connectors.empty()) istate = InteractionState::DRAW_SELECTION;
|
||||
@@ -163,7 +163,7 @@ int main(){
|
||||
DrawRectangleLines(select1.x, select1.y, select2.x, select2.y, (Color){150,150,150,150});
|
||||
selection = (Rectangle){select1.x, select1.y, select2.x, select2.y};
|
||||
|
||||
for(auto& n : app.nm.nodes){
|
||||
for(auto& n : app.nm.nodes | std::views::values){
|
||||
if(CheckCollisionPointRec(n.position, selection)) {
|
||||
n.in_rect = true;
|
||||
} else {
|
||||
@@ -173,7 +173,7 @@ int main(){
|
||||
}
|
||||
|
||||
if(mouse_released){
|
||||
for(auto& n : app.nm.nodes){
|
||||
for(auto& n : app.nm.nodes | std::views::values){
|
||||
if(CheckCollisionPointRec(n.position, selection)) {
|
||||
n.selected = true;
|
||||
n.in_rect = false;
|
||||
@@ -236,24 +236,25 @@ int main(){
|
||||
if(mouse_released) {
|
||||
if(&hovering_nodes.front() != &connecting_nodes.front() && &connecting_nodes.front() != &hovering_connectors.front()){
|
||||
if(!hovering_nodes.empty()){
|
||||
app.cm.addConnection(&connecting_nodes.front(), &hovering_nodes.front());
|
||||
app.cm.addConnection(connecting_nodes.front().id, hovering_nodes.front().id);
|
||||
} else if(!hovering_connectors.empty()){
|
||||
app.cm.addConnection(&connecting_nodes.front(), &hovering_connectors.front());
|
||||
app.cm.addConnection(connecting_nodes.front().id, hovering_connectors.front().id);
|
||||
} else {
|
||||
app.nm.addNode(mouse_pos.x, mouse_pos.y);
|
||||
app.cm.addConnection(&connecting_nodes.front(), &app.nm.nodes.back());
|
||||
int id = app.nm.addNode(mouse_pos.x, mouse_pos.y);
|
||||
app.cm.addConnection(connecting_nodes.front().id, id);
|
||||
}
|
||||
}
|
||||
connecting_nodes.front().connecting = false;
|
||||
istate = InteractionState::HOVER_CANVAS;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case InteractionState::DELETE_SELECTED_NODES:
|
||||
{
|
||||
for(auto &n : app.nm.nodes){
|
||||
for(auto &n : selected_nodes){
|
||||
n.erase = true;
|
||||
}
|
||||
app.nm.removeNodes();
|
||||
app.removeNodes();
|
||||
break;
|
||||
}
|
||||
};
|
||||
@@ -279,8 +280,7 @@ int main(){
|
||||
DrawPixel(x, y, (Color){130,130,130,200});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
app.draw(&mouse_pos, &camera);
|
||||
|
||||
EndMode2D();
|
||||
|
||||
Reference in New Issue
Block a user