Mercurial > MadButterfly
comparison src/X_main.c @ 53:ffed18510d55
Use animate feacilities to demo all animation.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 10 Aug 2008 00:12:18 +0800 |
parents | 59a295651480 |
children | 1b6dbafdf906 |
comparison
equal
deleted
inserted
replaced
52:59a295651480 | 53:ffed18510d55 |
---|---|
18 #define ERR -1 | 18 #define ERR -1 |
19 | 19 |
20 Display *display; | 20 Display *display; |
21 Window win; | 21 Window win; |
22 | 22 |
23 struct test_motion_data { | |
24 paint_t *text_stroke; | |
25 redraw_man_t *rdman; | |
26 }; | |
27 | |
28 void test_motion(const mb_timeval_t *tmo, | |
29 const mb_timeval_t *now, | |
30 void *arg) { | |
31 struct test_motion_data *data = (struct test_motion_data *)arg; | |
32 | |
33 paint_color_set(data->text_stroke, 1, 0.5, 0.5, 0.5); | |
34 rdman_paint_changed(data->rdman, data->text_stroke); | |
35 rdman_redraw_changed(data->rdman); | |
36 } | |
37 | |
38 void hint_shape(redraw_man_t *rdman, shape_t *shape) { | 23 void hint_shape(redraw_man_t *rdman, shape_t *shape) { |
39 static shape_t *last_shape = NULL; | 24 static shape_t *last_shape = NULL; |
40 if(last_shape != shape) { | 25 if(last_shape != shape) { |
41 if(last_shape != NULL && last_shape->stroke != NULL) { | 26 if(last_shape != NULL && last_shape->stroke != NULL) { |
42 last_shape->stroke_width -= 2; | 27 last_shape->stroke_width -= 2; |
43 rdman_shape_changed(rdman, last_shape); | 28 rdman_shape_changed(rdman, last_shape); |
44 } | 29 } |
45 if(shape != NULL && shape->stroke != NULL) { | 30 if(shape != NULL && shape->stroke != NULL) { |
46 shape->stroke_width += 2; | 31 shape->stroke_width += 2; |
47 rdman_shape_changed(rdman, shape); | 32 rdman_shape_changed(rdman, shape); |
48 rdman_redraw_changed(rdman); | |
49 } | 33 } |
50 } | 34 } |
51 last_shape = shape; | 35 last_shape = shape; |
52 } | 36 } |
53 | 37 |
78 /* rdman_redraw_area(rdman, evt.xexpose.x, evt.xexpose.y, | 62 /* rdman_redraw_area(rdman, evt.xexpose.x, evt.xexpose.y, |
79 evt.xexpose.width, evt.xexpose.height); */ | 63 evt.xexpose.width, evt.xexpose.height); */ |
80 break; | 64 break; |
81 } | 65 } |
82 } | 66 } |
67 rdman_redraw_changed(rdman); | |
83 XFlush(display); | 68 XFlush(display); |
84 } | 69 } |
85 | 70 |
86 void handle_connection(Display *display, mb_tman_t *tman, | 71 void handle_connection(Display *display, mb_tman_t *tman, |
87 redraw_man_t *rdman, int w, int h) { | 72 redraw_man_t *rdman, int w, int h) { |
88 int xcon; | 73 int xcon; |
89 fd_set rds; | 74 fd_set rds; |
90 int nfds; | 75 int nfds; |
91 struct timeval tmo; | 76 struct timeval tmo; |
92 mb_timeval_t mb_tmo; | 77 mb_timeval_t mb_tmo, next_mb_tmo; |
93 int r, r1; | 78 int r, r1; |
94 | 79 |
95 XSelectInput(display, win, PointerMotionMask | ExposureMask); | 80 XSelectInput(display, win, PointerMotionMask | ExposureMask); |
96 XFlush(display); | 81 XFlush(display); |
97 | 82 |
107 | 92 |
108 while(1) { | 93 while(1) { |
109 FD_ZERO(&rds); | 94 FD_ZERO(&rds); |
110 FD_SET(xcon, &rds); | 95 FD_SET(xcon, &rds); |
111 | 96 |
112 r = mb_tman_next_timeout(tman, &mb_tmo, &mb_tmo); | 97 r = mb_tman_next_timeout(tman, &mb_tmo, &next_mb_tmo); |
113 if(r != OK) | 98 if(r != OK) |
114 r = select(nfds, &rds, NULL, NULL, NULL); | 99 r = select(nfds, &rds, NULL, NULL, NULL); |
115 else { | 100 else { |
116 tmo.tv_sec = MB_TIMEVAL_SEC(&mb_tmo); | 101 tmo.tv_sec = MB_TIMEVAL_SEC(&next_mb_tmo); |
117 tmo.tv_usec = MB_TIMEVAL_USEC(&mb_tmo); | 102 tmo.tv_usec = MB_TIMEVAL_USEC(&next_mb_tmo); |
118 r = select(nfds, &rds, NULL, NULL, &tmo); | 103 r = select(nfds, &rds, NULL, NULL, &tmo); |
119 } | 104 } |
120 | 105 |
121 if(r == -1) { | 106 if(r == -1) { |
122 perror("select"); | 107 perror("select"); |
123 return; | 108 return; |
124 } | 109 } |
125 | 110 |
126 r1 = gettimeofday(&tmo, NULL); | 111 MB_TIMEVAL_ADD(&mb_tmo, &next_mb_tmo); |
127 if(r1 == -1) { | |
128 perror("gettimeofday"); | |
129 return; | |
130 } | |
131 MB_TIMEVAL_SET(&mb_tmo, tmo.tv_sec, tmo.tv_usec); | |
132 | 112 |
133 if(r == 0) { | 113 if(r == 0) { |
134 MB_TIMEVAL_SET(&mb_tmo, tmo.tv_sec, tmo.tv_usec); | |
135 mb_tman_handle_timeout(tman, &mb_tmo); | 114 mb_tman_handle_timeout(tman, &mb_tmo); |
136 rdman_redraw_changed(rdman); | 115 rdman_redraw_changed(rdman); |
137 XFlush(display); | 116 XFlush(display); |
138 } else if(FD_ISSET(xcon, &rds)) { | 117 } else if(FD_ISSET(xcon, &rds)) { |
139 event_interaction(display, rdman, w, h); | 118 event_interaction(display, rdman, w, h); |
150 paint_t *fill1, *fill2, *fill3; | 129 paint_t *fill1, *fill2, *fill3; |
151 paint_t *stroke, *text_stroke; | 130 paint_t *stroke, *text_stroke; |
152 shape_t *text; | 131 shape_t *text; |
153 grad_stop_t fill3_stops[3]; | 132 grad_stop_t fill3_stops[3]; |
154 cairo_font_face_t *face; | 133 cairo_font_face_t *face; |
155 struct test_motion_data mdata; | |
156 struct timeval tv; | 134 struct timeval tv; |
157 mb_tman_t *tman; | 135 mb_tman_t *tman; |
158 mb_timeval_t mbtv, start, playing; | 136 mb_timeval_t mbtv, start, playing; |
159 mb_progm_t *progm; | 137 mb_progm_t *progm; |
160 mb_word_t *word; | 138 mb_word_t *word; |
161 mb_action_t *act; | 139 mb_action_t *act; |
162 int i; | |
163 | 140 |
164 tmpsuf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); | 141 tmpsuf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); |
165 tmpcr = cairo_create(tmpsuf); | 142 tmpcr = cairo_create(tmpsuf); |
166 | 143 |
167 cairo_set_source_surface(cr, tmpsuf, 0, 0); | 144 cairo_set_source_surface(cr, tmpsuf, 0, 0); |
178 face = cairo_get_font_face(tmpcr); | 155 face = cairo_get_font_face(tmpcr); |
179 text = sh_text_new("hello \xe6\xbc\xa2\xe5\xad\x97", 10, h / 4, | 156 text = sh_text_new("hello \xe6\xbc\xa2\xe5\xad\x97", 10, h / 4, |
180 36.0, face); | 157 36.0, face); |
181 rdman_paint_stroke(&rdman, text_stroke, text); | 158 rdman_paint_stroke(&rdman, text_stroke, text); |
182 text->stroke_width = 0.5; | 159 text->stroke_width = 0.5; |
160 rdman_paint_fill(&rdman, fill1, text); | |
183 rdman_add_shape(&rdman, text, coord3); | 161 rdman_add_shape(&rdman, text, coord3); |
184 | 162 |
185 path1 = sh_path_new("M 22,89.36218 C -34,-0.63782 39,-9.637817 82,12.36218 C 125,34.36218 142,136.36218 142,136.36218 C 100.66667,125.36218 74.26756,123.42795 22,89.36218 z "); | 163 path1 = sh_path_new("M 22,89.36218 C -34,-0.63782 39,-9.637817 82,12.36218 C 125,34.36218 142,136.36218 142,136.36218 C 100.66667,125.36218 74.26756,123.42795 22,89.36218 z "); |
186 rdman_paint_fill(&rdman, fill1, path1); | 164 rdman_paint_fill(&rdman, fill1, path1); |
187 rdman_paint_stroke(&rdman, stroke, path1); | 165 rdman_paint_stroke(&rdman, stroke, path1); |
217 | 195 |
218 rdman_redraw_all(&rdman); | 196 rdman_redraw_all(&rdman); |
219 | 197 |
220 XFlush(display); | 198 XFlush(display); |
221 | 199 |
222 for(i = 0; i < 50; i++) { | |
223 usleep(20000); | |
224 path1->stroke_width = i / 10; | |
225 path2->stroke_width = i / 10; | |
226 coord1->matrix[2] += 1; | |
227 coord1->matrix[5] += 1; | |
228 coord2->matrix[2] -= 1; | |
229 coord2->matrix[5] += 1; | |
230 paint_color_set(fill1, 1, 1, (i/25) & 0x1, 0.5); | |
231 paint_color_set(fill2, (i/25) & 0x1, 1, 1, 0.5); | |
232 rdman_paint_changed(&rdman, fill1); | |
233 rdman_paint_changed(&rdman, fill2); | |
234 rdman_coord_changed(&rdman, coord1); | |
235 rdman_coord_changed(&rdman, coord2); | |
236 rdman_redraw_changed(&rdman); | |
237 XFlush(display); | |
238 } | |
239 | |
240 for(i = 0; i < 5; i++) { | |
241 usleep(100000); | |
242 paint_color_set(fill1, 1, i % 2, 0, 0.5); | |
243 paint_color_set(fill2, 0, i % 2, 1, 0.5); | |
244 rdman_paint_changed(&rdman, fill1); | |
245 rdman_paint_changed(&rdman, fill2); | |
246 rdman_redraw_changed(&rdman); | |
247 XFlush(display); | |
248 } | |
249 | |
250 for(i = 0; i < 4; i++) { | |
251 usleep(100000); | |
252 path1->stroke_width -= 1; | |
253 path2->stroke_width -= 1; | |
254 rdman_shape_changed(&rdman, path1); | |
255 rdman_shape_changed(&rdman, path2); | |
256 rdman_redraw_changed(&rdman); | |
257 XFlush(display); | |
258 } | |
259 for(i = 0; i < 4; i++) { | |
260 usleep(100000); | |
261 path1->stroke_width += 1; | |
262 path2->stroke_width += 1; | |
263 rdman_shape_changed(&rdman, path1); | |
264 rdman_shape_changed(&rdman, path2); | |
265 rdman_redraw_changed(&rdman); | |
266 XFlush(display); | |
267 } | |
268 | |
269 for(i = 0; i < 4; i++) { | |
270 usleep(100000); | |
271 text->stroke_width += 1; | |
272 rdman_shape_changed(&rdman, text); | |
273 coord3->matrix[2] += 5; | |
274 rdman_coord_changed(&rdman, coord3); | |
275 rdman_redraw_changed(&rdman); | |
276 XFlush(display); | |
277 } | |
278 for(i = 0; i < 4; i++) { | |
279 usleep(100000); | |
280 text->stroke_width -= 1; | |
281 rdman_shape_changed(&rdman, text); | |
282 coord3->matrix[2] -= 5; | |
283 rdman_coord_changed(&rdman, coord3); | |
284 rdman_redraw_changed(&rdman); | |
285 XFlush(display); | |
286 } | |
287 | |
288 for(i = 0; i < 4; i++) { | |
289 usleep(100000); | |
290 text->stroke_width += 1; | |
291 rdman_shape_changed(&rdman, text); | |
292 coord3->matrix[5] += 5; | |
293 rdman_coord_changed(&rdman, coord3); | |
294 rdman_redraw_changed(&rdman); | |
295 XFlush(display); | |
296 } | |
297 for(i = 0; i < 4; i++) { | |
298 usleep(100000); | |
299 text->stroke_width -= 1; | |
300 rdman_shape_changed(&rdman, text); | |
301 coord3->matrix[5] -= 5; | |
302 rdman_coord_changed(&rdman, coord3); | |
303 rdman_redraw_changed(&rdman); | |
304 XFlush(display); | |
305 } | |
306 | |
307 tman = mb_tman_new(); | 200 tman = mb_tman_new(); |
308 if(tman) { | 201 if(tman) { |
309 progm = mb_progm_new(2, &rdman); | 202 progm = mb_progm_new(10, &rdman); |
310 | 203 |
204 MB_TIMEVAL_SET(&start, 0, 0); | |
205 MB_TIMEVAL_SET(&playing, 1, 0); | |
206 word = mb_progm_next_word(progm, &start, &playing); | |
207 | |
208 act = mb_shift_new(50, 50, coord1, word); | |
209 act = mb_shift_new(-50, 50, coord2, word); | |
210 | |
311 MB_TIMEVAL_SET(&start, 1, 0); | 211 MB_TIMEVAL_SET(&start, 1, 0); |
312 MB_TIMEVAL_SET(&playing, 2, 0); | 212 MB_TIMEVAL_SET(&playing, 2, 0); |
313 word = mb_progm_next_word(progm, &start, &playing); | 213 word = mb_progm_next_word(progm, &start, &playing); |
214 | |
314 act = mb_shift_new(0, 20, coord1, word); | 215 act = mb_shift_new(0, 20, coord1, word); |
315 | |
316 act = mb_shift_new(0, -20, coord2, word); | 216 act = mb_shift_new(0, -20, coord2, word); |
317 | 217 |
318 MB_TIMEVAL_SET(&start, 3, 0); | 218 MB_TIMEVAL_SET(&start, 3, 0); |
319 MB_TIMEVAL_SET(&playing, 2, 0); | 219 MB_TIMEVAL_SET(&playing, 2, 0); |
320 word = mb_progm_next_word(progm, &start, &playing); | 220 word = mb_progm_next_word(progm, &start, &playing); |
221 | |
321 act = mb_shift_new(0, -20, coord1, word); | 222 act = mb_shift_new(0, -20, coord1, word); |
322 | |
323 act = mb_shift_new(0, 20, coord2, word); | 223 act = mb_shift_new(0, 20, coord2, word); |
324 | |
325 act = mb_chgcolor_new(0, 0, 1, 0.5, fill1, word); | 224 act = mb_chgcolor_new(0, 0, 1, 0.5, fill1, word); |
326 act = mb_chgcolor_new(1, 0, 0, 0.5, fill2, word); | 225 act = mb_chgcolor_new(1, 0, 0, 0.5, fill2, word); |
327 | 226 |
328 gettimeofday(&tv, NULL); | 227 gettimeofday(&tv, NULL); |
329 MB_TIMEVAL_SET(&mbtv, tv.tv_sec, tv.tv_usec); | 228 MB_TIMEVAL_SET(&mbtv, tv.tv_sec, tv.tv_usec); |
330 mb_progm_start(progm, tman, &mbtv); | 229 mb_progm_start(progm, tman, &mbtv); |
331 | |
332 mdata.text_stroke = text_stroke; | |
333 mdata.rdman = &rdman; | |
334 gettimeofday(&tv, NULL); | |
335 tv.tv_sec += 3; | |
336 MB_TIMEVAL_SET(&mbtv, tv.tv_sec, tv.tv_usec); | |
337 mb_tman_timeout(tman, &mbtv, test_motion, &mdata); | |
338 | 230 |
339 handle_connection(display, tman, &rdman, w, h); | 231 handle_connection(display, tman, &rdman, w, h); |
340 | 232 |
341 mb_tman_free(tman); | 233 mb_tman_free(tman); |
342 } | 234 } |