[英]How to rescale subMorph when the container does?
I am exploring Squeak, release 5.2 in MacOS. 我正在探索Squeak,在MacOS上发布5.2版本。
I am drawing lines (PolygonMorph) inside a RectangleMorph 'r'. 我在RectangleMorph'r'中绘制线条(PolygonMorph)。 When I translate 'r' the lines translate but when I rescale 'r' the lines do not rescale. 当我翻译'r'时,线条会转换,但是当我重新缩放'r'时,线条不会重新缩放。
Run the snipped below. 运行下面的剪辑。 Then with the Halo translate and resize the rectangle 'r'. 然后用Halo翻译并调整矩形'r'的大小。 You will see line 'p' get translated but not rescaled. 你会看到'p'行被翻译但没有重新缩放。
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 ? 如何让'p'重新缩放?
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. 'add halo'
某处写了'add halo'
并右键单击以使用该文字带来所有方法。 #addHalo:
as the associated message to the menu item. 找到#addHalo:
作为菜单项的关联消息。 halt
to debug #addHalo:
. 插入一个halt
调试#addHalo:
. addGrow:with:
to the morph. Cmd +点击带晕并调试,直到我发现调整大小句柄会发送addGrow:with:
变形。 addGrow:with:
sends setExtentFromHalo:
and that this sends extent:
. 然后我看到addGrow:with:
发送setExtentFromHalo:
并且它发送了extent:
. My conclusion is that you would need a new subclass of RectangleMorph
that resizes all its sub-morphs, proportionally, when it receives setExtentFromHalo:
. 我的结论是你需要一个新的RectangleMorph
子类,当它收到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. 尝试一下(我没有),让我们知道它是怎么回事。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.