draw window frame
[windtk] / src / windtk.h
1 #ifndef WINDTK_H_
2 #define WINDTK_H_
3
4 enum {
5         WT_TYPE_WIDGET,
6         WT_TYPE_WINDOW,
7         WT_TYPE_LABEL,
8         WT_TYPE_BUTTON,
9         WT_TYPE_CHECKBOX,
10         WT_TYPE_TEXTFIELD
11 };
12
13 enum {
14         WT_KEY_UP = 0x100,
15         WT_KEY_DOWN,
16         WT_KEY_LEFT,
17         WT_KEY_RIGHT,
18         WT_KEY_HOME,
19         WT_KEY_END,
20         WT_KEY_PGUP,
21         WT_KEY_PGDN
22 };
23
24 enum {
25         WT_WS_DEFAULT,
26         WT_WS_NOFRM
27 };
28
29 enum {
30         WT_CB_FOCUS,
31         WT_CB_UNFOCUS,
32         WT_CB_MODIFY,
33         WT_CB_CLICK,
34         WT_CB_MBUTTON,
35         WT_CB_MMOTION,
36
37         WT_NUM_CALLBACKS
38 };
39
40 typedef struct wt_widget wt_widget;
41 typedef void (*wt_callback_func)(wt_widget*, void*);
42
43 struct wt_image {
44         int width, height;
45         int bpp;
46         int pitch;
47         void *pixels;
48         void *udata;
49 };
50
51 struct wt_rect {
52         int x, y, width, height;
53 };
54
55 struct wt_graphics {
56         int (*newcolor)(int r, int g, int b);
57         void (*color)(int c);
58
59         void (*fillrect)(struct wt_rect *rect);
60         void (*line)(int x0, int y0, int x1, int y1);
61
62         int (*newimage)(struct wt_image *img);
63         void (*blit)(int img, int x, int y, int w, int h);
64
65         void (*text)(int font, const char *s, int x, int y);
66         void (*textbox)(int font, const char *s, int x, int y, struct wt_rect *boxret);
67         int (*lineheight)(int font);
68         int (*baseline)(int font);
69 };
70
71 typedef void (*wt_draw_func)(wt_widget*, struct wt_graphics*);
72
73 struct wt_theme {
74         char *name;
75         void *so;
76         wt_draw_func draw_window;
77         wt_draw_func draw_label;
78         wt_draw_func draw_button;
79         wt_draw_func draw_checkbox;
80         wt_draw_func draw_textfield;
81
82         struct wt_theme *next;
83 };
84
85 void wt_allocator(void *(*allocfunc)(size_t), void (*freefunc)(void*));
86
87 int wt_init(int w, int h, struct wt_graphics *gfx);
88 void wt_destroy(void);
89
90 struct wt_theme *wt_load_theme(const char *path);       /* load dynamically, where applicable */
91 void wt_unload_theme(struct wt_theme *theme);
92 void wt_use_theme(struct wt_theme *theme);
93
94 void wt_viewport(int x, int y, int w, int h);
95 void wt_graphics(struct wt_graphics *gfx);
96
97 void wt_inp_key(int key, int press);
98 void wt_inp_mouse(int bn, int st, int x, int y);
99 void wt_inp_motion(int x, int y);
100
101 void wt_draw(void);
102
103 wt_widget *wt_alloc_widget(wt_widget *par);
104 void wt_free_widget(wt_widget *w);
105 void wt_free_tree(wt_widget *tree);
106
107 wt_widget *wt_window(wt_widget *par, const char *title, int style, int x, int y, int width, int height);
108 wt_widget *wt_label(wt_widget *par, const char *text, int x, int y);
109 wt_widget *wt_button(wt_widget *par, const char *text, int x, int y, int width, int height);
110 wt_widget *wt_button_cb(wt_widget *par, const char *text, int x, int y, int width,
111                 int height,     wt_callback_func cbclick, void *cls);
112 wt_widget *wt_checkbox(wt_widget *par, const char *text, int chk, int x, int y, int width, int height);
113 wt_widget *wt_checkbox_cb(wt_widget *par, const char *text, int chk, int x, int y,
114                 int width, int height, wt_callback_func cbtoggle, void *cls);
115 wt_widget *wt_textfield(wt_widget *par, const char *text, int x, int y, int width, int height);
116
117 int wt_type(wt_widget *w);
118
119 int wt_set_text(wt_widget *w, const char *text);
120 const char *wt_text(wt_widget *w);
121
122 int wt_add_child(wt_widget *w, wt_widget *c);
123 int wt_remove_child(wt_widget *w, wt_widget *c);
124 wt_widget *wt_parent(wt_widget *w);                     /* parent widget */
125 wt_widget *wt_widget_window(wt_widget *w);      /* first ancestor of type window */
126 int wt_child_count(wt_widget *w);                       /* number of children */
127 wt_widget *wt_child(wt_widget *w, int idx);     /* get child idx */
128
129 void wt_move(wt_widget *w, int x, int y);
130 void wt_resize(wt_widget *w, int x, int y);
131 int *wt_position(wt_widget *w, int *xret, int *yret);
132 int *wt_size(wt_widget *w, int *xret, int *yret);
133
134 int wt_hittest(wt_widget *w, int x, int y);
135 wt_widget *wt_widget_at(int x, int y);
136
137 void wt_layout(wt_widget *w, int layout);
138 void wt_padding(wt_widget *w, int pad);
139 /* calculates layout of child widgets and updates dimensions */
140 void wt_relayout(wt_widget *w);
141
142 void wt_focus(wt_widget *w);
143 void wt_unfocus(wt_widget *w);
144 int wt_isfocused(wt_widget *w);
145
146 void wt_hover(wt_widget *w);
147 void wt_unhover(wt_widget *w);
148 int wt_ishover(wt_widget *w);
149
150 void wt_enable(wt_widget *w);
151 void wt_disable(wt_widget *w);
152 int wt_isenabled(wt_widget *w);
153
154 void wt_callback(wt_widget *w, int type, wt_callback_func func, void *cls);
155
156 void wt_rect(struct wt_rect *r, int x, int y, int w, int h);
157
158 #endif  /* WINDTK_H_ */