629c625af4c40b891d72c3bd33782619ba39e009
[sdlhildon] / sdlhaa / test / basic.c
1 /* basic - a simple SDL_haa sample
2  *
3  * This file is in the public domain, furnished "as is", without technical
4  * support, and with no warranty, express or implied, as to its usefulness for
5  * any purpose.
6  */
7
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <stdbool.h>
11 #include <assert.h>
12
13 #include <SDL.h>
14 #include <SDL_haa.h>
15
16 static SDL_Surface *screen;
17
18 static HAA_Actor *actor;
19
20 static int degrees = 0;
21
22 static Uint32 tick(Uint32 interval, void* param)
23 {
24         SDL_Event e;
25         e.type = SDL_VIDEOEXPOSE;
26
27         degrees = (degrees+2) % 360;
28         SDL_PushEvent(&e);
29
30         return interval;
31 }
32
33 int main()
34 {
35         int res;
36         res = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
37         assert(res == 0);
38
39         res = HAA_Init(0);
40         assert(res == 0);
41
42         screen = SDL_SetVideoMode(0, 0, 16, SDL_SWSURFACE);
43         assert(screen);
44         
45         SDL_TimerID timer = SDL_AddTimer(10, tick, NULL);
46         assert(timer != NULL);
47
48         actor = HAA_CreateActor(SDL_SWSURFACE, 200, 200, 16);
49         assert(actor);
50         
51         SDL_FillRect(actor->surface, NULL,
52                 SDL_MapRGB(actor->surface->format, 0, 255, 0));
53         
54         HAA_SetPosition(actor, 200, 100);
55         HAA_Show(actor);
56
57         SDL_Event event;
58         while (SDL_WaitEvent(&event)) {
59                 if (HAA_FilterEvent(&event) == 0) continue;
60                 switch (event.type) {
61                         case SDL_QUIT:
62                                 goto quit;
63                         case SDL_VIDEOEXPOSE:
64                                 HAA_SetRotation(actor, HAA_Y_AXIS, degrees, 0, 0, 0);
65                                 res = HAA_Flip(actor);
66                                 assert(res == 0);
67                                 break;
68                 }
69         }
70
71 quit:
72         HAA_FreeActor(actor);
73
74         HAA_Quit();
75         SDL_Quit();
76
77         return 0;
78 }