[cairo] Shifting (scrolling) a translucent surface?

Stefan Salewski mail at ssalewski.de
Fri Mar 9 11:07:47 PST 2012


On Thu, 2012-03-08 at 01:16 +0100, Stefan Salewski wrote:
> I just tried to make scrolling faster for a small toy application,
> (http://www.ssalewski.de/PetEd.html.en). Indeed I was successful, I am
> reusing the background grid (with correct offset of course) instead of
> redrawing, and I draw the foreground some pixes larger, so that I can
> copy it with some offset to the GTK drawing area, for small scrolls. For
> larger scrolls I have to shift the cairo surface, before I paint to the
> uncovered stripe. Works fine, but now I have to cleanup (and better
> understand) the code...
> 
> For translating/shifting the foreground I have currently code like this
> 
> $ cat pet_canvas.rb
> [...]
> >elsif ((offx.abs < $OFFSET) and (offy.abs < $OFFSET))
> >  return
> >else
> >  t = cr.target
> >  cr.identity_matrix
> >  cr.push_group
> >  cr.set_source(t, offx, offy)
> >  cr.paint
> >  cr.pop_group_to_source
> >  cr.set_operator(Cairo::OPERATOR_CLEAR)
> >  cr.paint
> >  cr.set_operator(Cairo::OPERATOR_OVER)
> >  cr.paint
> >  offx = 0
> >  offy = 0
> >end
> 
> I guess overlapping copies are not allowed for cairo, see
> 
> http://old.nabble.com/is-self-copy-supposed-to-work--td28410811.html
> 
> But is my code a good solution? My foreground picture is translucent, so
> I need that paint with operator_clear to erase all before copying back
> the translated content. Or is there an operator available which does the
> same with only one paint? And, I wonder how the OPERATOR_CLEAR depends
> on the source surface? First I tried cr.set_source_rgba(1,1,1,1) before
> the clear operation, to get a solid source for clearing operation. But
> it seems to be not necessary. Is the source ignored for clear operation?
> May it be a better approach to allocate an new cairo context with empty
> surface, copy the picture to that surface, discard the old and use the
> new one? 
> 


> And, I wonder how the OPERATOR_CLEAR depends
> on the source surface?

OK, from 

http://permalink.gmane.org/gmane.comp.lib.cairo/21625

we have

>(Please notice that setting the source is useless whenever the operator
>is CLEAR,

This is true from my observation.

But from 

http://www.cairographics.org/operators/

we have

>CAIRO_OPERATOR_CLEAR
>The effect of the CLEAR operator depends on the interpretation of the
>source.





More information about the cairo mailing list