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