new haa tests
authorJavier S. Pedro <maemo@javispedro.com>
Mon, 29 Mar 2010 19:08:49 +0000 (21:08 +0200)
committerJavier S. Pedro <maemo@javispedro.com>
Mon, 29 Mar 2010 19:11:15 +0000 (21:11 +0200)
sdlhaa/test/Makefile
sdlhaa/test/fullscreen.c
sdlhaa/test/switch.c [new file with mode: 0644]

index 964a4c0..8d6139b 100644 (file)
@@ -3,7 +3,7 @@ CFLAGS:=-g -O0 -Wall
 TEST_LDLIBS:=$(shell sdl-config --libs) -lSDL_haa
 TEST_CFLAGS:=$(shell sdl-config --cflags)
 
-TESTS:=basic multi alpha fullscreen
+TESTS:=basic multi alpha fullscreen switch
 
 all: $(TESTS)
 
index 4511096..8fc660b 100644 (file)
@@ -13,8 +13,6 @@
 #include <SDL.h>
 #include <SDL_haa.h>
 
-static bool fullscreen = false;
-
 static SDL_Surface *screen;
 
 static HAA_Actor *actor;
@@ -32,15 +30,6 @@ static Uint32 tick(Uint32 interval, void* param)
        return interval;
 }
 
-static void setup_video_mode()
-{
-       unsigned flags = SDL_SWSURFACE | (fullscreen ? SDL_FULLSCREEN : 0);
-       printf("video mode ...\n");
-       screen = SDL_SetVideoMode(0, 0, 16, flags);
-       assert(screen);
-       printf("video mode set\n");
-}
-
 int main()
 {
        int res;
@@ -50,7 +39,8 @@ int main()
        res = HAA_Init(0);
        assert(res == 0);
        
-       setup_video_mode();
+       screen = SDL_SetVideoMode(0, 0, 16, SDL_SWSURFACE | SDL_FULLSCREEN);
+       assert(screen);
        
        SDL_TimerID timer = SDL_AddTimer(10, tick, NULL);
        assert(timer != NULL);
@@ -71,15 +61,10 @@ int main()
                        case SDL_QUIT:
                                goto quit;
                        case SDL_VIDEOEXPOSE:
-                               //HAA_SetRotation(actor, HAA_Y_AXIS, degrees, 0, 0, 0);
+                               HAA_SetRotation(actor, HAA_Y_AXIS, degrees, 0, 0, 0);
                                res = HAA_Flip(actor);
                                assert(res == 0);
                                break;
-                       case SDL_MOUSEBUTTONUP:
-                               printf("Switching fullscreen\n");
-                               fullscreen = !fullscreen;
-                               setup_video_mode();
-                               break;
                }
        }
 
@@ -91,3 +76,4 @@ quit:
 
        return 0;
 }
+
diff --git a/sdlhaa/test/switch.c b/sdlhaa/test/switch.c
new file mode 100644 (file)
index 0000000..cd2414e
--- /dev/null
@@ -0,0 +1,97 @@
+/* fullscreen - a SDL_haa sample able to enter fullscreen mode
+ *
+ * This file is in the public domain, furnished "as is", without technical
+ * support, and with no warranty, express or implied, as to its usefulness for
+ * any purpose.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <assert.h>
+
+#include <SDL.h>
+#include <SDL_haa.h>
+
+static bool fullscreen = false;
+
+static SDL_Surface *screen;
+
+static HAA_Actor *actor;
+
+static int degrees = 0;
+
+static Uint32 tick(Uint32 interval, void* param)
+{
+       SDL_Event e;
+       e.type = SDL_VIDEOEXPOSE;
+
+       degrees = (degrees+2) % 360;
+       SDL_PushEvent(&e);
+
+       return interval;
+}
+
+static void setup_video_mode()
+{
+       unsigned flags = SDL_SWSURFACE | (fullscreen ? SDL_FULLSCREEN : 0);
+       printf("video mode ...\n");
+       screen = SDL_SetVideoMode(0, 0, 16, flags);
+       assert(screen);
+       printf("updating haa ...\n");
+       int res = HAA_SetVideoMode();
+       assert(res == 0);
+       printf("video mode set\n");
+}
+
+int main()
+{
+       int res;
+       res = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
+       assert(res == 0);
+
+       res = HAA_Init(0);
+       assert(res == 0);
+
+       setup_video_mode();
+
+       SDL_TimerID timer = SDL_AddTimer(10, tick, NULL);
+       assert(timer != NULL);
+
+       actor = HAA_CreateActor(SDL_SWSURFACE, 200, 200, 16);
+       assert(actor);
+
+       SDL_FillRect(actor->surface, NULL,
+               SDL_MapRGB(actor->surface->format, 255, 255, 0));
+
+       HAA_SetPosition(actor, 600, 120);
+       HAA_Show(actor);
+
+       SDL_Event event;
+       while (SDL_WaitEvent(&event)) {
+               if (HAA_FilterEvent(&event) == 0) continue;
+               switch (event.type) {
+                       case SDL_QUIT:
+                               goto quit;
+                       case SDL_VIDEOEXPOSE:
+                               //HAA_SetRotation(actor, HAA_Y_AXIS, degrees, 0, 0, 0);
+                               res = HAA_Flip(actor);
+                               assert(res == 0);
+                               break;
+                       case SDL_MOUSEBUTTONUP:
+                               printf("Switching fullscreen\n");
+                               fullscreen = !fullscreen;
+                               setup_video_mode();
+                               break;
+               }
+       }
+
+quit:
+       HAA_FreeActor(actor);
+
+       HAA_Quit();
+       SDL_Quit();
+
+       return 0;
+}
+