Shows the set of points
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 16 Aug 2008 14:49:19 +0000 (11:49 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 16 Aug 2008 14:49:19 +0000 (11:49 -0300)
gdk.c

diff --git a/gdk.c b/gdk.c
index df84edb..e8e6261 100644 (file)
--- a/gdk.c
+++ b/gdk.c
 
 #include <gtk/gtk.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
+#include "point.h"
+
+struct ctx
+{
+  GdkPixbuf *picture;
+  GArray *points;
+  int i;
+};
 
 #define FILENAME "/home/cascardo/fotos/debconf.jpg"
 #define WIDTH 800
@@ -34,15 +42,18 @@ queue (gpointer data)
 gboolean
 expose (GtkWidget *widget, GdkEventExpose *event, gpointer data)
 {
-  GdkPixbuf *picture;
   GdkPixbuf *screen;
-  picture = (GdkPixbuf *) data;
+  struct ctx *ctx;
+  Point point;
+  ctx = (struct ctx *) data;
+  ctx->i = (ctx->i >= ctx->points->len) ? 0 : ctx->i + 1;
+  point = g_array_index (ctx->points, Point, ctx->i);
   screen = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
                            event->area.width, event->area.height);
-  gdk_pixbuf_scale (picture, screen, 0, 0,
+  gdk_pixbuf_scale (ctx->picture, screen, 0, 0,
                     event->area.width, event->area.height,
-                   -event->area.x, -event->area.y,
-                   4.0, 4.0, GDK_INTERP_HYPER);
+                   -point.x + event->area.width/2, -point.y + event->area.height/2,
+                   1.0, 1.0, GDK_INTERP_HYPER);
   gdk_draw_pixbuf (widget->window, NULL, screen, 0, 0, 0, 0, -1, -1,
                    GDK_RGB_DITHER_NONE, 0, 0);
   gdk_pixbuf_unref (screen);
@@ -53,22 +64,24 @@ int
 main (int argc, char **argv)
 {
   char *filename;
-  GdkPixbuf *picture;
   GdkColorspace colorspace;
   gboolean has_alpha;
   int bits_per_sample;
   int width, height;
   GtkWidget *window;
   GtkWidget *draw;
+  struct ctx ctx;
   gtk_init (&argc, &argv);
   if (argc < 2)
     filename = FILENAME;
   else
     filename = argv[1];
-  picture = gdk_pixbuf_new_from_file (filename, NULL);
-  colorspace = gdk_pixbuf_get_colorspace (picture);
-  has_alpha = gdk_pixbuf_get_has_alpha (picture);
-  bits_per_sample = gdk_pixbuf_get_bits_per_sample (picture);
+  ctx.points = ReadPoints ("pro-gnu");
+  ctx.picture = gdk_pixbuf_new_from_file (filename, NULL);
+  ctx.i = ctx.points->len;
+  colorspace = gdk_pixbuf_get_colorspace (ctx.picture);
+  has_alpha = gdk_pixbuf_get_has_alpha (ctx.picture);
+  bits_per_sample = gdk_pixbuf_get_bits_per_sample (ctx.picture);
   width = WIDTH;
   height = HEIGHT;
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
@@ -79,9 +92,9 @@ main (int argc, char **argv)
   gtk_container_add (GTK_CONTAINER (window), draw);
   gtk_widget_show_all (window);
   g_signal_connect (G_OBJECT (draw), "expose_event",
-                    G_CALLBACK (expose), picture);
+                    G_CALLBACK (expose), &ctx);
   g_timeout_add (10, queue, draw);
   gtk_main ();
-  gdk_pixbuf_unref (picture);
+  gdk_pixbuf_unref (ctx.picture);
   return 0;
 }