【问题标题】:Squeak Circle Section吱吱声圈部分
【发布时间】:2011-12-09 06:22:15
【问题描述】:

我正在尝试在 Squeak-Smalltalk 中使用 Morphic 绘制四分之一圆。 它是如何工作的?

提前致谢!

【问题讨论】:

    标签: smalltalk squeak morphic


    【解决方案1】:

    最好的老师是形象本身。如果您在 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 的,但是,这可能是重构的标志:))

    【讨论】:

    • 谢谢,但它没有那么有用。我不明白这一点。 EllipseMorphs 绘制方法:codedrawOn: aCanvas aCanvas isShadowDrawing ifTrue: [^ aCanvas fillOval: bounds fillStyle: self fillStyle borderWidth: 0 borderColor: nil]。 aCanvas 填充椭圆:边界填充样式:自填充样式边框宽度:边框宽度边框颜色:边框颜色。 code 但是怎么画圆或者圆弧的一部分呢?如果你能给我一个代码片段,那就太好了。
    • 骗你玩儿!
    • 既然您知道 Morphs 在哪里绘制自己,那么您如何调整子变形中的该方法以执行您想要的操作?
    • 感谢您的更新,但我是 SmallTalk 初学者,现在尝试解决它几个小时,但没有任何正确结果。我尝试使用 CircleMorph 和 Arc。这是我尝试使用圆形变形的方法:|circle| circle := CircleMorph new. circle setProperty: #referencePosition toValue: (circle position + 20). circle changed. circle openInWorld. 但这不是您对剪切矩形的意图,或者?
    • 好吧,我不想折磨你 ;-) 我只是认为对于新的 Smalltalker 来说,意识到图像是一个活生生的例子非常重要(而且经常被忽略)。鉴于您的回复,我建议您从一些免费的 Smalltalk 书籍 (stephane.ducasse.free.fr/FreeBooks.html) 开始了解基础知识。 “... By Example” 是不错的首选。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多