dragging works. introducing connectors maybe

This commit is contained in:
Sebastian
2024-11-10 01:56:33 +01:00
parent 71dc08d21f
commit 4f48aa2d5a
11 changed files with 493 additions and 375 deletions
+5 -4
View File
@@ -143,7 +143,7 @@ namespace VISEQ::GRAPH {
}
SPTR_Node getClosestNode(Vec2Df position){
auto neighbors = nodes | RANGE_FILTER([](SPTR_Node n){ return !n->dragging;}) | std::ranges::to<VEC_SPTR_Node>();
auto neighbors = nodes | RANGE_FILTER([](SPTR_Node n){ return !n->picked_up;}) | std::ranges::to<VEC_SPTR_Node>();
std::sort(neighbors.begin(), neighbors.end(), [position](SPTR_Node na, SPTR_Node nb){ return na->position.dist(position) < nb->position.dist(position);});
return neighbors.front();
}
@@ -236,7 +236,7 @@ namespace VISEQ::GRAPH {
unsigned char opacity_from = 250.0f - Clamp(from_to_handle.dist(mouse_pos), 0.0f, 220.0f);
unsigned char opacity_to = 250.0f - Clamp(to_from_handle.dist(mouse_pos), 0.0f, 220.0f);
if(!c->start->dragging && !c->end->dragging){
if(!c->start->picked_up && !c->end->picked_up){
// On/Off switches on both sides
if(ViButton(mouse_pos, from_to_handle.x, from_to_handle.y, 8.0f, c->pass_forward ? (Color){120, 210, 115, opacity_from} : (Color){232, 50, 32, opacity_from} )) c->pass_forward = !c->pass_forward;
if(ViButton(mouse_pos, to_from_handle.x, to_from_handle.y, 8.0f, c->pass_backward ? (Color){120, 210, 115, opacity_to} : (Color){232, 50, 32, opacity_to} )) c->pass_backward = !c->pass_backward;
@@ -262,8 +262,9 @@ namespace VISEQ::GRAPH {
void drawNodes(Vec2Df mouse_pos, Camera2D camera){
float min_d = 480;
for(auto n : nodes){
if(n->dragging){
auto neighbors_local = nodes | RANGE_FILTER([mouse_pos](SPTR_Node n){ return !n->dragging && !n->selected && n->position.dist(mouse_pos) < 960;}) | std::ranges::to<VEC_SPTR_Node>();
n->update();
if(n->picked_up){
auto neighbors_local = nodes | RANGE_FILTER([mouse_pos](SPTR_Node n){ return !n->picked_up && !n->selected && n->position.dist(mouse_pos) < 960;}) | std::ranges::to<VEC_SPTR_Node>();
std::sort(neighbors_local.begin(), neighbors_local.end(), [n, mouse_pos](SPTR_Node na, SPTR_Node nb){ return na->position.dist(mouse_pos) < nb->position.dist(mouse_pos);});
if(!neighbors_local.empty()){
min_d = neighbors_local.front()->position.dist(mouse_pos);