4 #include <SDL_rect.h> |
4 #include <SDL_rect.h> |
5 #include <SDL_pixels.h> |
5 #include <SDL_pixels.h> |
6 #include <SDL_video.h> |
6 #include <SDL_video.h> |
7 #include <SDL_shape.h> |
7 #include <SDL_shape.h> |
8 #include <SDL_keysym.h> |
8 #include <SDL_keysym.h> |
|
9 #include <SDL_timer.h> |
9 |
10 |
10 #define SHAPED_WINDOW_X 150 |
11 #define SHAPED_WINDOW_X 150 |
11 #define SHAPED_WINDOW_Y 150 |
12 #define SHAPED_WINDOW_Y 150 |
12 #define SHAPED_WINDOW_DIMENSION 640 |
13 #define SHAPED_WINDOW_DIMENSION 640 |
|
14 |
|
15 #define TICK_INTERVAL 18 |
13 |
16 |
14 void render(SDL_Window* window,SDL_Texture *texture,SDL_Rect texture_dimensions) { |
17 void render(SDL_Window* window,SDL_Texture *texture,SDL_Rect texture_dimensions) { |
15 SDL_SelectRenderer(window); |
18 SDL_SelectRenderer(window); |
16 |
19 |
17 //Clear render-target to blue. |
20 //Clear render-target to blue. |
20 |
23 |
21 //Render the texture. |
24 //Render the texture. |
22 SDL_RenderCopy(texture,&texture_dimensions,&texture_dimensions); |
25 SDL_RenderCopy(texture,&texture_dimensions,&texture_dimensions); |
23 |
26 |
24 SDL_RenderPresent(); |
27 SDL_RenderPresent(); |
|
28 } |
|
29 |
|
30 static Uint32 next_time; |
|
31 |
|
32 Uint32 time_left() { |
|
33 Uint32 now = SDL_GetTicks(); |
|
34 if(next_time <= now) |
|
35 return 0; |
|
36 else |
|
37 return next_time - now; |
25 } |
38 } |
26 |
39 |
27 int main(int argc,char** argv) { |
40 int main(int argc,char** argv) { |
28 if(argc < 2) { |
41 if(argc < 2) { |
29 printf("SDL_Shape requires at least one bitmap file as argument.\n"); |
42 printf("SDL_Shape requires at least one bitmap file as argument.\n"); |
104 Uint32 format = 0,access = 0; |
117 Uint32 format = 0,access = 0; |
105 SDL_Rect texture_dimensions = {0,0,0,0}; |
118 SDL_Rect texture_dimensions = {0,0,0,0}; |
106 SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h); |
119 SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h); |
107 SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h); |
120 SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h); |
108 SDL_SetWindowShape(window,pictures[current_picture],&mode); |
121 SDL_SetWindowShape(window,pictures[current_picture],&mode); |
109 render(window,textures[current_picture],texture_dimensions); |
122 next_time = SDL_GetTicks() + TICK_INTERVAL; |
110 while(should_exit == 0) { |
123 while(should_exit == 0) { |
111 event_pending = SDL_PollEvent(&event); |
124 event_pending = SDL_PollEvent(&event); |
112 if(event_pending == 1) { |
125 if(event_pending == 1) { |
113 if(event.type == SDL_KEYDOWN) { |
126 if(event.type == SDL_KEYDOWN) { |
114 button_down = 1; |
127 button_down = 1; |
121 if(current_picture >= num_pictures) |
134 if(current_picture >= num_pictures) |
122 current_picture = 0; |
135 current_picture = 0; |
123 SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h); |
136 SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h); |
124 SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h); |
137 SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h); |
125 SDL_SetWindowShape(window,pictures[current_picture],&mode); |
138 SDL_SetWindowShape(window,pictures[current_picture],&mode); |
126 render(window,textures[current_picture],texture_dimensions); |
|
127 |
|
128 } |
139 } |
129 if(event.type == SDL_QUIT) |
140 if(event.type == SDL_QUIT) |
130 should_exit = 1; |
141 should_exit = 1; |
131 event_pending = 0; |
142 event_pending = 0; |
132 } |
143 } |
|
144 render(window,textures[current_picture],texture_dimensions); |
|
145 SDL_Delay(time_left()); |
|
146 next_time += TICK_INTERVAL; |
133 } |
147 } |
134 |
148 |
135 //Free the textures. |
149 //Free the textures. |
136 for(i=0;i<num_pictures;i++) |
150 for(i=0;i<num_pictures;i++) |
137 SDL_DestroyTexture(textures[i]); |
151 SDL_DestroyTexture(textures[i]); |