Logo-small Painter

Our application comes with a main window, a menubar, a toolbar and a drawing area. Naturally we have an instance for each one.

Object subclass: #Painter
instanceVariableNames: 'window menubar toolbar drawingArea'
classVariableNames: ''
poolDictionaries: ''
category: 'PharoCollaborActiveBook-GUI'

Installing the components

At the initialization time we install all the application components:

super initialize.
self installMenubar.
self installToolbar.
self installDrawingArea.
self window openInWorld.
self window extent: 300@250

The layout component use the technic explained in the previous section about Layout. For example to install the menu it looks like:

self window
addMorph: self menubar
fullFrame: (LayoutFrame
fractions: (0@0 corner: 1@0)
offsets: (0@0 corner: 0@ self menubar minExtent y))

At first, we write the menu should occupy 0% vertically, but we statically shift its bottom position to its y extent.

The toolbar installation is a bit more complex as we need to shift its vertical position according to the menu y extent. As for the menu, we write the toolbar should occupy 0% vertically, then we shift statically both its top and bottom positions:

self window
addMorph: self toolbar
fullFrame: (LayoutFrame
fractions: (0@0 corner: 1@0)
offsets: (0@self menubar minExtent y
corner: 0@ self menubar minExtent y + self toolbar minExtent y))

Instantiating the components

To create the menu, we use #newMenu and #newToolDockingBar, there are controls provided by the windows.

^ menubar ifNil: [ | menu |
menu := self window newMenu.
addToggle: 'Load'
target: self
selector: #load.
addToggle: 'Save'
target: self
selector: #save.
menubar := self window newToolDockingBar.
add: 'File'
font: self window theme menuBarFont
icon: nil
help: 'File operations'
subMenu: menu.

To understand from where are coming from these controls, we need to look at the windows instantiation:

^ window ifNil: [
window := StandardWindow labelled: 'Painter'.
window announcer
on: WindowResizing
do: [:ann | self drawingArea extent: ann newSize].

Our window is a StandardWindow, it comes with the TEasilyThemed traits, all the controls are coming from this traits:

SystemWindow subclass: #StandardWindow
uses: TEasilyThemed - {#theme}
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Polymorph-Widgets-Windows'

At the window instantiation we are defining an announcement: it says we should send #extent: to the drawingArea when the window is resized.

The drawing area instantiation itself is straight full:

^ drawingArea ifNil: [drawingArea := PaintCanvas new]

It is time now to look at the PaintCanvas class itself in the next section.

User Contributed Notes

max.bareis (26 June 2014, 2:28 am)

the installDrawingArea method is missing. Here is the code from the example-source:


self window

addMorph: self drawingArea

fullFrame: (


fractions: (0@0 corner: 1@1)

offsets: (0@(self menubar minExtent y + self toolbar minExtent y) corner: 0@0)).

self drawingArea color: Color red





Add a Note

Licensed under Creative Commons BY-NC-SA | Published using Pier |