aboutsummaryrefslogtreecommitdiff
path: root/libgui/inc
diff options
context:
space:
mode:
authorMarvin Borner2020-10-25 13:20:35 +0100
committerMarvin Borner2020-10-25 13:20:35 +0100
commitc9f89174b9ce73ed93bfad14d57b8f1a43db6bf6 (patch)
tree8a9fc5d2b7ac66b42b15521c421573db520d7d6b /libgui/inc
parentf83d5e4b8e315f2b17f0c8bf390bf967f02f5837 (diff)
Added gui event loop and onclick listener
Diffstat (limited to 'libgui/inc')
-rw-r--r--libgui/inc/gfx.h12
-rw-r--r--libgui/inc/gui.h22
2 files changed, 23 insertions, 11 deletions
diff --git a/libgui/inc/gfx.h b/libgui/inc/gfx.h
index fe48ac2..2ce588c 100644
--- a/libgui/inc/gfx.h
+++ b/libgui/inc/gfx.h
@@ -39,7 +39,7 @@
#define WF_NO_RESIZE (1 << 2)
#define WF_RELATIVE (1 << 3)
-enum message_type { WM_NEW_CONTEXT = EVENT_MAX + 1, WM_REDRAW, WM_KEYBOARD };
+enum message_type { GFX_NEW_CONTEXT = EVENT_MAX + 1, GFX_REDRAW };
// Generalized font struct
struct font {
@@ -61,12 +61,6 @@ struct context {
int flags;
};
-struct msg_keyboard {
- char ch;
- int press;
- int scancode;
-};
-
void gfx_write_char(struct context *ctx, int x, int y, u32 c, char ch);
void gfx_write(struct context *ctx, int x, int y, u32 c, char *text);
void gfx_load_image(struct context *ctx, char *path, int x, int y);
@@ -86,7 +80,7 @@ int gfx_font_width();
*/
#define gfx_new_ctx(ctx) \
- (msg_send(2, WM_NEW_CONTEXT, (ctx)), (struct context *)msg_receive_loop()->data)
-#define gfx_redraw() (msg_send(2, WM_REDRAW, NULL)) // TODO: Partial redraw (optimization)
+ (msg_send(2, GFX_NEW_CONTEXT, (ctx)), (struct context *)msg_receive_loop()->data)
+#define gfx_redraw() (msg_send(2, GFX_REDRAW, NULL)) // TODO: Partial redraw (optimization)
#endif
diff --git a/libgui/inc/gui.h b/libgui/inc/gui.h
index ea1e40e..e7573f8 100644
--- a/libgui/inc/gui.h
+++ b/libgui/inc/gui.h
@@ -10,11 +10,14 @@
#define MAX_CHILDS 100
+// TODO: Improve event types (maybe as struct header)
+enum window_event_type { GUI_KEYBOARD = 10, GUI_MOUSE, GUI_MAX };
enum element_type { GUI_TYPE_CONTAINER, GUI_TYPE_BUTTON, GUI_TYPE_TEXTBOX };
struct element_button {
const char *text;
u32 color;
+ void (*on_click)();
};
struct element_textbox {
@@ -37,8 +40,23 @@ struct window {
struct context *ctx;
};
+struct gui_event_keyboard {
+ char ch;
+ int press;
+ int scancode;
+};
+
+struct gui_event_mouse {
+ int x;
+ int y;
+ int but1;
+ int but2;
+ int but3;
+};
+
struct element *gui_init(const char *title, u32 width, u32 height);
-struct element *gui_add_button(struct element *container, int x, int y, u32 width, u32 height,
- const char *text, u32 color);
+void gui_event_loop(struct element *container);
+struct element_button *gui_add_button(struct element *container, int x, int y, u32 width,
+ u32 height, const char *text, u32 color);
#endif