In AthensTutorial where canvas comes from?
Asked Answered
B

1

6

I was doing the AthensTutorial , I understand the first step

surface := AthensCairoSurface extent: self extent asIntegerPoint.

and then step 2 is

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.

]

Where canvas comes from ? where is defined ? I just dont understand that part.

Bellboy answered 16/4, 2013 at 10:27 Comment(0)
M
7

That's a trick you will see in various Smalltalk frameworks. 'canvas' is a parameter to the block you pass to #drawDuring:. You can name it the way you want, it is totally up to you. The method #drawDuring: will create a canvas instance and will pass it to your block by calling the BlockClosure>>value: method on it.

Manila answered 16/4, 2013 at 12:16 Comment(1)
Thank you very much Damien it makes sense now :)Bellboy

© 2022 - 2024 — McMap. All rights reserved.