... | ... |
@@ -157,7 +157,7 @@ typedef struct wiclass_t { |
157 | 157 |
char *classname; |
158 | 158 |
int sizeclassglobaldata; |
159 | 159 |
char *classglobaldata; |
160 |
- void (*classcallback)(void *wi, struct wiclass_t *cl, widget_t *widget, wiclassop_t *op); |
|
160 |
+ int (*classcallback)(void *wi, struct wiclass_t *cl, widget_t *widget, wiclassop_t *op); |
|
161 | 161 |
} wiclass_t; |
162 | 162 |
|
163 | 163 |
typedef struct wifontinstance_t { |
... | ... |
@@ -194,10 +194,10 @@ typedef struct wi_t { |
194 | 194 |
wifont_t *fonts; |
195 | 195 |
} wi_t; |
196 | 196 |
|
197 |
-wi_t wi_init(void); |
|
197 |
+wi_t *wi_init(void); |
|
198 | 198 |
void wi_free(wi_t *wi); |
199 | 199 |
|
200 |
-int wi_class_register(wi_t *wi, char *classname, void (*classcallback)(void *wi, wiclass_t *cl, widget_t *widget, wiclassop_t *op)); |
|
200 |
+int wi_class_register(wi_t *wi, char *classname, int (*classcallback)(void *wi, wiclass_t *cl, widget_t *widget, wiclassop_t *op)); |
|
201 | 201 |
int wi_class_unregister(wi_t *wi, char *classname); |
202 | 202 |
|
203 | 203 |
int wi_toplevel_set(wi_t *wi, char *name); |
... | ... |
@@ -208,9 +208,9 @@ char *wi_add(wi_t *wi, char *debugfile, int debugline, char *class, char *path, |
208 | 208 |
char *wi_config(wi_t *wi, char *debugfile, int debugline, char *path, char *format,...); |
209 | 209 |
int wi_pack(wi_t *wi, char *debugfile, int debugline, char *path, char *format,...); |
210 | 210 |
#else |
211 |
- char *wi_add(wi_t *wi, char *debugfile, int debugline, char *class, char *path, char *format,...) __attribute__ ((format (printf,6,7)); |
|
212 |
- char *wi_config(wi_t *wi, char *debugfile, int debugline, char *path, char *format,...) __attribute__ ((format (printf,5,6)); |
|
213 |
- int wi_pack(wi_t *wi, char *debugfile, int debugline, char *path, char *format,...) __attribute__ ((format (printf,5,6)); |
|
211 |
+ char *wi_add(wi_t *wi, char *debugfile, int debugline, char *class, char *path, char *format,...) __attribute__ ((format (printf,6,7))); |
|
212 |
+ char *wi_config(wi_t *wi, char *debugfile, int debugline, char *path, char *format,...) __attribute__ ((format (printf,5,6))); |
|
213 |
+ int wi_pack(wi_t *wi, char *debugfile, int debugline, char *path, char *format,...) __attribute__ ((format (printf,5,6))); |
|
214 | 214 |
#endif |
215 | 215 |
int wi_destroy(wi_t *wi, char *path); |
216 | 216 |
|
... | ... |
@@ -225,8 +225,8 @@ int wi_var_destroy(wi_t *wi, char *vardata, int sizevardata); |
225 | 225 |
int wi_font_load(wi_t *wi, char *filename, char *fontname); |
226 | 226 |
|
227 | 227 |
/* default widgets */ |
228 |
-void wi_classcallback_frame(void *wi, wiclass_t *cl, widget_t *widget, wiclassop_t *op); |
|
229 |
-void wi_classcallback_label(void *wi, wiclass_t *cl, widget_t *widget, wiclassop_t *op); |
|
230 |
-void wi_classcallback_image(void *wi, wiclass_t *cl, widget_t *widget, wiclassop_t *op); |
|
228 |
+int wi_classcallback_frame(void *wi, wiclass_t *cl, widget_t *widget, wiclassop_t *op); |
|
229 |
+int wi_classcallback_label(void *wi, wiclass_t *cl, widget_t *widget, wiclassop_t *op); |
|
230 |
+int wi_classcallback_image(void *wi, wiclass_t *cl, widget_t *widget, wiclassop_t *op); |
|
231 | 231 |
#endif |
232 | 232 |
|
... | ... |
@@ -24,6 +24,14 @@ |
24 | 24 |
#define WI_FRAME "frame" |
25 | 25 |
#define WI_IMAGE "image" |
26 | 26 |
|
27 |
+/* debug info */ |
|
28 |
+#ifndef _F |
|
29 |
+#define _F __FILE__ |
|
30 |
+#endif |
|
31 |
+#ifndef _L |
|
32 |
+#define _L __LINE__ |
|
33 |
+#endif |
|
34 |
+ |
|
27 | 35 |
/* structs */ |
28 | 36 |
typedef struct xywh_t { |
29 | 37 |
int x; |
... | ... |
@@ -195,9 +203,15 @@ int wi_class_unregister(wi_t *wi, char *classname); |
195 | 203 |
int wi_toplevel_set(wi_t *wi, char *name); |
196 | 204 |
int wi_toplevel_destroy(wi_t *wi, char *name); |
197 | 205 |
|
206 |
+#ifndef __GNUC__ |
|
198 | 207 |
char *wi_add(wi_t *wi, char *debugfile, int debugline, char *class, char *path, char *format,...); |
199 | 208 |
char *wi_config(wi_t *wi, char *debugfile, int debugline, char *path, char *format,...); |
200 | 209 |
int wi_pack(wi_t *wi, char *debugfile, int debugline, char *path, char *format,...); |
210 |
+#else |
|
211 |
+ char *wi_add(wi_t *wi, char *debugfile, int debugline, char *class, char *path, char *format,...) __attribute__ ((format (printf,6,7)); |
|
212 |
+ char *wi_config(wi_t *wi, char *debugfile, int debugline, char *path, char *format,...) __attribute__ ((format (printf,5,6)); |
|
213 |
+ int wi_pack(wi_t *wi, char *debugfile, int debugline, char *path, char *format,...) __attribute__ ((format (printf,5,6)); |
|
214 |
+#endif |
|
201 | 215 |
int wi_destroy(wi_t *wi, char *path); |
202 | 216 |
|
203 | 217 |
int wi_alias_set(wi_t *wi, char *alias, char *path); |
... | ... |
@@ -14,6 +14,17 @@ |
14 | 14 |
|
15 | 15 |
#include <stdarg.h> |
16 | 16 |
|
17 |
+#include "SDL.h" |
|
18 |
+#include "SDL_rwops.h" |
|
19 |
+#include "SDL_image.h" |
|
20 |
+#include "SDL_ttf.h" |
|
21 |
+ |
|
22 |
+/* widget names */ |
|
23 |
+#define WI_LABEL "label" |
|
24 |
+#define WI_FRAME "frame" |
|
25 |
+#define WI_IMAGE "image" |
|
26 |
+ |
|
27 |
+/* structs */ |
|
17 | 28 |
typedef struct xywh_t { |
18 | 29 |
int x; |
19 | 30 |
int y; |
... | ... |
@@ -86,6 +97,9 @@ typedef struct widget_t { |
86 | 97 |
int sizeconfs; |
87 | 98 |
int usedconfs; |
88 | 99 |
wiconf_t **confs; |
100 |
+ SDL_Surface *surface; |
|
101 |
+ SDL_Texture *texture; |
|
102 |
+ int dirty; |
|
89 | 103 |
} widget_t; |
90 | 104 |
|
91 | 105 |
typedef struct witoplevel_t { |
... | ... |
@@ -100,6 +114,9 @@ typedef struct witoplevel_t { |
100 | 114 |
int sizeconfs; |
101 | 115 |
int usedconfs; |
102 | 116 |
wiconf_t **confs; |
117 |
+ SDL_Window *win; |
|
118 |
+ SDL_Renderer *renderer; |
|
119 |
+ int dirty; |
|
103 | 120 |
} witoplevel_t; |
104 | 121 |
|
105 | 122 |
typedef struct wialias_t { |
... | ... |
@@ -135,6 +152,21 @@ typedef struct wiclass_t { |
135 | 152 |
void (*classcallback)(void *wi, struct wiclass_t *cl, widget_t *widget, wiclassop_t *op); |
136 | 153 |
} wiclass_t; |
137 | 154 |
|
155 |
+typedef struct wifontinstance_t { |
|
156 |
+ int size; |
|
157 |
+ TTF_Font *font; |
|
158 |
+} wifontinstance_t; |
|
159 |
+ |
|
160 |
+typedef struct wifont_t { |
|
161 |
+ char *name; |
|
162 |
+ int sizedata; |
|
163 |
+ char *data; |
|
164 |
+ SDL_RWops *rwops; |
|
165 |
+ int sizefontinstances; |
|
166 |
+ int usedfontinstances; |
|
167 |
+ wifontinstance_t *fontinstances; |
|
168 |
+} wifont_t; |
|
169 |
+ |
|
138 | 170 |
typedef struct wi_t { |
139 | 171 |
int sizeclasses; |
140 | 172 |
int usedclasses; |
... | ... |
@@ -149,6 +181,9 @@ typedef struct wi_t { |
149 | 181 |
int sizevars; |
150 | 182 |
int usedvars; |
151 | 183 |
wivar_t **vars; |
184 |
+ int sizefonts; |
|
185 |
+ int usedfonts; |
|
186 |
+ wifont_t *fonts; |
|
152 | 187 |
} wi_t; |
153 | 188 |
|
154 | 189 |
wi_t wi_init(void); |
... | ... |
@@ -173,5 +208,11 @@ int wi_tree_move(wi_t *wi, char *path, char *newparent); |
173 | 208 |
int wi_var_updated(wi_t *wi, char *vardata, int sizevardata); |
174 | 209 |
int wi_var_destroy(wi_t *wi, char *vardata, int sizevardata); |
175 | 210 |
|
211 |
+int wi_font_load(wi_t *wi, char *filename, char *fontname); |
|
212 |
+ |
|
213 |
+/* default widgets */ |
|
214 |
+void wi_classcallback_frame(void *wi, wiclass_t *cl, widget_t *widget, wiclassop_t *op); |
|
215 |
+void wi_classcallback_label(void *wi, wiclass_t *cl, widget_t *widget, wiclassop_t *op); |
|
216 |
+void wi_classcallback_image(void *wi, wiclass_t *cl, widget_t *widget, wiclassop_t *op); |
|
176 | 217 |
#endif |
177 | 218 |
|
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,177 @@ |
1 |
+/* |
|
2 |
+ * widgetlib.h |
|
3 |
+ * |
|
4 |
+ * UI toolkit for C modelled after Tk |
|
5 |
+ * |
|
6 |
+ * HEADER FILE |
|
7 |
+ * |
|
8 |
+ * Author: Dario Rodriguez antartica@whereismybit.com |
|
9 |
+ * This program in licensed under the terms of the MIT/X license. |
|
10 |
+ */ |
|
11 |
+ |
|
12 |
+#ifndef WIDGETLIB_H |
|
13 |
+#define WIDGETLIB_H |
|
14 |
+ |
|
15 |
+#include <stdarg.h> |
|
16 |
+ |
|
17 |
+typedef struct xywh_t { |
|
18 |
+ int x; |
|
19 |
+ int y; |
|
20 |
+ int w; |
|
21 |
+ int h; |
|
22 |
+} xywh_t; |
|
23 |
+ |
|
24 |
+typedef struct wh_t { |
|
25 |
+ int w; |
|
26 |
+ int h; |
|
27 |
+} wh_t; |
|
28 |
+ |
|
29 |
+typedef enum wianchor_t { |
|
30 |
+ anchor_center=0, |
|
31 |
+ anchor_nw, |
|
32 |
+ anchor_n, |
|
33 |
+ anchor_ne, |
|
34 |
+ anchor_w, |
|
35 |
+ anchor_e, |
|
36 |
+ anchor_sw, |
|
37 |
+ anchor_s, |
|
38 |
+ anchor_se, |
|
39 |
+} wianchor_t; |
|
40 |
+ |
|
41 |
+typedef enum wifill_t { |
|
42 |
+ fill_none=0, |
|
43 |
+ fill_x, |
|
44 |
+ fill_y, |
|
45 |
+ fill_both, |
|
46 |
+} wifill_t; |
|
47 |
+ |
|
48 |
+typedef struct wiplace_t { |
|
49 |
+ int enabled; |
|
50 |
+ xywh_t xywh; |
|
51 |
+ int flag_whfromparent; |
|
52 |
+} wiplace_t; |
|
53 |
+ |
|
54 |
+typedef struct wiconf_t { |
|
55 |
+ char *name; |
|
56 |
+ int sizevalue; |
|
57 |
+ int usedvalue; |
|
58 |
+ char *value; |
|
59 |
+ int flag_var; /* value contains autovarname */ |
|
60 |
+ int flag_image; /* images are also vars (flag_var should also be set) */ |
|
61 |
+ wh_t image; |
|
62 |
+ void (*callback)(void *wi, char *toplevelname, char *widgetname, char *confname); |
|
63 |
+} wiconf_t; |
|
64 |
+ |
|
65 |
+typedef struct widget_t { |
|
66 |
+ int sizename; |
|
67 |
+ int usedname; |
|
68 |
+ char *name; |
|
69 |
+ char *classname; |
|
70 |
+ int sizeclassdata; |
|
71 |
+ char *classdata; |
|
72 |
+ wiplace_t place; |
|
73 |
+ xywh_t box; |
|
74 |
+ xywh_t padipadbox; |
|
75 |
+ xywh_t displaybox; |
|
76 |
+ int pad_left; |
|
77 |
+ int pad_right; |
|
78 |
+ int pad_top; |
|
79 |
+ int pad_bottom; |
|
80 |
+ int ipad_left; |
|
81 |
+ int ipad_right; |
|
82 |
+ int ipad_top; |
|
83 |
+ int ipad_bottom; |
|
84 |
+ wianchor_t anchor; |
|
85 |
+ wifill_t fill; |
|
86 |
+ int sizeconfs; |
|
87 |
+ int usedconfs; |
|
88 |
+ wiconf_t **confs; |
|
89 |
+} widget_t; |
|
90 |
+ |
|
91 |
+typedef struct witoplevel_t { |
|
92 |
+ char *toplevelname; |
|
93 |
+ widget_t rootwidget; |
|
94 |
+ int sizewidgets; |
|
95 |
+ int usedwidgets; |
|
96 |
+ widget_t **widgets; |
|
97 |
+ int sizebufwidgets; |
|
98 |
+ int usedbufwidgets; |
|
99 |
+ widget_t **bufwidgets; |
|
100 |
+ int sizeconfs; |
|
101 |
+ int usedconfs; |
|
102 |
+ wiconf_t **confs; |
|
103 |
+} witoplevel_t; |
|
104 |
+ |
|
105 |
+typedef struct wialias_t { |
|
106 |
+ char *alias; |
|
107 |
+ int sizepath; |
|
108 |
+ int usedpath; |
|
109 |
+ char *path; |
|
110 |
+} wialias_t; |
|
111 |
+ |
|
112 |
+typedef struct wivar_t { |
|
113 |
+ char *autovarname; |
|
114 |
+ int sizevardata; |
|
115 |
+ int usedvardata; |
|
116 |
+ char *vardata; |
|
117 |
+} wivar_t; |
|
118 |
+ |
|
119 |
+typedef enum wiclassoptype_t { |
|
120 |
+ classop_initclass=0, |
|
121 |
+ classop_freeclass, |
|
122 |
+ classop_initinstance, |
|
123 |
+ classop_freeinstance, |
|
124 |
+ classop_render, |
|
125 |
+} wiclassoptype_t; |
|
126 |
+ |
|
127 |
+typedef struct wiclassop_t { |
|
128 |
+ wiclassoptype_t op; |
|
129 |
+} wiclassop_t; |
|
130 |
+ |
|
131 |
+typedef struct wiclass_t { |
|
132 |
+ char *classname; |
|
133 |
+ int sizeclassglobaldata; |
|
134 |
+ char *classglobaldata; |
|
135 |
+ void (*classcallback)(void *wi, struct wiclass_t *cl, widget_t *widget, wiclassop_t *op); |
|
136 |
+} wiclass_t; |
|
137 |
+ |
|
138 |
+typedef struct wi_t { |
|
139 |
+ int sizeclasses; |
|
140 |
+ int usedclasses; |
|
141 |
+ wiclass_t *classes; |
|
142 |
+ int sizetoplevels; |
|
143 |
+ int usedltoplevels; |
|
144 |
+ witoplevel_t *toplevels; |
|
145 |
+ int currenttoplevel; |
|
146 |
+ int sizealiases; |
|
147 |
+ int usedaliases; |
|
148 |
+ wialias_t **aliases; |
|
149 |
+ int sizevars; |
|
150 |
+ int usedvars; |
|
151 |
+ wivar_t **vars; |
|
152 |
+} wi_t; |
|
153 |
+ |
|
154 |
+wi_t wi_init(void); |
|
155 |
+void wi_free(wi_t *wi); |
|
156 |
+ |
|
157 |
+int wi_class_register(wi_t *wi, char *classname, void (*classcallback)(void *wi, wiclass_t *cl, widget_t *widget, wiclassop_t *op)); |
|
158 |
+int wi_class_unregister(wi_t *wi, char *classname); |
|
159 |
+ |
|
160 |
+int wi_toplevel_set(wi_t *wi, char *name); |
|
161 |
+int wi_toplevel_destroy(wi_t *wi, char *name); |
|
162 |
+ |
|
163 |
+char *wi_add(wi_t *wi, char *debugfile, int debugline, char *class, char *path, char *format,...); |
|
164 |
+char *wi_config(wi_t *wi, char *debugfile, int debugline, char *path, char *format,...); |
|
165 |
+int wi_pack(wi_t *wi, char *debugfile, int debugline, char *path, char *format,...); |
|
166 |
+int wi_destroy(wi_t *wi, char *path); |
|
167 |
+ |
|
168 |
+int wi_alias_set(wi_t *wi, char *alias, char *path); |
|
169 |
+int wi_alias_unset(wi_t *wi, char *alias); |
|
170 |
+ |
|
171 |
+int wi_tree_move(wi_t *wi, char *path, char *newparent); |
|
172 |
+ |
|
173 |
+int wi_var_updated(wi_t *wi, char *vardata, int sizevardata); |
|
174 |
+int wi_var_destroy(wi_t *wi, char *vardata, int sizevardata); |
|
175 |
+ |
|
176 |
+#endif |
|
177 |
+ |