Added code to make testshape switch shapes on keystrokes and exit on an ESC keystroke.
authorEli Gottlieb <eligottlieb@gmail.com>
Sun, 18 Jul 2010 23:36:39 -0400
changeset 4803a4c1df880690
parent 4802 f14a8c05f5bb
child 4804 b33752266d8f
Added code to make testshape switch shapes on keystrokes and exit on an ESC keystroke.
test/testshape.c
     1.1 --- a/test/testshape.c	Sun Jul 18 23:05:40 2010 -0400
     1.2 +++ b/test/testshape.c	Sun Jul 18 23:36:39 2010 -0400
     1.3 @@ -5,6 +5,7 @@
     1.4  #include <SDL_pixels.h>
     1.5  #include <SDL_video.h>
     1.6  #include <SDL_shape.h>
     1.7 +#include <SDL_keysym.h>
     1.8  
     1.9  #define SHAPED_WINDOW_X 150
    1.10  #define SHAPED_WINDOW_Y 150
    1.11 @@ -86,7 +87,7 @@
    1.12  	event_pending = SDL_PollEvent(&event);
    1.13  	unsigned int current_picture = 0;
    1.14  	SDL_WindowShapeMode mode = {ShapeModeDefault,1};
    1.15 -	int mouse_down = 0;
    1.16 +	int button_down = 0;
    1.17  	Uint32 format = 0,access = 0;
    1.18  	SDL_Rect texture_dimensions = {0,0,0,0};
    1.19  	SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h);
    1.20 @@ -95,10 +96,13 @@
    1.21  	while(should_exit == 0) {
    1.22  		event_pending = SDL_PollEvent(&event);
    1.23  		if(event_pending == 1) {
    1.24 -			if(event.type == SDL_MOUSEBUTTONDOWN)
    1.25 -				mouse_down = 1;
    1.26 -			if(mouse_down && event.type == SDL_MOUSEBUTTONUP) {
    1.27 -				mouse_down = 0;
    1.28 +			if(event.type == SDL_KEYDOWN) {
    1.29 +				button_down = 1;
    1.30 +				if(event.key.keysym.sym == SDLK_ESCAPE)
    1.31 +					should_exit = 1;
    1.32 +			}
    1.33 +			if(button_down && event.type == SDL_KEYUP) {
    1.34 +				button_down = 0;
    1.35  				current_picture += 1;
    1.36  				if(current_picture >= num_pictures)
    1.37  					current_picture = 0;