[英]How to draw interactively with Pen on a Morph in Squeak?
It can't get the Pen to work properly in a Morph. 它无法使Pen在变形中正常工作。
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. 我试图在各种(sm,pen,(sm owner))对象中发送“更改”但它没有解决它。
In the snippet below the line gets drawn if I resize the window. 在下面的片段中,如果我调整窗口大小,则会绘制线条。 Or, also, if i put "openInWindow" as last line. 或者,如果我把“openInWindow”作为最后一行。
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.
The message you should send to the SketchMorph
, instead of #layoutChanged
, is 您应该发送到SketchMorph
而不是#layoutChanged
的消息是
sm revealPenStrokes
which is -pun intended- quite intention revealing; 这是-pun意图 - 非常意图揭示; isn't it? 不是吗?
Using the hint provided by Nicola, I debugged sm layoutChanged
trying to understand why it showed the line. 使用Nicola提供的提示,我调试了sm layoutChanged
试图理解它为何显示该行。 I had tried sm changed
before with no luck, so I knew that the clue had to be in generateRotatedForm
. 我之前尝试过sm changed
没有运气,所以我知道线索必须在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
. 由于这个方法重新定义了ivar rotatedForm
,我查找了所有改变它的方法,因为我怀疑问题是在一些缓存中没有被changed
失效。 Quickly enough, the selector revealPenStrokes
emerged victorious from the rather short list of methods modifying rotatedForm
. 很快,选择器revealPenStrokes
从修改rotatedForm
的相当短的方法列表中取得了胜利。
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 ? 如果我查看“layoutChanged”定义并尝试自己发送这些方法,我会看到规则是“generateRotatedForm”的命令...嗯...为什么?
If some Morphic expert would like to shed some light into this I would be grateful. 如果一些Morphic专家希望对此有所了解,我将不胜感激。
bye Nicola 再见尼古拉
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.