Logo-small

3.7.2.1 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:

initialize
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:

installMenubar
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:

installToolbar
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
^ menubar ifNil: [ | menu |
menu := self window newMenu.
menu
addToggle: 'Load'
target: self
selector: #load.
menu
addToggle: 'Save'
target: self
selector: #save.
menubar := self window newToolDockingBar.
menubar
add: 'File'
font: self window theme menuBarFont
icon: nil
help: 'File operations'
subMenu: menu.
menubar
]

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

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

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
^ 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:

installDrawingArea

self window

addMorph: self drawingArea

fullFrame: (

LayoutFrame

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

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

self drawingArea color: Color red

 

Regards

 

Max

Add a Note

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