From 14770f42df291753a240def91fb488a904a909c1 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 2 Dec 2021 14:20:48 +0100 Subject: Initial commit, set up skeleton with list and button --- include/alloc.h | 10 ++++++++++ include/common.h | 9 +++++++++ include/mgui/button.h | 22 ++++++++++++++++++++++ include/mgui/list.h | 33 +++++++++++++++++++++++++++++++++ include/mgui/widget.h | 33 +++++++++++++++++++++++++++++++++ include/resource_loader.h | 15 +++++++++++++++ 6 files changed, 122 insertions(+) create mode 100644 include/alloc.h create mode 100644 include/common.h create mode 100644 include/mgui/button.h create mode 100644 include/mgui/list.h create mode 100644 include/mgui/widget.h create mode 100644 include/resource_loader.h (limited to 'include') diff --git a/include/alloc.h b/include/alloc.h new file mode 100644 index 0000000..272326e --- /dev/null +++ b/include/alloc.h @@ -0,0 +1,10 @@ +#ifndef MGUI_ALLOC_H +#define MGUI_ALLOC_H + +#include + +void* mgui_alloc(size_t size); +void* mgui_realloc(void *mem, size_t new_size); +void mgui_free(void *mem); + +#endif /* MGUI_ALLOC_H */ diff --git a/include/common.h b/include/common.h new file mode 100644 index 0000000..3fb4f6f --- /dev/null +++ b/include/common.h @@ -0,0 +1,9 @@ +#ifndef MGUI_COMMON_H +#define MGUI_COMMON_H + +#include +#include + +bool mgui_rectangle_contains(mgl_vec2f rectangle_pos, mgl_vec2f rectangle_size, mgl_vec2f point); + +#endif /* MGUI_COMMON_H */ diff --git a/include/mgui/button.h b/include/mgui/button.h new file mode 100644 index 0000000..8f9a2db --- /dev/null +++ b/include/mgui/button.h @@ -0,0 +1,22 @@ +#ifndef MGUI_BUTTON_H +#define MGUI_BUTTON_H + +#include +#include +#include "widget.h" + +typedef struct { + mgui_widget widget; + mgl_rectangle background; + mgl_text label; +} mgui_button; + +mgui_button* mgui_button_create(); +mgui_widget* mgui_button_to_widget(mgui_button *list); +mgui_button* mgui_widget_to_button(mgui_widget *widget); + +void mgui_button_set_position(mgui_button *self, mgl_vec2i position); +void mgui_button_on_event(mgui_button *self, mgl_window *window, mgl_event *event); +void mgui_button_draw(mgui_button *self, mgl_window *window); + +#endif /* MGUI_BUTTON_H */ diff --git a/include/mgui/list.h b/include/mgui/list.h new file mode 100644 index 0000000..1da326d --- /dev/null +++ b/include/mgui/list.h @@ -0,0 +1,33 @@ +#ifndef MGUI_LIST_H +#define MGUI_LIST_H + +#include "widget.h" +#include + +typedef struct mgl_window mgl_window; +typedef struct mgl_event mgl_event; + +typedef enum { + MGUI_LIST_HORIZONITAL, + MGUI_LIST_VERTICAL +} mgui_list_direction; + +typedef struct { + mgui_widget widget; + mgui_list_direction direction; + mgl_vec2i position; + mgui_widget **items; + size_t num_items; + size_t items_capacity; +} mgui_list; + +mgui_list* mgui_list_create(mgui_list_direction direction); +mgui_widget* mgui_list_to_widget(mgui_list *list); +mgui_list* mgui_widget_to_list(mgui_widget *widget); + +void mgui_list_set_position(mgui_list *self, mgl_vec2i position); +void mgui_list_append(mgui_list *self, mgui_widget *widget); +void mgui_list_on_event(mgui_list *self, mgl_window *window, mgl_event *event); +void mgui_list_draw(mgui_list *self, mgl_window *window); + +#endif /* MGUI_LIST_H */ diff --git a/include/mgui/widget.h b/include/mgui/widget.h new file mode 100644 index 0000000..60f850c --- /dev/null +++ b/include/mgui/widget.h @@ -0,0 +1,33 @@ +#ifndef MGUI_WIDGET_H +#define MGUI_WIDGET_H + +#include + +typedef struct mgl_window mgl_window; +typedef struct mgl_event mgl_event; +typedef struct mgui_widget mgui_widget; + +typedef enum { + MGUI_WIDGET_LIST, + MGUI_WIDGET_BUTTON +} mgui_widget_type; + +typedef struct { + int left; + int top; + int right; + int bottom; +} mgui_margin; + +struct mgui_widget { + mgui_widget_type type; + mgui_margin margin; +}; + +void mgui_widget_init(mgui_widget *self, mgui_widget_type type); +void mgui_widget_set_margin(mgui_widget *self, int left, int top, int right, int bottom); +void mgui_widget_set_position(mgui_widget *self, mgl_vec2i position); +void mgui_widget_on_event(mgui_widget *self, mgl_window *window, mgl_event *event); +void mgui_widget_draw(mgui_widget *self, mgl_window *window); + +#endif /* MGUI_WIDGET_H */ diff --git a/include/resource_loader.h b/include/resource_loader.h new file mode 100644 index 0000000..6120faa --- /dev/null +++ b/include/resource_loader.h @@ -0,0 +1,15 @@ +#ifndef MGUI_RESOURCE_LOADER_H +#define MGUI_RESOURCE_LOADER_H + +typedef struct mgl_font mgl_font; + +typedef enum { + MGUI_FONT_LATIN, + MGUI_FONT_LATIN_BOLD, + MGUI_FONT_CJK +} mgui_font_type; + +/* Note: can return NULL if the font fails to load */ +mgl_font* mgui_get_font(mgui_font_type type, unsigned int character_size); + +#endif /* MGUI_RESOURCE_LOADER_H */ -- cgit v1.2.3