78 lines
1.9 KiB
C
78 lines
1.9 KiB
C
#ifndef PTK_PTK_H_
|
|
#define PTK_PTK_H_
|
|
|
|
#include <ptk_list.h>
|
|
#include <ptk_vec.h>
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
|
|
typedef struct {
|
|
uint32_t major;
|
|
uint32_t minor;
|
|
uint32_t patch;
|
|
} PtkVersion;
|
|
|
|
bool ptk_init(size_t width, size_t height, const char *title, PtkVersion application_version);
|
|
|
|
typedef struct PtkComponent *PtkHandle;
|
|
#define PTK_NULL_HANDLE (void *)0
|
|
|
|
typedef enum {
|
|
PTK_COMPONENT_TYPE_BOX = 0,
|
|
PTK_COMPONENT_TYPE_TRIANGLE = 1,
|
|
PTK_COMPONENT_TYPE_RECT = 2,
|
|
PTK_COMPONENT_TYPE_ELLIPSE = 3,
|
|
PTK_COMPONENT_TYPE_CLICKABLE = 4,
|
|
} PtkComponentType;
|
|
|
|
PTK_LIST_DEFINE(PtkHandle);
|
|
|
|
#define PTK_COMPONENT_DEFINE(name, ...) \
|
|
typedef struct name {\
|
|
PtkComponentType type;\
|
|
PtkHandle parent;\
|
|
PTK_LIST(PtkHandle) children;\
|
|
__VA_ARGS__\
|
|
} name
|
|
|
|
PTK_COMPONENT_DEFINE(PtkComponent, );
|
|
|
|
PTK_COMPONENT_DEFINE(PtkTriangle,
|
|
PtkPos vertices[3];
|
|
PtkColor color;
|
|
);
|
|
|
|
PTK_COMPONENT_DEFINE(PtkRect,
|
|
PtkPos top_left;
|
|
PtkSize size;
|
|
PtkColor color;
|
|
);
|
|
|
|
PTK_COMPONENT_DEFINE(PtkEllipse,
|
|
PtkPos center;
|
|
PtkSize radii;
|
|
PtkColor color;
|
|
);
|
|
|
|
typedef void (*MouseButtonCallback)(int button, int action, int mods);
|
|
|
|
PTK_COMPONENT_DEFINE(PtkClickable,
|
|
PtkHandle hitbox;
|
|
MouseButtonCallback on_press;
|
|
);
|
|
|
|
PtkHandle ptk_box(size_t child_count, PtkHandle *children);
|
|
PtkHandle ptk_triangle(PtkPos vertices[3], PtkColor color);
|
|
PtkHandle ptk_rect(PtkPos top_left, PtkSize size, PtkColor color);
|
|
PtkHandle ptk_square(PtkPos top_left, float size, PtkColor color);
|
|
PtkHandle ptk_ellipse(PtkPos center, PtkSize radii, PtkColor color);
|
|
PtkHandle ptk_circle(PtkPos center, float radius, PtkColor color);
|
|
PtkHandle ptk_clickable(PtkHandle hitbox, MouseButtonCallback on_press);
|
|
|
|
#define PTK_BOX(...) ptk_box(sizeof((PtkHandle []){ __VA_ARGS__ }) / sizeof(PtkHandle), (PtkHandle []) { __VA_ARGS__ })
|
|
|
|
int ptk_run(PtkHandle root);
|
|
|
|
#endif // PTK_PTK_H_
|