Add missing VS2012 test projects; update VS2010 and VS2012 solutions; update keybord suite for VS compiler warnings
2 Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
16 #include "SDL_shape.h"
18 #define SHAPED_WINDOW_X 150
19 #define SHAPED_WINDOW_Y 150
20 #define SHAPED_WINDOW_DIMENSION 640
22 #define TICK_INTERVAL 1000/10
24 typedef struct LoadedPicture {
27 SDL_WindowShapeMode mode;
30 void render(SDL_Renderer *renderer,SDL_Texture *texture,SDL_Rect texture_dimensions)
32 //Clear render-target to blue.
33 SDL_SetRenderDrawColor(renderer,0x00,0x00,0xff,0xff);
34 SDL_RenderClear(renderer);
37 SDL_RenderCopy(renderer,texture,&texture_dimensions,&texture_dimensions);
39 SDL_RenderPresent(renderer);
42 static Uint32 next_time;
46 Uint32 now = SDL_GetTicks();
50 return next_time - now;
53 int main(int argc,char** argv)
56 LoadedPicture* pictures;
58 SDL_PixelFormat* format = NULL;
60 SDL_Renderer *renderer;
61 SDL_Color black = {0,0,0,0xff};
63 int event_pending = 0;
65 unsigned int current_picture;
67 Uint32 pixelFormat = 0;
69 SDL_Rect texture_dimensions;;
72 printf("SDL_Shape requires at least one bitmap file as argument.\n");
76 if(SDL_VideoInit(NULL) == -1) {
77 printf("Could not initialize SDL video.\n");
81 num_pictures = argc - 1;
82 pictures = (LoadedPicture *)malloc(sizeof(LoadedPicture)*num_pictures);
83 for(i=0;i<num_pictures;i++)
84 pictures[i].surface = NULL;
85 for(i=0;i<num_pictures;i++) {
86 pictures[i].surface = SDL_LoadBMP(argv[i+1]);
87 if(pictures[i].surface == NULL) {
89 for(j=0;j<num_pictures;j++)
90 if(pictures[j].surface != NULL)
91 SDL_FreeSurface(pictures[j].surface);
94 printf("Could not load surface from named bitmap file.\n");
98 format = pictures[i].surface->format;
99 if(format->Amask != 0) {
100 pictures[i].mode.mode = ShapeModeBinarizeAlpha;
101 pictures[i].mode.parameters.binarizationCutoff = 255;
104 pictures[i].mode.mode = ShapeModeColorKey;
105 pictures[i].mode.parameters.colorKey = black;
109 window = SDL_CreateShapedWindow("SDL_Shape test",SHAPED_WINDOW_X,SHAPED_WINDOW_Y,SHAPED_WINDOW_DIMENSION,SHAPED_WINDOW_DIMENSION,SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN);
111 for(i=0;i<num_pictures;i++)
112 SDL_FreeSurface(pictures[i].surface);
115 printf("Could not create shaped window for SDL_Shape.\n");
118 renderer = SDL_CreateRenderer(window,-1,0);
120 SDL_DestroyWindow(window);
121 for(i=0;i<num_pictures;i++)
122 SDL_FreeSurface(pictures[i].surface);
125 printf("Could not create rendering context for SDL_Shape window.\n");
129 for(i=0;i<num_pictures;i++)
130 pictures[i].texture = NULL;
131 for(i=0;i<num_pictures;i++) {
132 pictures[i].texture = SDL_CreateTextureFromSurface(renderer,pictures[i].surface);
133 if(pictures[i].texture == NULL) {
135 for(j=0;j<num_pictures;i++)
136 if(pictures[i].texture != NULL)
137 SDL_DestroyTexture(pictures[i].texture);
138 for(i=0;i<num_pictures;i++)
139 SDL_FreeSurface(pictures[i].surface);
141 SDL_DestroyRenderer(renderer);
142 SDL_DestroyWindow(window);
144 printf("Could not create texture for SDL_shape.\n");
151 event_pending = SDL_PollEvent(&event);
154 texture_dimensions.h = 0;
155 texture_dimensions.w = 0;
156 texture_dimensions.x = 0;
157 texture_dimensions.y = 0;
158 SDL_QueryTexture(pictures[current_picture].texture,(Uint32 *)&pixelFormat,(int *)&access,&texture_dimensions.w,&texture_dimensions.h);
159 SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
160 SDL_SetWindowShape(window,pictures[current_picture].surface,&pictures[current_picture].mode);
161 next_time = SDL_GetTicks() + TICK_INTERVAL;
162 while(should_exit == 0) {
163 event_pending = SDL_PollEvent(&event);
164 if(event_pending == 1) {
165 if(event.type == SDL_KEYDOWN) {
167 if(event.key.keysym.sym == SDLK_ESCAPE)
170 if(button_down && event.type == SDL_KEYUP) {
172 current_picture += 1;
173 if(current_picture >= num_pictures)
175 SDL_QueryTexture(pictures[current_picture].texture,(Uint32 *)&pixelFormat,(int *)&access,&texture_dimensions.w,&texture_dimensions.h);
176 SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
177 SDL_SetWindowShape(window,pictures[current_picture].surface,&pictures[current_picture].mode);
179 if(event.type == SDL_QUIT)
183 render(renderer,pictures[current_picture].texture,texture_dimensions);
184 SDL_Delay(time_left());
185 next_time += TICK_INTERVAL;
189 for(i=0;i<num_pictures;i++)
190 SDL_DestroyTexture(pictures[i].texture);
191 SDL_DestroyRenderer(renderer);
192 //Destroy the window.
193 SDL_DestroyWindow(window);
194 //Free the original surfaces backing the textures.
195 for(i=0;i<num_pictures;i++)
196 SDL_FreeSurface(pictures[i].surface);
198 //Call SDL_VideoQuit() before quitting.
204 /* vi: set ts=4 sw=4 expandtab: */