dirty redraw and SDL framebuffer example
[windtk] / src / widget.c
index 07643db..02c3ff0 100644 (file)
@@ -9,10 +9,10 @@ wt_widget *wt_alloc_widget(wt_widget *par)
                return 0;
        }
        w->type = WT_TYPE_WIDGET;
+       w->dirty = 1;
 
-       if(par) {
-               wt_add_child(par, w);
-       }
+       if(!par) par = wt->root;
+       wt_add_child(par, w);
        return w;
 }
 
@@ -37,6 +37,17 @@ void wt_free_tree(wt_widget *tree)
        wt_free_widget(tree);
 }
 
+void wt_dirty_widget(wt_widget *w)
+{
+       int i;
+
+       w->dirty = 1;
+
+       for(i=0; i<w->num_child; i++) {
+               wt_dirty_widget(w->child[i]);
+       }
+}
+
 int wt_type(wt_widget *w)
 {
        return w->type;
@@ -73,6 +84,8 @@ static int find_child(wt_widget *w, wt_widget *c)
 
 int wt_add_child(wt_widget *w, wt_widget *c)
 {
+       if(!w || !c) return -1;
+
        if(find_child(w, c) != -1) {
                return 0;
        }
@@ -155,8 +168,8 @@ void wt_move(wt_widget *w, int x, int y)
 
 void wt_resize(wt_widget *w, int x, int y)
 {
-       w->rect.width = x;
-       w->rect.height = y;
+       w->rect.w = x;
+       w->rect.h = y;
        /* TODO: invalidate something */
 }
 
@@ -169,15 +182,15 @@ int *wt_position(wt_widget *w, int *xret, int *yret)
 
 int *wt_size(wt_widget *w, int *xret, int *yret)
 {
-       if(xret) *xret = w->rect.width;
-       if(yret) *yret = w->rect.height;
-       return &w->rect.width;
+       if(xret) *xret = w->rect.w;
+       if(yret) *yret = w->rect.h;
+       return &w->rect.w;
 }
 
 int wt_hittest(wt_widget *w, int x, int y)
 {
-       return x >= w->rect.x && y >= w->rect.y && x < w->rect.x + w->rect.width &&
-               y < w->rect.y + w->rect.height;
+       return x >= w->rect.x && y >= w->rect.y && x < w->rect.x + w->rect.w &&
+               y < w->rect.y + w->rect.h;
 }
 
 wt_widget *wt_widget_at(int x, int y)