wt_callback_func cb[WT_NUM_CALLBACKS];
void *cbcls[WT_NUM_CALLBACKS];
- void (*draw)(struct wt_widget *w);
+ wt_draw_func draw;
void (*click)(struct wt_widget *w);
void (*keypress)(struct wt_widget *w, int key);
void (*mbutton)(struct wt_widget *w, int bn, int st, int x, int y);
void (*mmotion)(struct wt_widget *w, int x, int y);
+
+ void (*use_theme)(struct wt_widget *w, struct wt_theme *theme);
};
#endif /* WIDGET_H_ */
#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)
{
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)
+static void draw_win(wt_widget *w, struct wt_graphics *gfx)
{
wt_gfx_color(COL_BG);
wt_gfx_fillrect(&w->rect);
}
+
+static void use_theme(wt_widget *w, struct wt_theme *theme)
+{
+ w->draw = theme && theme->draw_window ? theme->draw_window : draw_win;
+}
wt->root = 0;
}
+struct wt_theme *wt_load_theme(const char *path)
+{
+ return 0; /* TODO */
+}
+
+void wt_unload_theme(struct wt_theme *theme)
+{
+}
+
+static void use_theme(wt_widget *w, struct wt_theme *theme)
+{
+ int i;
+
+ if(w->use_theme) {
+ w->use_theme(w, theme);
+ }
+
+ for(i=0; i<w->num_child; i++) {
+ use_theme(w->child[i], theme);
+ }
+}
+
+void wt_use_theme(struct wt_theme *theme)
+{
+ wt->theme = theme;
+ use_theme(wt->root, theme);
+}
+
void wt_viewport(int x, int y, int w, int h)
{
wt_setrect(&wt->vp, x, y, w, h);
int i;
if(tree->draw) {
- tree->draw(tree);
+ tree->draw(tree, &wt->gfx);
}
for(i=0; i<tree->num_child; i++) {
int (*baseline)(int font);
};
+typedef void (*wt_draw_func)(wt_widget*, struct wt_graphics*);
+
+struct wt_theme {
+ char *name;
+ void *so;
+ wt_draw_func draw_window;
+ wt_draw_func draw_label;
+ wt_draw_func draw_button;
+ wt_draw_func draw_checkbox;
+ wt_draw_func draw_textfield;
+
+ struct wt_theme *next;
+};
+
void wt_allocator(void *(*allocfunc)(size_t), void (*freefunc)(void*));
int wt_init(int w, int h, struct wt_graphics *gfx);
void wt_destroy(void);
+struct wt_theme *wt_load_theme(const char *path); /* load dynamically, where applicable */
+void wt_unload_theme(struct wt_theme *theme);
+void wt_use_theme(struct wt_theme *theme);
+
void wt_viewport(int x, int y, int w, int h);
void wt_graphics(struct wt_graphics *gfx);
struct wt_graphics gfx;
struct wt_rect vp;
wt_widget *root;
+ struct wt_theme *theme;
int colors[NUM_COLORS];
};