45110967e6e09e6ba13b3e7c6ed7c2987fb170ac
[sdlhildon] / sdlhaa / test / fullscreen.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("video mode set\n");
42 }
43
44 int main()
45 {
46         int res;
47         res = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
48         assert(res == 0);
49
50         res = HAA_Init(0);
51         assert(res == 0);
52         
53         setup_video_mode();
54         
55         SDL_TimerID timer = SDL_AddTimer(10, tick, NULL);
56         assert(timer != NULL);
57
58         actor = HAA_CreateActor(SDL_SWSURFACE, 200, 200, 16);
59         assert(actor);
60         
61         SDL_FillRect(actor->surface, NULL,
62                 SDL_MapRGB(actor->surface->format, 255, 255, 0));
63         
64         HAA_SetPosition(actor, 400, 120);
65         HAA_Show(actor);
66
67         SDL_Event event;
68         while (SDL_WaitEvent(&event)) {
69                 if (HAA_FilterEvent(&event) == 0) continue;
70                 switch (event.type) {
71                         case SDL_QUIT:
72                                 goto quit;
73                         case SDL_VIDEOEXPOSE:
74                                 //HAA_SetRotation(actor, HAA_Y_AXIS, degrees, 0, 0, 0);
75                                 res = HAA_Flip(actor);
76                                 assert(res == 0);
77                                 break;
78                         case SDL_MOUSEBUTTONUP:
79                                 printf("Switching fullscreen\n");
80                                 fullscreen = !fullscreen;
81                                 setup_video_mode();
82                                 break;
83                 }
84         }
85
86 quit:
87         HAA_FreeActor(actor);
88
89         HAA_Quit();
90         SDL_Quit();
91
92         return 0;
93 }