dirty redraw and SDL framebuffer example
[windtk] / src / window.c
index cd39284..9925db4 100644 (file)
@@ -26,6 +26,14 @@ wt_widget *wt_window(wt_widget *par, const char *title, int style, int x, int y,
 #define TBARTHICK      12      /* TODO: base it on font metrics */
 #define TBAROFFS       (TBARTHICK + FRMBEVEL * 2)
 
+void calc_window_rect(struct wt_rect *r, wt_widget *w)
+{
+       r->x = w->rect.x - FRMOFFS;
+       r->y = w->rect.y - TBAROFFS - FRMOFFS;
+       r->w = w->rect.w + FRMOFFS * 2;
+       r->h = w->rect.h + TBAROFFS + FRMOFFS * 2;
+}
+
 static void draw_win(wt_widget *w, struct wt_graphics *gfx)
 {
        struct wt_rect fr, tmprect;
@@ -34,10 +42,7 @@ static void draw_win(wt_widget *w, struct wt_graphics *gfx)
        wt_gfx_color(COL_BG);
        wt_gfx_fillrect(&w->rect);
 
-       fr.x = w->rect.x - FRMOFFS;
-       fr.y = w->rect.y - TBAROFFS - FRMOFFS;
-       fr.width = w->rect.width + FRMOFFS * 2;
-       fr.height = w->rect.height + TBAROFFS + FRMOFFS * 2;
+       calc_window_rect(&fr, w);
 
        wt_gfx_frame(&fr, FRM_OUT | FRM_NOFILL, frmcol);        /* outer bevel */
 
@@ -46,35 +51,35 @@ static void draw_win(wt_widget *w, struct wt_graphics *gfx)
 
        fr.x += FRMBEVEL;
        fr.y += FRMBEVEL;
-       fr.width -= FRMBEVEL * 2;
-       fr.height -= FRMBEVEL * 2;
+       fr.w -= FRMBEVEL * 2;
+       fr.h -= FRMBEVEL * 2;
 
        tmprect = fr;
-       tmprect.width = FRMTHICK;
+       tmprect.w = FRMTHICK;
        wt_gfx_fillrect(&tmprect);      /* left bar */
-       tmprect.x += fr.width - FRMTHICK;
+       tmprect.x += fr.w - FRMTHICK;
        wt_gfx_fillrect(&tmprect);      /* right bar */
 
        tmprect = fr;
-       tmprect.height = FRMTHICK;
+       tmprect.h = FRMTHICK;
        tmprect.x += FRMTHICK;
-       tmprect.width -= FRMTHICK * 2;
+       tmprect.w -= FRMTHICK * 2;
        wt_gfx_fillrect(&tmprect);      /* top bar */
-       tmprect.y += fr.height - FRMTHICK;
+       tmprect.y += fr.h - FRMTHICK;
        wt_gfx_fillrect(&tmprect);      /* bottom bar */
 
        /* inner bevel */
        fr.x += FRMTHICK;
        fr.y += FRMTHICK;
-       fr.width -= FRMTHICK * 2;
-       fr.height -= FRMTHICK * 2;
+       fr.w -= FRMTHICK * 2;
+       fr.h -= FRMTHICK * 2;
        wt_gfx_frame(&fr, FRM_IN | FRM_NOFILL, frmcol);
 
        /* titlebar */
        fr.x = w->rect.x;
-       fr.width = w->rect.width;
+       fr.w = w->rect.w;
        fr.y += FRMBEVEL;
-       fr.height = TBARTHICK + FRMBEVEL * 2;
+       fr.h = TBARTHICK + FRMBEVEL * 2;
        wt_gfx_frame(&fr, FRM_OUT, frmcol);
 }