Getting a submorph to spaceFill
Ned Konz
ned at squeakland.org
Wed Mar 24 17:16:09 UTC 2004
On Wednesday 24 March 2004 4:35 am, Ed Cavazos wrote:
> Hello!
>
> I've only been Squeaking for 2 days so I've got a very elementary question
> about Morphic layout stuff...
>
> Below is a code snipet which illustrates the problem.
>
> "**************************************************"
> am := AlignmentMorph new.
> am extent: 500 at 500.
>
> picopaint := PicoPaintMorph new.
> picopaint hResizing: #spaceFill.
> picopaint vResizing: #spaceFill.
>
> am addMorphBack: picopaint.
> am openInWorld.
> "**************************************************"
>
> The PicoPaintMorph is from the "Introduction to Morphic" article by John
> Maloney.
>
> So after invoking doit, the AlignmentMorph appears and the PicoPaintMorph
> is inside it. However, the size of the PicoPaintMorph is still it's initial
> size. That is, it hasn't filled up the remaining space in the
> AlignmentMorph. If I activate the halo's on the AlignmentMorph and manually
> resize it, the PicoPaintMorph finally get's resized. How do I get it to
> fill the space from the very beginning so that it looks correct as soon as
> I send 'openInWorld' to the AlignmentMorph?
As you've probably guessed, the initial layout doesn't send #extent: so your
morph doesn't get resized. Instead it gets sent #bounds:.
Rather than overriding #bounds: as well, a better way to do this might be to
check the form size at drawing time.
The attached version of PicoPaint does this by adding an accessor for form
that checks to see if the size has been changed and copies the form if
necessary.
The two direct references to the form instance variable were replaced with
calls to this accessor.
--
Ned Konz
http://bike-nomad.com/squeak/
-------------- next part --------------
'From Squeak3.7alpha of 11 September 2003 [latest update: #5816] on 24 March 2004 at 9:15:52 am'!
"Change Set: PicoPaintLazyForm-nk
Date: 24 March 2004
Author: Ned Konz
John Maloney's PicoPaint example from 'Introduction to Morphic' changed to use an accessor for the Form and hence avoid problems with initial layout not resizing the form properly.
"!
Morph subclass: #PicoPaintMorph
instanceVariableNames: 'form brush lastMouse'
classVariableNames: ''
poolDictionaries: ''
category: 'Test'!
!PicoPaintMorph methodsFor: 'as yet unclassified' stamp: 'nk 3/24/2004 09:08'!
drawOn: aCanvas
aCanvas image: self form at: bounds origin! !
!PicoPaintMorph methodsFor: 'as yet unclassified' stamp: 'nk 3/24/2004 09:08'!
form
"Answer my form, perhaps created or resized if necessary."
| newForm |
(form notNil and: [ form extent = self extent ])
ifTrue: [ ^form ].
newForm := Form extent: self extent depth: 16.
newForm fillColor: Color veryLightGray.
form
ifNotNil: [form displayOn: newForm].
form := newForm.
^form! !
!PicoPaintMorph methodsFor: 'as yet unclassified' stamp: 'nk 3/24/2004 08:36'!
handlesMouseDown: evt
^ true! !
!PicoPaintMorph methodsFor: 'as yet unclassified' stamp: 'nk 3/24/2004 08:44'!
initialize
super initialize.
self extent: 200 @ 150! !
!PicoPaintMorph methodsFor: 'as yet unclassified' stamp: 'nk 3/24/2004 09:08'!
mouseDown: evt
brush := Pen newOnForm: self form.
brush roundNib: 3.
brush color: Color red.
lastMouse := evt cursorPoint - bounds origin.
brush drawFrom: lastMouse to: lastMouse.
self changed! !
!PicoPaintMorph methodsFor: 'as yet unclassified' stamp: 'nk 3/24/2004 08:36'!
mouseMove: evt
| p |
p := evt cursorPoint - bounds origin.
p = lastMouse
ifTrue: [^ self].
brush drawFrom: lastMouse to: p.
lastMouse := p.
self changed! !
PicoPaintMorph removeSelector: #extent:!
More information about the Squeak-dev
mailing list
|