some fixes to the testshape.c code so it more correctly works.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
diff --git a/test/testshape.c b/test/testshape.c
index c202d8e..bffa540 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;i<num_pictures;i++) {
pictures[i].surface = SDL_LoadBMP(argv[i+1]);
+ pictures[i].name = argv[i+1];
if(pictures[i].surface == NULL) {
j = 0;
for(j=0;j<num_pictures;j++)
SDL_FreeSurface(pictures[j].surface);
SDL_free(pictures);
SDL_VideoQuit();
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not load surface from named bitmap file.");
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not load surface from named bitmap file: %s", argv[i+1]);
exit(-3);
}
format = pictures[i].surface->format;
- 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;i++)
SDL_FreeSurface(pictures[i].surface);
@@ -157,23 +150,26 @@ int main(int argc,char** argv)
texture_dimensions.w = 0;
texture_dimensions.x = 0;
texture_dimensions.y = 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);
- next_time = SDL_GetTicks() + TICK_INTERVAL;
while(should_exit == 0) {
event_pending = SDL_PollEvent(&event);
if(event_pending == 1) {
if(event.type == SDL_KEYDOWN) {
button_down = 1;
- if(event.key.keysym.sym == SDLK_ESCAPE)
+ if(event.key.keysym.sym == SDLK_ESCAPE) {
should_exit = 1;
+ break;
+ }
}
if(button_down && event.type == SDL_KEYUP) {
button_down = 0;
current_picture += 1;
if(current_picture >= 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. */