diff options
Diffstat (limited to 'libgui')
-rw-r--r-- | libgui/gfx.c | 8 | ||||
-rw-r--r-- | libgui/gui.c | 20 | ||||
-rw-r--r-- | libgui/inc/gfx.h | 8 | ||||
-rw-r--r-- | libgui/png.c | 8 |
4 files changed, 25 insertions, 19 deletions
diff --git a/libgui/gfx.c b/libgui/gfx.c index 3eb388a..986ecda 100644 --- a/libgui/gfx.c +++ b/libgui/gfx.c @@ -96,6 +96,14 @@ static void draw_rectangle(struct context *ctx, int x1, int y1, int x2, int y2, } } +struct context *gfx_new_ctx(struct context *ctx) +{ + //struct message msg = { 0 }; + //msg_send(2, GFX_NEW_CONTEXT, ctx); + //memcpy(ctx, msg_receive_loop(&msg)->data, sizeof(*ctx)); + return ctx; +} + // On-demand font loading struct font *gfx_resolve_font(enum font_type font_type) { diff --git a/libgui/gui.c b/libgui/gui.c index afbc3ba..9b49c2e 100644 --- a/libgui/gui.c +++ b/libgui/gui.c @@ -465,6 +465,7 @@ struct element *gui_add_text_input(struct element *container, int x, int y, u32 ((struct element_text_input *)text_input->data)->x = x; ((struct element_text_input *)text_input->data)->y = y; ((struct element_text_input *)text_input->data)->width = width; + ((struct element_text_input *)text_input->data)->text[0] = '\0'; ((struct element_text_input *)text_input->data)->color_fg = color_fg; ((struct element_text_input *)text_input->data)->color_bg = color_bg; ((struct element_text_input *)text_input->data)->font_type = font_type; @@ -530,28 +531,28 @@ void gui_event_loop(struct element *container) if (!container) return; - struct message *msg; + struct message msg = { 0 }; struct element *focused = NULL; while (1) { - if (!(msg = msg_receive())) { - yield(); - continue; - } + /* if (!msg_receive(&msg)) { */ + yield(); + continue; + /* } */ - switch (msg->type) { + switch (msg.type) { case GUI_KILL: { remove_all(); exit(0); } case GUI_MOUSE: { - struct gui_event_mouse *event = msg->data; + struct gui_event_mouse *event = msg.data; focused = element_at(container, event->x, event->y); if (focused && focused->event.on_click && event->but1) focused->event.on_click(event, focused); break; } case GUI_KEYBOARD: { - struct gui_event_keyboard *event = msg->data; + struct gui_event_keyboard *event = msg.data; if (focused && focused->type == GUI_TYPE_TEXT_INPUT && event->press) { char *s = ((struct element_text_input *)focused->data)->text; @@ -583,14 +584,13 @@ void gui_event_loop(struct element *container) break; } case GUI_RESIZE: { - struct gui_event_resize *event = msg->data; + struct gui_event_resize *event = msg.data; struct element *root = get_root(container->window_id); root->ctx = event->new_ctx; gui_sync_window(container->window_id); break; } } - free(msg); } exit(1); diff --git a/libgui/inc/gfx.h b/libgui/inc/gfx.h index 0f4c631..718fd28 100644 --- a/libgui/inc/gfx.h +++ b/libgui/inc/gfx.h @@ -64,6 +64,7 @@ struct context { int flags; }; +struct context *gfx_new_ctx(struct context *ctx); struct font *gfx_resolve_font(enum font_type font_type); void gfx_write_char(struct context *ctx, int x, int y, enum font_type font_type, u32 c, char ch); void gfx_write(struct context *ctx, int x, int y, enum font_type font_type, u32 c, @@ -83,9 +84,8 @@ int gfx_font_width(enum font_type); * Wrappers */ -#define gfx_new_ctx(ctx) \ - (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) -#define gfx_redraw_focused() (msg_send(2, GFX_REDRAW_FOCUSED, NULL)) +#define gfx_redraw() \ + (void)42 //(msg_send(2, GFX_REDRAW, NULL)) // TODO: Partial redraw (optimization) +#define gfx_redraw_focused() (void)42 //(msg_send(2, GFX_REDRAW_FOCUSED, NULL)) #endif diff --git a/libgui/png.c b/libgui/png.c index 2db6e4d..ad65eba 100644 --- a/libgui/png.c +++ b/libgui/png.c @@ -1125,9 +1125,8 @@ static struct png *png_new(void) void png_free(struct png *png) { // Deallocate image buffer - /* if (png->buffer != NULL) { */ - /* free(png->buffer); */ - /* } */ + if (png->buffer) + free(png->buffer); // Deallocate source buffer, if necessary png_free_source(png); @@ -1167,7 +1166,7 @@ struct bmp *png_load(const char *path) return NULL; void *buf = sread(path); - if (!png) { + if (!buf) { SET_ERROR(png, PNG_ENOTFOUND); png_free(png); return NULL; @@ -1190,7 +1189,6 @@ struct bmp *png_load(const char *path) bmp->pitch = png->width * (bmp->bpp >> 3); png_free(png); - free(buf); return bmp; } |