diff --git a/include/nodes.h b/include/nodes.h new file mode 100644 index 0000000..99c50ce --- /dev/null +++ b/include/nodes.h @@ -0,0 +1,35 @@ +#ifndef NODES_H +#define NODES_H + +#include "window.h" + +#define MAX_NODES 1024 + +#define NODE_WIDTH 70 +#define NODE_HEIGHT 20 + +#define IO_NODE_FILL_COLOUR ((colour_t){.abgr = 0xff2c84b7}) +#define IO_NODE_BORDER_COLOUR ((colour_t){.abgr = 0xff122d5e}) +#define OP_NODE_FILL_COLOUR ((colour_t){.abgr = 0xffad6c3a}) +#define OP_NODE_BORDER_COLOUR ((colour_t){.abgr = 0xff592516}) + +typedef struct node node_t; + +enum comp_ops { + COMP_OP_ADD, + COMP_OP_SUB, + COMP_OP_MUL, + COMP_OP_DIV, + + COUNT_COMP_OPS, +}; + +struct node { + rect_t rect; + const char *path; +}; + +bool aabb(const node_t *node, i32 x, i32 y); +void draw_node(const window_t *wnd, const node_t *node); + +#endif // !NODES_H diff --git a/src/compositor.c b/src/compositor.c index ceac044..c5de28d 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -1,4 +1,5 @@ #include "aliases/aliases.h" +#include "nodes.h" #include "window.h" #include #include @@ -12,33 +13,7 @@ #define WINDOW_WIDTH 1280 #define WINDOW_HEIGHT 720 -#define MAX_NODES 1024 - -#define NODE_WIDTH 70 -#define NODE_HEIGHT 20 - -#define IO_NODE_FILL_COLOUR ((colour_t){.abgr = 0xff2c84b7}) -#define IO_NODE_BORDER_COLOUR ((colour_t){.abgr = 0xff122d5e}) -#define OP_NODE_FILL_COLOUR ((colour_t){.abgr = 0xffad6c3a}) -#define OP_NODE_BORDER_COLOUR ((colour_t){.abgr = 0xff592516}) - -typedef struct node node_t; typedef struct compositor compositor_t; - -enum comp_ops { - COMP_OP_ADD, - COMP_OP_SUB, - COMP_OP_MUL, - COMP_OP_DIV, - - COUNT_COMP_OPS, -}; - -struct node { - rect_t rect; - const char *path; -}; - struct compositor { window_t windows[MAX_WINDOWS]; SDL_Event event; @@ -51,9 +26,7 @@ struct compositor { bool move_node; }; -bool aabb(const node_t *node, i32 x, i32 y); void add_node(compositor_t *comp, const char *path, i32 x, i32 y); -void draw_node(const window_t *wnd, const node_t *node); i32 run_main_loop(void) { if (SDL_Init(SDL_INIT_EVERYTHING) != 0) { @@ -140,11 +113,6 @@ i32 run_main_loop(void) { return EXIT_SUCCESS; } -bool aabb(const node_t *node, i32 x, i32 y) { - return x > node->rect.topleft.x && x <= node->rect.topleft.x + node->rect.w && - y > node->rect.topleft.y && y <= node->rect.topleft.y + node->rect.h; -} - void add_node(compositor_t *comp, const char *path, i32 x, i32 y) { if (comp->count + 1 >= MAX_NODES) { return; @@ -161,8 +129,3 @@ void add_node(compositor_t *comp, const char *path, i32 x, i32 y) { .path = path, }; } - -void draw_node(const window_t *wnd, const node_t *node) { - fill_rect(wnd, &(node->rect), IO_NODE_FILL_COLOUR); - draw_rect(wnd, &(node->rect), IO_NODE_BORDER_COLOUR); -} diff --git a/src/nodes.c b/src/nodes.c new file mode 100644 index 0000000..a99de33 --- /dev/null +++ b/src/nodes.c @@ -0,0 +1,13 @@ +#include "nodes.h" +#include "aliases/aliases.h" +#include + +bool aabb(const node_t *node, i32 x, i32 y) { + return x > node->rect.topleft.x && x <= node->rect.topleft.x + node->rect.w && + y > node->rect.topleft.y && y <= node->rect.topleft.y + node->rect.h; +} + +void draw_node(const window_t *wnd, const node_t *node) { + fill_rect(wnd, &(node->rect), IO_NODE_FILL_COLOUR); + draw_rect(wnd, &(node->rect), IO_NODE_BORDER_COLOUR); +}