4

It can't get the Pen to work properly in a Morph.

I arrived at the snippet below but I don't understand how to update the view of the Morph after I moved the pen. I tried to send "changed" in various (sm, pen, (sm owner)) object but it does not solve it.

In the snippet below the line gets drawn if I resize the window. Or, also, if i put "openInWindow" as last line.

sm := SketchMorph new.
sm clearExtent: 600@600 fillColor: (Color yellow) darker darker.
sm position: 100@100.
sm openInWindow. 
pen := sm penOnMyForm.
pen defaultNib: 4; color: (Color red).
pen up.
pen goto: 10@10. 
pen down.
pen goto: 100@100.
Nicola Mingotti
  • 860
  • 6
  • 15

2 Answers2

5

The message you should send to the SketchMorph, instead of #layoutChanged, is

sm revealPenStrokes

which is -pun intended- quite intention revealing; isn't it?

How did I find it

Using the hint provided by Nicola, I debugged sm layoutChanged trying to understand why it showed the line. I had tried sm changed before with no luck, so I knew that the clue had to be in generateRotatedForm. And since this method redefines the ivar rotatedForm, I looked for all methods that changed it, as I suspected that the problem was in some cache not being invalidated by changed. Quickly enough, the selector revealPenStrokes emerged victorious from the rather short list of methods modifying rotatedForm.

Leandro Caniglia
  • 14,495
  • 4
  • 29
  • 51
  • Hi @Leandro definitely this is the proper method, thank you! It is quite hard to read those long lists in the System Browser. If I had the possibility of filtering the method list by "pen" i would not have missed it. I think Pharo has a similar selector for Categories, I will look around to see if Squeak has somoething similar. – Nicola Mingotti Aug 15 '19 at 04:08
  • @NicolaMingotti Thanks for the comment. I had to do some work to find the selector (I'm not a Squeak user), so I've added a description of the steps I followed, which could be more useful than telling just the selector. – Leandro Caniglia Aug 15 '19 at 12:47
1

I found the method, but I don't understand the logic.

Just add this at the end.

sm layoutChanged.
pen goto: 150@100.
sm layoutChanged.
" ... and so on "

If I look into the "layoutChanged" definition and I try to send those methods myself I see the command that rules is "generateRotatedForm" ... Umm ... why ?

If some Morphic expert would like to shed some light into this I would be grateful.

bye Nicola

Nicola Mingotti
  • 860
  • 6
  • 15