If picture does no exist, warn and exit
[cascardo/movie.git] / gdk.c
diff --git a/gdk.c b/gdk.c
index 8fc579c..d9ed4cd 100644 (file)
--- a/gdk.c
+++ b/gdk.c
@@ -17,6 +17,8 @@
  */
 
 
+#include <stdio.h>
+#include <stdlib.h>
 #include <gtk/gtk.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include "point.h"
@@ -28,9 +30,11 @@ struct ctx
   GArray *points;
   int i;
   gboolean move;
+  GdkGC *gc;
+  GdkGC *gc2;
+  PangoAttrList *list;
 };
 
-#define FILENAME "/home/cascardo/fotos/debconf.jpg"
 #define WIDTH 800
 #define HEIGHT 600
 
@@ -70,6 +74,16 @@ expose (GtkWidget *widget, GdkEventExpose *event, gpointer data)
   gdk_pixbuf_unref (screen);
   if (point.name)
     {
+      PangoLayout *layout;
+      int pw, ph;
+      layout = gtk_widget_create_pango_layout (ctx->draw, point.name);
+      pango_layout_set_attributes (layout, ctx->list);
+      pango_layout_get_pixel_size (layout, &pw, &ph);
+      gdk_draw_rectangle (widget->window, ctx->gc2, TRUE,
+                          (WIDTH - pw - 8) / 2, HEIGHT - ph - 20, pw + 8, ph);
+      gdk_draw_layout (widget->window, ctx->gc, (WIDTH - pw) / 2,
+                       HEIGHT - ph - 20, layout);
+      g_object_unref (layout);
       if (ctx->move)
         g_timeout_add (3000, queue, ctx);
     }
@@ -82,25 +96,52 @@ expose (GtkWidget *widget, GdkEventExpose *event, gpointer data)
   return FALSE;
 }
 
+#define FPF 40
+
+void
+usage ()
+{
+  fprintf (stderr, "movie picture dotsfile\n");
+  exit (0);
+}
+
 int
 main (int argc, char **argv)
 {
   char *filename;
+  char *dotsfile;
   GdkColorspace colorspace;
   gboolean has_alpha;
   int bits_per_sample;
   int width, height;
   GtkWidget *window;
   struct ctx ctx;
+  GdkColor Yellow;
+  GdkColor Black;
+  PangoAttribute *attr;
+  GError *error;
   gtk_init (&argc, &argv);
-  if (argc < 2)
-    filename = FILENAME;
+  if (argc < 3)
+    {
+      usage ();
+    }
   else
-    filename = argv[1];
-  ctx.points = ReadPoints ("pro-gnu");
-  ctx.points = drop_dup_frames (ctx.points, 20);
-  rescale_points (ctx.points, get_scales (20));
-  ctx.picture = gdk_pixbuf_new_from_file (filename, NULL);
+    {
+      filename = argv[1];
+      dotsfile = argv[2];
+    }
+  ctx.points = ReadPoints (dotsfile);
+  ctx.points = drop_dup_frames (ctx.points, FPF);
+  rescale_points (ctx.points, get_scales (FPF));
+  error = NULL;
+  ctx.picture = gdk_pixbuf_new_from_file (filename, &error);
+  if (ctx.picture == NULL)
+    {
+      fprintf (stderr, "Could not open picture %s: %s\n", filename,
+               error->message);
+      g_error_free (error);
+      exit (1);
+    }
   ctx.i = ctx.points->len;
   colorspace = gdk_pixbuf_get_colorspace (ctx.picture);
   has_alpha = gdk_pixbuf_get_has_alpha (ctx.picture);
@@ -116,6 +157,21 @@ main (int argc, char **argv)
   gtk_widget_show_all (window);
   g_signal_connect (G_OBJECT (ctx.draw), "expose_event",
                     G_CALLBACK (expose), &ctx);
+  Yellow.red = 0xFFFF;
+  Yellow.green = 0xFFFF;
+  Yellow.blue = 0;
+  Black.red = 0;
+  Black.green = 0;
+  Black.blue = 0;
+  ctx.gc = gdk_gc_new (ctx.draw->window);
+  gdk_gc_set_rgb_fg_color (ctx.gc, &Yellow);
+  ctx.gc2 = gdk_gc_new (ctx.draw->window);
+  gdk_gc_set_rgb_fg_color (ctx.gc2, &Black);
+  ctx.list = pango_attr_list_new ();
+  attr = pango_attr_size_new (32 * PANGO_SCALE);
+  pango_attr_list_insert (ctx.list, attr);
+  attr = pango_attr_weight_new (PANGO_WEIGHT_SEMIBOLD);
+  pango_attr_list_insert (ctx.list, attr);
   g_timeout_add (10, queue, &ctx);
   gtk_main ();
   gdk_pixbuf_unref (ctx.picture);