src/video/SDL_shape.c
changeset 4796 e8caf178d082
parent 4795 6f0bc179771c
child 4799 a0e096916474
equal deleted inserted replaced
4795:6f0bc179771c 4796:e8caf178d082
    28 #include "SDL_surface.h"
    28 #include "SDL_surface.h"
    29 #include "SDL_shape.h"
    29 #include "SDL_shape.h"
    30 
    30 
    31 SDL_Window* SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) {
    31 SDL_Window* SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) {
    32 	SDL_Window *result = SDL_CreateWindow(title,x,y,w,h,SDL_WINDOW_BORDERLESS | flags & !SDL_WINDOW_FULLSCREEN & !SDL_WINDOW_SHOWN);
    32 	SDL_Window *result = SDL_CreateWindow(title,x,y,w,h,SDL_WINDOW_BORDERLESS | flags & !SDL_WINDOW_FULLSCREEN & !SDL_WINDOW_SHOWN);
    33 	result->shaper = result->display->device->shape_driver.CreateShaper(result);
    33 	if(result != NULL) {
    34 	result->shaper->usershownflag = flags & SDL_WINDOW_SHOWN;
    34 		result->shaper = result->display->device->shape_driver.CreateShaper(result);
    35 	result->shaper->alphacutoff = 1;
    35 		if(result->shaper != NULL) {
    36 	result->shaper->hasshape = SDL_FALSE;
    36 			result->shaper->usershownflag = flags & SDL_WINDOW_SHOWN;
    37 	return result;
    37 			result->shaper->alphacutoff = 1;
       
    38 			result->shaper->hasshape = SDL_FALSE;
       
    39 			return result;
       
    40 		}
       
    41 		else {
       
    42 			SDL_DestroyWindow(result);
       
    43 			return NULL;
       
    44 		}
       
    45 	}
       
    46 	else
       
    47 		return NULL;
    38 }
    48 }
    39 
    49 
    40 SDL_bool SDL_IsShapedWindow(const SDL_Window *window) {
    50 SDL_bool SDL_IsShapedWindow(const SDL_Window *window) {
    41 	if(window == NULL)
    51 	if(window == NULL)
    42 		return SDL_FALSE;
    52 		return SDL_FALSE;
    53 	Uint32 bitmap_pixel;
    63 	Uint32 bitmap_pixel;
    54 	if(SDL_MUSTLOCK(shape))
    64 	if(SDL_MUSTLOCK(shape))
    55 		SDL_LockSurface(shape);
    65 		SDL_LockSurface(shape);
    56 	for(x = 0;x<shape->w;x++)
    66 	for(x = 0;x<shape->w;x++)
    57 		for(y = 0;y<shape->h;y++) {
    67 		for(y = 0;y<shape->h;y++) {
    58 			pixel = shape->pixels + (y*shape->pitch) + (x*shape->format->BytesPerPixel);
    68 			pixel = (Uint8 *)(shape->pixels) + (y*shape->pitch) + (x*shape->format->BytesPerPixel);
    59 			alpha = 0;
    69 			alpha = 0;
    60 			SDL_GetRGBA(*(Uint32*)pixel,shape->format,&r,&g,&b,&alpha);
    70 			SDL_GetRGBA(*(Uint32*)pixel,shape->format,&r,&g,&b,&alpha);
    61 			Uint32 bitmap_pixel = y*shape->w + x;
    71 			bitmap_pixel = y*shape->w + x;
    62 			bitmap[bitmap_pixel / ppb] |= (alpha >= alphacutoff ? value : 0) << ((ppb - 1) - (bitmap_pixel % ppb));
    72 			bitmap[bitmap_pixel / ppb] |= (alpha >= alphacutoff ? value : 0) << ((ppb - 1) - (bitmap_pixel % ppb));
    63 		}
    73 		}
    64 	if(SDL_MUSTLOCK(shape))
    74 	if(SDL_MUSTLOCK(shape))
    65 		SDL_UnlockSurface(shape);
    75 		SDL_UnlockSurface(shape);
    66 }
    76 }