diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/composite_widget.c | 4 | ||||
-rw-r--r-- | src/gui/composite_widget.h | 3 | ||||
-rw-r--r-- | src/gui/desktop.c | 9 | ||||
-rw-r--r-- | src/gui/desktop.h | 2 | ||||
-rw-r--r-- | src/gui/widget.c | 5 | ||||
-rw-r--r-- | src/gui/widget.h | 3 | ||||
-rw-r--r-- | src/kernel/kernel.c | 12 |
7 files changed, 28 insertions, 10 deletions
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 ); diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 3f97d67..de6dd90 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -21,6 +21,8 @@ #include "drivers/video/vga.h" #include "graphics_context.h" #include "widget.h" +#include "composite_widget.h" +#include "desktop.h" static jmp_buf panic_jmp_buf; @@ -194,6 +196,15 @@ static void handle_keyboard_event( keyboard_event_t *event, void *context ) switch( global_context->mode ) { case MODE_TEXT: if( vga_set_mode( vga, vga_make_mode( VGA_MODE_TYPE_GRAPHICS, 320, 200, 8 ) ) ) { + desktop_t desktop; + desktop_init( &desktop, 320, 200, VGA_COLOR_BLUE ); + + widget_t widget; + widget_init( &widget, (widget_t *)&desktop, 50, 50, 60, 70, VGA_COLOR_LIGHT_GREY ); + ((composite_widget_vtable_t *)desktop.vtable)->add_child( &desktop, &widget ); + + ((widget_vtable_t *)desktop.vtable)->draw( &desktop, &global_context->vga ); +#if 0 vga_clear_screen( vga, VGA_COLOR_BLUE ); vga_draw_char( vga, 'A', 10, 10, VGA_COLOR_BLUE, VGA_COLOR_WHITE ); @@ -214,6 +225,7 @@ static void handle_keyboard_event( keyboard_event_t *event, void *context ) widget_init( &widget, NULL, 50, 50, 60, 70 ); // as vga_t is equals to the graphical context for now widget.vtable->draw( &widget, &global_context->vga ); +#endif } global_context->mode = MODE_GRAPHICS; break; |