From 85b814d76fbc6830cad31da9e5b7352442362cb9 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Tue, 12 Aug 2008 01:59:06 -0300 Subject: [PATCH] Shows a moving image It shows 30 frames per second of a piece of a image moving from its top-left corner to its bottom-right corner. --- movie.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/movie.c b/movie.c index 8bba5ac..f6a20b9 100644 --- a/movie.c +++ b/movie.c @@ -16,25 +16,54 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define WIDTH 800 +#define HEIGHT 600 #include #include +SDL_Rect * +GetNextPoint (void) +{ + static SDL_Rect rect = {0, 0, WIDTH, HEIGHT}; + rect.x = (rect.x++) % WIDTH; + rect.y = (rect.y++) % HEIGHT; + return ▭ +} + +void +ShowPoint (SDL_Surface *screen, SDL_Surface *image, SDL_Rect *rect) +{ + SDL_BlitSurface (image, rect, screen, NULL); + SDL_UpdateRect (screen, 0, 0, 0, 0); +} + +Uint32 +ShowNext (Uint32 interval, void *data) +{ + SDL_UserEvent event; + event.type = SDL_USEREVENT; + event.code = 0; + SDL_PushEvent ((SDL_Event *) &event); + return 33; +} + int main (int argc, char **argv) { - SDL_Surface *image; SDL_Surface *screen; + SDL_Surface *image; SDL_Event event; SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER); screen = SDL_SetVideoMode (800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN); image = IMG_Load ("/home/cascardo/fotos/debconf.jpg"); - SDL_BlitSurface (image, NULL, screen, NULL); - SDL_UpdateRect (screen, 0, 0, 0, 0); + SDL_AddTimer (0, ShowNext, NULL); while (SDL_WaitEvent (&event)) { if (event.type == SDL_KEYDOWN) break; + else if (event.type == SDL_USEREVENT) + ShowPoint (screen, image, GetNextPoint ()); } SDL_FreeSurface (image); SDL_Quit (); -- 2.20.1