Rename data types and start implementing drawing quads in ui
This commit is contained in:
@@ -7,28 +7,28 @@
|
||||
|
||||
#define MAX_NODES 1024
|
||||
|
||||
typedef i32 (*node_func_t)(i32 a, i32 b);
|
||||
typedef enum node_type node_type_t;
|
||||
typedef union node_data node_data_t;
|
||||
typedef struct node node_t;
|
||||
typedef i32 (*node_func)(i32 a, i32 b);
|
||||
typedef enum node_type node_type;
|
||||
typedef union node_data node_data;
|
||||
typedef struct node node;
|
||||
|
||||
enum node_type {
|
||||
NODE_TYPE_IO,
|
||||
NODE_TYPE_OP,
|
||||
NODEYPE_IO,
|
||||
NODEYPE_OP,
|
||||
|
||||
COUNT_NODE_TYPES,
|
||||
COUNT_NODEYPES,
|
||||
};
|
||||
|
||||
union node_data {
|
||||
const char *path;
|
||||
node_func_t func;
|
||||
node_func func;
|
||||
};
|
||||
|
||||
struct node {
|
||||
rect_t rect;
|
||||
ui_elem_colours_t colours;
|
||||
node_type_t type;
|
||||
node_data_t data;
|
||||
rect rec;
|
||||
ui_elem_colours colours;
|
||||
node_type type;
|
||||
node_data data;
|
||||
};
|
||||
|
||||
#endif // !NODES_H
|
||||
|
@@ -18,7 +18,7 @@ i32 comp_sub(i32 a, i32 b);
|
||||
i32 comp_mul(i32 a, i32 b);
|
||||
i32 comp_div(i32 a, i32 b);
|
||||
|
||||
INTERNAL node_func_t ops[COUNT_COMP_OPS] = {
|
||||
INTERNAL node_func ops[COUNT_COMP_OPS] = {
|
||||
[COMP_OP_ADD] = comp_add,
|
||||
[COMP_OP_SUB] = comp_sub,
|
||||
[COMP_OP_MUL] = comp_mul,
|
||||
|
39
include/ui.h
39
include/ui.h
@@ -6,7 +6,7 @@
|
||||
#include "window.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#define MAX_UI_ELEMENTS 4096
|
||||
#define MAX_UI_ELEMENTS 8192
|
||||
|
||||
#define BUTTON_WIDTH 100
|
||||
#define BUTTON_HEIGHT 40
|
||||
@@ -14,11 +14,11 @@
|
||||
#define NODE_WIDTH 70
|
||||
#define NODE_HEIGHT 20
|
||||
|
||||
typedef enum ui_elem_type ui_elem_type_t;
|
||||
typedef struct ui_elem ui_elem_t;
|
||||
typedef struct ui_ctx ui_ctx_t;
|
||||
typedef enum ui_elemype ui_elemype;
|
||||
typedef struct ui_elem ui_elem;
|
||||
typedef struct ui_ctx ui_ctx;
|
||||
|
||||
enum ui_elem_type {
|
||||
enum ui_elemype {
|
||||
UI_ELEM_NODE,
|
||||
UI_ELEM_BUTTON,
|
||||
|
||||
@@ -27,14 +27,14 @@ enum ui_elem_type {
|
||||
|
||||
struct ui_elem {
|
||||
u64 id;
|
||||
rect_t rect;
|
||||
ui_elem_type_t type;
|
||||
rect rect;
|
||||
ui_elemype type;
|
||||
};
|
||||
|
||||
typedef struct ui_elem_colours ui_elem_colours_t;
|
||||
typedef struct ui_elem_colours ui_elem_colours;
|
||||
struct ui_elem_colours {
|
||||
colour_t fill;
|
||||
colour_t border;
|
||||
colour fill;
|
||||
colour border;
|
||||
};
|
||||
|
||||
struct ui_ctx {
|
||||
@@ -47,17 +47,16 @@ struct ui_ctx {
|
||||
i32 rel_y;
|
||||
bool mouse_down;
|
||||
bool mouse_up;
|
||||
const window_t *wnd;
|
||||
ui_elem_t elements[MAX_UI_ELEMENTS];
|
||||
const window *wnd;
|
||||
};
|
||||
|
||||
void init_ui_ctx(ui_ctx_t *ctx);
|
||||
void reset_ui_ctx(ui_ctx_t *ctx);
|
||||
void handle_ui_events(const window_t *wnd, ui_ctx_t *ctx,
|
||||
const SDL_Event *event);
|
||||
bool button(const window_t *wnd, ui_ctx_t *ctx, rect_t rect,
|
||||
ui_elem_colours_t colours);
|
||||
rect_t node(const window_t *wnd, ui_ctx_t *ctx, rect_t rect,
|
||||
ui_elem_colours_t colours);
|
||||
void init_ui_ctx(ui_ctx *ctx);
|
||||
void reset_ui_ctx(ui_ctx *ctx);
|
||||
void handle_ui_events(const window *wnd, ui_ctx *ctx, const SDL_Event *event);
|
||||
bool ui_button(const window *wnd, ui_ctx *ctx, rect rect,
|
||||
ui_elem_colours colours);
|
||||
rect ui_node(const window *wnd, ui_ctx *ctx, rect rect,
|
||||
ui_elem_colours colours);
|
||||
quad ui_quad(const window *wnd, ui_ctx *ctx, quad qd, ui_elem_colours colours);
|
||||
|
||||
#endif // !UI_H
|
||||
|
@@ -7,12 +7,12 @@
|
||||
#include <SDL2/SDL_video.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct point point_t;
|
||||
typedef struct line line_t;
|
||||
typedef struct triangle triangle_t;
|
||||
typedef struct gquad gquad_t;
|
||||
typedef struct rect rect_t;
|
||||
typedef struct window window_t;
|
||||
typedef struct point point;
|
||||
typedef struct line line;
|
||||
typedef struct triangle triangle;
|
||||
typedef struct quad quad;
|
||||
typedef struct rect rect;
|
||||
typedef struct window window;
|
||||
|
||||
struct point {
|
||||
i32 x;
|
||||
@@ -20,25 +20,25 @@ struct point {
|
||||
};
|
||||
|
||||
struct line {
|
||||
point_t p0;
|
||||
point_t p1;
|
||||
point p0;
|
||||
point p1;
|
||||
};
|
||||
|
||||
struct triangle {
|
||||
point_t p0;
|
||||
point_t p1;
|
||||
point_t p2;
|
||||
point p0;
|
||||
point p1;
|
||||
point p2;
|
||||
};
|
||||
|
||||
struct gquad {
|
||||
point_t p0;
|
||||
point_t p1;
|
||||
point_t p2;
|
||||
point_t p3;
|
||||
struct quad {
|
||||
point p0;
|
||||
point p1;
|
||||
point p2;
|
||||
point p3;
|
||||
};
|
||||
|
||||
struct rect {
|
||||
point_t topleft;
|
||||
point topleft;
|
||||
i32 w;
|
||||
i32 h;
|
||||
};
|
||||
@@ -54,7 +54,7 @@ struct window {
|
||||
SDL_Renderer *renderer;
|
||||
};
|
||||
|
||||
typedef struct colour colour_t;
|
||||
typedef struct colour colour;
|
||||
struct colour {
|
||||
union {
|
||||
u32 abgr;
|
||||
@@ -62,18 +62,18 @@ struct colour {
|
||||
};
|
||||
};
|
||||
|
||||
bool init_window(window_t *wnd, const char *title, u32 width, u32 height, i32 x,
|
||||
bool init_window(window *wnd, const char *title, u32 width, u32 height, i32 x,
|
||||
i32 y);
|
||||
void cleanup_window(window_t *wnd);
|
||||
void clear_window(const window_t *wnd, colour_t colour);
|
||||
void swap_buffers(const window_t *wnd);
|
||||
void draw_point(const window_t *wnd, point_t p, colour_t colour);
|
||||
void draw_line(const window_t *wnd, const line_t *ln, colour_t colour);
|
||||
void draw_triangle(const window_t *wnd, triangle_t triangle, colour_t colour);
|
||||
void fill_triangle(const window_t *wnd, triangle_t triangle, colour_t colour);
|
||||
void draw_gquad(const window_t *wnd, gquad_t gquad, colour_t colour);
|
||||
void fill_gquad(const window_t *wnd, gquad_t gquad, colour_t colour);
|
||||
void draw_rect(const window_t *wnd, rect_t rect, colour_t colour);
|
||||
void fill_rect(const window_t *wnd, rect_t rect, colour_t colour);
|
||||
void cleanup_window(window *wnd);
|
||||
void clear_window(const window *wnd, colour colour);
|
||||
void swap_buffers(const window *wnd);
|
||||
void draw_point(const window *wnd, point p, colour colour);
|
||||
void draw_line(const window *wnd, const line *ln, colour colour);
|
||||
void draw_triangle(const window *wnd, triangle triangle, colour colour);
|
||||
void fill_triangle(const window *wnd, triangle triangle, colour colour);
|
||||
void draw_quad(const window *wnd, quad qd, colour colour);
|
||||
void fill_quad(const window *wnd, quad qd, colour colour);
|
||||
void draw_rect(const window *wnd, rect rec, colour colour);
|
||||
void fill_rect(const window *wnd, rect rec, colour colour);
|
||||
|
||||
#endif // !WINDOW_H
|
||||
|
Reference in New Issue
Block a user