[cairo] cairo_in_fill w/rotate?

Uli Schlachter psychon at znc.in
Sat Feb 6 08:10:25 CET 2016


Am 06.02.2016 um 06:15 schrieb Mark Olesen:
> Is cairo_in_fill supposed to work with rotation?
> The following code gets hits on the un-rotated rectangle.
> It's like the rotation is ignored. Thanks in advance.
> 
[...]
>     cairo_new_path(cr);
>     cairo_rotate(cr, 45.0); // ROTATION SEEMS TO BE IGNORED
>     cairo_rectangle(cr, 0.0, 0.0, 100.0, 100.0);
> 
>     // only gets hits on un-rotated rectangle
>     l_hit = cairo_in_fill(cr, (*event).x, (*event).y);
>     printf("rect hit=%d %lf %lf\n", l_hit, (*event).x, (*event).y);
> 
>     cairo_destroy(cr);
> 
>     return 1;
> }
[...]

cairo_in_fill() gets a point in user coordinates. That means that the point is
rotated, too, before the hit test. Either undo the rotation with
cairo_rectangle(cr, -45.0) (what a weird angle....) or via:

cairo_save(cr);
cairo_rotate(cr, 45);
cairo_rectangle(cr, 0, 0, 100, 100);
cairo_restore(cr);

l_hit = cairo_in_fill(cr, x, y);

Cheers,
Uli
-- 
- Captain, I think I should tell you I've never
  actually landed a starship before.
- That's all right, Lieutenant, neither have I.


More information about the cairo mailing list