From 36e1daa2518c7ffc941160e0ecb71e84b462aaa4 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 24 Jun 2017 21:38:38 +0200 Subject: font is shown as a text widget now fixed setting of vtable in derived classes still some local to screen coordinate calculation problem in text widget --- src/gui/composite_widget.c | 5 +++-- src/gui/text_widget.c | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src/gui') diff --git a/src/gui/composite_widget.c b/src/gui/composite_widget.c index 9f2d1c1..e71bac6 100644 --- a/src/gui/composite_widget.c +++ b/src/gui/composite_widget.c @@ -28,6 +28,7 @@ void composite_widget_init( composite_widget_t *widget, widget_t *parent, const widget->focused_child = NULL; memset( widget->children, 0, MAX_NOF_WIDGET_CHILDREN * sizeof( widget_t * ) ); + widget->base.vtable = (widget_vtable_t *)&composite_widget_vtable; widget->vtable = &composite_widget_vtable; } @@ -35,7 +36,7 @@ void composite_widget_draw( void *obj, graphics_context_t *context ) { composite_widget_t *widget = obj; - widget->base.vtable->draw( obj, context ); + widget_draw( obj, context ); for( int i = widget->nof_children - 1; i >= 0; i-- ) { widget_t *child = widget->children[i]; @@ -49,7 +50,7 @@ void composite_widget_get_focus( void *obj, widget_t *widget ) o->focused_child = widget; - o->base.vtable->get_focus( o, widget ); + widget_get_focus( o, widget ); } void composite_widget_add_child( void *obj, widget_t *child ) diff --git a/src/gui/text_widget.c b/src/gui/text_widget.c index fbb3754..6071fd1 100644 --- a/src/gui/text_widget.c +++ b/src/gui/text_widget.c @@ -28,6 +28,7 @@ void text_widget_init( text_widget_t *widget, widget_t *parent, const int x, con // maybe with memory manager in place we can do this with a strdup widget->s = s; + widget->base.vtable = (widget_vtable_t *)&text_widget_vtable; widget->vtable = &text_widget_vtable; } @@ -35,16 +36,16 @@ void text_widget_draw( void *obj, graphics_context_t *context ) { text_widget_t *widget = obj; - widget->base.vtable->draw( obj, context ); + widget_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 ); + for( const char *p = widget->s; *p != '\0'; p++ ) { + vga_draw_char( context, *p, x, y, widget->base.background_color, + VGA_COLOR_WHITE ); x += 9; if( x >= widget->base.w - 9 ) { y += 16; -- cgit v1.2.3-54-g00ecf