From e6503671eecc2026130fe3544d79d644c1657b4c Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 1 Jul 2017 21:17:05 +0200 Subject: replaced some strange access to .base.base with casts of the class to the class needed to access the proper vtable --- src/gui/composite_widget.c | 2 +- src/gui/desktop.c | 2 +- src/gui/text_widget.c | 15 ++++++--------- src/gui/text_widget.h | 1 - src/gui/window.c | 22 +++++++++++----------- 5 files changed, 19 insertions(+), 23 deletions(-) (limited to 'src/gui') diff --git a/src/gui/composite_widget.c b/src/gui/composite_widget.c index 355e3c6..4a7a607 100644 --- a/src/gui/composite_widget.c +++ b/src/gui/composite_widget.c @@ -28,7 +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_t *)widget)->vtable = (widget_vtable_t *)&composite_widget_vtable; } void composite_widget_draw( void *obj, graphics_context_t *context ) diff --git a/src/gui/desktop.c b/src/gui/desktop.c index 08da59b..a27ac9a 100644 --- a/src/gui/desktop.c +++ b/src/gui/desktop.c @@ -30,7 +30,7 @@ void desktop_init( desktop_t *desktop, const int w, const int h, const vga_color desktop->mouse_y = h / 2; desktop->needs_redrawing = true; - desktop->base.base.vtable = (widget_vtable_t *)&desktop_vtable; + ((widget_t *)desktop)->vtable = (widget_vtable_t *)&desktop_vtable; } void desktop_draw( void *obj, graphics_context_t *context ) diff --git a/src/gui/text_widget.c b/src/gui/text_widget.c index 2567df3..170066a 100644 --- a/src/gui/text_widget.c +++ b/src/gui/text_widget.c @@ -13,7 +13,7 @@ static text_widget_vtable_t text_widget_vtable = { widget_on_mouse_up, widget_on_mouse_move, text_widget_on_key_down, - text_widget_on_key_up + widget_on_key_up }, text_widget_set_text }; @@ -28,7 +28,7 @@ void text_widget_init( text_widget_t *widget, widget_t *parent, const int x, con widget->base.focusable = true; - widget->base.vtable = (widget_vtable_t *)&text_widget_vtable; + ((widget_t *)widget)->vtable = (widget_vtable_t *)&text_widget_vtable; } void text_widget_draw( void *obj, graphics_context_t *context ) @@ -42,13 +42,14 @@ void text_widget_draw( void *obj, graphics_context_t *context ) int w = 0; int h = 0; - widget->base.vtable->model_to_screen( widget, &x, &y ); + ((widget_t *)widget)->vtable->model_to_screen( widget, &x, &y ); for( const char *p = widget->s; *p != '\0'; p++ ) { - vga_draw_char( context, *p, x + w, y + h, widget->base.background_color, + vga_draw_char( context, *p, x + w, y + h, + ((widget_t *)widget)->background_color, VGA_COLOR_WHITE ); w += 9; - if( w >= widget->base.w - 10 ) { + if( w >= ((widget_t *)widget)->w - 10 ) { h += 16; w = 0; } @@ -72,7 +73,3 @@ void text_widget_on_key_down( void *obj, char c ) widget->s[strlen( widget->s )+1] = '\0'; } } - -void text_widget_on_key_up( void *obj, char c ) -{ -} diff --git a/src/gui/text_widget.h b/src/gui/text_widget.h index 316f56e..2604eff 100644 --- a/src/gui/text_widget.h +++ b/src/gui/text_widget.h @@ -20,6 +20,5 @@ void text_widget_init( text_widget_t *widget, widget_t *parent, const int x, con void text_widget_draw( void *obj, graphics_context_t *context ); void text_widget_set_text( void *obj, const char *s ); void text_widget_on_key_down( void *obj, char c ); -void text_widget_on_key_up( void *obj, char c ); #endif // TEXT_WIDGET_H diff --git a/src/gui/window.c b/src/gui/window.c index f56c8e6..3a75434 100644 --- a/src/gui/window.c +++ b/src/gui/window.c @@ -29,24 +29,24 @@ void window_init( window_t *window, widget_t *parent, const int x, const int y, window->dragging = false; - window->base.base.vtable = (widget_vtable_t *)&window_vtable; + ((widget_t *)window)->vtable = (widget_vtable_t *)&window_vtable; } void window_draw( void *obj, graphics_context_t *context ) { window_t *widget = obj; - if( widget->base.base.x < 0 ) { - widget->base.base.x = 0; + if( ((widget_t *)widget)->x < 0 ) { + ((widget_t *)widget)->x = 0; } - if( widget->base.base.x > context->mode.x - widget->base.base.w ) { - widget->base.base.x = context->mode.x - widget->base.base.w; + if( ((widget_t *)widget)->x > context->mode.x - ((widget_t *)widget)->w ) { + ((widget_t *)widget)->x = context->mode.x - ((widget_t *)widget)->w; } - if( widget->base.base.y < 0 ) { - widget->base.base.y = 0; + if( ((widget_t *)widget)->y < 0 ) { + ((widget_t *)widget)->y = 0; } - if( widget->base.base.y > context->mode.y - widget->base.base.h ) { - widget->base.base.y = context->mode.y - widget->base.base.h; + if( ((widget_t *)widget)->y > context->mode.y - ((widget_t *)widget)->h ) { + ((widget_t *)widget)->y = context->mode.y - ((widget_t *)widget)->h; } composite_widget_draw( obj, context ); @@ -73,7 +73,7 @@ void window_on_mouse_move( void *obj, const int old_x, const int old_y, const in window_t *widget = obj; if( widget->dragging ) { - widget->base.base.x += x - old_x; - widget->base.base.y += y - old_y; + ((widget_t *)widget)->x += x - old_x; + ((widget_t *)widget)->y += y - old_y; } } -- cgit v1.2.3-54-g00ecf