[cairo] Scrolling/Copying
Bill Spitzak
spitzak at d2.com
Thu Jun 23 12:36:28 PDT 2005
Carl Worth wrote:
> 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.
>
> 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 just realized that if this is going to work while the CTM is not the
identity, it implies that somehow the CTM is cancelled out when the
source and destination surface are the same, or that all surfaces
contain a CTM. I don't think either of these are wanted for any uses
other than this copy-area.
So it may be that the best solution is to add another operator. It
should take a dx,dy and move all pixels in the clip region by dx,dy (a
vector transformed by the CTM). Pixels that are not in the clip region,
or where the source is outside the clip, would be unaffected. (I prefer
this over having the destination be the clip as this way the clip is
already set up for drawing the missing piece). I suspect dx,dy should be
rounded to the nearest integer after being transformed, since
misalignment is better than filtering the pixels, and obviously easier
to implement.
This would allow you to continue the current behavior where the results
are undefined if the source and destination are the same area of the
same surface, which I assumme makes the code much easier to write and
faster.
Another solution is to just say that copying areas is not supported by
Cairo. On modern systems with double-buffering and modern GUI's where
displays are hardly ever entirely static, it may not be worth it to try
to figure out what can be copied. Existing API's that support copying
usually have an interface to indicate what part was damaged (by
overlapping windows) so it would be easy to have these use Cairo by
doing nothing and returning the fact that the entire area was damaged.
More information about the cairo
mailing list