summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-06-30 09:10:26 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-06-30 09:10:26 +0200
commit58df0d3172ad548b85627e5bb0b92a27a6072736 (patch)
tree76d621778d30e541ab5bdce539b38bed27833abf /src/gui
parent587f8d3dbf25408100496854c8803ce3c918ec4f (diff)
downloadabaos-58df0d3172ad548b85627e5bb0b92a27a6072736.tar.gz
abaos-58df0d3172ad548b85627e5bb0b92a27a6072736.tar.bz2
added a window to gui which is draggable by the mouse
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/desktop.c3
-rw-r--r--src/gui/window.c81
-rw-r--r--src/gui/window.h25
3 files changed, 109 insertions, 0 deletions
diff --git a/src/gui/desktop.c b/src/gui/desktop.c
index 0c0aa01..6592b52 100644
--- a/src/gui/desktop.c
+++ b/src/gui/desktop.c
@@ -60,6 +60,7 @@ void desktop_draw( void *obj, graphics_context_t *context )
void desktop_on_mouse_down( void *obj, const int x, const int y )
{
+ composite_widget_on_mouse_down( obj, x, y );
}
void desktop_on_mouse_up( void *obj, const int x, const int y )
@@ -73,4 +74,6 @@ void desktop_on_mouse_move( void *obj, const int old_x, const int old_y, const i
desktop->mouse_x = x;
desktop->mouse_y = y;
+
+ composite_widget_on_mouse_move( obj, old_x, old_y, x, y );
}
diff --git a/src/gui/window.c b/src/gui/window.c
new file mode 100644
index 0000000..cd62e47
--- /dev/null
+++ b/src/gui/window.c
@@ -0,0 +1,81 @@
+#include "window.h"
+
+#include "string.h"
+#include "stddef.h"
+
+static window_vtable_t window_vtable = {
+ {
+ {
+ window_draw,
+ composite_widget_get_focus,
+ widget_model_to_screen,
+ widget_contains_coordinate,
+ window_on_mouse_down,
+ window_on_mouse_up,
+ window_on_mouse_move,
+ composite_widget_on_key_down,
+ composite_widget_on_key_up
+ },
+ composite_widget_add_child
+ }
+};
+
+
+void window_init( window_t *window, widget_t *parent, const int x, const int y, const int w, const int h, const vga_color_t background_color )
+{
+ memset( window, 0, sizeof( window_t ) );
+
+ composite_widget_init( &window->base, parent, x, y, w, h, background_color );
+
+ window->dragging = false;
+
+ window->base.base.vtable = (widget_vtable_t *)&window_vtable;
+ window->base.vtable = (composite_widget_vtable_t *)&window_vtable;
+ window->vtable = &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->base.base.x > context->mode.x - widget->base.base.w ) {
+ widget->base.base.x = context->mode.x - widget->base.base.w;
+ }
+ if( widget->base.base.y < 0 ) {
+ widget->base.base.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;
+ }
+
+ composite_widget_draw( obj, context );
+}
+
+void window_on_mouse_down( void *obj, const int x, const int y )
+{
+ window_t *widget = obj;
+
+ widget->dragging = true;
+ composite_widget_on_mouse_down( obj, x, y );
+}
+
+void window_on_mouse_up( void *obj, const int x, const int y )
+{
+ window_t *widget = obj;
+
+ widget->dragging = false;
+ composite_widget_on_mouse_up( obj, x, y );
+}
+
+void window_on_mouse_move( void *obj, const int old_x, const int old_y, const int x, const int y )
+{
+ window_t *widget = obj;
+
+ if( widget->dragging ) {
+ widget->base.base.x += x - old_x;
+ widget->base.base.y += y - old_y;
+ }
+}
diff --git a/src/gui/window.h b/src/gui/window.h
new file mode 100644
index 0000000..3a0cc97
--- /dev/null
+++ b/src/gui/window.h
@@ -0,0 +1,25 @@
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include "composite_widget.h"
+
+#include <stdbool.h>
+
+typedef struct {
+ composite_widget_vtable_t base;
+} window_vtable_t;
+
+typedef struct {
+ composite_widget_t base;
+ window_vtable_t *vtable;
+ bool dragging;
+} window_t;
+
+void window_init( window_t *window, widget_t *parent, const int x, const int y, const int w, const int h, const vga_color_t background_color );
+
+void window_draw( void *obj, graphics_context_t *context );
+void window_on_mouse_down( void *obj, const int x, const int y );
+void window_on_mouse_up( void *obj, const int x, const int y );
+void window_on_mouse_move( void *obj, const int old_x, const int old_y, const int x, const int y );
+
+#endif // WINDOW_H