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.
23 #include <SDL_image.h>
25 #define SWAP(x, y) do { \
26 x ^= y; y ^= x; x ^= y; \
29 #define ABS(x) ((x) < 0 ? -(x) : (x))
31 #define IS_CENTER(cx, cy, x, y) \
32 ((x + WIDTH/2 == cx) && (y + HEIGHT/2 == cy))
42 static SDL_Rect rect = {0, 0, WIDTH, HEIGHT};
44 static int inc, err, thre, swap;
45 static int x1, y1, x2, y2;
48 next = (cur + 1) % (sizeof (points) / sizeof (SDL_Rect));
49 if (IS_CENTER (points[next].x, points[next].y, rect.x, rect.y) || cur == -1)
52 next = (cur + 1) % (sizeof (points) / sizeof (SDL_Rect));
61 if (ABS (inc) > ABS (thre))
71 rect.x = (swap ? y : x) - WIDTH/2;
72 rect.y = (swap ? x : y) - HEIGHT/2;
73 (x2 < x1) ? x-- : x++;
75 if (err >= ABS (thre))
78 y += (inc < 0) ? -1 : 1;
84 ShowPoint (SDL_Surface *screen, SDL_Surface *image, SDL_Rect *rect)
86 SDL_BlitSurface (image, rect, screen, NULL);
87 SDL_UpdateRect (screen, 0, 0, 0, 0);
91 ShowNext (Uint32 interval, void *data)
94 event.type = SDL_USEREVENT;
96 SDL_PushEvent ((SDL_Event *) &event);
101 main (int argc, char **argv)
106 SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER);
107 screen = SDL_SetVideoMode (800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN);
108 image = IMG_Load ("/home/cascardo/fotos/debconf.jpg");
109 SDL_AddTimer (0, ShowNext, NULL);
110 while (SDL_WaitEvent (&event))
112 if (event.type == SDL_KEYDOWN)
114 else if (event.type == SDL_USEREVENT)
115 ShowPoint (screen, image, GetNextPoint ());
117 SDL_FreeSurface (image);