cd392845da8ef8db1fe64b9e899082d5960e65b4
[windtk] / src / window.c
1 #include "wtimpl.h"
2
3 static void draw_win(wt_widget *w, struct wt_graphics *gfx);
4 static void use_theme(wt_widget *w, struct wt_theme *theme);
5
6 wt_widget *wt_window(wt_widget *par, const char *title, int style, int x, int y, int xsz, int ysz)
7 {
8         wt_widget *w;
9
10         if(!(w = wt_alloc_widget(par))) {
11                 return 0;
12         }
13         w->type = WT_TYPE_WINDOW;
14         wt_set_text(w, title);
15         wt_move(w, x, y);
16         wt_resize(w, xsz, ysz);
17         /* TODO: style */
18
19         use_theme(w, wt->theme);
20         return w;
21 }
22
23 #define FRMTHICK        1
24 #define FRMBEVEL        1
25 #define FRMOFFS         (FRMTHICK + FRMBEVEL * 2)
26 #define TBARTHICK       12      /* TODO: base it on font metrics */
27 #define TBAROFFS        (TBARTHICK + FRMBEVEL * 2)
28
29 static void draw_win(wt_widget *w, struct wt_graphics *gfx)
30 {
31         struct wt_rect fr, tmprect;
32         int frmcol = COL_FFRM;//wt->focuswin == w ? COL_FFRM : COL_FRM;
33
34         wt_gfx_color(COL_BG);
35         wt_gfx_fillrect(&w->rect);
36
37         fr.x = w->rect.x - FRMOFFS;
38         fr.y = w->rect.y - TBAROFFS - FRMOFFS;
39         fr.width = w->rect.width + FRMOFFS * 2;
40         fr.height = w->rect.height + TBAROFFS + FRMOFFS * 2;
41
42         wt_gfx_frame(&fr, FRM_OUT | FRM_NOFILL, frmcol);        /* outer bevel */
43
44         /* draw main frame */
45         wt_gfx_color(frmcol);
46
47         fr.x += FRMBEVEL;
48         fr.y += FRMBEVEL;
49         fr.width -= FRMBEVEL * 2;
50         fr.height -= FRMBEVEL * 2;
51
52         tmprect = fr;
53         tmprect.width = FRMTHICK;
54         wt_gfx_fillrect(&tmprect);      /* left bar */
55         tmprect.x += fr.width - FRMTHICK;
56         wt_gfx_fillrect(&tmprect);      /* right bar */
57
58         tmprect = fr;
59         tmprect.height = FRMTHICK;
60         tmprect.x += FRMTHICK;
61         tmprect.width -= FRMTHICK * 2;
62         wt_gfx_fillrect(&tmprect);      /* top bar */
63         tmprect.y += fr.height - FRMTHICK;
64         wt_gfx_fillrect(&tmprect);      /* bottom bar */
65
66         /* inner bevel */
67         fr.x += FRMTHICK;
68         fr.y += FRMTHICK;
69         fr.width -= FRMTHICK * 2;
70         fr.height -= FRMTHICK * 2;
71         wt_gfx_frame(&fr, FRM_IN | FRM_NOFILL, frmcol);
72
73         /* titlebar */
74         fr.x = w->rect.x;
75         fr.width = w->rect.width;
76         fr.y += FRMBEVEL;
77         fr.height = TBARTHICK + FRMBEVEL * 2;
78         wt_gfx_frame(&fr, FRM_OUT, frmcol);
79 }
80
81 static void use_theme(wt_widget *w, struct wt_theme *theme)
82 {
83         w->draw = theme && theme->draw_window ? theme->draw_window : draw_win;
84 }