X-Git-Url: http://git.maemo.org/git/?p=sdlhildon;a=blobdiff_plain;f=sdlhaa%2Ftest%2Falpha.c;fp=sdlhaa%2Ftest%2Falpha.c;h=dd089568e42e2755fef468a905c4ed4286f69481;hp=0000000000000000000000000000000000000000;hb=4fed23fec414328a2135440d7a936e9b1604283f;hpb=effcd03c8ab831f04aee0b4ae836a5aef94da0fb diff --git a/sdlhaa/test/alpha.c b/sdlhaa/test/alpha.c new file mode 100644 index 0000000..dd08956 --- /dev/null +++ b/sdlhaa/test/alpha.c @@ -0,0 +1,95 @@ +/* alpha - a simple SDL_haa sample with a RGBA transparent actor + * + * 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 +#include +#include +#include + +#include +#include + +static SDL_Surface *screen; + +static HAA_Actor *actor; + +static int degrees = 0; + +static Uint32 tick(Uint32 interval, void* param) +{ + SDL_UserEvent e; + e.type = SDL_USEREVENT; + + degrees = (degrees+2) % 360; + SDL_PushEvent((SDL_Event*)&e); + + return interval; +} + +int main() +{ + int res; + res = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER); + assert(res == 0); + + res = HAA_Init(0); + assert(res == 0); + + screen = SDL_SetVideoMode(0, 0, 16, SDL_SWSURFACE); + assert(screen); + + SDL_FillRect(screen, NULL, + SDL_MapRGBA(screen->format, 150, 0, 0, 255)); + + SDL_Rect dark = {350, 180, 160, 50}; + SDL_FillRect(screen, &dark, + SDL_MapRGBA(screen->format, 255, 0, 0, 255)); + + actor = HAA_CreateActor(SDL_SWSURFACE, 200, 200, 32); + assert(actor); + + SDL_FillRect(actor->surface, NULL, + SDL_MapRGBA(actor->surface->format, 0, 255, 0, 250)); + + SDL_Rect hole = {63, 63, 74, 74}; + SDL_FillRect(actor->surface, &hole, + SDL_MapRGBA(actor->surface->format, 0, 0, 255, 80)); + + HAA_SetPosition(actor, 400, 160); + HAA_Show(actor); + + SDL_TimerID timer = SDL_AddTimer(10, tick, NULL); + assert(timer != NULL); + + SDL_Event event; + while (SDL_WaitEvent(&event)) { + if (HAA_FilterEvent(&event) == 0) continue; + switch (event.type) { + case SDL_QUIT: + goto quit; + case SDL_VIDEOEXPOSE: + res = HAA_Flip(actor); + assert(res == 0); + res = SDL_Flip(screen); + assert(res == 0); + break; + case SDL_USEREVENT: + HAA_SetRotation(actor, HAA_Y_AXIS, degrees, 0, 0, 0); + res = HAA_Commit(actor); + assert(res == 0); + break; + } + } + +quit: + HAA_FreeActor(actor); + + HAA_Quit(); + SDL_Quit(); + + return 0; +}