[cairo] clear operator
control H
control.h at gmail.com
Tue May 31 05:20:04 PDT 2011
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);
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);
cairo_set_source_surface(cr,surf1,0,0);
cairo_set_operator(cr,CAIRO_OPERATOR_OVER);
cairo_paint(cr);
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
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?
More information about the cairo
mailing list