Mercurial > MadButterfly
annotate src/X_main.c @ 47:f3818d996f4f
change interface of creating a animation action
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sat, 09 Aug 2008 16:41:33 +0800 |
parents | 7d9af44f095b |
children | bdf711cbf0fb |
rev | line source |
---|---|
3
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1 #include <stdio.h> |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
2 #include <unistd.h> |
39 | 3 #include <sys/time.h> |
4 #include <sys/select.h> | |
3
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
5 #include <X11/Xlib.h> |
6
772511b8b9be
Cairo specify RGB values in range 0.0 ~ 1.0.
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
6 #include <X11/Xutil.h> |
3
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
7 #include <cairo.h> |
10 | 8 #include <cairo-xlib.h> |
3
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
9 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
3
diff
changeset
|
10 #include <string.h> |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
3
diff
changeset
|
11 #include "shapes.h" |
12 | 12 #include "redraw_man.h" |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
13 #include "paint.h" |
39 | 14 #include "mb_timer.h" |
42 | 15 #include "animate.h" |
39 | 16 |
17 #define OK 0 | |
18 #define ERR -1 | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
3
diff
changeset
|
19 |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
20 Display *display; |
30
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
21 Window win; |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
22 |
39 | 23 struct test_motion_data { |
24 paint_t *text_stroke; | |
25 redraw_man_t *rdman; | |
26 }; | |
27 | |
41 | 28 void test_motion(const mb_timeval_t *tmo, |
29 const mb_timeval_t *now, | |
39 | 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 | |
30
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
38 void hint_shape(redraw_man_t *rdman, shape_t *shape) { |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
39 static shape_t *last_shape = NULL; |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
40 if(last_shape != shape) { |
33
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
32
diff
changeset
|
41 if(last_shape != NULL && last_shape->stroke != NULL) { |
30
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
42 last_shape->stroke_width -= 2; |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
43 rdman_shape_changed(rdman, last_shape); |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
44 } |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
45 if(shape != NULL && shape->stroke != NULL) { |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
46 shape->stroke_width += 2; |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
47 rdman_shape_changed(rdman, shape); |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
48 rdman_redraw_changed(rdman); |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
49 } |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
50 } |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
51 last_shape = shape; |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
52 } |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
53 |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
54 void event_interaction(Display *display, |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
55 redraw_man_t *rdman, int w, int h) { |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
56 XEvent evt; |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
57 XMotionEvent *mevt; |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
58 int r; |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
59 co_aix x, y; |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
60 shape_t *shape = NULL; |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
61 int in_stroke; |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
62 |
39 | 63 while(XEventsQueued(display, QueuedAfterReading) > 0) { |
64 r = XNextEvent(display, &evt); | |
65 if(r == -1) | |
66 break; | |
67 | |
30
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
68 switch(evt.type) { |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
69 case MotionNotify: |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
70 mevt = (XMotionEvent *)&evt; |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
71 x = mevt->x; |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
72 y = mevt->y; |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
73 shape = find_shape_at_pos(rdman, x, y, &in_stroke); |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
74 hint_shape(rdman, shape); |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
75 break; |
37 | 76 case Expose: |
77 rdman_redraw_all(rdman); | |
78 /* rdman_redraw_area(rdman, evt.xexpose.x, evt.xexpose.y, | |
79 evt.xexpose.width, evt.xexpose.height); */ | |
80 break; | |
30
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
81 } |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
82 } |
39 | 83 XFlush(display); |
84 } | |
85 | |
86 void handle_connection(Display *display, mb_tman_t *tman, | |
87 redraw_man_t *rdman, int w, int h) { | |
88 int xcon; | |
89 fd_set rds; | |
90 int nfds; | |
91 struct timeval tmo; | |
41 | 92 mb_timeval_t mb_tmo; |
39 | 93 int r; |
94 | |
95 XSelectInput(display, win, PointerMotionMask | ExposureMask); | |
96 XFlush(display); | |
97 | |
98 xcon = XConnectionNumber(display); | |
99 nfds = xcon + 1; | |
100 while(1) { | |
101 FD_ZERO(&rds); | |
102 FD_SET(xcon, &rds); | |
103 r = gettimeofday(&tmo, NULL); | |
104 if(r == -1) { | |
105 perror("gettimeofday"); | |
106 return; | |
107 } | |
108 | |
41 | 109 MB_TIMEVAL_SET(&mb_tmo, tmo.tv_sec, tmo.tv_usec); |
110 r = mb_tman_next_timeout(tman, &mb_tmo, &mb_tmo); | |
39 | 111 if(r != OK) |
112 r = select(nfds, &rds, NULL, NULL, NULL); | |
41 | 113 else { |
114 tmo.tv_sec = MB_TIMEVAL_SEC(&mb_tmo); | |
115 tmo.tv_usec = MB_TIMEVAL_USEC(&mb_tmo); | |
39 | 116 r = select(nfds, &rds, NULL, NULL, &tmo); |
41 | 117 } |
39 | 118 |
119 if(r == -1) { | |
120 perror("select"); | |
121 return; | |
122 } | |
123 if(r == 0) { | |
124 r = gettimeofday(&tmo, NULL); | |
125 if(r == -1) { | |
126 perror("gettimeofday"); | |
127 return; | |
128 } | |
41 | 129 MB_TIMEVAL_SET(&mb_tmo, tmo.tv_sec, tmo.tv_usec); |
130 mb_tman_handle_timeout(tman, &mb_tmo); | |
42 | 131 rdman_redraw_changed(rdman); |
39 | 132 XFlush(display); |
133 } else if(FD_ISSET(xcon, &rds)) { | |
134 event_interaction(display, rdman, w, h); | |
135 } | |
136 } | |
30
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
137 } |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
138 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
3
diff
changeset
|
139 void draw_path(cairo_t *cr, int w, int h) { |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
140 cairo_t *tmpcr; |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
141 cairo_surface_t *tmpsuf; |
12 | 142 redraw_man_t rdman; |
35
581a03196093
Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents:
33
diff
changeset
|
143 shape_t *path1, *path2, *rect; |
27 | 144 coord_t *coord1, *coord2, *coord3; |
23
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
145 paint_t *fill1, *fill2, *fill3; |
27 | 146 paint_t *stroke, *text_stroke; |
147 shape_t *text; | |
23
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
148 grad_stop_t fill3_stops[3]; |
27 | 149 cairo_font_face_t *face; |
39 | 150 struct test_motion_data mdata; |
151 struct timeval tv; | |
152 mb_tman_t *tman; | |
42 | 153 mb_timeval_t mbtv, start, playing; |
154 mb_progm_t *progm; | |
155 mb_word_t *word; | |
156 mb_action_t *act; | |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
157 int i; |
12 | 158 |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
159 tmpsuf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
160 tmpcr = cairo_create(tmpsuf); |
27 | 161 |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
162 cairo_set_source_surface(cr, tmpsuf, 0, 0); |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
163 redraw_man_init(&rdman, tmpcr, cr); |
19 | 164 coord1 = rdman_coord_new(&rdman, rdman.root_coord); |
165 coord2 = rdman_coord_new(&rdman, rdman.root_coord); | |
27 | 166 coord3 = rdman_coord_new(&rdman, rdman.root_coord); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
3
diff
changeset
|
167 |
21 | 168 fill1 = paint_color_new(&rdman, 1, 1, 0, 0.5); |
169 fill2 = paint_color_new(&rdman, 0, 1, 1, 0.5); | |
22 | 170 stroke = paint_color_new(&rdman, 0.4, 0.4, 0.4, 1); |
27 | 171 text_stroke = paint_color_new(&rdman, 0.5, 0.5, 0.5, 1); |
172 | |
173 face = cairo_get_font_face(tmpcr); | |
174 text = sh_text_new("hello \xe6\xbc\xa2\xe5\xad\x97", 10, h / 4, | |
175 36.0, face); | |
176 rdman_paint_stroke(&rdman, text_stroke, text); | |
177 text->stroke_width = 0.5; | |
178 rdman_add_shape(&rdman, text, coord3); | |
179 | |
19 | 180 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 "); |
181 rdman_paint_fill(&rdman, fill1, path1); | |
22 | 182 rdman_paint_stroke(&rdman, stroke, path1); |
19 | 183 coord1->matrix[0] = 0.8; |
184 coord1->matrix[1] = 0; | |
185 coord1->matrix[2] = 20; | |
186 coord1->matrix[4] = 0.8; | |
187 coord1->matrix[5] = 20; | |
27 | 188 |
19 | 189 path2 = 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 "); |
190 rdman_paint_fill(&rdman, fill2, path2); | |
22 | 191 rdman_paint_stroke(&rdman, stroke, path2); |
19 | 192 coord2->matrix[0] = -0.8; |
193 coord2->matrix[1] = 0; | |
20
74d3d5dc9aaa
rename XXX_draw() to XXX_fill()
Thinker K.F. Li <thinker@branda.to>
parents:
19
diff
changeset
|
194 coord2->matrix[2] = 180; |
19 | 195 coord2->matrix[4] = 0.8; |
196 coord2->matrix[5] = 20; | |
27 | 197 |
19 | 198 rdman_coord_changed(&rdman, coord1); |
199 rdman_coord_changed(&rdman, coord2); | |
200 rdman_add_shape(&rdman, (shape_t *)path1, coord1); | |
201 rdman_add_shape(&rdman, (shape_t *)path2, coord2); | |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
13
diff
changeset
|
202 |
23
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
203 |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
204 fill3 = paint_linear_new(&rdman, 50, 50, 150, 150); |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
205 grad_stop_init(fill3_stops, 0, 1, 0, 0, 0.5); |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
206 grad_stop_init(fill3_stops + 1, 0.5, 0, 1, 0, 0.5); |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
207 grad_stop_init(fill3_stops + 2, 1, 0, 0, 1, 0.5); |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
208 paint_linear_stops(fill3, 3, fill3_stops); |
35
581a03196093
Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents:
33
diff
changeset
|
209 rect = sh_rect_new(50, 50, 100, 100, 20, 20); |
581a03196093
Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents:
33
diff
changeset
|
210 rdman_paint_fill(&rdman, fill3, rect); |
581a03196093
Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents:
33
diff
changeset
|
211 rdman_add_shape(&rdman, (shape_t *)rect, rdman.root_coord); |
23
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
212 |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
13
diff
changeset
|
213 rdman_redraw_all(&rdman); |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
13
diff
changeset
|
214 |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
215 XFlush(display); |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
216 |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
217 for(i = 0; i < 50; i++) { |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
218 usleep(20000); |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
219 path1->stroke_width = i / 10; |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
220 path2->stroke_width = i / 10; |
19 | 221 coord1->matrix[2] += 1; |
222 coord1->matrix[5] += 1; | |
223 coord2->matrix[2] -= 1; | |
224 coord2->matrix[5] += 1; | |
21 | 225 paint_color_set(fill1, 1, 1, (i/25) & 0x1, 0.5); |
226 paint_color_set(fill2, (i/25) & 0x1, 1, 1, 0.5); | |
19 | 227 rdman_paint_changed(&rdman, fill1); |
228 rdman_paint_changed(&rdman, fill2); | |
229 rdman_coord_changed(&rdman, coord1); | |
230 rdman_coord_changed(&rdman, coord2); | |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
231 rdman_redraw_changed(&rdman); |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
232 XFlush(display); |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
233 } |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
234 |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
235 for(i = 0; i < 5; i++) { |
31
da770188a44d
resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
236 usleep(100000); |
21 | 237 paint_color_set(fill1, 1, i % 2, 0, 0.5); |
238 paint_color_set(fill2, 0, i % 2, 1, 0.5); | |
19 | 239 rdman_paint_changed(&rdman, fill1); |
240 rdman_paint_changed(&rdman, fill2); | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
241 rdman_redraw_changed(&rdman); |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
242 XFlush(display); |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
243 } |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
244 |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
245 for(i = 0; i < 4; i++) { |
31
da770188a44d
resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
246 usleep(100000); |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
247 path1->stroke_width -= 1; |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
248 path2->stroke_width -= 1; |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
249 rdman_shape_changed(&rdman, path1); |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
250 rdman_shape_changed(&rdman, path2); |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
251 rdman_redraw_changed(&rdman); |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
252 XFlush(display); |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
253 } |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
254 for(i = 0; i < 4; i++) { |
31
da770188a44d
resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
255 usleep(100000); |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
256 path1->stroke_width += 1; |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
257 path2->stroke_width += 1; |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
258 rdman_shape_changed(&rdman, path1); |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
259 rdman_shape_changed(&rdman, path2); |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
260 rdman_redraw_changed(&rdman); |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
261 XFlush(display); |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
262 } |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
263 |
27 | 264 for(i = 0; i < 4; i++) { |
31
da770188a44d
resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
265 usleep(100000); |
27 | 266 text->stroke_width += 1; |
267 rdman_shape_changed(&rdman, text); | |
268 coord3->matrix[2] += 5; | |
269 rdman_coord_changed(&rdman, coord3); | |
270 rdman_redraw_changed(&rdman); | |
271 XFlush(display); | |
272 } | |
273 for(i = 0; i < 4; i++) { | |
31
da770188a44d
resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
274 usleep(100000); |
27 | 275 text->stroke_width -= 1; |
276 rdman_shape_changed(&rdman, text); | |
277 coord3->matrix[2] -= 5; | |
278 rdman_coord_changed(&rdman, coord3); | |
279 rdman_redraw_changed(&rdman); | |
280 XFlush(display); | |
281 } | |
282 | |
283 for(i = 0; i < 4; i++) { | |
31
da770188a44d
resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
284 usleep(100000); |
27 | 285 text->stroke_width += 1; |
286 rdman_shape_changed(&rdman, text); | |
287 coord3->matrix[5] += 5; | |
288 rdman_coord_changed(&rdman, coord3); | |
289 rdman_redraw_changed(&rdman); | |
290 XFlush(display); | |
291 } | |
292 for(i = 0; i < 4; i++) { | |
31
da770188a44d
resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
293 usleep(100000); |
27 | 294 text->stroke_width -= 1; |
295 rdman_shape_changed(&rdman, text); | |
296 coord3->matrix[5] -= 5; | |
297 rdman_coord_changed(&rdman, coord3); | |
298 rdman_redraw_changed(&rdman); | |
299 XFlush(display); | |
300 } | |
301 | |
39 | 302 tman = mb_tman_new(); |
303 if(tman) { | |
42 | 304 progm = mb_progm_new(2, &rdman); |
305 | |
306 MB_TIMEVAL_SET(&start, 1, 0); | |
307 MB_TIMEVAL_SET(&playing, 2, 0); | |
308 word = mb_progm_next_word(progm, &start, &playing); | |
47
f3818d996f4f
change interface of creating a animation action
Thinker K.F. Li <thinker@branda.to>
parents:
44
diff
changeset
|
309 act = mb_shift_new(0, 20, coord1, word); |
42 | 310 |
311 MB_TIMEVAL_SET(&start, 3, 0); | |
312 MB_TIMEVAL_SET(&playing, 2, 0); | |
47
f3818d996f4f
change interface of creating a animation action
Thinker K.F. Li <thinker@branda.to>
parents:
44
diff
changeset
|
313 act = mb_shift_new(0, 20, coord2, word); |
44
7d9af44f095b
Demo of concurrent words
Thinker K.F. Li <thinker@branda.to>
parents:
42
diff
changeset
|
314 |
7d9af44f095b
Demo of concurrent words
Thinker K.F. Li <thinker@branda.to>
parents:
42
diff
changeset
|
315 MB_TIMEVAL_SET(&start, 3, 0); |
7d9af44f095b
Demo of concurrent words
Thinker K.F. Li <thinker@branda.to>
parents:
42
diff
changeset
|
316 MB_TIMEVAL_SET(&playing, 2, 0); |
42 | 317 word = mb_progm_next_word(progm, &start, &playing); |
47
f3818d996f4f
change interface of creating a animation action
Thinker K.F. Li <thinker@branda.to>
parents:
44
diff
changeset
|
318 act = mb_shift_new(0, -20, coord1, word); |
44
7d9af44f095b
Demo of concurrent words
Thinker K.F. Li <thinker@branda.to>
parents:
42
diff
changeset
|
319 |
7d9af44f095b
Demo of concurrent words
Thinker K.F. Li <thinker@branda.to>
parents:
42
diff
changeset
|
320 MB_TIMEVAL_SET(&start, 3, 0); |
7d9af44f095b
Demo of concurrent words
Thinker K.F. Li <thinker@branda.to>
parents:
42
diff
changeset
|
321 MB_TIMEVAL_SET(&playing, 2, 0); |
47
f3818d996f4f
change interface of creating a animation action
Thinker K.F. Li <thinker@branda.to>
parents:
44
diff
changeset
|
322 act = mb_shift_new(0, -20, coord2, word); |
42 | 323 |
324 gettimeofday(&tv, NULL); | |
325 MB_TIMEVAL_SET(&mbtv, tv.tv_sec, tv.tv_usec); | |
326 mb_progm_start(progm, tman, &mbtv); | |
327 | |
39 | 328 mdata.text_stroke = text_stroke; |
329 mdata.rdman = &rdman; | |
330 gettimeofday(&tv, NULL); | |
331 tv.tv_sec += 3; | |
41 | 332 MB_TIMEVAL_SET(&mbtv, tv.tv_sec, tv.tv_usec); |
333 mb_tman_timeout(tman, &mbtv, test_motion, &mdata); | |
39 | 334 |
335 handle_connection(display, tman, &rdman, w, h); | |
41 | 336 |
39 | 337 mb_tman_free(tman); |
338 } | |
30
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
27
diff
changeset
|
339 |
19 | 340 fill1->free(fill1); |
341 fill2->free(fill2); | |
27 | 342 stroke->free(stroke); |
343 text_stroke->free(text_stroke); | |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
13
diff
changeset
|
344 redraw_man_destroy(&rdman); |
19 | 345 sh_path_free(path1); |
346 sh_path_free(path2); | |
35
581a03196093
Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents:
33
diff
changeset
|
347 sh_rect_free(rect); |
27 | 348 sh_text_free(text); |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
349 cairo_destroy(tmpcr); |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
350 cairo_surface_destroy(tmpsuf); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
3
diff
changeset
|
351 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
3
diff
changeset
|
352 |
3
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
353 void drawing(cairo_surface_t *surface, int w, int h) { |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
354 cairo_t *cr; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
355 |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
356 cr = cairo_create(surface); |
7
569f3168ba53
Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents:
6
diff
changeset
|
357 cairo_set_source_rgb(cr, 0, 0, 0); |
569f3168ba53
Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents:
6
diff
changeset
|
358 cairo_paint(cr); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
3
diff
changeset
|
359 draw_path(cr, w, h); |
27 | 360 cairo_destroy(cr); |
3
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
361 } |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
362 |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
363 int |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
364 main(int argc, char * const argv[]) { |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
365 Window root; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
366 Visual *visual; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
367 int screen; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
368 XSetWindowAttributes wattr; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
369 int depth; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
370 cairo_surface_t *surface; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
371 int w, h; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
372 int x, y; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
373 int r; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
374 |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
375 display = XOpenDisplay(":0.0"); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
376 if(display == NULL) |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
377 printf("XOpenDisplay\n"); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
378 screen = DefaultScreen(display); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
379 root = DefaultRootWindow(display); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
380 visual = DefaultVisual(display, screen); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
381 depth = DefaultDepth(display, screen); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
382 wattr.override_redirect = False; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
383 x = 10; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
384 y = 10; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
385 w = 200; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
386 h = 200; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
387 win = XCreateWindow(display, root, |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
388 x, y, |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
389 w, h, |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
390 1, depth, InputOutput, visual, |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
391 CWOverrideRedirect, &wattr); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
392 r = XMapWindow(display, win); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
393 |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
394 surface = cairo_xlib_surface_create(display, win, visual, w, h); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
395 if(surface == NULL) |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
396 printf("cairo_xlib_surface_create\n"); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
397 |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
398 drawing(surface, w, h); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
399 |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
400 XFlush(display); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
401 sleep(10); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
402 |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
403 XCloseDisplay(display); |
10 | 404 return 0; |
3
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
405 } |