summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-06-30 16:45:12 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-06-30 16:45:12 +0200
commitc1bbac52d78b2e3e93fa43a5a7b3907073493216 (patch)
tree13ec009562358d01b1845dd08135f4ac8d384551 /src/gui
parent915dd4b023d0826166d4887100dbed64d46821a9 (diff)
downloadabaos-c1bbac52d78b2e3e93fa43a5a7b3907073493216.tar.gz
abaos-c1bbac52d78b2e3e93fa43a5a7b3907073493216.tar.bz2
text widget has a constant buffer and owns the string to draw now
(passing a const char * from a local stack context is not really a good idea!) added more efficiet draw method for characters in vga driver protected desktop for now against too often redraws (boolean global variable needs_redraw, this is later a soffisticated set-of-areas-to -redraw algorithm)
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/desktop.c17
-rw-r--r--src/gui/desktop.h3
-rw-r--r--src/gui/text_widget.c7
-rw-r--r--src/gui/text_widget.h4
4 files changed, 25 insertions, 6 deletions
diff --git a/src/gui/desktop.c b/src/gui/desktop.c
index 6592b52..ad4aad9 100644
--- a/src/gui/desktop.c
+++ b/src/gui/desktop.c
@@ -28,6 +28,7 @@ void desktop_init( desktop_t *desktop, const int w, const int h, const vga_color
desktop->mouse_x = w / 2;
desktop->mouse_y = h / 2;
+ desktop->needs_redrawing = true;
desktop->base.base.vtable = (widget_vtable_t *)&desktop_vtable;
desktop->base.vtable = (composite_widget_vtable_t *)&desktop_vtable;
@@ -38,6 +39,10 @@ void desktop_draw( void *obj, graphics_context_t *context )
{
desktop_t *desktop = obj;
+ if( !desktop->needs_redrawing ) {
+ return;
+ }
+
vga_clear_screen( context, desktop->base.base.background_color );
composite_widget_draw( obj, context );
@@ -56,16 +61,26 @@ void desktop_draw( void *obj, graphics_context_t *context )
vga_set_pixel( context, desktop->mouse_x, desktop->mouse_y + i, VGA_COLOR_WHITE );
}
}
+
+ desktop->needs_redrawing = false;
}
void desktop_on_mouse_down( void *obj, const int x, const int y )
{
+ desktop_t *desktop = obj;
+
composite_widget_on_mouse_down( obj, x, y );
+
+ desktop->needs_redrawing = true;
}
void desktop_on_mouse_up( void *obj, const int x, const int y )
{
+ desktop_t *desktop = obj;
+
composite_widget_on_mouse_up( obj, x, y );
+
+ desktop->needs_redrawing = true;
}
void desktop_on_mouse_move( void *obj, const int old_x, const int old_y, const int x, const int y )
@@ -76,4 +91,6 @@ void desktop_on_mouse_move( void *obj, const int old_x, const int old_y, const i
desktop->mouse_y = y;
composite_widget_on_mouse_move( obj, old_x, old_y, x, y );
+
+ desktop->needs_redrawing = true;
}
diff --git a/src/gui/desktop.h b/src/gui/desktop.h
index a8db094..a9d1946 100644
--- a/src/gui/desktop.h
+++ b/src/gui/desktop.h
@@ -5,6 +5,8 @@
#define MAX_NOF_WIDGET_CHILDREN 100
+#include <stdbool.h>
+
typedef struct {
composite_widget_vtable_t base;
} desktop_vtable_t;
@@ -14,6 +16,7 @@ typedef struct {
desktop_vtable_t *vtable;
int mouse_x;
int mouse_y;
+ bool needs_redrawing;
} desktop_t;
void desktop_init( desktop_t *widget, const int w, const int h, const vga_color_t background_color );
diff --git a/src/gui/text_widget.c b/src/gui/text_widget.c
index eea2613..db237af 100644
--- a/src/gui/text_widget.c
+++ b/src/gui/text_widget.c
@@ -24,9 +24,7 @@ void text_widget_init( text_widget_t *widget, widget_t *parent, const int x, con
widget_init( &widget->base, parent, x, y, w, h, background_color );
- // TODO: const for now, caller has to preserve the text
- // maybe with memory manager in place we can do this with a strdup
- widget->s = s;
+ text_widget_set_text( widget, s );
widget->base.vtable = (widget_vtable_t *)&text_widget_vtable;
widget->vtable = &text_widget_vtable;
@@ -61,7 +59,6 @@ void text_widget_set_text( void *obj, const char *s )
{
text_widget_t *widget = obj;
- // TODO: see above
- widget->s = s;
+ strlcpy( widget->s, s, TEXT_WIDGET_MAX_TEXT_SIZE );
}
diff --git a/src/gui/text_widget.h b/src/gui/text_widget.h
index 4b00b4f..7e87a3c 100644
--- a/src/gui/text_widget.h
+++ b/src/gui/text_widget.h
@@ -3,6 +3,8 @@
#include "widget.h"
+#define TEXT_WIDGET_MAX_TEXT_SIZE 100
+
typedef struct {
widget_vtable_t base;
void (*set_text)( void *obj, const char *s );
@@ -11,7 +13,7 @@ typedef struct {
typedef struct {
widget_t base;
text_widget_vtable_t *vtable;
- const char *s;
+ char s[TEXT_WIDGET_MAX_TEXT_SIZE];
} text_widget_t;
void text_widget_init( text_widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h, const vga_color_t background_color, const char *s );