]> Pileus Git - ~andy/gtk/commitdiff
It was cold and rainy this Saturday morning, so I needed something to warm
authorFederico Mena Quintero <federico@helixcode.com>
Sun, 11 Jun 2000 18:18:28 +0000 (18:18 +0000)
committerFederico Mena Quintero <federico@src.gnome.org>
Sun, 11 Jun 2000 18:18:28 +0000 (18:18 +0000)
2000-06-10  Federico Mena Quintero  <federico@helixcode.com>

* demo/pixbuf-demo.c: It was cold and rainy this Saturday morning,
so I needed something to warm my thighs.  Running plain infinite
loops on your laptop to make it hot is not very much fun.  A demo
of the gdk-pixbuf scaling functions is way better, and looks
prettier, too.

* configure.in (AC_OUTPUT): Added the demo Makefile.

* Makefile.am (SUBDIRS): Added the demo directory.

12 files changed:
demos/apple-red.png [new file with mode: 0644]
demos/background.jpg [new file with mode: 0644]
demos/gnome-applets.png [new file with mode: 0644]
demos/gnome-calendar.png [new file with mode: 0644]
demos/gnome-foot.png [new file with mode: 0644]
demos/gnome-gimp.png [new file with mode: 0644]
demos/gnome-gmush.png [new file with mode: 0644]
demos/gnome-gsame.png [new file with mode: 0644]
demos/gnu-keys.png [new file with mode: 0644]
demos/pixbuf-demo.c [new file with mode: 0644]
demos/testpixbuf-scale.c
gdk-pixbuf/ChangeLog

diff --git a/demos/apple-red.png b/demos/apple-red.png
new file mode 100644 (file)
index 0000000..b0a24e9
Binary files /dev/null and b/demos/apple-red.png differ
diff --git a/demos/background.jpg b/demos/background.jpg
new file mode 100644 (file)
index 0000000..86c006a
Binary files /dev/null and b/demos/background.jpg differ
diff --git a/demos/gnome-applets.png b/demos/gnome-applets.png
new file mode 100644 (file)
index 0000000..8d3549e
Binary files /dev/null and b/demos/gnome-applets.png differ
diff --git a/demos/gnome-calendar.png b/demos/gnome-calendar.png
new file mode 100644 (file)
index 0000000..889f329
Binary files /dev/null and b/demos/gnome-calendar.png differ
diff --git a/demos/gnome-foot.png b/demos/gnome-foot.png
new file mode 100644 (file)
index 0000000..0476658
Binary files /dev/null and b/demos/gnome-foot.png differ
diff --git a/demos/gnome-gimp.png b/demos/gnome-gimp.png
new file mode 100644 (file)
index 0000000..f6bbc6d
Binary files /dev/null and b/demos/gnome-gimp.png differ
diff --git a/demos/gnome-gmush.png b/demos/gnome-gmush.png
new file mode 100644 (file)
index 0000000..0a4b0d0
Binary files /dev/null and b/demos/gnome-gmush.png differ
diff --git a/demos/gnome-gsame.png b/demos/gnome-gsame.png
new file mode 100644 (file)
index 0000000..01c0611
Binary files /dev/null and b/demos/gnome-gsame.png differ
diff --git a/demos/gnu-keys.png b/demos/gnu-keys.png
new file mode 100644 (file)
index 0000000..58a3377
Binary files /dev/null and b/demos/gnu-keys.png differ
diff --git a/demos/pixbuf-demo.c b/demos/pixbuf-demo.c
new file mode 100644 (file)
index 0000000..199ee32
--- /dev/null
@@ -0,0 +1,228 @@
+/* GdkPixbuf library - Scaling and compositing demo
+ *
+ * Copyright (C) 1999 The Free Software Foundation
+ *
+ * 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
+ * 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.
+ *
+ * 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.
+ */
+
+#include <config.h>
+#include <stdlib.h>
+#include <gtk/gtk.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <math.h>
+
+\f
+
+#define FRAME_DELAY 50
+
+#define BACKGROUND_NAME "background.jpg"
+
+static const char *image_names[] = {
+       "apple-red.png",
+       "gnome-applets.png",
+       "gnome-calendar.png",
+       "gnome-foot.png",
+       "gnome-gmush.png",
+       "gnome-gimp.png",
+       "gnome-gsame.png",
+       "gnu-keys.png"
+};
+
+#define N_IMAGES (sizeof (image_names) / sizeof (image_names[0]))
+
+/* Current frame */
+static GdkPixbuf *frame;
+
+/* Background image */
+static GdkPixbuf *background;
+int back_width, back_height;
+
+/* Images */
+static GdkPixbuf *images[N_IMAGES];
+
+/* Widgets */
+GtkWidget *da;
+
+\f
+
+/* Loads the images for the demo and returns whether the operation succeeded */
+static gboolean
+load_pixbufs (void)
+{
+       int i;
+
+       background = gdk_pixbuf_new_from_file (BACKGROUND_NAME);
+       if (!background)
+               return FALSE;
+
+       back_width = gdk_pixbuf_get_width (background);
+       back_height = gdk_pixbuf_get_height (background);
+
+       for (i = 0; i < N_IMAGES; i++) {
+               images[i] = gdk_pixbuf_new_from_file (image_names[i]);
+               if (!images[i])
+                       return FALSE;
+       }
+
+       return TRUE;
+}
+
+/* Expose callback for the drawing area */
+static gint
+expose_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
+{
+       guchar *pixels;
+       int rowstride;
+
+       rowstride = gdk_pixbuf_get_rowstride (frame);
+
+       pixels = gdk_pixbuf_get_pixels (frame) + rowstride * event->area.y + event->area.x * 3;
+                 
+       gdk_draw_rgb_image_dithalign (widget->window,
+                                     widget->style->black_gc,
+                                     event->area.x, event->area.y,
+                                     event->area.width, event->area.height,
+                                     GDK_RGB_DITHER_NORMAL,
+                                     pixels, rowstride,
+                                     event->area.x, event->area.y);
+
+       return TRUE;
+}
+
+#define CYCLE_LEN 60
+
+static int frame_num;
+
+/* Timeout handler to regenerate the frame */
+static gint
+timeout (gpointer data)
+{
+       double f;
+       int i;
+       double xmid, ymid;
+       double radius;
+
+       gdk_pixbuf_copy_area (background, 0, 0, back_width, back_height,
+                             frame, 0, 0);
+
+       f = (double) (frame_num % CYCLE_LEN) / CYCLE_LEN;
+
+       xmid = back_width / 2.0;
+       ymid = back_height / 2.0;
+
+       radius = MIN (xmid, ymid) / 2.0;
+
+       for (i = 0; i < N_IMAGES; i++) {
+               double ang;
+               int xpos, ypos;
+               int iw, ih;
+               double r;
+               GdkRectangle r1, r2, dest;
+               double k;
+
+               ang = 2.0 * M_PI * (double) i / N_IMAGES - f * 2.0 * M_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);
+
+               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 = 2.0 * k * k;
+               k = MAX (0.25, k);
+
+               r1.x = xpos;
+               r1.y = ypos;
+               r1.width = iw * k;
+               r1.height = ih * k;
+
+               r2.x = 0;
+               r2.y = 0;
+               r2.width = back_width;
+               r2.height = back_height;
+
+               if (gdk_rectangle_intersect (&r1, &r2, &dest))
+                       gdk_pixbuf_composite (images[i],
+                                             frame,
+                                             dest.x, dest.y,
+                                             dest.width, dest.height,
+                                             xpos, ypos,
+                                             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)))));
+       }
+
+       gtk_widget_draw (da, NULL);
+
+       frame_num++;
+       return TRUE;
+}
+
+static guint timeout_id;
+
+/* Destroy handler for the window */
+static void
+destroy_cb (GtkObject *object, gpointer data)
+{
+       gtk_timeout_remove (timeout_id);
+       timeout_id = 0;
+
+       gtk_main_quit ();
+}
+
+int
+main (int argc, char **argv)
+{
+       GtkWidget *window;
+
+       gtk_init (&argc, &argv);
+       gdk_rgb_init ();
+
+       if (!load_pixbufs ()) {
+               g_message ("main(): Could not load all the pixbufs!");
+               exit (EXIT_FAILURE);
+       }
+
+       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);
+
+       da = gtk_drawing_area_new ();
+
+       gtk_signal_connect (GTK_OBJECT (da), "expose_event",
+                           GTK_SIGNAL_FUNC (expose_cb), NULL);
+
+       gtk_container_add (GTK_CONTAINER (window), da);
+
+       timeout_id = gtk_timeout_add (FRAME_DELAY, timeout, NULL);
+
+       gtk_widget_show_all (window);
+       gtk_main ();
+
+       return 0;
+}
index a99977fbda35d4d98774be4a167716fb55ba60f5..f0059d4ab03677b4de779947bcca6ea55a59518f 100644 (file)
@@ -29,19 +29,41 @@ gboolean
 expose_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
 {
   GdkPixbuf *dest;
+  GdkGC *gc;
+  GdkColormap *colormap;
+  GdkColor color;
 
-  gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
+  color.red = 0xffff;
+  color.green = 0xffff;
+  color.blue = 0xffff;
   
-  dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, event->area.width, event->area.height);
+  gc = gdk_gc_new (widget->window);
+  colormap = gdk_window_get_colormap (widget->window);
+  gdk_colormap_alloc_color (colormap, &color, TRUE, TRUE);
+  gdk_gc_set_foreground (gc, &color);
+  gdk_draw_rectangle (widget->window, gc,      
+                     TRUE,
+                     event->area.x, 
+                     event->area.y, 
+                     event->area.width, event->area.height);
+
+  gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
 
-  gdk_pixbuf_composite_color (pixbuf, dest,
-                             0, 0, event->area.width, event->area.height,
-                             -event->area.x, -event->area.y,
-                             (double) widget->allocation.width / gdk_pixbuf_get_width (pixbuf),
-                             (double) widget->allocation.height / gdk_pixbuf_get_height (pixbuf),
-                             interp_type, overall_alpha,
-                             event->area.x, event->area.y, 16, 0xaaaaaa, 0x555555);
 
+  dest = gdk_pixbuf_get_from_drawable(NULL,
+                                     widget->window,
+                                     gdk_window_get_colormap (widget->window),
+                                     event->area.x, 
+                                     event->area.y, 
+                                     0, 0, event->area.width, event->area.height);
+
+  gdk_pixbuf_composite (pixbuf, dest,
+                       0, 0, event->area.width, event->area.height,
+                       -event->area.x, -event->area.y,
+                       (double) widget->allocation.width / gdk_pixbuf_get_width (pixbuf),
+                       (double) widget->allocation.height / gdk_pixbuf_get_height (pixbuf),
+                       interp_type, overall_alpha);
+  
   gdk_pixbuf_render_to_drawable (dest, widget->window, widget->style->fg_gc[GTK_STATE_NORMAL],
                                 0, 0, event->area.x, event->area.y,
                                 event->area.width, event->area.height,
index ec1014025c32132857bf568851e2468823746d0d..0b0ad0b6afc31189fb12f9c177f0917947ce1c7d 100644 (file)
@@ -1,3 +1,15 @@
+2000-06-10  Federico Mena Quintero  <federico@helixcode.com>
+
+       * demo/pixbuf-demo.c: It was cold and rainy this Saturday morning,
+       so I needed something to warm my thighs.  Running plain infinite
+       loops on your laptop to make it hot is not very much fun.  A demo
+       of the gdk-pixbuf scaling functions is way better, and looks
+       prettier, too.
+
+       * configure.in (AC_OUTPUT): Added the demo Makefile.
+
+       * Makefile.am (SUBDIRS): Added the demo directory.
+
 2000-06-09  Larry Ewing  <lewing@helixcode.com>
 
        * gdk-pixbuf/io-png.c (gdk_pixbuf__png_image_load_increment):