comparison src/X_main.c @ 27:19c603dd6ff9

Add text shape.
author Thinker K.F. Li <thinker@branda.to>
date Mon, 04 Aug 2008 10:10:47 +0800
parents d50f33040de6
children e06a4a667ce2
comparison
equal deleted inserted replaced
26:d50f33040de6 27:19c603dd6ff9
15 void draw_path(cairo_t *cr, int w, int h) { 15 void draw_path(cairo_t *cr, int w, int h) {
16 cairo_t *tmpcr; 16 cairo_t *tmpcr;
17 cairo_surface_t *tmpsuf; 17 cairo_surface_t *tmpsuf;
18 redraw_man_t rdman; 18 redraw_man_t rdman;
19 shape_t *path1, *path2, *path3; 19 shape_t *path1, *path2, *path3;
20 coord_t *coord1, *coord2; 20 coord_t *coord1, *coord2, *coord3;
21 paint_t *fill1, *fill2, *fill3; 21 paint_t *fill1, *fill2, *fill3;
22 paint_t *stroke; 22 paint_t *stroke, *text_stroke;
23 shape_t *text;
23 grad_stop_t fill3_stops[3]; 24 grad_stop_t fill3_stops[3];
25 cairo_font_face_t *face;
24 int i; 26 int i;
25 27
26 tmpsuf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); 28 tmpsuf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
27 tmpcr = cairo_create(tmpsuf); 29 tmpcr = cairo_create(tmpsuf);
30
28 cairo_set_source_surface(cr, tmpsuf, 0, 0); 31 cairo_set_source_surface(cr, tmpsuf, 0, 0);
29 redraw_man_init(&rdman, tmpcr, cr); 32 redraw_man_init(&rdman, tmpcr, cr);
30 coord1 = rdman_coord_new(&rdman, rdman.root_coord); 33 coord1 = rdman_coord_new(&rdman, rdman.root_coord);
31 coord2 = rdman_coord_new(&rdman, rdman.root_coord); 34 coord2 = rdman_coord_new(&rdman, rdman.root_coord);
35 coord3 = rdman_coord_new(&rdman, rdman.root_coord);
32 36
33 fill1 = paint_color_new(&rdman, 1, 1, 0, 0.5); 37 fill1 = paint_color_new(&rdman, 1, 1, 0, 0.5);
34 fill2 = paint_color_new(&rdman, 0, 1, 1, 0.5); 38 fill2 = paint_color_new(&rdman, 0, 1, 1, 0.5);
35 stroke = paint_color_new(&rdman, 0.4, 0.4, 0.4, 1); 39 stroke = paint_color_new(&rdman, 0.4, 0.4, 0.4, 1);
40 text_stroke = paint_color_new(&rdman, 0.5, 0.5, 0.5, 1);
41
42 face = cairo_get_font_face(tmpcr);
43 text = sh_text_new("hello \xe6\xbc\xa2\xe5\xad\x97", 10, h / 4,
44 36.0, face);
45 rdman_paint_stroke(&rdman, text_stroke, text);
46 text->stroke_width = 0.5;
47 rdman_add_shape(&rdman, text, coord3);
48
36 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 "); 49 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 ");
37 rdman_paint_fill(&rdman, fill1, path1); 50 rdman_paint_fill(&rdman, fill1, path1);
38 rdman_paint_stroke(&rdman, stroke, path1); 51 rdman_paint_stroke(&rdman, stroke, path1);
39 coord1->matrix[0] = 0.8; 52 coord1->matrix[0] = 0.8;
40 coord1->matrix[1] = 0; 53 coord1->matrix[1] = 0;
41 coord1->matrix[2] = 20; 54 coord1->matrix[2] = 20;
42 coord1->matrix[4] = 0.8; 55 coord1->matrix[4] = 0.8;
43 coord1->matrix[5] = 20; 56 coord1->matrix[5] = 20;
57
44 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 "); 58 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 ");
45 rdman_paint_fill(&rdman, fill2, path2); 59 rdman_paint_fill(&rdman, fill2, path2);
46 rdman_paint_stroke(&rdman, stroke, path2); 60 rdman_paint_stroke(&rdman, stroke, path2);
47 coord2->matrix[0] = -0.8; 61 coord2->matrix[0] = -0.8;
48 coord2->matrix[1] = 0; 62 coord2->matrix[1] = 0;
49 coord2->matrix[2] = 180; 63 coord2->matrix[2] = 180;
50 coord2->matrix[4] = 0.8; 64 coord2->matrix[4] = 0.8;
51 coord2->matrix[5] = 20; 65 coord2->matrix[5] = 20;
66
52 rdman_coord_changed(&rdman, coord1); 67 rdman_coord_changed(&rdman, coord1);
53 rdman_coord_changed(&rdman, coord2); 68 rdman_coord_changed(&rdman, coord2);
54 rdman_add_shape(&rdman, (shape_t *)path1, coord1); 69 rdman_add_shape(&rdman, (shape_t *)path1, coord1);
55 rdman_add_shape(&rdman, (shape_t *)path2, coord2); 70 rdman_add_shape(&rdman, (shape_t *)path2, coord2);
56 71
113 rdman_shape_changed(&rdman, path2); 128 rdman_shape_changed(&rdman, path2);
114 rdman_redraw_changed(&rdman); 129 rdman_redraw_changed(&rdman);
115 XFlush(display); 130 XFlush(display);
116 } 131 }
117 132
133 for(i = 0; i < 4; i++) {
134 usleep(500000);
135 text->stroke_width += 1;
136 rdman_shape_changed(&rdman, text);
137 coord3->matrix[2] += 5;
138 rdman_coord_changed(&rdman, coord3);
139 rdman_redraw_changed(&rdman);
140 XFlush(display);
141 }
142 for(i = 0; i < 4; i++) {
143 usleep(500000);
144 text->stroke_width -= 1;
145 rdman_shape_changed(&rdman, text);
146 coord3->matrix[2] -= 5;
147 rdman_coord_changed(&rdman, coord3);
148 rdman_redraw_changed(&rdman);
149 XFlush(display);
150 }
151
152 for(i = 0; i < 4; i++) {
153 usleep(500000);
154 text->stroke_width += 1;
155 rdman_shape_changed(&rdman, text);
156 coord3->matrix[5] += 5;
157 rdman_coord_changed(&rdman, coord3);
158 rdman_redraw_changed(&rdman);
159 XFlush(display);
160 }
161 for(i = 0; i < 4; i++) {
162 usleep(500000);
163 text->stroke_width -= 1;
164 rdman_shape_changed(&rdman, text);
165 coord3->matrix[5] -= 5;
166 rdman_coord_changed(&rdman, coord3);
167 rdman_redraw_changed(&rdman);
168 XFlush(display);
169 }
170
118 fill1->free(fill1); 171 fill1->free(fill1);
119 fill2->free(fill2); 172 fill2->free(fill2);
173 stroke->free(stroke);
174 text_stroke->free(text_stroke);
120 redraw_man_destroy(&rdman); 175 redraw_man_destroy(&rdman);
121 sh_path_free(path1); 176 sh_path_free(path1);
122 sh_path_free(path2); 177 sh_path_free(path2);
178 sh_text_free(text);
123 cairo_destroy(tmpcr); 179 cairo_destroy(tmpcr);
124 cairo_surface_destroy(tmpsuf); 180 cairo_surface_destroy(tmpsuf);
125 } 181 }
126 182
127 void drawing(cairo_surface_t *surface, int w, int h) { 183 void drawing(cairo_surface_t *surface, int w, int h) {
128 cairo_t *cr; 184 cairo_t *cr;
129 185
130 cr = cairo_create(surface); 186 cr = cairo_create(surface);
131 cairo_set_source_rgb(cr, 0, 0, 0); 187 cairo_set_source_rgb(cr, 0, 0, 0);
132 cairo_paint(cr); 188 cairo_paint(cr);
133 cairo_set_source_rgb(cr, 0.9, 0.1, 0.1);
134 draw_path(cr, w, h); 189 draw_path(cr, w, h);
135 cairo_set_source_rgb(cr, 0.5, 0.9, 0.8); 190 cairo_destroy(cr);
136 cairo_move_to(cr, 10, h / 2);
137 cairo_set_font_size(cr, 36.0);
138 cairo_text_path(cr, "hello \xe6\xbc\xa2\xe5\xad\x97");
139 cairo_set_line_width(cr, 2);
140 cairo_stroke(cr);
141 } 191 }
142 192
143 int 193 int
144 main(int argc, char * const argv[]) { 194 main(int argc, char * const argv[]) {
145 Window root; 195 Window root;