]> Pileus Git - ~andy/gtk/blobdiff - demos/pixbuf-demo.c
Fix #150125:
[~andy/gtk] / demos / pixbuf-demo.c
index 199ee32492bc487d4fe232d25915e286aee723bd..eaacf83f5977b26ddf568feab2acc87dc7797564 100644 (file)
@@ -5,16 +5,16 @@
  * Authors: Federico Mena-Quintero <federico@gimp.org>
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser 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.
@@ -23,7 +23,6 @@
 #include <config.h>
 #include <stdlib.h>
 #include <gtk/gtk.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
 #include <math.h>
 
 \f
@@ -50,13 +49,13 @@ static GdkPixbuf *frame;
 
 /* Background image */
 static GdkPixbuf *background;
-int back_width, back_height;
+static int back_width, back_height;
 
 /* Images */
 static GdkPixbuf *images[N_IMAGES];
 
 /* Widgets */
-GtkWidget *da;
+static GtkWidget *da;
 
 \f
 
@@ -66,7 +65,11 @@ load_pixbufs (void)
 {
        int i;
 
-       background = gdk_pixbuf_new_from_file (BACKGROUND_NAME);
+        /* We pass NULL for the error return location, we don't care
+         * about the error message.
+         */
+        
+       background = gdk_pixbuf_new_from_file (BACKGROUND_NAME, NULL);
        if (!background)
                return FALSE;
 
@@ -74,7 +77,7 @@ load_pixbufs (void)
        back_height = gdk_pixbuf_get_height (background);
 
        for (i = 0; i < N_IMAGES; i++) {
-               images[i] = gdk_pixbuf_new_from_file (image_names[i]);
+               images[i] = gdk_pixbuf_new_from_file (image_names[i], NULL);
                if (!images[i])
                        return FALSE;
        }
@@ -135,17 +138,17 @@ timeout (gpointer data)
                GdkRectangle r1, r2, dest;
                double k;
 
-               ang = 2.0 * M_PI * (double) i / N_IMAGES - f * 2.0 * M_PI;
+               ang = 2.0 * G_PI * (double) i / N_IMAGES - f * 2.0 * G_PI;
 
                iw = gdk_pixbuf_get_width (images[i]);
                ih = gdk_pixbuf_get_height (images[i]);
 
-               r = radius + (radius / 3.0) * sin (f * 2.0 * M_PI);
+               r = radius + (radius / 3.0) * sin (f * 2.0 * G_PI);
 
                xpos = floor (xmid + r * cos (ang) - iw / 2.0 + 0.5);
                ypos = floor (ymid + r * sin (ang) - ih / 2.0 + 0.5);
 
-               k = (i & 1) ? sin (f * 2.0 * M_PI) : cos (f * 2.0 * M_PI);
+               k = (i & 1) ? sin (f * 2.0 * G_PI) : cos (f * 2.0 * G_PI);
                k = 2.0 * k * k;
                k = MAX (0.25, k);
 
@@ -168,11 +171,11 @@ timeout (gpointer data)
                                              k, k,
                                              GDK_INTERP_NEAREST,
                                              ((i & 1)
-                                              ? MAX (127, fabs (255 * sin (f * 2.0 * M_PI)))
-                                              : MAX (127, fabs (255 * cos (f * 2.0 * M_PI)))));
+                                              ? MAX (127, fabs (255 * sin (f * 2.0 * G_PI)))
+                                              : MAX (127, fabs (255 * cos (f * 2.0 * G_PI)))));
        }
 
-       gtk_widget_draw (da, NULL);
+       gtk_widget_queue_draw (da);
 
        frame_num++;
        return TRUE;
@@ -184,19 +187,21 @@ static guint timeout_id;
 static void
 destroy_cb (GtkObject *object, gpointer data)
 {
-       gtk_timeout_remove (timeout_id);
+       g_source_remove (timeout_id);
        timeout_id = 0;
 
        gtk_main_quit ();
 }
 
+extern void pixbuf_init();
+
 int
 main (int argc, char **argv)
 {
        GtkWidget *window;
 
+       pixbuf_init ();
        gtk_init (&argc, &argv);
-       gdk_rgb_init ();
 
        if (!load_pixbufs ()) {
                g_message ("main(): Could not load all the pixbufs!");
@@ -206,20 +211,21 @@ main (int argc, char **argv)
        frame = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, back_width, back_height);
 
        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-       gtk_widget_set_usize (window, back_width, back_height);
-       gtk_window_set_policy (GTK_WINDOW (window), FALSE, FALSE, FALSE);
 
-       gtk_signal_connect (GTK_OBJECT (window), "destroy",
-                           GTK_SIGNAL_FUNC (destroy_cb), NULL);
+       gtk_widget_set_size_request (window, back_width, back_height);
+        gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
+
+       g_signal_connect (window, "destroy",
+                         G_CALLBACK (destroy_cb), NULL);
 
        da = gtk_drawing_area_new ();
 
-       gtk_signal_connect (GTK_OBJECT (da), "expose_event",
-                           GTK_SIGNAL_FUNC (expose_cb), NULL);
+       g_signal_connect (da, "expose_event",
+                         G_CALLBACK (expose_cb), NULL);
 
        gtk_container_add (GTK_CONTAINER (window), da);
 
-       timeout_id = gtk_timeout_add (FRAME_DELAY, timeout, NULL);
+       timeout_id = g_timeout_add (FRAME_DELAY, timeout, NULL);
 
        gtk_widget_show_all (window);
        gtk_main ();