Mouse handler on a morph

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Mouse handler on a morph

Erwan Douaille
Hi.

I would like to know if it's possible to add a mouse handler on a specific morph ?
I have a window and i would like to know the position of my mouse only in this window.

For exemple i also use :

self on: #mouseDown send: #captureMouse: to: self.

But it give me the mouse position in pharo environment and not only in my window.


Thanks :)

--
Douaille Erwan <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Mouse handler on a morph

Chris Muller-3
This is because, under rare circumstances, it is desirable to do
something in/on/to the desktop based on the position in the local
morph.

To get the local coordinates look for a method with the word "global"
in it -- globalToLocal: or something like that.  It's in Squeak, not
sure whether this is still in Pharo though..  If anything, you could
always just subtract the upperleft coordinate of your window from the
MouseEvent's position..

On Wed, May 2, 2012 at 9:02 AM, Erwan Douaille <[hidden email]> wrote:

> Hi.
>
> I would like to know if it's possible to add a mouse handler on a specific
> morph ?
> I have a window and i would like to know the position of my mouse only in
> this window.
>
> For exemple i also use :
>
> self on: #mouseDown send: #captureMouse: to: self.
>
> But it give me the mouse position in pharo environment and not only in my
> window.
>
>
> Thanks :)
>
> --
> Douaille Erwan <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: Mouse handler on a morph

Stéphane Ducasse
In reply to this post by Erwan Douaille
Erwan
I guess that you should get the mouse position and the window corner and compute the coordinates by yourself.

World activeHand position

Stef

> Hi.
>
> I would like to know if it's possible to add a mouse handler on a specific morph ?
> I have a window and i would like to know the position of my mouse only in this window.
>
> For exemple i also use :
>
> self on: #mouseDown send: #captureMouse: to: self.
>
> But it give me the mouse position in pharo environment and not only in my window.
>
>
> Thanks :)
>
> --
> Douaille Erwan <[hidden email]>


Reply | Threaded
Open this post in threaded view
|

Re: Mouse handler on a morph

Erwan Douaille
In reply to this post by Chris Muller-3
Okay, but i didn't find anything with globalToLocal. And i've find another solution, just use soustraction for this problem : 

captureMouse: event
Transcript cr;show: event position - self position.

That's work too :)

Thanks ;)

2012/5/2 Chris Muller <[hidden email]>
This is because, under rare circumstances, it is desirable to do
something in/on/to the desktop based on the position in the local
morph.

To get the local coordinates look for a method with the word "global"
in it -- globalToLocal: or something like that.  It's in Squeak, not
sure whether this is still in Pharo though..  If anything, you could
always just subtract the upperleft coordinate of your window from the
MouseEvent's position..

On Wed, May 2, 2012 at 9:02 AM, Erwan Douaille <[hidden email]> wrote:
> Hi.
>
> I would like to know if it's possible to add a mouse handler on a specific
> morph ?
> I have a window and i would like to know the position of my mouse only in
> this window.
>
> For exemple i also use :
>
> self on: #mouseDown send: #captureMouse: to: self.
>
> But it give me the mouse position in pharo environment and not only in my
> window.
>
>
> Thanks :)
>
> --
> Douaille Erwan <[hidden email]>




--
Douaille Erwan <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Mouse handler on a morph

Gary Chambers-4
Hi,
 
I guess that properly you should do:
 
    (self globalPointToLocal: event position) - self position
 
which should deal with the case of being embedded in a scroll pane or other transform

Regards, Gary
----- Original Message -----
Sent: Thursday, May 03, 2012 8:35 AM
Subject: Re: [Pharo-project] Mouse handler on a morph

Okay, but i didn't find anything with globalToLocal. And i've find another solution, just use soustraction for this problem : 

captureMouse: event
Transcript cr;show: event position - self position.

That's work too :)

Thanks ;)

2012/5/2 Chris Muller <[hidden email]>
This is because, under rare circumstances, it is desirable to do
something in/on/to the desktop based on the position in the local
morph.

To get the local coordinates look for a method with the word "global"
in it -- globalToLocal: or something like that.  It's in Squeak, not
sure whether this is still in Pharo though..  If anything, you could
always just subtract the upperleft coordinate of your window from the
MouseEvent's position..

On Wed, May 2, 2012 at 9:02 AM, Erwan Douaille <[hidden email]> wrote:

> Hi.
>
> I would like to know if it's possible to add a mouse handler on a specific
> morph ?
> I have a window and i would like to know the position of my mouse only in
> this window.
>
> For exemple i also use :
>
> self on: #mouseDown send: #captureMouse: to: self.
>
> But it give me the mouse position in pharo environment and not only in my
> window.
>
>
> Thanks :)
>
> --
> Douaille Erwan <[hidden email]>




--
Douaille Erwan <[hidden email]>