Logo

18.9 Rendering

The Glamour model is formed by entities such as Browser , Pane , Presentation and Transmission (see Section 18.2), and its main goal is to handle the abstract logic of the browser. Even if the main goal of Glamour is to produce actual browsers, this model is independent of the rendering technology.

This decoupling is realized through a Visitor pattern. Every Pane and Presentations classes understand renderGlamorouslyOn:, and as an implementation, they delegate to a Renderer . It is then the job of the renderer to actually produce the actual widget that will appear on the screen and link it with the model of Glamour. The basic structure can be seen in the below class diagram.

An excerpt of the Glamour model showing the rendering related structure.

The Renderer class provides the abstract class that is meant to be subclassed by each new rendering platform. The default implementation uses Morphic, the default Pharo user interface framework, and it can be found in the GLMMorphicRenderer class.

To better understand how the mechanism works, let us take a closer look at the code related to rendering a text presentation:

GLMTextPresentation>>renderGlamorouslyOn: aRenderer 
self registerAnnouncements.
^ aRenderer renderTextPresentation: self

The corresponding code in the MorphicRenderer uses a helper class:

renderTextPresentation: aTextPresentation 
^ GLMMorphicTextRenderer render: aTextPresentation from: self

Finally, the GLMMorphicTextRenderer provides the actual code:

GLMMorphicTextRenderer>>render: aPresentation
textModel := GLMTextModel new glamourPresentation: aPresentation "...".
textMorph := aPresentation highlightSmalltalk
ifTrue: [self smalltalkTextMorphForModel: textModel]
ifFalse: [self textMorphForModel: textModel].
"... more code that sets
the state of the presentation based on the morph events,
and the state of the morphs based on the internal Glamour announcements"

^ textMorph

The implication of this design is twofold. First, if you want to support a new platform, you have to create a new subclass of Renderer. Second, if you create a new presentation or browser, you have to also provide the rendering code in all Renderers.

Add a Note