<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;" dir="ltr">
<p>Hi,</p>
<p><br>
</p>
<p>I'm currently writing a program that uses cairo (cairo-xlib precisely), and I seem to be having a problem with the cairo source operator.</p>
<p><br>
</p>
<p>My program redraws itself many times per second, which means (I believe) that I have two options regarding transparency: clear the surface before each redraw, or use CAIRO_OPERATOR_SOURCE for each draw (please correct me if I'm wrong).</p>
<p><br>
</p>
<p>I'm trying to draw some rounded rectangles against a surface, which seems to involve some transparency (anti-aliasing I'm sure). My problem is that each subsequent redraw of the rounded rectangle causes the edges to become more defined, until they're eventually
just 45 degree lines. I would expect this behavior from CAIRO_OPERATOR_OVER, but not CAIRO_OPERATOR_SOURCE; is there something I'm missing?</p>
<p><br>
</p>
<p>Is it possible that there is some kind of overlapping going on, even with CAIRO_OPERATOR_SOURCE?</p>
<p><br>
</p>
<p>It is necessary that I redraw the rounded rectangle often.</p>
<p><br>
</p>
<p>Here's what I'm using for a rounded rectangle (taken mostly from <span>http://cairographics.org/samples/rounded_rectangle/)</span>:</p>
<p></p>
<div><span style="font-size: 9pt; font-family: "Courier New", monospace;">void rounded_rectangle(cairo_t *context,</span></div>
<div><span style="font-size: 9pt; font-family: "Courier New", monospace;"> double x, double y,</span></div>
<div><span style="font-size: 9pt; font-family: "Courier New", monospace;"> double width, double height,</span></div>
<div><span style="font-size: 9pt; font-family: "Courier New", monospace;"> double corner_radius)</span></div>
<div><span style="font-size: 9pt; font-family: "Courier New", monospace;">{</span></div>
<div><span style="font-size: 9pt; font-family: "Courier New", monospace;"> const double aspect = 1.0;</span></div>
<div><br>
</div>
<div><span style="font-size: 9pt; font-family: "Courier New", monospace;"> double radius = corner_radius / aspect;</span></div>
<div><span style="font-size: 9pt; font-family: "Courier New", monospace;"> double degrees = M_PI / 180.0;</span></div>
<div><br>
</div>
<div><span style="font-size: 9pt; font-family: "Courier New", monospace;"> cairo_new_sub_path(context);</span></div>
<div><span style="font-size: 9pt; font-family: "Courier New", monospace;"> cairo_arc(context, x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees);</span></div>
<div><span style="font-size: 9pt; font-family: "Courier New", monospace;"> cairo_arc(context, x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees);</span></div>
<div><span style="font-size: 9pt; font-family: "Courier New", monospace;"> cairo_arc(context, x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees);</span></div>
<div><span style="font-size: 9pt; font-family: "Courier New", monospace;"> cairo_arc(context, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);</span></div>
<div><span style="font-size: 9pt; font-family: "Courier New", monospace;"> cairo_close_path(context);</span></div>
<div><span style="font-size: 9pt; font-family: "Courier New", monospace;">}</span></div>
<div><br>
</div>
<div>Here's how I'm redrawing:</div>
<div>for (running = 1; running == 1;)</div>
<div>{</div>
<div> <span style="font-family: "Courier New", monospace; font-size: 9pt;">
...</span></div>
<div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;"> </span>
<span style="font-family: "Courier New", monospace; font-size: 9pt;"><span style="font-family: "Courier New", monospace; font-size: 9pt;">cairo_set_operator(</span><span style="font-family: "Courier New", monospace; font-size: 9pt;">ctx, CAIRO_OPERATOR_SOURCE);</span></span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;"> cairo_set_source_rgba(ctx, c.red, c.green, c.blue, c.alpha);</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;"> <span style="font-family: "Courier New", monospace;">
rounded_rectangle(context, x, y, w, h, opt.rounding);</span></span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;"> cairo_fill_preserve(context);</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;"> ...</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">}</span></div>
<div><br>
</div>
</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;"></span></div>
<div>Sorry if the formatting is poor, and thanks for any help!</div>
</div>
<div><br>
</div>
<div>Regards,</div>
<div>Mike</div>
<br>
<p></p>
</div>
</body>
</html>