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