start by copying windtk and dropping dirty rects and indexed colors
[anigui] / src / anigui.h
1 #ifndef ANIGUI_H_
2 #define ANIGUI_H_
3
4 enum {
5         AG_TYPE_WIDGET,
6         AG_TYPE_WINDOW,
7         AG_TYPE_LABEL,
8         AG_TYPE_BUTTON,
9         AG_TYPE_CHECKBOX,
10         AG_TYPE_TEXTFIELD
11 };
12
13 enum {
14         AG_KEY_UP = 0x100,
15         AG_KEY_DOWN,
16         AG_KEY_LEFT,
17         AG_KEY_RIGHT,
18         AG_KEY_HOME,
19         AG_KEY_END,
20         AG_KEY_PGUP,
21         AG_KEY_PGDN
22 };
23
24 enum {
25         AG_WS_DEFAULT,
26         AG_WS_NOFRM
27 };
28
29 enum {
30         AG_CB_FOCUS,
31         AG_CB_UNFOCUS,
32         AG_CB_MODIFY,
33         AG_CB_CLICK,
34         AG_CB_MBUTTON,
35         AG_CB_MMOTION,
36
37         AG_NUM_CALLBACKS
38 };
39
40 typedef struct ag_widget ag_widget;
41 typedef void (*ag_callback_func)(ag_widget*, void*);
42
43 struct ag_image {
44         int width, height;
45         int bpp;
46         int pitch;
47         void *pixels;
48         void *udata;
49 };
50
51 struct ag_rect {
52         int x, y, w, h;
53 };
54
55 struct ag_graphics {
56         unsigned int flags;
57
58         void (*color)(int r, int g, int b);
59
60         void (*fillrect)(struct ag_rect *rect);
61         void (*line)(int x0, int y0, int x1, int y1);
62
63         int (*newimage)(struct ag_image *img);
64         void (*blit)(int img, int x, int y, int w, int h);
65
66         void (*text)(int font, const char *s, int x, int y);
67         void (*textbox)(int font, const char *s, int x, int y, struct ag_rect *boxret);
68         int (*lineheight)(int font);
69         int (*baseline)(int font);
70 };
71
72 typedef void (*ag_draw_func)(ag_widget*, struct ag_graphics*);
73
74 struct ag_theme {
75         char *name;
76         void *so;
77         ag_draw_func draw_window;
78         ag_draw_func draw_label;
79         ag_draw_func draw_button;
80         ag_draw_func draw_checkbox;
81         ag_draw_func draw_textfield;
82
83         struct ag_theme *next;
84 };
85
86 void ag_allocator(void *(*allocfunc)(size_t), void (*freefunc)(void*));
87
88 int ag_init(int w, int h, struct ag_graphics *gfx);
89 void ag_destroy(void);
90
91 struct ag_theme *ag_load_theme(const char *path);       /* load dynamically, where applicable */
92 void ag_unload_theme(struct ag_theme *theme);
93 void ag_use_theme(struct ag_theme *theme);
94
95 void ag_viewport(int x, int y, int w, int h);
96 void ag_graphics(struct ag_graphics *gfx);
97
98 void ag_inp_key(int key, int press);
99 void ag_inp_mouse(int bn, int st, int x, int y);
100 void ag_inp_motion(int x, int y);
101
102 void ag_draw(void);
103
104 ag_widget *ag_alloc_widget(ag_widget *par);
105 void ag_free_widget(ag_widget *w);
106 void ag_free_tree(ag_widget *tree);
107
108 ag_widget *ag_window(ag_widget *par, const char *title, int style, int x, int y, int width, int height);
109 ag_widget *ag_label(ag_widget *par, const char *text, int x, int y);
110 ag_widget *ag_button(ag_widget *par, const char *text, int x, int y, int width, int height);
111 ag_widget *ag_button_cb(ag_widget *par, const char *text, int x, int y, int width,
112                 int height,     ag_callback_func cbclick, void *cls);
113 ag_widget *ag_checkbox(ag_widget *par, const char *text, int chk, int x, int y, int width, int height);
114 ag_widget *ag_checkbox_cb(ag_widget *par, const char *text, int chk, int x, int y,
115                 int width, int height, ag_callback_func cbtoggle, void *cls);
116 ag_widget *ag_textfield(ag_widget *par, const char *text, int x, int y, int width, int height);
117
118 int ag_type(ag_widget *w);
119
120 int ag_set_text(ag_widget *w, const char *text);
121 const char *ag_text(ag_widget *w);
122
123 int ag_add_child(ag_widget *w, ag_widget *c);
124 int ag_remove_child(ag_widget *w, ag_widget *c);
125 ag_widget *ag_parent(ag_widget *w);                     /* parent widget */
126 ag_widget *ag_widget_window(ag_widget *w);      /* first ancestor of type window */
127 int ag_child_count(ag_widget *w);                       /* number of children */
128 ag_widget *ag_child(ag_widget *w, int idx);     /* get child idx */
129
130 void ag_move(ag_widget *w, int x, int y);
131 void ag_resize(ag_widget *w, int x, int y);
132 int *ag_position(ag_widget *w, int *xret, int *yret);
133 int *ag_size(ag_widget *w, int *xret, int *yret);
134
135 int ag_hittest(ag_widget *w, int x, int y);
136 ag_widget *ag_widget_at(int x, int y);
137
138 void ag_layout(ag_widget *w, int layout);
139 void ag_padding(ag_widget *w, int pad);
140 /* calculates layout of child widgets and updates dimensions */
141 void ag_relayout(ag_widget *w);
142
143 void ag_focus(ag_widget *w);
144 void ag_unfocus(ag_widget *w);
145 int ag_isfocused(ag_widget *w);
146
147 void ag_hover(ag_widget *w);
148 void ag_unhover(ag_widget *w);
149 int ag_ishover(ag_widget *w);
150
151 void ag_enable(ag_widget *w);
152 void ag_disable(ag_widget *w);
153 int ag_isenabled(ag_widget *w);
154
155 void ag_callback(ag_widget *w, int type, ag_callback_func func, void *cls);
156
157 void ag_rect(struct ag_rect *r, int x, int y, int w, int h);
158 void ag_rect_union(struct ag_rect *a, struct ag_rect *b);
159 int ag_rect_overlap(struct ag_rect *a, struct ag_rect *b);
160
161 #endif  /* ANIGUI_H_ */