5

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

Nicola Mingotti
  • 860
  • 6
  • 15
  • 1
    May I suggest you to explore a bit more on your own? Debug `p scale: 1.2` to see why it does scale. And then debug `r scale: 1.2` to see why it does not scale. This should give you some insight. – Leandro Caniglia Jul 30 '19 at 12:30
  • After your message I discovered CMD+D :/ It will take me a lot of time to unravel all of this. If you can give me a hand and tell me how things are and if I can at all get what I ask I would be grateful. – Nicola Mingotti Jul 30 '19 at 14:11
  • I didn't mean to be enigmatic, I just told you what I would do. Anyway, if I have a chance, I'll download Squeak and give it a try myself. No promise though, so keep debugging. That's the most efficient way to learn. – Leandro Caniglia Jul 30 '19 at 14:16
  • Ok, I will try to get what I can from the debugger, I am very new to SmallTalk. I tested the script in Pharo (7.0.3 MacOS) as well, similar problem. – Nicola Mingotti Jul 30 '19 at 14:39
  • 1
    As you move the resize halo, the rectangle will receive `doGrow:with:`, which in turn sends `setExtentFromHalo:`, which only sends `extent:`. So, if you create a subclass of `RectangleMorph` which, besides changing its `extent`, changes the `extents` of all its submorphs (proportionally), you should get the effect you are looking for (by using the new subclass instead of a `RectangleMorph`). – Leandro Caniglia Jul 30 '19 at 20:16
  • Don't forget to accept the answer when it answers your question. https://stackoverflow.com/help/someone-answers – tukan Oct 22 '19 at 06:30

1 Answers1

4

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.

  1. I'm not a Squeak (or Pharo) user, so I downloaded Squeak from the web.
  2. Pasted your code in a Workspace and executed it.
  3. Reproduced the behavior you observed: resizing the rectangle has no effect on its polygon sub-morph.
  4. Popped up the rectangle menu and saw the 'add halo' item.
  5. Wrote 'add halo' somewhere and right-clicked to bring all methods with that literal.
  6. Found #addHalo: as the associated message to the menu item.
  7. Inserted a halt to debug #addHalo:.
  8. Cmd+clicked to bring the halo and debugged until I found that the resize handle would send addGrow:with: to the morph.
  9. Then I saw that 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.

Leandro Caniglia
  • 14,495
  • 4
  • 29
  • 51