dirty redraw and SDL framebuffer example
[windtk] / src / window.c
index a103ed4..9925db4 100644 (file)
@@ -1,6 +1,7 @@
 #include "wtimpl.h"
 
-static void draw_win(wt_widget *w);
+static void draw_win(wt_widget *w, struct wt_graphics *gfx);
+static void use_theme(wt_widget *w, struct wt_theme *theme);
 
 wt_widget *wt_window(wt_widget *par, const char *title, int style, int x, int y, int xsz, int ysz)
 {
@@ -15,12 +16,74 @@ wt_widget *wt_window(wt_widget *par, const char *title, int style, int x, int y,
        wt_resize(w, xsz, ysz);
        /* TODO: style */
 
-       w->draw = draw_win;
+       use_theme(w, wt->theme);
        return w;
 }
 
-static void draw_win(wt_widget *w)
+#define FRMTHICK       1
+#define FRMBEVEL       1
+#define FRMOFFS                (FRMTHICK + FRMBEVEL * 2)
+#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;
+       int frmcol = COL_FFRM;//wt->focuswin == w ? COL_FFRM : COL_FRM;
+
        wt_gfx_color(COL_BG);
        wt_gfx_fillrect(&w->rect);
+
+       calc_window_rect(&fr, w);
+
+       wt_gfx_frame(&fr, FRM_OUT | FRM_NOFILL, frmcol);        /* outer bevel */
+
+       /* draw main frame */
+       wt_gfx_color(frmcol);
+
+       fr.x += FRMBEVEL;
+       fr.y += FRMBEVEL;
+       fr.w -= FRMBEVEL * 2;
+       fr.h -= FRMBEVEL * 2;
+
+       tmprect = fr;
+       tmprect.w = FRMTHICK;
+       wt_gfx_fillrect(&tmprect);      /* left bar */
+       tmprect.x += fr.w - FRMTHICK;
+       wt_gfx_fillrect(&tmprect);      /* right bar */
+
+       tmprect = fr;
+       tmprect.h = FRMTHICK;
+       tmprect.x += FRMTHICK;
+       tmprect.w -= FRMTHICK * 2;
+       wt_gfx_fillrect(&tmprect);      /* top bar */
+       tmprect.y += fr.h - FRMTHICK;
+       wt_gfx_fillrect(&tmprect);      /* bottom bar */
+
+       /* inner bevel */
+       fr.x += FRMTHICK;
+       fr.y += FRMTHICK;
+       fr.w -= FRMTHICK * 2;
+       fr.h -= FRMTHICK * 2;
+       wt_gfx_frame(&fr, FRM_IN | FRM_NOFILL, frmcol);
+
+       /* titlebar */
+       fr.x = w->rect.x;
+       fr.w = w->rect.w;
+       fr.y += FRMBEVEL;
+       fr.h = TBARTHICK + FRMBEVEL * 2;
+       wt_gfx_frame(&fr, FRM_OUT, frmcol);
+}
+
+static void use_theme(wt_widget *w, struct wt_theme *theme)
+{
+       w->draw = theme && theme->draw_window ? theme->draw_window : draw_win;
 }