[Cuis] mouseButton2Up:localPosition:

Juan Vuletich juan at jvuletich.org
Fri May 1 13:55:16 CDT 2015


Hi Dan,

On 4/29/2015 11:45 AM, Dan Norton wrote:
> On 27 Apr 2015 at 8:10, Juan Vuletich wrote:
>
> > Hi Dan,
> >
> > So, where's the bug? It's in your #mouseButton2Up:localPosition: .
> > You get
> > a point in local coordinates (you can check this bu just adding
> > 'localEventPosition print'). And you ask for the menu to open there.
> > But
> > the menu is not a submorph. It will be a submorph of the world.
> > (this is
> > again easy to check by opening an inspector on the menu, by doing
> > 'self
> > inspect').
> >
> Interesting. Please allow me to state my understanding of the case. 
> When writing code for a Morph subclass, it's easy to assume that the 
> "localPosition" refers to that of the receiver and it does. But 
> PopUpMenu inherits from Object rather than Morph and when told to 
> position itself 'at: localPosition', PopUpMenu has the display screen 
> as its reference and interprets localPosition accordingly.

Well, no. The position of a morph is expressed in the coordinate system 
of the owner, i.e. the morph containing it. The morph getting the event 
gets the mouse position in its own coordinates. But it doesn't add the 
Menu as its submorph: the menu is added as a submorph of the world. 
Therefore, the position must be expressed in world coordinates.

> > What you want is, instead of just using 'localEventPosition' to use
> > '(self
> > externalizeToWorld: localEventPosition)'.
>
> #externalizeToWorld: transforms the parameter from the coordinates of 
> self to the coordinates of the display screen. Using this as the 
> location for PopUpMenu will cause it to appear over the top morph 
> where the click occurred - the receiver.

In my experiment, doing 'self externalizeToWorld: localEventPositon' 
made the menu open exactly under the mouse pointer. Wasn't this the case 
for you?

> Your alternative
> > #xmouseButton2Activity is perfectly fine too.
> >
>
> This gets "right to the point." Is this sent from 
> MouseClickState>handleEvent:from: ?.
>
> I hope I got all this right.
>
>  - Dan
>

If you want to see where stuff is called from, add  'self halt' at that 
point. Doing this in Morphic code sometimes is risky, as it might result 
in an infinite sequence of debuggers opening. Doing 'thisContext 
printStack: 10' is safer.

Cheers,
Juan Vuletich
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jvuletich.org/pipermail/cuis_jvuletich.org/attachments/20150501/f2b4b5e7/attachment-0003.html>


More information about the Cuis mailing list