links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Morphic Event Handling
Last updated at 3:51 am UTC on 12 May 2018
Main page:

How Morphic processes events


(need to be refined)

Eddie Cottongim writes: I know of three main ways to handle events in Morphic.

1. The first, and most common/best AFAIK, is to use the pattern:

on: eventName send: selector to: recipient

As in:

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:.

2. 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.

3. 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)?

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