Isolate the node drawing code into separate files
This commit is contained in:
parent
95d9f5e5cf
commit
c397bcd17d
35
include/nodes.h
Normal file
35
include/nodes.h
Normal file
@ -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
|
@ -1,4 +1,5 @@
|
||||
#include "aliases/aliases.h"
|
||||
#include "nodes.h"
|
||||
#include "window.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_events.h>
|
||||
@ -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);
|
||||
}
|
||||
|
13
src/nodes.c
Normal file
13
src/nodes.c
Normal file
@ -0,0 +1,13 @@
|
||||
#include "nodes.h"
|
||||
#include "aliases/aliases.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user