[cairo-commit] [cairo-www] src/samples

M. Joonas Pihlaja joonas at freedesktop.org
Wed Feb 17 13:32:32 PST 2010


 src/samples/rounded_rectangle.mdwn |   43 ++++++++++++++++---------------------
 1 file changed, 19 insertions(+), 24 deletions(-)

New commits:
commit 43a92186048d6d342047ac49ee561b407c623ee0
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date:   Wed Feb 17 23:18:02 2010 +0200

    [samples] Trimmed the rounded_rectangles code.
    
    The move_to and line_to commands are redundant when
    using cairo_arc() since it does an implicit line_to
    to the start of the arc.  When there's no current
    point the first line_to gets converted to a move_to,
    so that's gone as well.

diff --git a/src/samples/rounded_rectangle.mdwn b/src/samples/rounded_rectangle.mdwn
index 9849132..0d7784c 100644
--- a/src/samples/rounded_rectangle.mdwn
+++ b/src/samples/rounded_rectangle.mdwn
@@ -1,29 +1,24 @@
 <div class="tutright">[[!img "rounded_rectangle.png" link="no"]]</div>
 	/* a custom shape that could be wrapped in a function */
-        double x             = 25.6,            /* parameters like cairo_rectangle */
-               y             = 25.6,
-               width         = 204.8,
-               height        = 204.8,
-               aspect        = 1.0,             /* aspect ratio */
-               corner_radius = height / 10.0;   /* and corner curvature radius */
+	double x	     = 25.6,		/* parameters like cairo_rectangle */
+	       y	     = 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;
+	double radius = corner_radius / aspect;
+	double degrees = M_PI / 180.0;
 
-        cairo_move_to (cr, x + radius, y);
+	cairo_new_sub_path (cr);
+	cairo_arc (cr, x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees);
+	cairo_arc (cr, x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees);
+	cairo_arc (cr, x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees);
+	cairo_arc (cr, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
+	cairo_close_path (cr);
 
-        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);
+	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