cairo grouphwhile:

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

cairo grouphwhile:

Annick
Hi,

What is the usage of groupWhile: in cairo ?
I tried it without success.

Annick Fron


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: cairo grouphwhile:

Travis Griggs-4

On Aug 25, 2010, at 9:45 AM, Annick Fron wrote:

> Hi,
>
> What is the usage of groupWhile: in cairo ?
> I tried it without success.


Sorry for the belated reply Annick, I saw this, meant to respond ASAP,  
and then got distracted.

A simple example might look something like this:

p := Pixmap extent: 400 @ 400.
p graphicsContext newCairoContextWhile:
                [:cr |
                cr groupWhile:
                                [cr source: ColorValue blue.
                                cr paint].
                cr paint].
p asImage

Inspect that and you'll see a blue image. The example is overly trite,  
there is no real value in doing a groupWhile: there. But the possibly  
missed part, is that you need to do something with the result of  
groupWhile: to actually see anything. The beginning action of a  
groupWhile: is temporarily retarget the cr at a second/temporary  
surface of the same type as the original, the blocks actions are  
executed, and then the cr is returned to the original surface AND the  
temporary surface is set as the current source. So in the example  
above, that's where the second paint call, outside of the block comes  
in. I've used a group to paint a blue source, but it's not been  
painted onto my current surface. You can use this pattern, with paint,  
to basically get double buffering, showing the result of a lot of  
complex drawing operations in one single final paint. But you're not  
limited to paint'ing the result of a groupWhile:

p := Pixmap extent: 100 @ 100.
p graphicsContext newCairoContextWhile:
                [:cr |
                cr groupWhile:
                                [cr source: ColorValue blue.
                                cr circleCenter: p extent half radius: p width half.
                                cr fill].
                cr rectangle: (p bounds insetBy: 6).
                cr strokeWidth: 3.
                cr stroke].
p asImage

In this example, we use the group to draw a blue filled circle, which  
is then set as the source. But rather than just painting that, we then  
create a rectangle and stroke the rectangle with the blue circle. So  
it plays in basically building composition stacks.

groupWhile: is just a handy helper btw, the real meat of the  
functionality are found in the methods #pushGroup, #popGroup, and  
#popGroupToSource.

HTH

--
Travis Griggs
Objologist
"The best way to know you have a mind is to change it" -Judge Pierre  
Leval




_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc