5 void *(*wt_alloc)(size_t sz) = malloc;
6 void (*wt_free)(void *p) = free;
8 /* one day I may want to allow multiple contexts */
9 static struct wt_context defctx;
10 struct wt_context *wt_curctx_ = &defctx;
12 static unsigned int def_colors[] = {
13 0xf0f0f0, /* font/foreground */
14 0x333333, /* background */
15 0x444444, /* highlight */
16 0x222222, /* shadow */
17 0x403065, /* inactive frame */
18 0x54349c, /* inactive frame highlight */
19 0x221e2c, /* inactive frame shadow */
20 0x8032aa, /* active frame */
21 0xb14de8, /* active frame highlight */
22 0x3b2846, /* active frame shadow */
26 void *wt_zalloc(size_t sz)
28 void *p = wt_alloc(sz);
35 void wt_allocator(void *(*allocfunc)(size_t), void (*freefunc)(void *p))
37 wt_alloc = allocfunc ? allocfunc : malloc;
38 wt_free = freefunc ? freefunc : free;
42 int wt_init(int w, int h, struct wt_graphics *gfx)
45 if(!(wt->root = wt_alloc_widget(0))) {
49 wt_viewport(0, 0, w, h);
56 wt_free_tree(wt->root);
60 void wt_viewport(int x, int y, int w, int h)
62 wt_setrect(&wt->vp, x, y, w, h);
63 wt_move(wt->root, x, y);
64 wt_resize(wt->root, w, h);
67 void wt_graphics(struct wt_graphics *gfx)
72 for(i=0; i<NUM_COLORS; i++) {
73 r = def_colors[i] >> 16;
74 g = (def_colors[i] >> 8) & 0xff;
75 b = def_colors[i] & 0xff;
76 if((wt->colors[i] = gfx->newcolor(r, g, b)) == -1) {
77 wt->colors[i] = i ? wt->colors[i - 1] : 0;
82 void wt_inp_key(int key, int press)
86 void wt_inp_mouse(int bn, int st, int x, int y)
90 void wt_inp_motion(int x, int y)
94 void wt_draw_tree(wt_widget *tree)
102 for(i=0; i<tree->num_child; i++) {
103 wt_draw_tree(tree->child[i]);
109 wt_draw_tree(wt->root);
112 void wt_gfx_color(int cidx)
114 wt->gfx.color(wt->colors[cidx]);
117 void wt_gfx_fillrect(struct wt_rect *r)
122 void wt_gfx_frame(struct wt_rect *r, int style, int basecol)
124 wt_gfx_color(basecol);
126 wt_gfx_color(style == FRM_OUT ? basecol + 2 : basecol + 1);
127 wt_gfx_line(r->x, r->y + r->height, r->x + r->width - 1, r->y + r->height);
128 wt_gfx_line(r->x + r->width, r->y + 1, r->x + r->width, r->y + r->height);
129 wt_gfx_color(style == FRM_OUT ? basecol + 1 : basecol + 2);
130 wt_gfx_line(r->x, r->y, r->x + r->width, r->y);
131 wt_gfx_line(r->x, r->y + 1, r->x, r->y + r->height - 1);
134 void wt_gfx_line(int x0, int y0, int x1, int y1)
136 wt->gfx.line(x0, y0, x1, y1);
139 void wt_setrect(struct wt_rect *r, int x, int y, int w, int h)