Re: GdkDrawable from GtkDrawingArea and it's cairo surface

2011/7/24 Carlos López Camey <c lopez kmels net>:
> Hello again,
> Let's say I'd like to save a GtkDrawingArea 'screenshot' to a file.
> I'm able to do
> cairo_t *cr = gtkDrawingAreaWidget->window;
> cairo_surface_t *screenshot = cairo_get_target(cr);
> cairo_surface_write_to_png(screenshot,"screenshot.png");
> but what this code does is save a screenshot for the *entire window*,
> including other widgets in it (e.g. toolbar). I can't get a cairo
> context for a GtkDrawingArea since it's not GdkDrawable, and it's not
> possible to have child GtkWindow. I've seen
> gtk_widget_set_has_window() but it didn't work, I think because it
> says "This function should only be called by widget implementations".
> Is there a work-around?

First, create a similar surface with the size of the GtkDrawingArea's
Then call cairo_set_source_surface on the new surface's context with
x, y from GtkDrawingArea's allocation.
Set the operator to OPERATOR_SOURCE and then cairo_paint().

> What I'm really trying to do: Save my drawing area surface everytime
> it's modified (drawn on it), so I can later do "undos" and set the
> surface source to a previous one.
> Thanks,
> Carlos


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]