Morphs implemented from scratch come with a drawOn: method to produce their visual representation. We already encountered this method in the Introduction. Let’s interrogate our running Cuis-Smalltalk system to find out which morphs are involved:
Morph allSubclasses size. ⇒ 155. (Morph allSubclasses select: [:each | each selectors includes: #drawOn:]) size. ⇒ 69.
Example 3.1: How many morphs implement drawing operations?
We observe that the majority of morphs are implemented by composing existing morphs, which was the topic of the previous chapter. We want to interrogate the Cuis-Smalltalk system a bit further by considering the line count of the drawOn: method of each morph.
| morphs | morphs := Morph allSubclasses select: [:each | each selectors includes: #drawOn:]. morphs sort: [:classA :classB | (classA sourceCodeAt: #drawOn:) lineCount > (classB sourceCodeAt: #drawOn:) lineCount]
Example 3.2: Line count of each drawOn:
This script should be executed to open an object explorer, Alt-Shift-I. Unfortunately, this result is not representative of the complexity of the drawing operations. Indeed, well-written Smalltalk code tends to be composed of small, well-factored methods. Nevertheless, the object explorer lets us quickly jump from one method to another.
To improve the exploration experience, we can go a bit further in our previous script to present both the classes and the source code of the drawOn: methods:
| morphs | morphs := Morph allSubclasses select: [:each | each selectors includes: #drawOn:]. morphs := morphs sort: [:classA :classB | (classA sourceCodeAt: #drawOn:) lineCount > (classB sourceCodeAt: #drawOn:) lineCount]. morphs := morphs collect: [:each | each -> (each sourceCodeAt: #drawOn:)]. morphs explore.
Example 3.3: Tooling to review each drawOn:
Once the code is executed, we have an object explorer to review methods. The items at the top of the object explorer are those with longer drawOn: methods:
Figure 3.1: Explorer of the draw methods
In this list, several items are Sample*** classes; they are
examples found in the Morphic-Examples
class category. They
demonstrate the capabilities of the VectorGraphics
engine.