new haa tests
[sdlhildon] / sdlhaa / test / switch.c
1 /* fullscreen - a SDL_haa sample able to enter fullscreen mode
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 bool fullscreen = false;
17
18 static SDL_Surface *screen;
19
20 static HAA_Actor *actor;
21
22 static int degrees = 0;
23
24 static Uint32 tick(Uint32 interval, void* param)
25 {
26         SDL_Event e;
27         e.type = SDL_VIDEOEXPOSE;
28
29         degrees = (degrees+2) % 360;
30         SDL_PushEvent(&e);
31
32         return interval;
33 }
34
35 static void setup_video_mode()
36 {
37         unsigned flags = SDL_SWSURFACE | (fullscreen ? SDL_FULLSCREEN : 0);
38         printf("video mode ...\n");
39         screen = SDL_SetVideoMode(0, 0, 16, flags);
40         assert(screen);
41         printf("updating haa ...\n");
42         int res = HAA_SetVideoMode();
43         assert(res == 0);
44         printf("video mode set\n");
45 }
46
47 int main()
48 {
49         int res;
50         res = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
51         assert(res == 0);
52
53         res = HAA_Init(0);
54         assert(res == 0);
55
56         setup_video_mode();
57
58         SDL_TimerID timer = SDL_AddTimer(10, tick, NULL);
59         assert(timer != NULL);
60
61         actor = HAA_CreateActor(SDL_SWSURFACE, 200, 200, 16);
62         assert(actor);
63
64         SDL_FillRect(actor->surface, NULL,
65                 SDL_MapRGB(actor->surface->format, 255, 255, 0));
66
67         HAA_SetPosition(actor, 600, 120);
68         HAA_Show(actor);
69
70         SDL_Event event;
71         while (SDL_WaitEvent(&event)) {
72                 if (HAA_FilterEvent(&event) == 0) continue;
73                 switch (event.type) {
74                         case SDL_QUIT:
75                                 goto quit;
76                         case SDL_VIDEOEXPOSE:
77                                 //HAA_SetRotation(actor, HAA_Y_AXIS, degrees, 0, 0, 0);
78                                 res = HAA_Flip(actor);
79                                 assert(res == 0);
80                                 break;
81                         case SDL_MOUSEBUTTONUP:
82                                 printf("Switching fullscreen\n");
83                                 fullscreen = !fullscreen;
84                                 setup_video_mode();
85                                 break;
86                 }
87         }
88
89 quit:
90         HAA_FreeActor(actor);
91
92         HAA_Quit();
93         SDL_Quit();
94
95         return 0;
96 }
97