[cairo] Scrolling/Copying
Tim Teulings
rael at edge.ping.de
Thu Jun 23 13:25:03 PDT 2005
Hello!
> Is there any reason that you can't just use XCopyArea()?
Of course I could but in priciple I would avoid mixing X11 and Cairo for
drawing operations (In fact I recently droped the X11 GC from the
relevant code).
>>Nevertheless, can someone still explain me the to coords params to the
>>cairo_set_source_surface method?
> It's really simple - it's just the coordinates of the upper left corner
> of the surface in user space coordinates.
I rewrite the relevant code snipped:
cairo_set_source_surface(gc,surface,dX-sX,dY-sY);
cairo_rectangle(gc,dX,dY,width,height);
cairo_fill(gc);
Hmmm, where exactly is the origin of the "user space"? If it is the top
left corner of window I would have called
cairo_set_source_surface(gc,surface,sX,sY)
But in the code above it is relative to the top left of the rectangle!?
I assume what really happens is, that the (negated) parameter of
set_source_surface are added to the coordinates of every "pixel" during
a drawing operation to calculate their position in the pattern.
So for cairo_rectangle the top left x coordinate calculates to
dX+(-(dX-sX) with results into sX and the bottom right x coordinate
calculates to dX+width-1+(-(dX-sX)) which calculates to sX+width-1,
which is exactly what I want :-)
So the parameters are not coordinates but they define the (negated) 2
dimensional transformation vector that gets applied to every "pixel"
covered by a drawing operation to calculate the originating pixel within
the pattern source surface. In fact that is what the code that Carl has
quoted more clearly shows.
So while the documentation is true ("the x and y patterns are negated
and then set as translation values in the pattern matrix") I would add
(or exchange that part) by a more "visual" and less mathematical
description of what is happing. For example: "The parameters x and y
that are passed to this method are substraced from the coordinates of
every drawing operation to calculate their matching source coordinates
in the source surface relative to their origin." Is this better?
--
Gruß...
Tim.
More information about the cairo
mailing list