Morphic Event Handling
Last updated at 2:17 pm UTC on 15 September 2017
Three kinds of key events
See Morphic Key Events
(need to be refined)
Eddie Cottongim writes: I know of three main ways to handle events in Morphic.
- The first, and most common/best AFAIK, is to use the pattern:
on: eventName send: selector to: recipient
myMorph on: #mouseDown send: #clicked to: self.
A list of recognized eventNames is in EventHandler on:send:to:. I went ahead and copied them.
This is flexible, and allows you to send events to arbitrary objects. You don't have to subclass the Morph. There are also other variations like on:send:to:withValue:.
- The second way involves working with a Morph subclass. see How to add a mouse-up action in your own subclass of Morph. This method isn't as flexible, and doesn't support as many events, but may be better in some circumstances.
- The third way is to create your own EventHandler, and install it with Morph #eventHandler:. I haven't done this myself, but it might be useful if you need to apply many custom behaviors to many different morphs. Morphs can share EventHandlers, btw.
You may need to inspect an event. (What key was pressed, what mouse button was clicked)? See Morphic Event Handling.
The section above is part of YetAnotherMorphicTutorial.
To Eddie: Look at Squeak and Events (Observer pattern) to see how to use events for dependencies mechanism implementation. Stephane Ducasse
Also see...for more detail: How Morphic processes events
And see...for some insight: Making the most of Mouse events