polar snapping (almost bug free)
This commit is contained in:
+23
-3
@@ -16,6 +16,7 @@
|
||||
/*Pink: (176, 82, 121); #b05279*/
|
||||
/*Blue: (108, 153, 187); #6c99bb*/
|
||||
|
||||
#include <algorithm>
|
||||
#define RAYGUI_IMPLEMENTATION
|
||||
|
||||
#include "datatypes.h"
|
||||
@@ -127,12 +128,17 @@ int main(){
|
||||
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);});
|
||||
|
||||
for(auto &n : app.nm.nodes | std::ranges::views::values){
|
||||
if(hovering_nodes.empty()) n.hovering = false;
|
||||
if(hovering_connectors.empty()) n.hover_connect = false;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if(!hovering_nodes.empty() && !mouse_down && !mouse_right_down) istate = InteractionState::HOVER_NODE;
|
||||
if(!dragging_nodes.empty()) istate = InteractionState::DRAG_NODE;
|
||||
if(!hovering_connectors.empty() && istate == InteractionState::HOVER_CANVAS) istate = InteractionState::HOVER_CONNECTOR;
|
||||
if(!hovering_connectors.empty() && !mouse_right_down && istate == InteractionState::HOVER_CANVAS) istate = InteractionState::HOVER_CONNECTOR;
|
||||
if(!connecting_nodes.empty()) istate = InteractionState::CONNECT_NODE;
|
||||
|
||||
if(!selected_nodes.empty() && IsKeyPressed(KEY_DELETE)) istate = InteractionState::DELETE_SELECTED_NODES;
|
||||
@@ -207,6 +213,10 @@ int main(){
|
||||
|
||||
if(IsKeyDown(KEY_LEFT_CONTROL)) {
|
||||
dragging_nodes.front().position = (Vec2D<float>){round((mouse_pos.x+dragging_nodes.front().drag_offset.x)/app.settings.grid)*app.settings.grid, round((mouse_pos.y+dragging_nodes.front().drag_offset.y)/app.settings.grid)*app.settings.grid};
|
||||
} else if(IsKeyDown(KEY_LEFT_SHIFT)){
|
||||
float steps = round(dragging_nodes.front().neighbor->position.dist(mouse_pos) / 60.0f) * 60.0f;
|
||||
Vec2D<float> polar = dragging_nodes.front().neighbor->position - (dragging_nodes.front().neighbor->position - (mouse_pos + dragging_nodes.front().drag_offset)).norm() * steps;
|
||||
dragging_nodes.front().position = polar;
|
||||
} else {
|
||||
dragging_nodes.front().position = mouse_pos + dragging_nodes.front().drag_offset;
|
||||
}
|
||||
@@ -230,8 +240,10 @@ int main(){
|
||||
}
|
||||
case InteractionState::HOVER_CONNECTOR:
|
||||
{
|
||||
hovering_connectors.front().hover_connect = true;
|
||||
if(mouse_clicked) hovering_connectors.front().connecting = true;
|
||||
if(!hovering_connectors.empty()){
|
||||
hovering_connectors.front().hover_connect = true;
|
||||
if(mouse_clicked) hovering_connectors.front().connecting = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case InteractionState::CONNECT_NODE:
|
||||
@@ -240,8 +252,16 @@ int main(){
|
||||
|
||||
if(connecting_nodes.front().connecting && mouse_down){
|
||||
DrawLine(connector_position.x, connector_position.y, mouse_pos.x, mouse_pos.y, (Color){229, 181, 103, 255});
|
||||
connecting_nodes.front().hovering = true;
|
||||
connecting_nodes.front().hover_connect = true;
|
||||
}
|
||||
|
||||
if(!hovering_connectors.empty()) {
|
||||
hovering_connectors.front().hovering = true;
|
||||
hovering_connectors.front().hover_connect = true;
|
||||
}
|
||||
if(!hovering_nodes.empty()) hovering_nodes.front().hovering = true;
|
||||
|
||||
if(mouse_released) {
|
||||
if(&hovering_nodes.front() != &connecting_nodes.front() && &connecting_nodes.front() != &hovering_connectors.front()){
|
||||
if(!hovering_nodes.empty()){
|
||||
|
||||
Reference in New Issue
Block a user