Questions about using GtkOffscreenWindow



Hi,

   I've managed to create a GtkOffscreenWindow that can snapshot a
single widget, but I need to snapshot a bunch of widget and I'm having
difficulties.

   I'm not sure if the design of GtkOffscreenWindow is such that I'm
supposed to:
1) reuse one window, adding and removing widgets to be snapshotted or
2) create a new GtkOffscreenWindow each time

If the intent is 1, how am I supposed to remove objects from the
window? I thought that just gtk_widget_destroy on the widget would
remove it from the window, but I get a GTK_IS_DRAWABLE assertion error
in the main loop after doing that and trying to snapshot a new widget.

If the intent is 2, how am I supposed to destroy the window? I get a
GTK_IS_WIDGET assertion error when I try to gtk_widget_destroy it.

Currently, I'm doing neither, and creating a new window each time I
snapshot a widget, but I'm pretty sure I'm leaking offscreen windows.

Here's my code (note, this is all transcribed by hand from Java JNA
code, the function names are right but I haven't compiled it so am not
sure if there are any typos).


// CODE

GtkOffscreenWindow* offscreenWindow;

void force_draw(GtkWidget* widget) {
    gtk_widget_queue_draw(widget);

    GdkWindow* window = gtk_widget_get_window(widget);

    gdk_window_process_updates(window, true);
}

GtkPixmap* snapshotWidget(GtkWidget* widget) {
	// Caching doesn't work, must create a new one every time (the widget
parameter is gtk_widget_destroy'ed by the caller)
	// if (!offscreenWindow)
		offscreenWindow = gtk_offscreen_window_new();

	gtk_container_add(offscreenWindow, widget);
	gtk_widget_show(offscreenWindow);
	force_draw(widget);

        // This doesn't seem to make any difference
        // force_draw(offscreenWindow);

        GtkPixmap* result = gtk_offscreen_window_get_pixmap(offscreenWindow)

	// Doesn't work
	// gtk_widget_destroy(offscreenWindow);

	// Doesn't work
	// gtk_container_remove(offscreenWindow, widget);

        // Doesn't work
        // gtk_widget_destroy(widget);

	return result;
}



-- Aaron


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