Add support for maintaining connected noodle when parent node moves
This commit is contained in:
parent
f2faa56e5f
commit
8078a72deb
@ -7,11 +7,13 @@
|
|||||||
#define MAX_NODES 1024
|
#define MAX_NODES 1024
|
||||||
#define IO_INPUT_COUNT 0
|
#define IO_INPUT_COUNT 0
|
||||||
#define OP_INPUT_COUNT 2
|
#define OP_INPUT_COUNT 2
|
||||||
|
#define EMPTY_NODE 0
|
||||||
|
|
||||||
typedef i32 (*node_func)(i32 a, i32 b);
|
typedef i32 (*node_func)(i32 a, i32 b);
|
||||||
typedef enum node_type node_type;
|
typedef enum node_type node_type;
|
||||||
typedef union node_data node_data;
|
typedef union node_data node_data;
|
||||||
typedef struct node node;
|
typedef struct node node;
|
||||||
|
typedef struct noodle noodle;
|
||||||
|
|
||||||
enum node_type {
|
enum node_type {
|
||||||
NODE_TYPE_IO,
|
NODE_TYPE_IO,
|
||||||
@ -25,13 +27,18 @@ union node_data {
|
|||||||
node_func func;
|
node_func func;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct noodle {
|
||||||
|
line ln;
|
||||||
|
u64 connected_node;
|
||||||
|
};
|
||||||
|
|
||||||
struct node {
|
struct node {
|
||||||
rect rec;
|
rect rec;
|
||||||
ui_elem_colours colours;
|
ui_elem_colours colours;
|
||||||
node_type type;
|
node_type type;
|
||||||
node_data data;
|
node_data data;
|
||||||
u64 inputs;
|
u64 inputs;
|
||||||
line *noodles;
|
noodle *noodles;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !NODES_H
|
#endif // !NODES_H
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define MAX_UI_ELEMENTS 8192
|
#define MAX_UI_ELEMENTS 8192
|
||||||
#define RESERVED_UI_SLOT 0
|
|
||||||
#define UI_ELEM_START_INDEX 1
|
|
||||||
|
|
||||||
#define BUTTON_WIDTH 100
|
#define BUTTON_WIDTH 100
|
||||||
#define BUTTON_HEIGHT 40
|
#define BUTTON_HEIGHT 40
|
||||||
|
@ -162,20 +162,20 @@ i32 run_main_loop(void) {
|
|||||||
|
|
||||||
for (u64 j = 0; j < comp.nodes[i].inputs; ++j) {
|
for (u64 j = 0; j < comp.nodes[i].inputs; ++j) {
|
||||||
f64 new_angle = angle + angle_delta * delta_multiplier;
|
f64 new_angle = angle + angle_delta * delta_multiplier;
|
||||||
line *ln = &(node_elem->noodles[j]);
|
noodle *ndl = &(node_elem->noodles[j]);
|
||||||
|
|
||||||
if (ln->p0.x == ln->p1.x && ln->p0.y == ln->p1.y) {
|
if (ndl->ln.p0.x == ndl->ln.p1.x && ndl->ln.p0.y == ndl->ln.p1.y) {
|
||||||
point origin = {node_elem->rec.topleft.x + node_elem->rec.w / 2,
|
point origin = {node_elem->rec.topleft.x + node_elem->rec.w / 2,
|
||||||
node_elem->rec.topleft.y + node_elem->rec.h / 2};
|
node_elem->rec.topleft.y + node_elem->rec.h / 2};
|
||||||
|
|
||||||
*ln = line_from_origin(origin, new_angle, DEFAULT_NOODLE_LENGTH);
|
ndl->ln = line_from_origin(origin, new_angle, DEFAULT_NOODLE_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ui_noodle(main_window, &(comp.ctx), *ln, node_elem->colours,
|
switch (ui_noodle(main_window, &(comp.ctx), ndl->ln, node_elem->colours,
|
||||||
node_elem->rec)) {
|
node_elem->rec)) {
|
||||||
case NOODLE_ACTION_DRAGGING:
|
case NOODLE_ACTION_DRAGGING:
|
||||||
ln->p0.x += comp.ctx.rel_x;
|
ndl->ln.p0.x += comp.ctx.rel_x;
|
||||||
ln->p0.y += comp.ctx.rel_y;
|
ndl->ln.p0.y += comp.ctx.rel_y;
|
||||||
break;
|
break;
|
||||||
case NOODLE_ACTION_RELEASED:
|
case NOODLE_ACTION_RELEASED:
|
||||||
for (u64 k = 0; k < comp.count; ++k) {
|
for (u64 k = 0; k < comp.count; ++k) {
|
||||||
@ -189,9 +189,11 @@ i32 run_main_loop(void) {
|
|||||||
point p0 = {nd->rec.topleft.x + nd->rec.w / 2,
|
point p0 = {nd->rec.topleft.x + nd->rec.w / 2,
|
||||||
nd->rec.topleft.y + nd->rec.h / 2};
|
nd->rec.topleft.y + nd->rec.h / 2};
|
||||||
|
|
||||||
ln->p0 = p0;
|
ndl->ln.p0 = p0;
|
||||||
|
ndl->connected_node = k;
|
||||||
} else {
|
} else {
|
||||||
ln->p0 = ln->p1;
|
ndl->ln.p0 = ndl->ln.p1;
|
||||||
|
ndl->connected_node = EMPTY_NODE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -215,13 +217,16 @@ i32 run_main_loop(void) {
|
|||||||
node_elem->rec.topleft.x += comp.ctx.rel_x;
|
node_elem->rec.topleft.x += comp.ctx.rel_x;
|
||||||
node_elem->rec.topleft.y += comp.ctx.rel_y;
|
node_elem->rec.topleft.y += comp.ctx.rel_y;
|
||||||
|
|
||||||
for (u64 j = 0; j < comp.nodes[i].inputs; ++j) {
|
for (u64 j = 0; j < node_elem->inputs; ++j) {
|
||||||
line *ln = &(node_elem->noodles[j]);
|
noodle *ndl = &(node_elem->noodles[j]);
|
||||||
|
|
||||||
ln->p0.x += comp.ctx.rel_x;
|
if (ndl->connected_node == EMPTY_NODE) {
|
||||||
ln->p0.y += comp.ctx.rel_y;
|
ndl->ln.p0.x += comp.ctx.rel_x;
|
||||||
ln->p1.x += comp.ctx.rel_x;
|
ndl->ln.p0.y += comp.ctx.rel_y;
|
||||||
ln->p1.y += comp.ctx.rel_y;
|
}
|
||||||
|
|
||||||
|
ndl->ln.p1.x += comp.ctx.rel_x;
|
||||||
|
ndl->ln.p1.y += comp.ctx.rel_y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -250,8 +255,8 @@ void add_node(compositor *comp, node_type type, node_data data, u64 inputs,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 alloc_size = inputs * sizeof(line);
|
u64 alloc_size = inputs * sizeof(noodle);
|
||||||
line *noodles = mem_arena_alloc(comp->arena, alloc_size);
|
noodle *noodles = mem_arena_alloc(comp->arena, alloc_size);
|
||||||
if (!noodles) {
|
if (!noodles) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -263,7 +268,7 @@ void add_node(compositor *comp, node_type type, node_data data, u64 inputs,
|
|||||||
.h = NODE_HEIGHT,
|
.h = NODE_HEIGHT,
|
||||||
};
|
};
|
||||||
|
|
||||||
comp->nodes[(comp->count)++] = (node){
|
comp->nodes[++(comp->count)] = (node){
|
||||||
.rec = rec,
|
.rec = rec,
|
||||||
.colours = colours,
|
.colours = colours,
|
||||||
.type = type,
|
.type = type,
|
||||||
|
Loading…
Reference in New Issue
Block a user