diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2017-06-24 21:38:38 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2017-06-24 21:38:38 +0200 |
commit | 36e1daa2518c7ffc941160e0ecb71e84b462aaa4 (patch) | |
tree | 384a632c4a50e2d9524922dcd800d0161b5d933d | |
parent | e74065e71667d8df1529f8ca32e14f3e54119ea1 (diff) | |
download | abaos-36e1daa2518c7ffc941160e0ecb71e84b462aaa4.tar.gz abaos-36e1daa2518c7ffc941160e0ecb71e84b462aaa4.tar.bz2 |
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
-rw-r--r-- | src/gui/composite_widget.c | 5 | ||||
-rw-r--r-- | src/gui/text_widget.c | 9 | ||||
-rw-r--r-- | src/kernel/kernel.c | 26 |
3 files changed, 17 insertions, 23 deletions
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; diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index e6462e1..1c816a5 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -201,33 +201,25 @@ static void handle_keyboard_event( keyboard_event_t *event, void *context ) desktop_init( &desktop, 320, 200, VGA_COLOR_BLUE ); widget_t widget1; - widget_init( &widget1, (widget_t *)&desktop, 60, 60, 60, 70, VGA_COLOR_LIGHT_GREY ); + widget_init( &widget1, (widget_t *)&desktop, 60, 90, 60, 70, VGA_COLOR_LIGHT_GREY ); ((composite_widget_vtable_t *)desktop.vtable)->add_child( &desktop, &widget1 ); widget_t widget2; - widget_init( &widget2, (widget_t *)&desktop, 130, 50, 60, 70, VGA_COLOR_GREEN ); + widget_init( &widget2, (widget_t *)&desktop, 130, 80, 60, 70, VGA_COLOR_GREEN ); ((composite_widget_vtable_t *)desktop.vtable)->add_child( &desktop, &widget2 ); + char s[100]; + char *p = s; + for( char c = ' '; c <= '~'; c++ ) { + *p++ = c; + } + *p = '\n'; text_widget_t widget3; - text_widget_init( &widget3, (widget_t *)&desktop, 5, 5, vga->mode.x - 10 , 50, VGA_COLOR_RED, "Hello" ); + text_widget_init( &widget3, (widget_t *)&desktop, 5, 5, vga->mode.x - 10 , 100, VGA_COLOR_RED, s ); ((composite_widget_vtable_t *)desktop.vtable)->add_child( &desktop, (widget_t *)&widget3 ); // as vga_t is equals to the graphical context for now ((widget_vtable_t *)desktop.vtable)->draw( &desktop, vga ); - -#if 0 - int x = 0; - int y = 0; - for( char c = ' '; c <= '~'; c++ ) { - vga_draw_char( vga, c, x, y, VGA_COLOR_BLUE, - VGA_COLOR_WHITE ); - x += 9; - if( x >= vga->mode.x - 9 ) { - y += 16; - x = 0; - } - } -#endif } global_context->mode = MODE_GRAPHICS; break; |