From c8f2689dbeca2bf51d41bbf861c495bb4b0c29ce Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Wed, 21 Jun 2017 20:25:27 +0200 Subject: started to rewrite to use the main desktop widget --- src/gui/composite_widget.c | 4 ++-- src/gui/composite_widget.h | 3 ++- src/gui/desktop.c | 9 ++++++--- src/gui/desktop.h | 2 +- src/gui/widget.c | 5 +++-- src/gui/widget.h | 3 ++- 6 files changed, 16 insertions(+), 10 deletions(-) (limited to 'src/gui') diff --git a/src/gui/composite_widget.c b/src/gui/composite_widget.c index afef28c..9f2d1c1 100644 --- a/src/gui/composite_widget.c +++ b/src/gui/composite_widget.c @@ -18,11 +18,11 @@ static composite_widget_vtable_t composite_widget_vtable = { composite_widget_add_child }; -void composite_widget_init( composite_widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h ) +void composite_widget_init( composite_widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h, const vga_color_t background_color ) { memset( widget, 0, sizeof( composite_widget_t ) ); - widget_init( &widget->base, parent, x, y, w, h ); + widget_init( &widget->base, parent, x, y, w, h, background_color ); widget->nof_children = 0; widget->focused_child = NULL; diff --git a/src/gui/composite_widget.h b/src/gui/composite_widget.h index d3ba90a..2b27e32 100644 --- a/src/gui/composite_widget.h +++ b/src/gui/composite_widget.h @@ -16,9 +16,10 @@ typedef struct { widget_t *children[MAX_NOF_WIDGET_CHILDREN]; int nof_children; widget_t *focused_child; + vga_color_t background_color; } composite_widget_t; -void composite_widget_init( composite_widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h ); +void composite_widget_init( composite_widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h, const vga_color_t background_color ); void composite_widget_draw( void *obj, graphics_context_t *context ); void composite_widget_get_focus( void *obj, widget_t *widget ); diff --git a/src/gui/desktop.c b/src/gui/desktop.c index 1a0a5a8..ee4a6e5 100644 --- a/src/gui/desktop.c +++ b/src/gui/desktop.c @@ -15,15 +15,16 @@ static desktop_vtable_t desktop_vtable = { desktop_on_mouse_move, composite_widget_on_key_down, composite_widget_on_key_up - } + }, + composite_widget_add_child } }; -void desktop_init( desktop_t *desktop, const int w, const int h ) +void desktop_init( desktop_t *desktop, const int w, const int h, const vga_color_t background_color ) { memset( desktop, 0, sizeof( desktop_t ) ); - composite_widget_init( &desktop->base, NULL, 0, 0, w, h ); + composite_widget_init( &desktop->base, NULL, 0, 0, w, h, background_color ); desktop->vtable = &desktop_vtable; } @@ -32,6 +33,8 @@ void desktop_draw( void *obj, graphics_context_t *context ) { desktop_t *desktop = obj; + vga_clear_screen( context, desktop->base.base.background_color ); + ((widget_vtable_t *)(desktop->base.vtable))->draw( obj, context ); // TODO: use a mouse bitmap and copy it diff --git a/src/gui/desktop.h b/src/gui/desktop.h index b160dc0..1f3ef93 100644 --- a/src/gui/desktop.h +++ b/src/gui/desktop.h @@ -14,7 +14,7 @@ typedef struct { desktop_vtable_t *vtable; } desktop_t; -void desktop_init( desktop_t *widget, const int w, const int h ); +void desktop_init( desktop_t *widget, const int w, const int h, const vga_color_t background_color ); void desktop_draw( void *obj, graphics_context_t *context ); void desktop_on_mouse_down( void *obj, const int x, const int y ); diff --git a/src/gui/widget.c b/src/gui/widget.c index cd77d03..1c26680 100644 --- a/src/gui/widget.c +++ b/src/gui/widget.c @@ -15,7 +15,7 @@ static widget_vtable_t widget_vtable = { widget_on_key_up }; -void widget_init( widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h ) +void widget_init( widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h, const vga_color_t background_color ) { memset( widget, 0, sizeof( widget_t ) ); @@ -24,6 +24,7 @@ void widget_init( widget_t *widget, widget_t *parent, const int x, const int y, widget->y = y; widget->w = w; widget->h = h; + widget->background_color = background_color; widget->vtable = &widget_vtable; } @@ -37,7 +38,7 @@ void widget_draw( void *obj, graphics_context_t *context ) widget->vtable->model_to_screen( widget, &x, &y ); vga_draw_rectangle( context, x, y, widget->w, widget->h, - vga_make_RGB( 0xFF, 0xFF, 0xFF ) ); + widget->background_color ); } void widget_get_focus( void *obj, widget_t *widget ) diff --git a/src/gui/widget.h b/src/gui/widget.h index 1fd23ac..ceb5b71 100644 --- a/src/gui/widget.h +++ b/src/gui/widget.h @@ -24,12 +24,13 @@ typedef struct widget_t { int y; int w; int h; + vga_color_t background_color; bool focusable; 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_init( widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h, const vga_color_t background_color ); void widget_draw( void *obj, graphics_context_t *context ); void widget_get_focus( void *obj, widget_t *widget ); -- cgit v1.2.3-54-g00ecf