[cairo] Scrolling/Copying

Carl Worth cworth at redhat.com
Thu Jun 23 14:31:30 PDT 2005


On 23 Jun 2005 22:25:03 +0200, "Tim Teulings" wrote:
> > It's really simple - it's just the coordinates of the upper left corner
> > of the surface in user space coordinates.

Owen's description above is perfectly accurate.

Perhaps it's the concept of "user space coordinates" that's not
understood here?

>         cairo_set_source_surface(gc,surface,dX-sX,dY-sY);
>         cairo_rectangle(gc,dX,dY,width,height);
>         cairo_fill(gc);

This code is giving you the results you want, (aside from the
overlapping copy bug), right?

First, let's make one simplifying assumption that the current
transformation matrix (CTM) is the default identity matrix. This means
that user space, (the coordinate space in which values passed to
cairo_t functions are expressed), is the same as device space, (the
coordinate space of the target surface).

In that case, the result of the above operation can be depicted
in crude ASCII art as:

   target surface (eg. "window")
0,0--------------------------------------------------------
  |                                                        |
  |            source surface                              |
  | dX-sX,dY-sY--------------------------------------      |
  |           |                                      |     |
  |           |       rectangle                      |     |
  |           |  dX,dY---------                      |     |
  |           |      |/////////|                     |     |
  |           |      |/////////|                     |     |
  |           |      |/////////|                     |     |
  |           |       ---------dX+width,dY+height    |     |
  |           |                                      |     |
  |            --------------------------------------      |
  |                                                        |
   --------------------------------------------------------

All coordinates shown in the figure are in user-space which as we
assumed above happens to be the same as the target device space.

The shaded region of the rectangle is what actually gets painted by
the call to cairo_fill. The bounds of the source surface would not
appear in the result, but are provided on the diagram as a reference
to indicate which portion of the source surface will appear within the
rectangle.

And as you can see, within user space, the upper-left corner of the
source surface is at exactly the coordinate passed to
cairo_set_source_surface.

> Hmmm, where exactly is the origin of the "user space"? If it is the top
> left corner of window I would have called

The user-space origin is obviously always at (0,0) in user space. And
given the default CTM, this is also the top left corner of the target
window.

> 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.

All drawing operations do involve mapping user-space coordinates to
the source pattern space in order to obtain color information. And
this mapping is controlled by the source pattern's matrix.

> 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 :-)

Yes, that's the lookup that goes on for obtaining color information
from the source surface.

> 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?

The phrase "subtracted from the coordinates of every drawing
operation" is a bit ambiguous. You've been talking about the
transformation from user space to pattern space to obtain
color. Meanwhile, there is also a transformation from user space to
device space (the CTM) that is applied to all user-space coordinates,
(such as those passed to cairo_set_source_surface and cairo_rectangle
above).

I don't think we can capture all of those transformations in the
documentation for cairo_set_source_surface. We'll need to just provide
a pointer to an introductory chapter that explains the general imaging
model, including the use of the source pattern matrix.

Anyway, is any of this helping you to make more sense of things?

-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050623/0a2b17db/attachment.pgp


More information about the cairo mailing list