Method for making Morphs
Last updated at 9:09 pm UTC on 14 August 2017
Q: How do I create my own subclass of Morph?
- I usually start with an empty subclass of some generic morph like RectangleMorph or EllipseMorph
- then add some instance variables
- and an initialization method (e.g. a "currentPosition" variable to store the slider's position),
- then a "drawOn:" method.
- At that point, I make an instance in a PasteUpMorph to see what it looks like,
- and possibly modify the drawOn: method.
- I then add mouse behavior by overriding the mouse handling protocol. Be sure to to override "handlesMouseDown:" to return true.
- Then add behavior for mouse down, move, and up.
- You can also add keyboard control Morph keyboard event
It typically takes me under an hour to get a new interactive widget going, and most of that time is spent tweaking the appearance, which is rather enjoyable. It may take you longer the first time you do it, but by following the example of existing Morphs I suspect you'll have something going in under a day. – JohnMaloney, March 2003