diff options
author | Benjamin Otte <otte@redhat.com> | 2010-08-12 23:38:17 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2010-08-12 23:43:24 +0200 |
commit | cc09ec07328aed90d97f4acd2d3d53470b35599f (patch) | |
tree | 01f2445af15762f26aa29a2e28d7b2ea418742c1 /demos/gtk-demo/drawingarea.c | |
parent | c989d3000a8f26a09d01282c8dfc7e2d5fde47d8 (diff) | |
download | gtk+-cc09ec07328aed90d97f4acd2d3d53470b35599f.tar.gz |
gtk-demo: update drawingarea example
Use gdk_window_create_similar_surface() instead of gdk_pixmap_new()
Diffstat (limited to 'demos/gtk-demo/drawingarea.c')
-rw-r--r-- | demos/gtk-demo/drawingarea.c | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/demos/gtk-demo/drawingarea.c b/demos/gtk-demo/drawingarea.c index b84004ecca..84f3958c73 100644 --- a/demos/gtk-demo/drawingarea.c +++ b/demos/gtk-demo/drawingarea.c @@ -17,9 +17,9 @@ static GtkWidget *window = NULL; /* Pixmap for scribble area, to store current scribbles */ -static GdkPixmap *pixmap = NULL; +static cairo_surface_t *surface = NULL; -/* Create a new pixmap of the appropriate size to store our scribbles */ +/* Create a new surface of the appropriate size to store our scribbles */ static gboolean scribble_configure_event (GtkWidget *widget, GdkEventConfigure *event, @@ -27,16 +27,16 @@ scribble_configure_event (GtkWidget *widget, { cairo_t *cr; - if (pixmap) - g_object_unref (pixmap); + if (surface) + cairo_surface_destroy (surface); - pixmap = gdk_pixmap_new (widget->window, - widget->allocation.width, - widget->allocation.height, - -1); + surface = gdk_window_create_similar_surface (widget->window, + CAIRO_CONTENT_COLOR, + widget->allocation.width, + widget->allocation.height); - /* Initialize the pixmap to white */ - cr = gdk_cairo_create (pixmap); + /* Initialize the surface to white */ + cr = cairo_create (surface); cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); @@ -47,7 +47,7 @@ scribble_configure_event (GtkWidget *widget, return TRUE; } -/* Redraw the screen from the pixmap */ +/* Redraw the screen from the surface */ static gboolean scribble_expose_event (GtkWidget *widget, GdkEventExpose *event, @@ -57,7 +57,7 @@ scribble_expose_event (GtkWidget *widget, cr = gdk_cairo_create (widget->window); - gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0); + cairo_set_source_surface (cr, surface, 0, 0); gdk_cairo_rectangle (cr, &event->area); cairo_fill (cr); @@ -80,12 +80,14 @@ draw_brush (GtkWidget *widget, update_rect.width = 6; update_rect.height = 6; - /* Paint to the pixmap, where we store our state */ - cr = gdk_cairo_create (pixmap); + /* Paint to the surface, where we store our state */ + cr = cairo_create (surface); gdk_cairo_rectangle (cr, &update_rect); cairo_fill (cr); + cairo_destroy (cr); + /* Now invalidate the affected region of the drawing area. */ gdk_window_invalidate_rect (widget->window, &update_rect, @@ -97,7 +99,7 @@ scribble_button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer data) { - if (pixmap == NULL) + if (surface == NULL) return FALSE; /* paranoia check, in case we haven't gotten a configure event */ if (event->button == 1) @@ -115,7 +117,7 @@ scribble_motion_notify_event (GtkWidget *widget, int x, y; GdkModifierType state; - if (pixmap == NULL) + if (surface == NULL) return FALSE; /* paranoia check, in case we haven't gotten a configure event */ /* This call is very important; it requests the next motion event. @@ -202,9 +204,9 @@ close_window (void) { window = NULL; - if (pixmap) - g_object_unref (pixmap); - pixmap = NULL; + if (surface) + g_object_unref (surface); + surface = NULL; } GtkWidget * @@ -271,7 +273,7 @@ do_drawingarea (GtkWidget *do_widget) gtk_container_add (GTK_CONTAINER (frame), da); - /* Signals used to handle backing pixmap */ + /* Signals used to handle backing surface */ g_signal_connect (da, "expose-event", G_CALLBACK (scribble_expose_event), NULL); |