compositor-test/include/ui.h

80 lines
1.5 KiB
C

#ifndef UI_H
#define UI_H
#include "SDL_events.h"
#include "aliases.h"
#include "window.h"
#include <stdbool.h>
#define MAX_UI_ELEMENTS 8192
#define RESERVED_UI_SLOT 0
#define UI_ELEM_START_INDEX 1
#define BUTTON_WIDTH 100
#define BUTTON_HEIGHT 40
#define NODE_WIDTH 70
#define NODE_HEIGHT 20
#define DEFAULT_NOODLE_LENGTH 60
typedef enum ui_elem_type ui_elem_type;
typedef struct ui_elem ui_elem;
typedef struct ui_ctx ui_ctx;
typedef struct ui_elem_colours ui_elem_colours;
typedef enum noodle_action noodle_action;
enum ui_elem_type {
UI_ELEM_NODE,
UI_ELEM_NOODLE,
UI_ELEM_BUTTON,
COUNT_UI_ELEM,
};
struct ui_elem {
u64 id;
union {
rect rec;
line ln;
};
ui_elem_type type;
};
struct ui_elem_colours {
colour fill;
colour border;
};
enum noodle_action {
NOODLE_ACTION_NONE,
NOODLE_ACTION_DRAGGING,
NOODLE_ACTION_RELEASED,
};
struct ui_ctx {
u64 count;
i64 hovered;
i64 active;
i32 mouse_x;
i32 mouse_y;
i32 rel_x;
i32 rel_y;
bool mouse_down;
bool mouse_up;
const window *wnd;
ui_elem elements[MAX_UI_ELEMENTS];
};
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);
bool ui_node(const window *wnd, ui_ctx *ctx, rect rect,
ui_elem_colours colours);
noodle_action ui_noodle(const window *wnd, ui_ctx *ctx, line ln,
ui_elem_colours colours, rect parent_node);
#endif // !UI_H