[cairo] Coordinate from device to user space without a context

Bryce W. Harrington b.harrington at samsung.com
Thu Nov 7 19:22:45 CET 2013


On Thu, Nov 07, 2013 at 04:24:29PM +0200, Donn wrote:
> On 07/11/2013 15:48, ed44 wrote:
> >>So, x = [18,53,17,51] See the jumps?
> >
> >Yes , i see.
> >But if you use the above formula and the matrix values are constant
> >there should not be any jumps.
> 
> I'm not seeing the bug.
> 1. The matrix does change because it has to. It comes from a
> translate(x,y) [line 120], then gets saved into mymatrix [line 126],
> 2. then the move() method causes x,y to shift to mousex,y [called
> from line 39. The method at line 58]
> 3. Then a queue_draw() happens [line 420]
> 4. In draw(), a call to set_matrix(cr) happens [e.g. line 305],
> 5. which is back to 1 were the latest x,y is used.
> 
> Look, both you and Bryce tell me that formula should work as
> expected, so I'm happy to think there's a bug in my code. I just
> gotta find it!
> 
> Thanks for your time,
> \d
> (code attached this time.)

My guess is you've got a number of matrix calls peppered through your
code, so the applied matrix is probably changing out from under you.

You could just save the values from the matrix the first time through,
and never update them; that would get rid of the jumps.  However, if the
two coordinate systems *can* vary during run time, then you'll need to
but be careful as to *when* you update it (to make sure other calls
aren't tinkering with it.)

It's hard to spot which matrix calls in there might be modifying your
matrix for certain.  If I were you I'd probably start afresh with just
the formulas I gave you, and make a little toy app that *just* does the
mouse -> userspace conversion, without any other matrix calls.  This
would help avoid any confusion being called by all the identity matrices
and so on.

Btw, when you make cr.translate(), cr.rotate(), and cr.scale() calls,
those are really just helper routines for modifying the internal
matrix.  So be aware of those too.

Bryce


More information about the cairo mailing list