[cairo] Scrolling/Copying

Tim Teulings rael at edge.ping.de
Thu Jun 23 10:30:18 PDT 2005


Hallo!

> So, let's say you've got a cairo_surface_t *surface and you want to
> copy a rectangle, (x1,y1,width,height) to a position (x2,y2) on a
> cairo_t *cr.

Yes, that is exactly what I want to do. x2,y may be positioned
everywhere, above below or even within the x1,y,1,width,height rectangle.

> I would write something like the following code to do that:
> 
> 	cairo_set_source_surface (cr, x2 - x1, y2 - y1);
> 	cairo_rectangle (cr, x2, y2, width, height);
> 	cairo_fill (cr);

I tried that. But it only worked partially. It worked if y2-y1 was
negative (in my test x1 and x2 are equal), but the output looked
destroyed if y2-y1 was positive.

I must admit I do not understand the meaning of the two coordinate
parameter of cairo_set_source_surface. The description sounded like this
are the coordinates of the top left position of my within the surface.
But this would IMHO suggest to handle x1,y1 as parameters. Please
enlighten me :-)

> But there are several other ways that would express the same thing,
> (eg. one might use cairo_translate to do the positioning). Try
> whichever seems most natural, and let us know if things are slower
> than they should be, (eg. we know that code like this should end up
> just calling XCopyArea).

I recently switched form 0.4 to 0.5.1 and saw a general speed
improvement that made me quite happy :-) Especially text rendering look
faster!

-- 
Gruß...
       Tim.



More information about the cairo mailing list