Re: Experiments with goocanvas.Item.translate
- From: Damon Chaplin <damon karuna eclipse co uk>
- To: Alexander Savelyev <geodeman gmail com>
- Cc: goocanvas-list gnome org
- Subject: Re: Experiments with goocanvas.Item.translate
- Date: Sat, 22 Aug 2009 10:57:23 +0100
On Fri, 2009-08-21 at 16:14 -0500, Alexander Savelyev wrote:
> I was working on an implementation of motion grab for my project and I
> noticed some interesting behavior caused by goocanvas.Item.translate()
> routine.
>
> I set up an event handler that intercepts clicks on the root item of
> my canvas. I'm printing out the location of the click using event.x
> and event.y properties. What I found is that if I click an item first
> instead of clicking the canvas directly, and the item is translated,
> then the event.x and event.y values get somehow translated as well.
>
> I did not expect this behavior, because the event handler is set up
> for root canvas item, not for the translated items that it contains. I
> would naturally expect the coordinates of the click to be converted to
> the canvas space before I'm granted access to them.
> What's even more confusing, the coordinates of the click are not in
> the item space either - they are in some sort of "translated canvas
> space".
I'm not sure I understand this problem. If you translate an item by e.g.
(200, 200) then the item space is simply that offset from canvas space.
i.e. (10, 10) in item space would be (210, 210) in canvas space.
(Obviously rotations and scales and combinations get more complicated.)
> The issue is easily solved by using event.x_root and event.y_root
> properties instead, but the logic behind the behavior described about
> still eludes me. If I'm processing a click on the root canvas,
> shouldn't it be in the canvas space? Why should it matter what items
> are on top, let alone are they translated or not?
>
> Does anybody know if this is a bug or a feature?
It is the intended behavior. The event.x and y are always in the target
item's coordinate space (the docs are a bit misleading).
You could argue either way for this - sometimes the target item
coordinate space is needed and sometimes the signal handler object's
coordinate space is more useful.
You can use goo_canvas_convert_to_item_space () to convert the canvas
coordinates to the signal handler object's coordinate space.
Damon
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]