【发布时间】:2011-12-09 06:22:15
【问题描述】:
我正在尝试在 Squeak-Smalltalk 中使用 Morphic 绘制四分之一圆。 它是如何工作的?
提前致谢!
【问题讨论】:
我正在尝试在 Squeak-Smalltalk 中使用 Morphic 绘制四分之一圆。 它是如何工作的?
提前致谢!
【问题讨论】:
最好的老师是形象本身。如果您在 CircleMorph 上打开浏览器,您会看到它的超类 EllipseMorph 定义了 #drawOn:,这就是变形如何绘制自己。从那里,您可以获得制作自定义变形的所有信息和灵感。
更新:我的第一个想法是手动绘制它(完全覆盖#drawOn:),但在 Canvas 中没有任何明显的候选者。通过让圆形自己绘制,同时将剪切矩形设置为它的四分之一,它几乎变成了一条线。
更新 2: 四分之一圆的诀窍是让 CircleMorph 为您完成大部分工作!我想出的最好的是:
QuarterCircleMorph>>drawOn: aCanvas
| realBounds |
"Save the actual bounds of the morph"
realBounds := bounds.
"Pretend the bounds are 4x as big"
bounds := bounds bottom: bounds bottom + bounds height.
bounds := bounds right: bounds right + bounds width.
"Let CircleMorph handle the drawing"
super drawOn: aCanvas.
"Restore the actual bounds"
bounds := realBounds.
QuarterCircleMorph 是 CircleMorph 的子类。因为你不能画出它的真实界限,所以一切都会好起来的。注意在实际代码中,cmets 将是矫枉过正(除了可能是 4x 的,但是,这可能是重构的标志:))
【讨论】:
codedrawOn: aCanvas aCanvas isShadowDrawing ifTrue: [^ aCanvas fillOval: bounds fillStyle: self fillStyle borderWidth: 0 borderColor: nil]。 aCanvas 填充椭圆:边界填充样式:自填充样式边框宽度:边框宽度边框颜色:边框颜色。 code 但是怎么画圆或者圆弧的一部分呢?如果你能给我一个代码片段,那就太好了。
|circle| circle := CircleMorph new. circle setProperty: #referencePosition toValue: (circle position + 20). circle changed. circle openInWorld. 但这不是您对剪切矩形的意图,或者?