]> Pileus Git - ~andy/gtk/blobdiff - tests/testcairo.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / tests / testcairo.c
index 06257cd9af37fc4139359c2861b062e78d1b8163..8c45bc1c9b78074458d6a21b40bb56c491c574b5 100644 (file)
@@ -15,9 +15,7 @@
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <math.h>
@@ -115,36 +113,31 @@ draw_3circles (cairo_t *cr,
   cairo_fill (cr);
 }
 
-static void
-draw (cairo_t *cr,
-      int      width,
-      int      height)
+static gboolean
+on_draw (GtkWidget *widget,
+         cairo_t   *cr)
 {
   cairo_surface_t *overlay, *punch, *circles;
   cairo_t *overlay_cr, *punch_cr, *circles_cr;
 
   /* Fill the background */
+  int width = gtk_widget_get_allocated_width (widget);
+  int height = gtk_widget_get_allocated_height (widget);
   double radius = 0.5 * (width < height ? width : height) - 10;
   double xc = width / 2.;
   double yc = height / 2.;
 
   overlay = cairo_surface_create_similar (cairo_get_target (cr),
-                                         CAIRO_FORMAT_ARGB32,
+                                         CAIRO_CONTENT_COLOR_ALPHA,
                                          width, height);
-  if (overlay == NULL)
-    return;
 
   punch = cairo_surface_create_similar (cairo_get_target (cr),
-                                       CAIRO_FORMAT_A8,
+                                       CAIRO_CONTENT_ALPHA,
                                        width, height);
-  if (punch == NULL)
-    return;
 
   circles = cairo_surface_create_similar (cairo_get_target (cr),
-                                         CAIRO_FORMAT_ARGB32,
+                                         CAIRO_CONTENT_COLOR_ALPHA,
                                          width, height);
-  if (circles == NULL)
-    return;
     
   fill_checks (cr, 0, 0, width, height);
 
@@ -188,20 +181,6 @@ draw (cairo_t *cr,
   cairo_surface_destroy (overlay);
   cairo_surface_destroy (punch);
   cairo_surface_destroy (circles);
-}
-
-static gboolean
-on_expose_event (GtkWidget      *widget,
-                GdkEventExpose *event,
-                gpointer        data)
-{
-  cairo_t *cr;
-
-  cr = gdk_drawable_create_cairo_context (widget->window);
-
-  draw (cr, widget->allocation.width, widget->allocation.height);
-
-  cairo_destroy (cr);
 
   return FALSE;
 }
@@ -221,8 +200,8 @@ main (int argc, char **argv)
   darea = gtk_drawing_area_new ();
   gtk_container_add (GTK_CONTAINER (window), darea);
 
-  g_signal_connect (darea, "expose-event",
-                   G_CALLBACK (on_expose_event), NULL);
+  g_signal_connect (darea, "draw",
+                   G_CALLBACK (on_draw), NULL);
   g_signal_connect (window, "destroy-event",
                    G_CALLBACK (gtk_main_quit), NULL);