SmileyMorph: Just learning Morphic

Jon K Anderson jonkanderson at yahoo.com
Mon Oct 9 20:16:38 UTC 2000


Hello everybody,

I have been trying to learn Morphic and have been reading John Maloney's
"Introduction to Morphic" draft chapter as a guide.  It was very helpful
and I really appreciate his work, but I wanted to do something more
"prototype-oriented" rather than "code-oriented".  If I understand
correctly from my readings, the basic philosophy behind morphic in Self
is to always start from prototypes.

In that spirit, I am going to describe what I have been trying to do in
morphic and I would like it if any of you have some feedback to give me
and the list.  The sort of feedback I am looking for is:
   1) Is this an appropriate design for
       using prototypes,
   2) What sort of pitfalls do you see
       in the code, and
   3) Is this the sort of design concept
       that new users should be presented
       with?

This is what I have: I have been working to add to a "game" that I put
together for my two-year-old son.  (It is more like an activity desktop
where he can move shapes around, catch a sketch of a bug which keeps
moving in circles, and type text in a box.  Morphic is really fun!!!)
My latest idea is to add a smiley face :-) which changes to an oooh face
:-o when he picks it up and moves it, but then changes back to a smile
again when he drops it.

In an effort to make this as simple as possible I created a subclass of
SketchMorph called SmileyMorph.  I instantiated it and painted it as a
smiley face without a mouth.  Then I created two sketches: one
smileMouth and one oooMouth.  I embedded them both in the smile sketch
and I saved this morph in a class variable named Prototype.  Next I
overloaded SmileyMorph>>new so that it only returned a deep copy of
Prototype.  (I took the idea from what I could understand of the
PaintBoxMorph.)

Creating the smile sketch with its embedded mouths was easy.  All seemed
to go fine until I overloaded the #mouseDown: method because suddenly
the mouth would change but the morph would no longer be picked up.  The
reason was because I simplistically implemented #mouseDown: like this:
   mouseDown: evt
      self oooMouth show.
      self smileMouth hide.
      super mouseDown: evt.
I dug around and then changed the code to call #grabMorph: in
#mouseDown:, and #dropMorphsEvent: in #mouseUp: instead of expecting
super to do it.  Anyway, I thought that this might be a common error for
new users and they might want to know how to deal with it.  TestMorph in
John Maloney's chapter indicated that the default functionality would be
lost, but it didn't show how to extend the functionality; it only
switched the handling based on using the shift key.  (Which is also good
to know.)

Well, that's it.  I included the Smalltalk code below (because it's
short).  It works for what I described, but I would like to improve it
by making the submorph mouths resize appropriately when the face is
resized.  (Any ideas on how this should be done?  Implement #extent:
somehow?)

I welcome any comments or advice. Do you think this would be hard to
manage if a larger project managed the whole view layer in this way?

Thanks,
Jon

--------------------------------------------

SketchMorph subclass: #SmileyMorph
 instanceVariableNames: ''
 classVariableNames: 'Prototype '
 poolDictionaries: ''
 category: 'Learning Morphic'!

!SmileyMorph methodsFor: 'as yet unclassified' stamp: 'jA 10/9/2000
00:07'!
handlesMouseDown: evt
 ^true
!
mouseDown: evt
 self oooMouth show.
 self smileMouth hide.
 evt hand grabMorph: (self rootForGrabOf: self).
!
mouseUp: evt
 self smileMouth show.
 self oooMouth hide.
 evt hand dropMorphsEvent: evt.
!
oooMouth
 ^self submorphs at: 1
!
smileMouth
 ^self submorphs at: 2
!!

!SmileyMorph class methodsFor: 'as yet unclassified' stamp: 'jA
10/8/2000 22:52'!
new
 ^Prototype fullCopy show
!!






More information about the Squeak-dev mailing list