]> Pileus Git - ~andy/gtk/blob - tests/testoffscreenwindow.c
Add gtk_offscreen_window_get_pixmap() and gtk_offscreen_window_get_pixbuf(), some...
[~andy/gtk] / tests / testoffscreenwindow.c
1 #include <gtk/gtk.h>
2
3 static gboolean
4 da_expose (GtkWidget *widget,
5            GdkEventExpose *event,
6            gpointer user_data)
7 {
8   GtkOffscreenWindow *offscreen = (GtkOffscreenWindow *)user_data;
9   GdkPixmap *pixmap;
10   cairo_t *cr;
11
12   if (GTK_WIDGET_DRAWABLE (widget))
13     {
14       pixmap = gtk_offscreen_window_get_pixmap (offscreen);
15
16       cr = gdk_cairo_create (widget->window);
17       gdk_cairo_set_source_pixmap (cr, pixmap, 50, 50);
18       cairo_paint (cr);
19       cairo_destroy (cr);
20     }
21
22   return FALSE;
23 }
24
25 static gboolean
26 offscreen_damage (GtkWidget      *widget,
27                   GdkEventExpose *event,
28                   GtkWidget      *da)
29 {
30   gtk_widget_queue_draw (da);
31
32   return TRUE;
33 }
34
35 static gboolean
36 da_button_press (GtkWidget *area, GdkEventButton *event, GtkWidget *button)
37 {
38   gtk_widget_set_size_request (button, 150, 60);
39   return TRUE;
40 }
41
42 int
43 main (int argc, char **argv)
44 {
45   GtkWidget *window;
46   GtkWidget *button;
47   GtkWidget *offscreen;
48   GtkWidget *da;
49
50   gtk_init (&argc, &argv);
51
52   offscreen = gtk_offscreen_window_new ();
53
54   button = gtk_button_new_with_label ("Test");
55   gtk_widget_set_size_request (button, 50, 50);
56   gtk_container_add (GTK_CONTAINER (offscreen), button);
57   gtk_widget_show (button);
58
59   gtk_widget_show (offscreen);
60
61   /* Queue exposures and ensure they are handled so
62    * that the result is uptodate for the first
63    * expose of the window. If you want to get further
64    * changes, also track damage on the offscreen
65    * as done above.
66    */
67   gtk_widget_queue_draw (offscreen);
68
69   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
70   g_signal_connect (window, "delete-event",
71                     G_CALLBACK (gtk_main_quit), window);
72   da = gtk_drawing_area_new ();
73   gtk_container_add (GTK_CONTAINER (window), da);
74
75   g_signal_connect (da,
76                     "expose-event",
77                     G_CALLBACK (da_expose),
78                     offscreen);
79
80   g_signal_connect (offscreen,
81                     "damage-event",
82                     G_CALLBACK (offscreen_damage),
83                     da);
84
85   gtk_widget_add_events (da, GDK_BUTTON_PRESS_MASK);
86   g_signal_connect (da, "button_press_event", G_CALLBACK (da_button_press),
87                     button);
88
89   gtk_widget_show_all (window);
90
91   gtk_main();
92
93   return 0;
94 }