[Newbies] Morphic event-handling confusion

Michael van der Gulik mikevdg at gulik.co.nz
Thu Mar 15 10:23:31 UTC 2007

Max OrHai wrote:

>I'm trying to use Morphic, in Squeak 3.9, to make a very simple "physics
>model" I call a HockeyPuck. The idea is that it's a CircleMorph subclass
>that one should be able to pick up with the Hand and "throw", and have
>it bounce off the World edge (and then, hopefully, other such Pucks).
>I've got the "step" animation thing figured out pretty well, and I have
>some idea how to compute the motion and bounces and such, but I'm
>stumped as to how to properly handle the mouse events. On Eddie
>Cottongim's suggestion, at http://wiki.squeak.org/squeak/2477 , I tried
>using  "self on: #startDrag send: #beginThrow to: self" (in my
>initialize method) but that seems a little weird, and doesn't seem to
>allow the default dragging behavior to go through. I also tried the
>approach of overriding handlesMouseDown and mouseDown, and sending
>"super mouseDown" in the latter, but that doesn't seem to work any
>better, although it makes a little more sense to me.
>There's a two-step sequence of messages I'd like my Puck to receive
>while still doing the normal getting-moved-by-the-Hand stuff. The first
>is #beginThrow, to be sent either on a mouseDown or (preferably) on a
>startDrag event. The second is #endThrow, to be sent on the subsequent
>mouseUp. How can I make this happen?
Hi Max.

Firstly, I might just make the point that Morphic is a pain to work 
with. I've often been at my wits end trying to work out what on earth it 
is doing and how to get it to behave. You're not the only one.

I've just had a bit of a play around, and I think you'll want the 
following six methods in your Puck morph:

handlesMouseDown: evt
    ^ true.

mouseDown: evt
    Transcript show: 'Mouse down'; cr.

handlesMouseStillDown: evt
    ^ true

mouseStillDown: evt
    self position: evt hand position.

handlesMouseUp: evt
    ^ true

mouseUp: evt
    Transcript show: 'Mouse up'; cr.

You can also define all the above methods using the "on:send:to:" 
mechanism if you want.


More information about the Beginners mailing list