A message for Linux.com registered users: We are in the process of making changes to the Linux forums. Starting Monday, 8/13/18 at 6:00 PM PT, you will be unable to access the forums. They will re-launch as soon as possible on Wednesday, 8/15/18 with new features and improved functionality. Thank you for your patience and stay tuned for the new improved forums.

June 3, 2011

cairo draw over alpha

Hi, I'd like to draw with cairo over a surface of a GtkDrawingArea. My problem is that drawing over the surface doesn't draw a solid color over a color with alpha channel. I don't use any special cairo operators and the result is that I see some unneeded rectangles with alpha channel where there shouldn't be any.

cr = gdk_cairo_create(GTK_WIDGET(editor->drawing_area)->window);
cairo_push_group(cr);

cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
cairo_rectangle(cr, 0.0, 0.0, (double) widget->allocation.width, (double) widget->allocation.height);
cairo_fill(cr);

/* do some other drawing */

/* draw with alpha channel */
cairo_set_source_rgba(cr, 0.25, 0.5, 1.0, 0.5);
cairo_rectangle(cr, (double) x, (double) y, (double) width, (double) height);
cairo_fill(cr);

/* pop it to source */
cairo_pop_group_to_source(cr);
cairo_paint(cr);

Click Here!