Read the names of people from the file
[cascardo/movie.git] / movie.c
diff --git a/movie.c b/movie.c
index 31da099..4af9eb2 100644 (file)
--- a/movie.c
+++ b/movie.c
 #define HBORDER 32
 #define VBORDER 8
 
+#define STOP_INTERVAL (5*1000)
+#define FPS (4)
+
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
 #include <cairo.h>
 #include <SDL.h>
 #include <SDL_image.h>
@@ -40,7 +45,9 @@
 TTF_Font *font;
 
 SDL_Rect *points;
+char **names;
 int psize;
+int stop = 0;
 
 void
 ReadPoints (char *filename)
@@ -49,19 +56,25 @@ ReadPoints (char *filename)
   char *buffer;
   char *next;
   size_t len;
+  ssize_t r;
   int i;
   file = fopen (filename, "r");
   fscanf (file, "%d\n", &psize);
   points = malloc (sizeof (SDL_Rect) * psize);
-  if (points == NULL)
+  names = malloc (sizeof (char *) * psize);
+  if (points == NULL || names == NULL)
     abort ();
   buffer = NULL;
   len = 0;
   for (i = 0; i < psize; i++)
   {
-    getline (&buffer, &len, file);
+    r = getline (&buffer, &len, file);
+    buffer[r - 1] = '\0';
     points[i].x = strtol (buffer, &next, 0);
-    points[i].y = strtol (next+1, NULL, 0);
+    points[i].y = strtol (next+1, &next, 0);
+    strtol (next, &next, 0);
+    while (isspace (*next)) next++;
+    names[i] = strdup (next);
   }
   fclose (file);
 }
@@ -78,6 +91,7 @@ GetNextPoint (void)
   next = (cur + 1) % psize;
   if ((points[next].x == rect.x && points[next].y == rect.y) || cur == -1)
   {
+    stop = 1;
     cur = next;
     next = (cur + 1) % psize;
     err = 0;
@@ -204,7 +218,12 @@ ShowNext (Uint32 interval, void *data)
   event.type = SDL_USEREVENT;
   event.code = 0;
   SDL_PushEvent ((SDL_Event *) &event);
-  return 33;
+  if (stop)
+  {
+    stop = 0;
+    return STOP_INTERVAL;
+  }
+  return 1000/FPS;
 }
 
 int
@@ -214,11 +233,12 @@ main (int argc, char **argv)
   SDL_Surface *image;
   SDL_Surface *slice;
   SDL_Event event;
+  int i;
   ReadPoints ("pro-gnu");
   SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER);
   TTF_Init ();
   font = TTF_OpenFont ("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", 48);
-  screen = SDL_SetVideoMode (800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
+  screen = SDL_SetVideoMode (WIDTH, HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
   image = IMG_Load ("/home/cascardo/fotos/debconf.jpg");
   SDL_AddTimer (0, ShowNext, NULL);
   while (SDL_WaitEvent (&event))
@@ -237,5 +257,8 @@ main (int argc, char **argv)
   TTF_Quit ();
   SDL_Quit ();
   free (points);
+  for (i = 0; i < psize; i++)
+    free (names[i]);
+  free (names);
   return 0;
 }