Mercurial > MadButterfly
diff 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 |
line wrap: on
line diff
--- a/src/X_main.c Sun Aug 03 13:04:55 2008 +0800 +++ b/src/X_main.c Mon Aug 04 10:10:47 2008 +0800 @@ -17,22 +17,35 @@ cairo_surface_t *tmpsuf; redraw_man_t rdman; shape_t *path1, *path2, *path3; - coord_t *coord1, *coord2; + coord_t *coord1, *coord2, *coord3; paint_t *fill1, *fill2, *fill3; - paint_t *stroke; + paint_t *stroke, *text_stroke; + shape_t *text; grad_stop_t fill3_stops[3]; + cairo_font_face_t *face; int i; tmpsuf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); tmpcr = cairo_create(tmpsuf); + cairo_set_source_surface(cr, tmpsuf, 0, 0); redraw_man_init(&rdman, tmpcr, cr); coord1 = rdman_coord_new(&rdman, rdman.root_coord); coord2 = rdman_coord_new(&rdman, rdman.root_coord); + coord3 = rdman_coord_new(&rdman, rdman.root_coord); fill1 = paint_color_new(&rdman, 1, 1, 0, 0.5); fill2 = paint_color_new(&rdman, 0, 1, 1, 0.5); stroke = paint_color_new(&rdman, 0.4, 0.4, 0.4, 1); + text_stroke = paint_color_new(&rdman, 0.5, 0.5, 0.5, 1); + + face = cairo_get_font_face(tmpcr); + text = sh_text_new("hello \xe6\xbc\xa2\xe5\xad\x97", 10, h / 4, + 36.0, face); + rdman_paint_stroke(&rdman, text_stroke, text); + text->stroke_width = 0.5; + rdman_add_shape(&rdman, text, coord3); + 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 "); rdman_paint_fill(&rdman, fill1, path1); rdman_paint_stroke(&rdman, stroke, path1); @@ -41,6 +54,7 @@ coord1->matrix[2] = 20; coord1->matrix[4] = 0.8; coord1->matrix[5] = 20; + 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 "); rdman_paint_fill(&rdman, fill2, path2); rdman_paint_stroke(&rdman, stroke, path2); @@ -49,6 +63,7 @@ coord2->matrix[2] = 180; coord2->matrix[4] = 0.8; coord2->matrix[5] = 20; + rdman_coord_changed(&rdman, coord1); rdman_coord_changed(&rdman, coord2); rdman_add_shape(&rdman, (shape_t *)path1, coord1); @@ -115,11 +130,52 @@ XFlush(display); } + for(i = 0; i < 4; i++) { + usleep(500000); + text->stroke_width += 1; + rdman_shape_changed(&rdman, text); + coord3->matrix[2] += 5; + rdman_coord_changed(&rdman, coord3); + rdman_redraw_changed(&rdman); + XFlush(display); + } + for(i = 0; i < 4; i++) { + usleep(500000); + text->stroke_width -= 1; + rdman_shape_changed(&rdman, text); + coord3->matrix[2] -= 5; + rdman_coord_changed(&rdman, coord3); + rdman_redraw_changed(&rdman); + XFlush(display); + } + + for(i = 0; i < 4; i++) { + usleep(500000); + text->stroke_width += 1; + rdman_shape_changed(&rdman, text); + coord3->matrix[5] += 5; + rdman_coord_changed(&rdman, coord3); + rdman_redraw_changed(&rdman); + XFlush(display); + } + for(i = 0; i < 4; i++) { + usleep(500000); + text->stroke_width -= 1; + rdman_shape_changed(&rdman, text); + coord3->matrix[5] -= 5; + rdman_coord_changed(&rdman, coord3); + rdman_redraw_changed(&rdman); + XFlush(display); + } + fill1->free(fill1); fill2->free(fill2); + stroke->free(stroke); + text_stroke->free(text_stroke); redraw_man_destroy(&rdman); sh_path_free(path1); sh_path_free(path2); + sh_text_free(text); cairo_destroy(tmpcr); cairo_surface_destroy(tmpsuf); } @@ -130,14 +186,8 @@ cr = cairo_create(surface); cairo_set_source_rgb(cr, 0, 0, 0); cairo_paint(cr); - cairo_set_source_rgb(cr, 0.9, 0.1, 0.1); draw_path(cr, w, h); - cairo_set_source_rgb(cr, 0.5, 0.9, 0.8); - cairo_move_to(cr, 10, h / 2); - cairo_set_font_size(cr, 36.0); - cairo_text_path(cr, "hello \xe6\xbc\xa2\xe5\xad\x97"); - cairo_set_line_width(cr, 2); - cairo_stroke(cr); + cairo_destroy(cr); } int