我正试着在Squeak-Smalltalk中用Morphic画一个四分之一的圆。它怎麽工作?
提前感谢!
发布于 2011-12-07 03:02:12
最好的老师是形象本身。如果您在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的子类。因为你不能越过它的实际界限,一切都会解决的。注:在实际代码中,注释可能会过度杀伤力(可能除了4x的注释,但这是可能重构的信号:)
https://stackoverflow.com/questions/8404803
复制相似问题