[cairo-commit] [cairo-www] src/samples
Carl Worth
cworth at freedesktop.org
Wed Feb 17 12:22:52 PST 2010
src/samples/rounded_rectangle.mdwn | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
New commits:
commit 30eec41ef86bb45c662e27fa821519e0c2da9dab
Author: mccann <mccann at web>
Date: Wed Feb 17 12:22:52 2010 -0800
Add rounded rectangle sample
diff --git a/src/samples/rounded_rectangle.mdwn b/src/samples/rounded_rectangle.mdwn
new file mode 100644
index 0000000..1729e25
--- /dev/null
+++ b/src/samples/rounded_rectangle.mdwn
@@ -0,0 +1,29 @@
+<div class="tutright">[[!img "rounded_rectangle.png" link="no"]]</div>
+ /* a custom shape that could be wrapped in a function */
+ double x0 = 25.6, /* parameters like cairo_rectangle */
+ y0 = 25.6,
+ width = 204.8,
+ height = 204.8,
+ aspect = 1.0, /* aspect ratio */
+ corner_radius = height / 10.0; /* and corner curvature radius */
+
+ double radius = corner_radius / aspect;
+
+ cairo_move_to (cr, x + radius, y);
+
+ cairo_line_to (cr, x + width - radius, y);
+ cairo_arc (cr, x + width - radius, y + radius, radius, -90.0 * M_PI / 180.0, 0.0);
+ cairo_line_to (cr, x + width, y + height - radius);
+ cairo_arc (cr, x + width - radius, y + height - radius, radius, 0.0, 90.0 * M_PI / 180.0);
+ cairo_line_to (cr, x + radius, y + height);
+ cairo_arc (cr, x + radius, y + height - radius, radius, 90.0 * M_PI / 180.0, 180.0 * M_PI / 180.0);
+ cairo_line_to (cr, x, y + radius);
+ cairo_arc (cr, x + radius, y + radius, radius, 180.0 * M_PI / 180.0f, 270.0 * M_PI / 180.0);
+ cairo_close_path (cr);
+
+
+ cairo_set_source_rgb (cr, 0.5, 0.5, 1);
+ cairo_fill_preserve (cr);
+ cairo_set_source_rgba (cr, 0.5, 0, 0, 0.5);
+ cairo_set_line_width (cr, 10.0);
+ cairo_stroke (cr);
More information about the cairo-commit
mailing list