From f2faa56e5fa6f72d416beacb6757ed0871fedb5a Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sun, 25 Feb 2024 20:52:44 +0000 Subject: [PATCH] Handle ui_noodle return states and start introducing connected nodes --- src/compositor.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/compositor.c b/src/compositor.c index 19b8338..47be6d9 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -171,10 +171,32 @@ i32 run_main_loop(void) { *ln = line_from_origin(origin, new_angle, DEFAULT_NOODLE_LENGTH); } - if (ui_noodle(main_window, &(comp.ctx), *ln, node_elem->colours, - node_elem->rec)) { + switch (ui_noodle(main_window, &(comp.ctx), *ln, node_elem->colours, + node_elem->rec)) { + case NOODLE_ACTION_DRAGGING: ln->p0.x += comp.ctx.rel_x; ln->p0.y += comp.ctx.rel_y; + break; + case NOODLE_ACTION_RELEASED: + for (u64 k = 0; k < comp.count; ++k) { + if (k == i) { + continue; + } + + const node *nd = &(comp.nodes[k]); + + if (aabb(nd->rec, comp.ctx.mouse_x, comp.ctx.mouse_y)) { + point p0 = {nd->rec.topleft.x + nd->rec.w / 2, + nd->rec.topleft.y + nd->rec.h / 2}; + + ln->p0 = p0; + } else { + ln->p0 = ln->p1; + } + } + break; + default: + break; } if (delta_multiplier > 0) {