Mercurial > MadButterfly
annotate src/X_main.c @ 33:d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
- logical error in X_main.c.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 06 Aug 2008 00:40:04 +0800 |
parents | 69c8e264890d |
children | 581a03196093 |
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> |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
3 #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
|
4 #include <X11/Xutil.h> |
3
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
5 #include <cairo.h> |
10 | 6 #include <cairo-xlib.h> |
3
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
7 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
3
diff
changeset
|
8 #include <string.h> |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
3
diff
changeset
|
9 #include "shapes.h" |
12 | 10 #include "redraw_man.h" |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
11 #include "paint.h" |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
3
diff
changeset
|
12 |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
13 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
|
14 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
|
15 |
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
|
16 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
|
17 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
|
18 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
|
19 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
|
20 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
|
21 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
|
22 } |
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
|
23 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
|
24 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
|
25 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
|
26 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
|
27 } |
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
|
28 } |
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
|
29 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
|
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
|
31 |
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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 |
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 XSelectInput(display, win, PointerMotionMask); |
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 while((r = XNextEvent(display, &evt)) == 0) { |
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 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 break; |
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 } |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
54 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
3
diff
changeset
|
55 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
|
56 cairo_t *tmpcr; |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
57 cairo_surface_t *tmpsuf; |
12 | 58 redraw_man_t rdman; |
23
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
59 shape_t *path1, *path2, *path3; |
27 | 60 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
|
61 paint_t *fill1, *fill2, *fill3; |
27 | 62 paint_t *stroke, *text_stroke; |
63 shape_t *text; | |
23
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
64 grad_stop_t fill3_stops[3]; |
27 | 65 cairo_font_face_t *face; |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
66 int i; |
12 | 67 |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
68 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
|
69 tmpcr = cairo_create(tmpsuf); |
27 | 70 |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
71 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
|
72 redraw_man_init(&rdman, tmpcr, cr); |
19 | 73 coord1 = rdman_coord_new(&rdman, rdman.root_coord); |
74 coord2 = rdman_coord_new(&rdman, rdman.root_coord); | |
27 | 75 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
|
76 |
21 | 77 fill1 = paint_color_new(&rdman, 1, 1, 0, 0.5); |
78 fill2 = paint_color_new(&rdman, 0, 1, 1, 0.5); | |
22 | 79 stroke = paint_color_new(&rdman, 0.4, 0.4, 0.4, 1); |
27 | 80 text_stroke = paint_color_new(&rdman, 0.5, 0.5, 0.5, 1); |
81 | |
82 face = cairo_get_font_face(tmpcr); | |
83 text = sh_text_new("hello \xe6\xbc\xa2\xe5\xad\x97", 10, h / 4, | |
84 36.0, face); | |
85 rdman_paint_stroke(&rdman, text_stroke, text); | |
86 text->stroke_width = 0.5; | |
87 rdman_add_shape(&rdman, text, coord3); | |
88 | |
19 | 89 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 "); |
90 rdman_paint_fill(&rdman, fill1, path1); | |
22 | 91 rdman_paint_stroke(&rdman, stroke, path1); |
19 | 92 coord1->matrix[0] = 0.8; |
93 coord1->matrix[1] = 0; | |
94 coord1->matrix[2] = 20; | |
95 coord1->matrix[4] = 0.8; | |
96 coord1->matrix[5] = 20; | |
27 | 97 |
19 | 98 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 "); |
99 rdman_paint_fill(&rdman, fill2, path2); | |
22 | 100 rdman_paint_stroke(&rdman, stroke, path2); |
19 | 101 coord2->matrix[0] = -0.8; |
102 coord2->matrix[1] = 0; | |
20
74d3d5dc9aaa
rename XXX_draw() to XXX_fill()
Thinker K.F. Li <thinker@branda.to>
parents:
19
diff
changeset
|
103 coord2->matrix[2] = 180; |
19 | 104 coord2->matrix[4] = 0.8; |
105 coord2->matrix[5] = 20; | |
27 | 106 |
19 | 107 rdman_coord_changed(&rdman, coord1); |
108 rdman_coord_changed(&rdman, coord2); | |
109 rdman_add_shape(&rdman, (shape_t *)path1, coord1); | |
110 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
|
111 |
23
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
112 |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
113 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
|
114 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
|
115 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
|
116 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
|
117 paint_linear_stops(fill3, 3, fill3_stops); |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
118 path3 = sh_path_new("M 50,50 L 50,150 L 150,150 L 150,50 z"); |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
119 rdman_paint_fill(&rdman, fill3, path3); |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
120 rdman_add_shape(&rdman, (shape_t *)path3, rdman.root_coord); |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
121 |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
13
diff
changeset
|
122 rdman_redraw_all(&rdman); |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
13
diff
changeset
|
123 |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
124 XFlush(display); |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
125 |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
126 for(i = 0; i < 50; i++) { |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
127 usleep(20000); |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
128 path1->stroke_width = i / 10; |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
129 path2->stroke_width = i / 10; |
19 | 130 coord1->matrix[2] += 1; |
131 coord1->matrix[5] += 1; | |
132 coord2->matrix[2] -= 1; | |
133 coord2->matrix[5] += 1; | |
21 | 134 paint_color_set(fill1, 1, 1, (i/25) & 0x1, 0.5); |
135 paint_color_set(fill2, (i/25) & 0x1, 1, 1, 0.5); | |
19 | 136 rdman_paint_changed(&rdman, fill1); |
137 rdman_paint_changed(&rdman, fill2); | |
138 rdman_coord_changed(&rdman, coord1); | |
139 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
|
140 rdman_redraw_changed(&rdman); |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
141 XFlush(display); |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
142 } |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
143 |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
144 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
|
145 usleep(100000); |
21 | 146 paint_color_set(fill1, 1, i % 2, 0, 0.5); |
147 paint_color_set(fill2, 0, i % 2, 1, 0.5); | |
19 | 148 rdman_paint_changed(&rdman, fill1); |
149 rdman_paint_changed(&rdman, fill2); | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
150 rdman_redraw_changed(&rdman); |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
151 XFlush(display); |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
152 } |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
153 |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
154 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
|
155 usleep(100000); |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
156 path1->stroke_width -= 1; |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
157 path2->stroke_width -= 1; |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
158 rdman_shape_changed(&rdman, path1); |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
159 rdman_shape_changed(&rdman, path2); |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
160 rdman_redraw_changed(&rdman); |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
161 XFlush(display); |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
162 } |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
163 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
|
164 usleep(100000); |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
165 path1->stroke_width += 1; |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
166 path2->stroke_width += 1; |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
167 rdman_shape_changed(&rdman, path1); |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
168 rdman_shape_changed(&rdman, path2); |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
169 rdman_redraw_changed(&rdman); |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
170 XFlush(display); |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
171 } |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
172 |
27 | 173 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
|
174 usleep(100000); |
27 | 175 text->stroke_width += 1; |
176 rdman_shape_changed(&rdman, text); | |
177 coord3->matrix[2] += 5; | |
178 rdman_coord_changed(&rdman, coord3); | |
179 rdman_redraw_changed(&rdman); | |
180 XFlush(display); | |
181 } | |
182 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
|
183 usleep(100000); |
27 | 184 text->stroke_width -= 1; |
185 rdman_shape_changed(&rdman, text); | |
186 coord3->matrix[2] -= 5; | |
187 rdman_coord_changed(&rdman, coord3); | |
188 rdman_redraw_changed(&rdman); | |
189 XFlush(display); | |
190 } | |
191 | |
192 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
|
193 usleep(100000); |
27 | 194 text->stroke_width += 1; |
195 rdman_shape_changed(&rdman, text); | |
196 coord3->matrix[5] += 5; | |
197 rdman_coord_changed(&rdman, coord3); | |
198 rdman_redraw_changed(&rdman); | |
199 XFlush(display); | |
200 } | |
201 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
|
202 usleep(100000); |
27 | 203 text->stroke_width -= 1; |
204 rdman_shape_changed(&rdman, text); | |
205 coord3->matrix[5] -= 5; | |
206 rdman_coord_changed(&rdman, coord3); | |
207 rdman_redraw_changed(&rdman); | |
208 XFlush(display); | |
209 } | |
210 | |
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
|
211 event_interaction(display, &rdman, w, 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
|
212 |
19 | 213 fill1->free(fill1); |
214 fill2->free(fill2); | |
27 | 215 stroke->free(stroke); |
216 text_stroke->free(text_stroke); | |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
13
diff
changeset
|
217 redraw_man_destroy(&rdman); |
19 | 218 sh_path_free(path1); |
219 sh_path_free(path2); | |
27 | 220 sh_text_free(text); |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
221 cairo_destroy(tmpcr); |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
222 cairo_surface_destroy(tmpsuf); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
3
diff
changeset
|
223 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
3
diff
changeset
|
224 |
3
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
225 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
|
226 cairo_t *cr; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
227 |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
228 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
|
229 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
|
230 cairo_paint(cr); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
3
diff
changeset
|
231 draw_path(cr, w, h); |
27 | 232 cairo_destroy(cr); |
3
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
233 } |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
234 |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
235 int |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
236 main(int argc, char * const argv[]) { |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
237 Window root; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
238 Visual *visual; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
239 int screen; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
240 XSetWindowAttributes wattr; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
241 int depth; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
242 cairo_surface_t *surface; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
243 int w, h; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
244 int x, y; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
245 int r; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
246 |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
247 display = XOpenDisplay(":0.0"); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
248 if(display == NULL) |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
249 printf("XOpenDisplay\n"); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
250 screen = DefaultScreen(display); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
251 root = DefaultRootWindow(display); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
252 visual = DefaultVisual(display, screen); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
253 depth = DefaultDepth(display, screen); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
254 wattr.override_redirect = False; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
255 x = 10; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
256 y = 10; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
257 w = 200; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
258 h = 200; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
259 win = XCreateWindow(display, root, |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
260 x, y, |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
261 w, h, |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
262 1, depth, InputOutput, visual, |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
263 CWOverrideRedirect, &wattr); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
264 r = XMapWindow(display, win); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
265 |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
266 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
|
267 if(surface == NULL) |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
268 printf("cairo_xlib_surface_create\n"); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
269 |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
270 drawing(surface, w, h); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
271 |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
272 XFlush(display); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
273 sleep(10); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
274 |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
275 XCloseDisplay(display); |
10 | 276 return 0; |
3
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
277 } |