I am exploring Squeak, release 5.2 in MacOS.
I am drawing lines (PolygonMorph) inside a RectangleMorph 'r'. When I translate 'r' the lines translate but when I rescale 'r' the lines do not rescale.
Run the snipped below. Then with the Halo translate and resize the rectangle 'r'. You will see line 'p' get translated but not rescaled.
r := RectangleMorph new.
"[Pharo] r:= Morph.new."
r extent: 500@500.
r openInWindow.
p := PolygonMorph
vertices: {(r left)@(r top). (r right)@(r bottom)}
color: Color white borderWidth: 2 borderColor: Color white.
r addMorph: p.
How can I get 'p' to rescale ?
bye
This may not be the complete answer you are looking for, but sharing what I did, might help you to make some progress with your interesting problem.
'add halo'
somewhere and right-clicked to bring all methods with that literal.#addHalo:
as the associated message to the menu item.halt
to debug #addHalo:
.addGrow:with:
to the morph.addGrow:with:
sends setExtentFromHalo:
and that this sends extent:
.My conclusion is that you would need a new subclass of RectangleMorph
that resizes all its sub-morphs, proportionally, when it receives setExtentFromHalo:
. Something on the lines of
ScalableRectangleMorph >> #setExtentFromHalo: aPoint
current := self extent.
super setExtentFromHalo: aPoint.
scale := self extent - current / current.
self submorphsDo: [:m | m extent: (m extent * scale) rounded]
Give this a try (I haven't), and let us know how it went.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With