diff options
Diffstat (limited to 'src/gui/text_widget.c')
-rw-r--r-- | src/gui/text_widget.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/gui/text_widget.c b/src/gui/text_widget.c new file mode 100644 index 0000000..fbb3754 --- /dev/null +++ b/src/gui/text_widget.c @@ -0,0 +1,64 @@ +#include "text_widget.h" + +#include "string.h" +#include "stddef.h" + +static text_widget_vtable_t text_widget_vtable = { + { + text_widget_draw, + widget_get_focus, + widget_model_to_screen, + widget_contains_coordinate, + widget_on_mouse_down, + widget_on_mouse_up, + widget_on_mouse_move, + widget_on_key_down, + widget_on_key_up + }, + text_widget_set_text +}; + +void text_widget_init( text_widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h, const vga_color_t background_color, const char *s ) +{ + memset( widget, 0, sizeof( text_widget_t ) ); + + widget_init( &widget->base, parent, x, y, w, h, background_color ); + + // TODO: const for now, caller has to preserve the text + // maybe with memory manager in place we can do this with a strdup + widget->s = s; + + widget->vtable = &text_widget_vtable; +} + +void text_widget_draw( void *obj, graphics_context_t *context ) +{ + text_widget_t *widget = obj; + + widget->base.vtable->draw( obj, context ); + + int x = 0; + int y = 0; + + widget->base.vtable->model_to_screen( widget, &x, &y ); + + for( char c = widget->s[0]; c != '\0'; c++ ) { + vga_draw_char( context, c, x, y, widget->base.background_color, + VGA_COLOR_WHITE ); + x += 9; + if( x >= widget->base.w - 9 ) { + y += 16; + x = 0; + } + } + +} + +void text_widget_set_text( void *obj, const char *s ) +{ + text_widget_t *widget = obj; + + // TODO: see above + widget->s = s; +} + |