Bug 24442 - New cairo_path_t method - cairo_rounded_rectangle
Summary: New cairo_path_t method - cairo_rounded_rectangle
Status: RESOLVED WONTFIX
Alias: None
Product: cairo
Classification: Unclassified
Component: general (show other bugs)
Version: 1.8.8
Hardware: Other All
: medium normal
Assignee: Carl Worth
QA Contact: cairo-bugs mailing list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-10 08:09 UTC by Kevin DeKorte
Modified: 2009-10-26 05:28 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Kevin DeKorte 2009-10-10 08:09:12 UTC
Please add the following cairo_path_t method to cairo.

void cairo_rounded_rectangle(cairo_t *cr, double x, double y, double width, double height, double radius)
{

	cairo_new_sub_path(cr);
	cairo_arc(cr, x + radius, y + height - radius, radius, 90.0 * (M_PI / 180.0), 180.0 * (M_PI / 180.));
	cairo_line_to(cr, x, y + radius);
	cairo_new_sub_path(cr);
	cairo_arc(cr, x + radius, y + radius, radius, 180.0 * (M_PI / 180.0), 270.0 * (M_PI / 180.));
	cairo_line_to(cr, x + width - radius, y);
	cairo_new_sub_path(cr);
	cairo_arc(cr, x + width - radius, y + radius, radius, 270.0 * (M_PI / 180.0), 360.0 * (M_PI / 180.));
	cairo_line_to(cr, x + width, y + height - radius);
	cairo_new_sub_path(cr);
	cairo_arc(cr, x + width - radius, y + height - radius, radius, 360.0 * (M_PI / 180.0), 90.0 * (M_PI / 180.));
	cairo_line_to(cr, x + radius, y + height);

}
Comment 1 Kevin DeKorte 2009-10-10 08:19:13 UTC
Version with a little less math

void cairo_rounded_rectangle(cairo_t *cr, double x, double y, double width, double height, double radius)
{

	cairo_new_sub_path(cr);
	cairo_arc(cr, x + radius, y + height - radius, radius, 0.5 * M_PI, M_PI);
	cairo_line_to(cr, x, y + radius);
	cairo_new_sub_path(cr);
	cairo_arc(cr, x + radius, y + radius, radius, M_PI, 1.5 * M_PI);
	cairo_line_to(cr, x + width - radius, y);
	cairo_new_sub_path(cr);
	cairo_arc(cr, x + width - radius, y + radius, radius, 1.5 * M_PI, 2.0 * M_PI);
	cairo_line_to(cr, x + width, y + height - radius);
	cairo_new_sub_path(cr);
	cairo_arc(cr, x + width - radius, y + height - radius, radius, 2.0 * M_PI, 0.5 * M_PI);
	cairo_line_to(cr, x + radius, y + height);

}
Comment 2 Chris Wilson 2009-10-26 05:28:41 UTC
Note that for your rounded rectangle all your need is (hmm, without checking through the the ordering of corners):

cairo_new_sub_path (cr);
cairo_arc (cr, x + radius, y + height - radius, radius, 0.5 * M_PI, M_PI);
cairo_arc (cr, x + radius, y + radius, radius, M_PI, 1.5 * M_PI);
cairo_arc (cr, x + width - radius, y + radius, radius, 1.5 * M_PI, 2.0 * M_PI);
cairo_arc (cr, x + width - radius, y + height - radius, radius, 2.0 *M_PI, 0.5 * M_PI);
cairo_close_path (cr);

However, there is a big difference between cairo_rectangle() and cairo_rounded_rectangle(), namely that nobody will agree on how cairo_rounded_rectangle() should work. In other words, everybody has a different aesthetic interpretation of how the rounded rectangle should look... You used constant radius of curvature around the corners, maybe they should vary in proportional to the relative edge lengths? Perhaps they should be inverted for use in snug fitting scrollbars? This is not a decision that can be made by cairo, but must be made in conjunction with the graphics designers and as demonstrated will only need a trivial function to emit the correct shape - but one that varies with intent.




Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.