[Cuis] mouseButton2Up:localPosition:
Dan Norton
dnorton at mindspring.com
Sun May 3 15:37:20 CDT 2015
On 1 May 2015 at 15:55, Juan Vuletich wrote:
>
> 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.
>
Ah, the owner of the pop-up is the PasteUpMorph called [world].
> > 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?
>
Yes, under the mouse and over the morph :)
> 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.
>
Great. I'll try that. The red blizzard is no fun.
More information about the Cuis
mailing list