Compare commits
No commits in common. "f2faa56e5fa6f72d416beacb6757ed0871fedb5a" and "373e48216d32a67e7976eac1beeeb427c28be485" have entirely different histories.
f2faa56e5f
...
373e48216d
13
include/ui.h
13
include/ui.h
@ -21,8 +21,6 @@
|
|||||||
typedef enum ui_elem_type ui_elem_type;
|
typedef enum ui_elem_type ui_elem_type;
|
||||||
typedef struct ui_elem ui_elem;
|
typedef struct ui_elem ui_elem;
|
||||||
typedef struct ui_ctx ui_ctx;
|
typedef struct ui_ctx ui_ctx;
|
||||||
typedef struct ui_elem_colours ui_elem_colours;
|
|
||||||
typedef enum noodle_action noodle_action;
|
|
||||||
|
|
||||||
enum ui_elem_type {
|
enum ui_elem_type {
|
||||||
UI_ELEM_NODE,
|
UI_ELEM_NODE,
|
||||||
@ -41,17 +39,12 @@ struct ui_elem {
|
|||||||
ui_elem_type type;
|
ui_elem_type type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct ui_elem_colours ui_elem_colours;
|
||||||
struct ui_elem_colours {
|
struct ui_elem_colours {
|
||||||
colour fill;
|
colour fill;
|
||||||
colour border;
|
colour border;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum noodle_action {
|
|
||||||
NOODLE_ACTION_NONE,
|
|
||||||
NOODLE_ACTION_DRAGGING,
|
|
||||||
NOODLE_ACTION_RELEASED,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ui_ctx {
|
struct ui_ctx {
|
||||||
u64 count;
|
u64 count;
|
||||||
i64 hovered;
|
i64 hovered;
|
||||||
@ -73,7 +66,7 @@ bool ui_button(const window *wnd, ui_ctx *ctx, rect rect,
|
|||||||
ui_elem_colours colours);
|
ui_elem_colours colours);
|
||||||
bool ui_node(const window *wnd, ui_ctx *ctx, rect rect,
|
bool ui_node(const window *wnd, ui_ctx *ctx, rect rect,
|
||||||
ui_elem_colours colours);
|
ui_elem_colours colours);
|
||||||
noodle_action ui_noodle(const window *wnd, ui_ctx *ctx, line ln,
|
bool ui_noodle(const window *wnd, ui_ctx *ctx, line ln, ui_elem_colours colours,
|
||||||
ui_elem_colours colours, rect parent_node);
|
rect parent_node);
|
||||||
|
|
||||||
#endif // !UI_H
|
#endif // !UI_H
|
||||||
|
@ -171,32 +171,10 @@ i32 run_main_loop(void) {
|
|||||||
*ln = line_from_origin(origin, new_angle, DEFAULT_NOODLE_LENGTH);
|
*ln = line_from_origin(origin, new_angle, DEFAULT_NOODLE_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ui_noodle(main_window, &(comp.ctx), *ln, node_elem->colours,
|
if (ui_noodle(main_window, &(comp.ctx), *ln, node_elem->colours,
|
||||||
node_elem->rec)) {
|
node_elem->rec)) {
|
||||||
case NOODLE_ACTION_DRAGGING:
|
|
||||||
ln->p0.x += comp.ctx.rel_x;
|
ln->p0.x += comp.ctx.rel_x;
|
||||||
ln->p0.y += comp.ctx.rel_y;
|
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) {
|
if (delta_multiplier > 0) {
|
||||||
|
17
src/ui.c
17
src/ui.c
@ -141,10 +141,10 @@ bool ui_node(const window *wnd, ui_ctx *ctx, rect rect,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
noodle_action ui_noodle(const window *wnd, ui_ctx *ctx, line ln,
|
bool ui_noodle(const window *wnd, ui_ctx *ctx, line ln, ui_elem_colours colours,
|
||||||
ui_elem_colours colours, rect parent_node) {
|
rect parent_node) {
|
||||||
if (ctx->count + 1 >= MAX_UI_ELEMENTS) {
|
if (ctx->count + 1 >= MAX_UI_ELEMENTS) {
|
||||||
return NOODLE_ACTION_NONE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 id = get_id(ctx);
|
u64 id = get_id(ctx);
|
||||||
@ -220,25 +220,24 @@ noodle_action ui_noodle(const window *wnd, ui_ctx *ctx, line ln,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (wnd != ctx->wnd || (ctx->active >= 0 && ctx->active != id)) {
|
if (wnd != ctx->wnd || (ctx->active >= 0 && ctx->active != id)) {
|
||||||
return NOODLE_ACTION_NONE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->mouse_up) {
|
if (ctx->mouse_up) {
|
||||||
if (ctx->hovered == ctx->active && ctx->hovered == id) {
|
if (ctx->hovered == ctx->active && ctx->hovered == id) {
|
||||||
ctx->hovered = ctx->active = -1;
|
ctx->hovered = ctx->active = -1;
|
||||||
return NOODLE_ACTION_RELEASED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NOODLE_ACTION_NONE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->hovered == id && ctx->active == id) {
|
if (ctx->hovered == id && ctx->active == id) {
|
||||||
return NOODLE_ACTION_DRAGGING;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!aabb(bounding_box, ctx->mouse_x, ctx->mouse_y) ||
|
if (!aabb(bounding_box, ctx->mouse_x, ctx->mouse_y) ||
|
||||||
aabb(parent_node, ctx->mouse_x, ctx->mouse_y)) {
|
aabb(parent_node, ctx->mouse_x, ctx->mouse_y)) {
|
||||||
return NOODLE_ACTION_NONE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->hovered = id;
|
ctx->hovered = id;
|
||||||
@ -247,7 +246,7 @@ noodle_action ui_noodle(const window *wnd, ui_ctx *ctx, line ln,
|
|||||||
ctx->active = id;
|
ctx->active = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NOODLE_ACTION_NONE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal u64 get_id(ui_ctx *ctx) {
|
internal u64 get_id(ui_ctx *ctx) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user