test/testshape.c
changeset 4800 6d4be626225f
parent 4799 a0e096916474
child 4802 f14a8c05f5bb
     1.1 --- a/test/testshape.c	Sun Jul 18 21:31:22 2010 -0400
     1.2 +++ b/test/testshape.c	Sun Jul 18 22:17:52 2010 -0400
     1.3 @@ -40,7 +40,9 @@
     1.4  		}
     1.5  		//THIS CONVERSION ROUTINE IS FRAGILE!  It relies in the fact that only certain portions of the format structure must be filled in to use it.
     1.6  		SDL_PixelFormat format = {NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
     1.7 -		SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_RGBA8888,&format.BitsPerPixel,&format.Rmask,&format.Gmask,&format.Bmask,&format.Amask);
     1.8 +		int bpp = 0;
     1.9 +		SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_RGBA8888,&bpp,&format.Rmask,&format.Gmask,&format.Bmask,&format.Amask);
    1.10 +		format.BitsPerPixel = bpp;
    1.11  		format.BytesPerPixel = format.BitsPerPixel / 8 + (format.BitsPerPixel % 8 > 0 ? 1 : 0);
    1.12  		pictures[i] = SDL_ConvertSurface(original,&format,0);
    1.13  		//We have no more need of the original now that we have our desired format.
    1.14 @@ -64,11 +66,11 @@
    1.15  		int y =0,x = 0;
    1.16  		for(y=0;y<pictures[i]->h;y++)
    1.17  			for(x=0;x<pictures[i]->w;x++) {
    1.18 -				Uint32* pixel = pixels+y*pitch+x*pictures[i]->format->BytesPerPixel;
    1.19 +				Uint32* pixel = pixels + y * pitch + x * pictures[i]->format->BytesPerPixel;
    1.20  				Uint8 r = 0,g = 0,b = 0;
    1.21  				SDL_GetRGB(*pixel,pictures[i]->format,&r,&g,&b);
    1.22 -				if(r == g == b == 0x00)
    1.23 -					*pixel = SDL_MapRGBA(pictures[i]->format,r,g,b,0);
    1.24 +				//if(r == g == b == 0xff)
    1.25 +				//	*pixel = SDL_MapRGBA(pictures[i]->format,r,g,b,0);
    1.26  			}
    1.27  			
    1.28  		if(SDL_MUSTLOCK(pictures[i]))
    1.29 @@ -117,7 +119,7 @@
    1.30  	}
    1.31  	
    1.32  	SDL_Event event;
    1.33 -	int event_pending = 0;
    1.34 +	int event_pending = 0,should_exit = 0;
    1.35  	event_pending = SDL_PollEvent(&event);
    1.36  	unsigned int current_picture = 0;
    1.37  	SDL_WindowShapeMode mode = {ShapeModeDefault,1};
    1.38 @@ -127,17 +129,23 @@
    1.39  	SDL_Rect texture_dimensions = {0,0,0,0};
    1.40  	SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h);
    1.41  	SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
    1.42 -	while(event.type != SDL_QUIT) {
    1.43 -		if(event.type == SDL_MOUSEBUTTONDOWN)
    1.44 -			mouse_down = 1;
    1.45 -		if(mouse_down && event.type == SDL_MOUSEBUTTONUP) {
    1.46 -			mouse_down = 0;
    1.47 -			current_picture += 1;
    1.48 -			if(current_picture >= num_pictures)
    1.49 -				current_picture = 0;
    1.50 -			SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h);
    1.51 -			SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
    1.52 -			SDL_SetWindowShape(window,pictures[current_picture],&mode);
    1.53 +	while(should_exit == 0) {
    1.54 +		event_pending = SDL_PollEvent(&event);
    1.55 +		if(event_pending == 1) {
    1.56 +			if(event.type == SDL_MOUSEBUTTONDOWN)
    1.57 +				mouse_down = 1;
    1.58 +			if(mouse_down && event.type == SDL_MOUSEBUTTONUP) {
    1.59 +				mouse_down = 0;
    1.60 +				current_picture += 1;
    1.61 +				if(current_picture >= num_pictures)
    1.62 +					current_picture = 0;
    1.63 +				SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h);
    1.64 +				SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
    1.65 +				SDL_SetWindowShape(window,pictures[current_picture],&mode);
    1.66 +			}
    1.67 +			if(event.type == SDL_QUIT)
    1.68 +				should_exit = 1;
    1.69 +			event_pending = 0;
    1.70  		}
    1.71  		
    1.72  		SDL_SelectRenderer(window);
    1.73 @@ -150,7 +158,6 @@
    1.74  		SDL_RenderCopy(textures[current_picture],&texture_dimensions,&texture_dimensions);
    1.75  		
    1.76  		SDL_RenderPresent();
    1.77 -		event_pending = SDL_PollEvent(&event);
    1.78  	}
    1.79  	
    1.80  	//Free the textures.