summaryrefslogtreecommitdiff
path: root/src/gui/widget.c
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-06-21 14:25:13 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-06-21 14:25:13 +0200
commite158c4832aa1d5dc8603fb9c33cac3f7cc19abc9 (patch)
tree0055162852966fab10afb7a230744796007a9c2f /src/gui/widget.c
parent32f14fa04237963d8b6016d8cc0c6d853e68d2fe (diff)
downloadabaos-e158c4832aa1d5dc8603fb9c33cac3f7cc19abc9.tar.gz
abaos-e158c4832aa1d5dc8603fb9c33cac3f7cc19abc9.tar.bz2
added the widget and the composite widget classes
Diffstat (limited to 'src/gui/widget.c')
-rw-r--r--src/gui/widget.c74
1 files changed, 67 insertions, 7 deletions
diff --git a/src/gui/widget.c b/src/gui/widget.c
index 313fd49..cd77d03 100644
--- a/src/gui/widget.c
+++ b/src/gui/widget.c
@@ -5,12 +5,14 @@
static widget_vtable_t widget_vtable = {
widget_draw,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL
+ widget_get_focus,
+ widget_model_to_screen,
+ widget_contains_coordinate,
+ widget_on_mouse_down,
+ widget_on_mouse_up,
+ widget_on_mouse_move,
+ widget_on_key_down,
+ 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 )
@@ -29,7 +31,65 @@ void widget_init( widget_t *widget, widget_t *parent, const int x, const int y,
void widget_draw( void *obj, graphics_context_t *context )
{
widget_t *widget = obj;
+ int x = 0;
+ int y = 0;
- vga_draw_rectangle( context, widget->x, widget->y, widget->w, widget->h,
+ widget->vtable->model_to_screen( widget, &x, &y );
+
+ vga_draw_rectangle( context, x, y, widget->w, widget->h,
vga_make_RGB( 0xFF, 0xFF, 0xFF ) );
}
+
+void widget_get_focus( void *obj, widget_t *widget )
+{
+ widget_t *o = obj;
+
+ if( o->parent != NULL ) {
+ o->parent->vtable->get_focus( widget->parent, widget );
+ }
+}
+
+void widget_model_to_screen( void *obj, int *x, int *y )
+{
+ widget_t *widget = obj;
+
+ if( widget->parent != NULL ) {
+ widget->parent->vtable->model_to_screen( widget->parent, x, y );
+ }
+
+ *x += widget->x;
+ *y += widget->y;
+}
+
+bool widget_contains_coordinate( void *obj, const int x, const int y )
+{
+ widget_t *widget = obj;
+
+ return widget->x <= x && x < widget->x + widget->w &&
+ widget->y <= y && y < widget->y + widget->h;
+}
+
+void widget_on_mouse_down( void *obj, const int x, const int y )
+{
+ widget_t *widget = obj;
+
+ if( widget->focusable ) {
+ widget->vtable->get_focus( widget, widget );
+ }
+}
+
+void widget_on_mouse_up( void *obj, const int x, const int y )
+{
+}
+
+void widget_on_mouse_move( void *obj, const int old_x, const int old_y, const int x, const int y )
+{
+}
+
+void widget_on_key_down( void *obj, char c )
+{
+}
+
+void widget_on_key_up( void *obj, char c )
+{
+}