[Pharo-users] What is the difference between a form and a morph?

Markus Stumptner mst at cs.unisa.edu.au
Mon Feb 24 22:58:34 EST 2020

Normally, there should not be an inheritance relationship between 
wrapper and wrappee, but I agree that describing Morphs as wrappers 
around Forms seems to miss the point. The notion of wrapper usually 
implies that there is little modification to the protocol of the 
wrappee, a wrapper should not need a lot of code. But Morphs are a 
completely different level of the architecture, with a large and complex 
protocol that's very different from Forms. So let's start again.

Forms are images (implemented as rectangular pixel arrays, as stated).

Morphs are the objects that describe how the graphical interface works, 
they control displaying (for which they use Forms), handling of user 
input (mouse clicks, dragging etc) and above all the internal structure 
of the interface (for example the different regions that make up a 
window on the screen are Morphs). Note that the user display side of the 
Pharo interface is handled by class DisplayScreen, which is a subclass 
of Form.  So the Morphs in the user interface display themselves by 
inserting their Forms in the proper places on the Form that is the 
internal representation of the screen.

So, as Subbu said, you don't convert Morphs to Forms, they serve 
different purposes.  Morphs (some Morphs) have instance variables that 
allow them to refer to the Form that they use for displaying.  Hope that 
helps a bit.

I note that all of this (plus some more) you can essentially get from 
the class comments of the two.


On 25/2/20 12:22 pm, Steve Quezadas wrote:
> Ben,
> I checked, [Form] is inherited from class [DisplayMedium]. So in
> smalltalk, the inheritence pattern is:
> Object -> DisplayObject -> DisplayMedium -> Form
> The inheritence pattern of ImageMorph is:
> Object -> Morph -> ImageMorph
> One does not inherit the other and is not a wrapper, at least in Pharo8
> On Sun, Feb 23, 2020 at 10:11 PM Ben Coman <btc at openinworld.com 
> <mailto:btc at openinworld.com>> wrote:
>     On Mon, 24 Feb 2020 at 04:31, Steve Quezadas <steveeq1 at gmail.com
>     <mailto:steveeq1 at gmail.com>> wrote:
>         I usually like to go through the source code to answer my own
>         question, but I can't tell by reading it.
>         [Morph], from what I understand, deals with manipulating
>         graphics on smalltalk. But when I use ZnEasy to get a jpeg
>         file, I notice that it returns a [Form] and not a [Morph] to
>         display a jpeg. Spec2 also wants [Form] for displaying images
>         rather than [Morph].
>         So what is the difference between a [Form] and a [Morph] since
>         they both seem to deal with graphics?
>     I don't know the exact answer, but if you review method
>     ImageMorph>>form
>     you will see that the ImageMorph is a wrapper around a Form.
>     So some simple differences that may be inferred.
>     - Many morphs are not bitmaps.
>     - Morphs are GUI elements, i.e. interact with mouse and keyboard
>     - Forms are not GUI elements
>     - Forms can be manipulated without displaying them.
>     In some other graphics system, an analogy could be putting an
>     image on a button and asking "what is the difference between an
>     'image' and a 'button' ?"
>     wrt Spec2, Morph is one backend that Spec2 might use to display a
>     Form,
>     or Spec2 might display the Form using a GTK widget.
>     cheers -ben

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-users_lists.pharo.org/attachments/20200225/7da7f4c0/attachment-0001.html>

More information about the Pharo-users mailing list