Re: Wrong mous Position when transformating the matrix



On Thu, Dec 30, 2010 at 5:37 PM, Damon Chaplin
<damon karuna eclipse co uk> wrote:
> On Wed, 2010-12-29 at 17:42 +0100, Fionn Ziegler wrote:
>> Hi,
>> I'm changing the orientation of my Ball (GooCanvasItem) with this code:
>>
>>        angle = math.atan2(rotation[0], rotation[1]);
>>        matrix2 = cairo.Matrix(1, 0, 0, 1, 0, 0)
>>        matrix2.translate(x2, y2)
>>        matrix2.rotate(angle);
>>        matrix2.translate(-x2, -y2)
>>        goo.set_transform(matrix2)
>>
>> I also have a function when I press on the ball, hold the  mouse
>> button and move the mouse to another position it should draw a line
>> between the Ball and the current mouse position.
>> Since I transform the GooCanvasItem by rotating, it won't work. Seems
>> like it draws with the current angle (wrong direction).
>> Any ideas??
>
> Where in the code are you drawing the line? In the Ball's draw function?

in the signal handler:
 ellipse.connect("button_press_event", self.draw_item_event)
 ellipse.connect("button_release_event", self.draw_item_event)
 ellipse.connect("motion_notify_event", self.draw_item_event)
1) in the press event, i create a line
2) in the notify event i draw the line according to the mouse position
3) when I release the mouse button it should finish
>
> You could convert the mouse position to the item's coordinate space
> using functions like goo_canvas_convert_from_pixels() and
> goo_canvas_convert_to_item_space().
I tried it in many constellations:
    xx = target.get_canvas().convert_to_item_space(self.rootitem,event.x,event.y)[0]
    yy = target.get_canvas().convert_to_item_space(self.rootitem,event.x,event.y)[1]
or got I something wrong?
The API says:

"Converts a coordinate from the canvas coordinate space to the given
item's coordinate space, applying all transformation matrices
including the item's own transformation matrix, if it has one.

So it's giving the matrix to the other canvas!?

>
> Though it might be simpler to use a separate canvas item for the line,
> and use the canvas coordinate space for its coordinates.

Do you mean that I shouldn't use the "mouse listener" on the ellipse
but on the root item? Maybe I could give that a try...

Thanks,

Fionn
>
> Damon
>
>
>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]