Re: drawing on offscreen surface
- From: Prasanta Sadhukhan <psadhukhan gmail com>
- To: Tadej Borovšak <tadeboro gmail com>
- Cc: gtk-list gnome org, Paul Davis <paul linuxaudiosystems com>
- Subject: Re: drawing on offscreen surface
- Date: Fri, 10 Aug 2012 13:07:08 +0530
> Also, I would like to know how to render contents from main window AND from
> offscreen both together on main visible window
> say, a primitive (Rectangle) on main window and another primitive (circle)
> from offscreen? Could you please show me how?
Not sure what is giving you trouble here. Drawing from offscreen is
done by two simple function calls: cairo_set_source_surface() and
cairo_paint(). If you need something else drawn onto your widgets,
simply draw that from inside draw (or expose-event for GTK+ 2.x)
callbackusing cairo drawing functions.
Cheers,
Tadej
Thanks for your suggestion.
I am using gtk+2.0. Actually what I am trying to achieve is drawing a green rectangle in offscreen and a blue rectangle in main window. So, when we render offscreen contents in main window, we will have both rectangles being shown.
However, with the below code, I am getting a a window filled with green background and a blue rectangle on top of the green background.
If I comment cairo_paint() then I am getting a blue rectangle and a green one too which is what I want but not calling cairo_paint() does it imply I am not blitting from offscreen to main window?
Also, if offscreen "surface" is associated with cairo context "cr" in expose_event() via cairo_set_source_surface(cr, surface, 0, 0)
how can I be sure that green rectangle is not getting drawn in offscreen and is getting drawn only in main?
Regards
Prasanta
static gboolean
expose_event (GtkWidget *widget,GdkEventExpose *event, gpointer data)
{
g_print("draw event main\n");
cairo_t *cr = gdk_cairo_create(widget->window);
// draw blue rectangle into offscreen
cairo_set_source_surface(cr, surface, 0, 0);
cairo_set_source_rgb(cr, 0, 0, 1);
cairo_rectangle(cr, 300, 300, 200, 200);
cairo_stroke(cr);
cairo_paint(cr);
//draw green rectangle onto main window
cairo_set_source_rgb(cr, 0, 1, 0);
cairo_rectangle(cr, 100, 100, 200, 200);
cairo_stroke(cr)
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]