6

我在做AthensTutorial,第一步我明白了

surface := AthensCairoSurface extent: self extent asIntegerPoint.

然后第2步是

surface drawDuring: [:canvas |

"First, we clear the surface"
surface clear. 

"we can use 

surface clear: Color black.  

as well. A #clear is equivalent to: (surface clear: Color transparent).   "

"Let''s draw a simple green rectangle"
canvas setPaint: Color green.
canvas setShape: (40@40 corner: 100@100).
canvas draw.

]

画布从何而来?在哪里定义?我只是不明白那部分。

4

1 回答 1

7

这是您将在各种 Smalltalk 框架中看到的技巧。'canvas' 是您传递给#drawDuring: 的块的参数。您可以按照自己的方式命名,这完全取决于您。#drawDuring: 方法将创建一个画布实例,并通过调用 BlockClosure>>value: 方法将其传递给您的块。

于 2013-04-16T12:16:54.660 回答