From 93fd65f76257c3fd36095b6a4ce5974e4140c491 Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Wed, 8 Jan 2014 14:18:11 -0500 Subject: [PATCH] some fixes to the testshape.c code so it more correctly works. --- test/testshape.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/test/testshape.c b/test/testshape.c index c202d8ec6..bffa540e8 100644 --- a/test/testshape.c +++ b/test/testshape.c @@ -19,12 +19,11 @@ #define SHAPED_WINDOW_Y 150 #define SHAPED_WINDOW_DIMENSION 640 -#define TICK_INTERVAL 1000/10 - typedef struct LoadedPicture { SDL_Surface *surface; SDL_Texture *texture; SDL_WindowShapeMode mode; + const char* name; } LoadedPicture; void render(SDL_Renderer *renderer,SDL_Texture *texture,SDL_Rect texture_dimensions) @@ -39,17 +38,6 @@ void render(SDL_Renderer *renderer,SDL_Texture *texture,SDL_Rect texture_dimensi SDL_RenderPresent(renderer); } -static Uint32 next_time; - -Uint32 time_left() -{ - Uint32 now = SDL_GetTicks(); - if(next_time <= now) - return 0; - else - return next_time - now; -} - int main(int argc,char** argv) { Uint8 num_pictures; @@ -87,18 +75,19 @@ int main(int argc,char** argv) pictures[i].surface = NULL; for(i=0;iformat; - if(format->Amask != 0) { + if(SDL_ISPIXELFORMAT_ALPHA(format->format)) { pictures[i].mode.mode = ShapeModeBinarizeAlpha; pictures[i].mode.parameters.binarizationCutoff = 255; } @@ -108,7 +97,11 @@ int main(int argc,char** argv) } } - window = SDL_CreateShapedWindow("SDL_Shape test",SHAPED_WINDOW_X,SHAPED_WINDOW_Y,SHAPED_WINDOW_DIMENSION,SHAPED_WINDOW_DIMENSION,SDL_WINDOW_RESIZABLE); + window = SDL_CreateShapedWindow("SDL_Shape test", + SHAPED_WINDOW_X, SHAPED_WINDOW_Y, + SHAPED_WINDOW_DIMENSION,SHAPED_WINDOW_DIMENSION, + 0); + SDL_SetWindowPosition(window, SHAPED_WINDOW_X, SHAPED_WINDOW_Y); if(window == NULL) { for(i=0;i= num_pictures) current_picture = 0; + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Changing to shaped bmp: %s", pictures[current_picture].name); SDL_QueryTexture(pictures[current_picture].texture,(Uint32 *)&pixelFormat,(int *)&access,&texture_dimensions.w,&texture_dimensions.h); SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h); SDL_SetWindowShape(window,pictures[current_picture].surface,&pictures[current_picture].mode); @@ -183,8 +179,7 @@ int main(int argc,char** argv) event_pending = 0; } render(renderer,pictures[current_picture].texture,texture_dimensions); - SDL_Delay(time_left()); - next_time += TICK_INTERVAL; + SDL_Delay(10); } /* Free the textures. */