[cairo] clear operator
Andrea Canciani
ranma42 at gmail.com
Tue May 31 11:54:02 PDT 2011
On Tue, May 31, 2011 at 2:20 PM, control H <control.h at gmail.com> wrote:
> Hi,
>
> I'm trying to use the CLEAR operator, but it doesn't give the expected
> results. I'm using gtk, the configure event I made looks like this:
>
> static cairo_surface_t *surface = NULL;
>
> static gboolean
> configure_event (GtkWidget *widget,
> GdkEventConfigure *event,
> gpointer data)
> {
> GtkAllocation allocation;
> cairo_t *cr,*cr1,*cr2;
> cairo_surface_type_t st;
> cairo_surface_t *surf1,*surf2;
>
> int w,h,r;
>
> if (surface)
> cairo_surface_destroy (surface);
>
> gtk_widget_get_allocation (widget, &allocation);
> w=allocation.width;
> h=allocation.height;
> r=h/2;
>
> surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget),
> CAIRO_CONTENT_COLOR,
> allocation.width,
> allocation.height);
> /* Initialize the surface to white */
> cr=cairo_create (surface);
> cairo_set_source_rgb (cr, 1, 1, 1);
> cairo_paint (cr);
surface is now completely white
>
> surf1=cairo_surface_create_similar(cairo_get_target(cr),
> CAIRO_CONTENT_COLOR_ALPHA,
> w,h);
> cr1=cairo_create(surf1);
> cairo_set_source_rgba(cr1,0.,1.,0.,.8);
> cairo_move_to(cr1,w/2,h/2);
> cairo_arc(cr1,w/2,h/2,MIN(w,h)/3,0,2*G_PI);
> cairo_fill(cr1);
>
> surf2=cairo_surface_create_similar(cairo_get_target(cr),
> CAIRO_CONTENT_COLOR_ALPHA,
> w,h);
> cr2=cairo_create(surf2);
> cairo_set_source_rgba(cr2,1.,1.,0.,.7);
> cairo_arc(cr2,w/2.5,h/2,MIN(w,h)/4,0,2*G_PI);
> cairo_fill(cr2);
>
> cairo_set_operator(cr1,CAIRO_OPERATOR_CLEAR);
> //cairo_set_operator(cr1,CAIRO_OPERATOR_DEST_OUT);
> cairo_set_source_surface(cr1,surf2,0,0);
> cairo_paint(cr1);
surf1 is now completely transparent
>
> cairo_set_source_surface(cr,surf1,0,0);
> cairo_set_operator(cr,CAIRO_OPERATOR_OVER);
> cairo_paint(cr);
This is actually a no-op.
>
> cairo_surface_destroy(surf1);
> cairo_surface_destroy(surf2);
> cairo_destroy(cr1);
> cairo_destroy(cr2);
>
> cairo_destroy (cr);
>
> return TRUE;
> }
>
> The result is just a white screen. However, if I change
This is expected. When you paint() cr1 with a CLEAR
operator, you make it completely transparent.
Painting surf1 OVER cr has thus no effect at all
and correctly leaves surface white.
Andrea
> cairo_set_operator(cr1,CAIRO_OPERATOR_CLEAR);
> into
> cairo_set_operator(cr1,CAIRO_OPERATOR_DEST_OUT);
> or any other operator, it gives the expected result. What am I missing here?
> --
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>
More information about the cairo
mailing list