Mercurial > MadButterfly
comparison src/X_main.c @ 41:400b4b5db0dc
Working on animation
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Fri, 08 Aug 2008 21:34:53 +0800 |
parents | db2aa914e14b |
children | e3295c07faa9 |
comparison
equal
deleted
inserted
replaced
40:e292beec12d4 | 41:400b4b5db0dc |
---|---|
22 struct test_motion_data { | 22 struct test_motion_data { |
23 paint_t *text_stroke; | 23 paint_t *text_stroke; |
24 redraw_man_t *rdman; | 24 redraw_man_t *rdman; |
25 }; | 25 }; |
26 | 26 |
27 void test_motion(mbsec_t sec, mbusec_t usec, | 27 void test_motion(const mb_timeval_t *tmo, |
28 mbsec_t now_sec, mbusec_t now_usec, | 28 const mb_timeval_t *now, |
29 void *arg) { | 29 void *arg) { |
30 struct test_motion_data *data = (struct test_motion_data *)arg; | 30 struct test_motion_data *data = (struct test_motion_data *)arg; |
31 | 31 |
32 paint_color_set(data->text_stroke, 1, 0.5, 0.5, 0.5); | 32 paint_color_set(data->text_stroke, 1, 0.5, 0.5, 0.5); |
33 rdman_paint_changed(data->rdman, data->text_stroke); | 33 rdman_paint_changed(data->rdman, data->text_stroke); |
86 redraw_man_t *rdman, int w, int h) { | 86 redraw_man_t *rdman, int w, int h) { |
87 int xcon; | 87 int xcon; |
88 fd_set rds; | 88 fd_set rds; |
89 int nfds; | 89 int nfds; |
90 struct timeval tmo; | 90 struct timeval tmo; |
91 mb_timeval_t mb_tmo; | |
91 int r; | 92 int r; |
92 | 93 |
93 XSelectInput(display, win, PointerMotionMask | ExposureMask); | 94 XSelectInput(display, win, PointerMotionMask | ExposureMask); |
94 XFlush(display); | 95 XFlush(display); |
95 | 96 |
102 if(r == -1) { | 103 if(r == -1) { |
103 perror("gettimeofday"); | 104 perror("gettimeofday"); |
104 return; | 105 return; |
105 } | 106 } |
106 | 107 |
107 r = mb_tman_next_timeout(tman, | 108 MB_TIMEVAL_SET(&mb_tmo, tmo.tv_sec, tmo.tv_usec); |
108 tmo.tv_sec, tmo.tv_usec, | 109 r = mb_tman_next_timeout(tman, &mb_tmo, &mb_tmo); |
109 (mbsec_t *)&tmo.tv_sec, | |
110 (mbusec_t *)&tmo.tv_usec); | |
111 if(r != OK) | 110 if(r != OK) |
112 r = select(nfds, &rds, NULL, NULL, NULL); | 111 r = select(nfds, &rds, NULL, NULL, NULL); |
113 else | 112 else { |
113 tmo.tv_sec = MB_TIMEVAL_SEC(&mb_tmo); | |
114 tmo.tv_usec = MB_TIMEVAL_USEC(&mb_tmo); | |
114 r = select(nfds, &rds, NULL, NULL, &tmo); | 115 r = select(nfds, &rds, NULL, NULL, &tmo); |
116 } | |
115 | 117 |
116 if(r == -1) { | 118 if(r == -1) { |
117 perror("select"); | 119 perror("select"); |
118 return; | 120 return; |
119 } | 121 } |
121 r = gettimeofday(&tmo, NULL); | 123 r = gettimeofday(&tmo, NULL); |
122 if(r == -1) { | 124 if(r == -1) { |
123 perror("gettimeofday"); | 125 perror("gettimeofday"); |
124 return; | 126 return; |
125 } | 127 } |
126 mb_tman_handle_timeout(tman, tmo.tv_sec, tmo.tv_usec); | 128 MB_TIMEVAL_SET(&mb_tmo, tmo.tv_sec, tmo.tv_usec); |
129 mb_tman_handle_timeout(tman, &mb_tmo); | |
127 XFlush(display); | 130 XFlush(display); |
128 } else if(FD_ISSET(xcon, &rds)) { | 131 } else if(FD_ISSET(xcon, &rds)) { |
129 event_interaction(display, rdman, w, h); | 132 event_interaction(display, rdman, w, h); |
130 } | 133 } |
131 } | 134 } |
143 grad_stop_t fill3_stops[3]; | 146 grad_stop_t fill3_stops[3]; |
144 cairo_font_face_t *face; | 147 cairo_font_face_t *face; |
145 struct test_motion_data mdata; | 148 struct test_motion_data mdata; |
146 struct timeval tv; | 149 struct timeval tv; |
147 mb_tman_t *tman; | 150 mb_tman_t *tman; |
151 mb_timeval_t mbtv; | |
148 int i; | 152 int i; |
149 | 153 |
150 tmpsuf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); | 154 tmpsuf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); |
151 tmpcr = cairo_create(tmpsuf); | 155 tmpcr = cairo_create(tmpsuf); |
152 | 156 |
294 if(tman) { | 298 if(tman) { |
295 mdata.text_stroke = text_stroke; | 299 mdata.text_stroke = text_stroke; |
296 mdata.rdman = &rdman; | 300 mdata.rdman = &rdman; |
297 gettimeofday(&tv, NULL); | 301 gettimeofday(&tv, NULL); |
298 tv.tv_sec += 3; | 302 tv.tv_sec += 3; |
299 mb_tman_timeout(tman, tv.tv_sec, tv.tv_usec, | 303 MB_TIMEVAL_SET(&mbtv, tv.tv_sec, tv.tv_usec); |
300 test_motion, &mdata); | 304 mb_tman_timeout(tman, &mbtv, test_motion, &mdata); |
301 | 305 |
302 handle_connection(display, tman, &rdman, w, h); | 306 handle_connection(display, tman, &rdman, w, h); |
307 | |
303 mb_tman_free(tman); | 308 mb_tman_free(tman); |
304 } | 309 } |
305 | 310 |
306 fill1->free(fill1); | 311 fill1->free(fill1); |
307 fill2->free(fill2); | 312 fill2->free(fill2); |