2 * Copyright (C) 2008 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <SDL_image.h>
27 #define SWAP(x, y) do { \
28 x ^= y; y ^= x; x ^= y; \
31 #define ABS(x) ((x) < 0 ? -(x) : (x))
33 #define IS_CENTER(cx, cy, x, y) \
34 ((x + WIDTH/2 == cx) && (y + HEIGHT/2 == cy))
40 ReadPoints (char *filename)
47 file = fopen (filename, "r");
48 fscanf (file, "%d\n", &psize);
49 points = malloc (sizeof (SDL_Rect) * psize);
54 for (i = 0; i < psize; i++)
56 getline (&buffer, &len, file);
57 points[i].x = strtol (buffer, &next, 0);
58 points[i].y = strtol (next+1, NULL, 0);
66 static SDL_Rect rect = {0, 0, WIDTH, HEIGHT};
68 static int inc, err, thre, swap;
69 static int x1, y1, x2, y2;
72 next = (cur + 1) % psize;
73 if (IS_CENTER (points[next].x, points[next].y, rect.x, rect.y) || cur == -1)
76 next = (cur + 1) % psize;
85 if (ABS (inc) > ABS (thre))
95 rect.x = (swap ? y : x) - WIDTH/2;
96 rect.y = (swap ? x : y) - HEIGHT/2;
97 (x2 < x1) ? x-- : x++;
99 if (err >= ABS (thre))
102 y += (inc < 0) ? -1 : 1;
108 ShowPoint (SDL_Surface *screen, SDL_Surface *image, SDL_Rect *rect)
110 SDL_BlitSurface (image, rect, screen, NULL);
111 SDL_UpdateRect (screen, 0, 0, 0, 0);
115 ShowNext (Uint32 interval, void *data)
118 event.type = SDL_USEREVENT;
120 SDL_PushEvent ((SDL_Event *) &event);
125 main (int argc, char **argv)
130 ReadPoints ("pro-gnu");
131 SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER);
132 screen = SDL_SetVideoMode (800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN);
133 image = IMG_Load ("/home/cascardo/fotos/debconf.jpg");
134 SDL_AddTimer (0, ShowNext, NULL);
135 while (SDL_WaitEvent (&event))
137 if (event.type == SDL_KEYDOWN)
139 else if (event.type == SDL_USEREVENT)
140 ShowPoint (screen, image, GetNextPoint ());
142 SDL_FreeSurface (image);