From c6cdddeff0cb0437b1d54520d99460a58db39fdc Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 18 Jun 2017 10:57:35 +0200 Subject: started the widget framework --- src/gui/widget.c | 35 +++++++++++++++++++++++++++++++++++ src/gui/widget.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/gui/widget.c create mode 100644 src/gui/widget.h (limited to 'src/gui') diff --git a/src/gui/widget.c b/src/gui/widget.c new file mode 100644 index 0000000..313fd49 --- /dev/null +++ b/src/gui/widget.c @@ -0,0 +1,35 @@ +#include "widget.h" + +#include "string.h" +#include "stddef.h" + +static widget_vtable_t widget_vtable = { + widget_draw, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL +}; + +void widget_init( widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h ) +{ + memset( widget, 0, sizeof( widget_t ) ); + + widget->parent = parent; + widget->x = x; + widget->y = y; + widget->w = w; + widget->h = h; + + widget->vtable = &widget_vtable; +} + +void widget_draw( void *obj, graphics_context_t *context ) +{ + widget_t *widget = obj; + + vga_draw_rectangle( context, widget->x, widget->y, widget->w, widget->h, + vga_make_RGB( 0xFF, 0xFF, 0xFF ) ); +} diff --git a/src/gui/widget.h b/src/gui/widget.h new file mode 100644 index 0000000..a1e9a21 --- /dev/null +++ b/src/gui/widget.h @@ -0,0 +1,29 @@ +#ifndef WIDGET_H +#define WIDGET_H + +#include "graphics_context.h" + +typedef struct { + void (*draw)( void *obj, graphics_context_t *context ); + void (*get_focus)( void *obj ); + void (*widget_model_to_screen)( void *obj, int *x, int *y ); + void (*on_mouse_down)( void *obj, const int x, const int y ); + void (*on_mouse_up)( void *obj, const int x, const int y ); + void (*on_mouse_move)( void *obj, const int old_x, const int old_y, const int x, const int y ); + void (*on_key_down)( void *obj, char c ); +} widget_vtable_t; + +typedef struct widget_t { + int x; + int y; + int w; + int h; + struct widget_t *parent; + widget_vtable_t *vtable; +} widget_t; + +void widget_init( widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h ); + +void widget_draw( void *obj, graphics_context_t *context ); + +#endif // WIDGET_H -- cgit v1.2.3-54-g00ecf