[Pharo-project] Fwd: about athens cairo

Fernando Olivero fernando.olivero at usi.ch
Thu Jan 26 21:21:10 CET 2012


In this example i'm "painting" the backgroundSurface over the
destination: the overlaySurface.

Since i dont have to specify a path to do so, i have to bypass #drawShape:,
and send #loadOn: and paintOn:.

overlaySurface drawDuring:[:canvas|
		| paint |
		paint := canvas setPaint: backgroundSurface.
		paint loadOn: canvas at: 0 at 0; paintOn: canvas.
                ..].
	
i'm not sure that fill is the only verb in place.
Would like to know your thoughts on this.

Fernando


---------- Forwarded message ----------
From: Fernando Olivero <fernando.olivero at usi.ch>
Date: Thu, Jan 26, 2012 at 9:06 PM
Subject: Re: about athens cairo
To: Igor Stasenko <siguctua at gmail.com>
Cc: Stéphane Ducasse <stephane.ducasse at inria.fr>


On Thu, Jan 26, 2012 at 2:19 PM, Igor Stasenko <siguctua at gmail.com> wrote:
> On 26 January 2012 13:46, Fernando Olivero <fernando.olivero at usi.ch> wrote:
>> I noticed the class SurfaceManager. I understand now, you want to
>> reify the surface plugin within the image! Cool.
>>
>> Since i'm redoing the DamageRecorder, for a vectorial UI, instead of a
>> single global display as Morphic, i'm adding AthensCairoSurfacePaint,
>> to be able to use surfaces as cairo sources for painting, not filling.
>>
>> paint: A drawing operator that paints the current source everywhere
>> within the current clip region.
>>
> so if i understood you want to do something like:
>
> paint := AthensCairoSurfacePaint new init ....
>
> canvas setPaint: paint.
>
> canvas drawShape: someShape.
>
> ?
> Because there is no other way. Only one :)

well, in cairo filling and painting are different operations. Paint
doesn't rely on the path,
its useful for clearing surfaces, all of its contents. Surely you can
achieve the same with fill and a rectangle, but you have to explicitly
load it in the latter case.

The only "verb" Athens supports is fill. but shouldn't it support
paint and mask too?

According to you answer below, then the paint should know the proper
"verb" to execute, fill,paint, mask or stroke.

Another "verb" i've added is  AthensCairoPaint>>preservePath:, because
in Cairo a fill or stroke, clears the path, therefore you can use
fill_preserve or stroke_preserve.



http://cairographics.org/tutorial/

Paint
The cairo_paint() operation uses a mask that transfers the entire
source to the destination. Some people consider this an infinitely
large mask, and others consider it no mask; the result is the same.

Mask
The cairo_mask() and cairo_mask_surface() operations allow transfer
according to the transparency/opacity of a second source pattern or
surface. Where the pattern or surface is opaque, the current source is
transferred to the destination. Where the pattern or surface is
transparent, nothing is transferred.


>
>
>>
>> The question is whom should be responsible for dispatching either a
>> paint of a fill command?
>>
>> Rectangle>>paintFillsUsing: aPaint on: anAthensCanvas
>>        ^ aPaint fillRectangle: self on: anAthensCanvas
>>
>> sent by Canvas>>drawShape:
>>
>
> There is no "paint shape" command, only fill shape (refer to above response ;).
>
> Ultimately, paint's only responsibility is to fill the shape. there is
> no "half fill , or stroke shape"
> this is specific to paint how it will fill the shape, and so, canvas
> always starts dispatch from shape,
> and then shape does more precise (like fillRectangle: ) dispatch to
> paint object,
> so paint having better idea, about proper way to fill such kind of shape.
>
> So, at the end, a paint should receive message like:
>
> fillXYZ: shape on: canvas
>
> and how it fills it, is completely up to paint.
>
>> Options:
>> 1) Canvas>>paintShape:
>> 2) Canvas>>drawShape: and the paint itself knows wether to fill of paint?
>>
>> Option 2 seems more suited to the overall design in Athens. In that
>> case, can we define the following ivars?
>>
>> AthensPaint.paintOrFill
>> AthensPaint.paintOperator (compositing operators, similar to the ones in BitBlt)
>>
>
> No. Not in paints IMO. Because paint mode is usually globally set and
> applied to all operations.
> Setting paint mode per each paint is also expensive. Because you
> usually switching paints more often than paint mode.
>
> For composing rules i thinking about same way as with with matrices:
>
> canvas paintMode over.  "set 'over' paint mode"
>
> canvas paintMode alphablend. "set alpha-blend paint mode"
> .. etc..
>
> mode := canvas paintMode current "get current paint mode"
> canvas paintMode setTo: mode  "set to previously remembered mode"
>
> paint can query the paint mode from canvas, before performing "fill on
> shape" and pick appropriate method if needed.
>
>> Fernando

ahh..ok. much better this way.



More information about the Pharo-project mailing list