src/video/SDL_shape.c
changeset 4852 c19c729eb201
parent 4851 5624fb0190b5
child 4855 6d4d6605a0d3
equal deleted inserted replaced
4851:5624fb0190b5 4852:c19c729eb201
    30 #include "SDL_shape.h"
    30 #include "SDL_shape.h"
    31 #include "SDL_shape_internals.h"
    31 #include "SDL_shape_internals.h"
    32 
    32 
    33 SDL_Window*
    33 SDL_Window*
    34 SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) {
    34 SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) {
    35     SDL_Window *result = SDL_CreateWindow(title,x,y,w,h,flags | SDL_WINDOW_BORDERLESS & !SDL_WINDOW_FULLSCREEN & !SDL_WINDOW_RESIZABLE);
    35     SDL_Window *result = SDL_CreateWindow(title,x,y,w,h,flags | SDL_WINDOW_BORDERLESS & ~SDL_WINDOW_FULLSCREEN & ~SDL_WINDOW_RESIZABLE);
    36     if(result != NULL) {
    36     if(result != NULL) {
    37         result->shaper = result->display->device->shape_driver.CreateShaper(result);
    37         result->shaper = result->display->device->shape_driver.CreateShaper(result);
    38         if(result->shaper != NULL) {
    38         if(result->shaper != NULL) {
    39             result->shaper->userx = x;
    39             result->shaper->userx = x;
    40             result->shaper->usery = y;
    40             result->shaper->usery = y;
   124     SDL_bool pixel_opaque = SDL_FALSE;
   124     SDL_bool pixel_opaque = SDL_FALSE;
   125     int last_opaque = -1;
   125     int last_opaque = -1;
   126     SDL_Color key;
   126     SDL_Color key;
   127     SDL_ShapeTree* result = (SDL_ShapeTree*)SDL_malloc(sizeof(SDL_ShapeTree));
   127     SDL_ShapeTree* result = (SDL_ShapeTree*)SDL_malloc(sizeof(SDL_ShapeTree));
   128     SDL_Rect next = {0,0,0,0};
   128     SDL_Rect next = {0,0,0,0};
   129     for(y=dimensions.y;y<dimensions.y + dimensions.h;y++)
   129     for(y=dimensions.y;y<dimensions.y + dimensions.h;y++) {
   130         for(x=dimensions.x;x<dimensions.x + dimensions.w;x++) {
   130         for(x=dimensions.x;x<dimensions.x + dimensions.w;x++) {
   131             pixel_value = 0;
   131             pixel_value = 0;
   132             pixel = (Uint8 *)(mask->pixels) + (y*mask->pitch) + (x*mask->format->BytesPerPixel);
   132             pixel = (Uint8 *)(mask->pixels) + (y*mask->pitch) + (x*mask->format->BytesPerPixel);
   133             switch(mask->format->BytesPerPixel) {
   133             switch(mask->format->BytesPerPixel) {
   134                 case(1):
   134                 case(1):
   181                 //Unneeded: next.y = dimensions.y + dimensions.h /2;
   181                 //Unneeded: next.y = dimensions.y + dimensions.h /2;
   182                 result->data.children.downright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
   182                 result->data.children.downright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
   183                 return result;
   183                 return result;
   184             }
   184             }
   185         }
   185         }
       
   186     }
   186     //If we never recursed, all the pixels in this quadrant have the same "value".
   187     //If we never recursed, all the pixels in this quadrant have the same "value".
   187     result->kind = (last_opaque == SDL_TRUE ? OpaqueShape : TransparentShape);
   188     result->kind = (last_opaque == SDL_TRUE ? OpaqueShape : TransparentShape);
   188     result->data.shape = dimensions;
   189     result->data.shape = dimensions;
   189     return result;
   190     return result;
   190 }
   191 }
   238     
   239     
   239     if(shape_mode != NULL)
   240     if(shape_mode != NULL)
   240         window->shaper->mode = *shape_mode;
   241         window->shaper->mode = *shape_mode;
   241     result = window->display->device->shape_driver.SetWindowShape(window->shaper,shape,shape_mode);
   242     result = window->display->device->shape_driver.SetWindowShape(window->shaper,shape,shape_mode);
   242     window->shaper->hasshape = SDL_TRUE;
   243     window->shaper->hasshape = SDL_TRUE;
   243     if(window->shaper->userx == 0 && window->shaper->usery == 0) {
   244     if(window->shaper->userx != 0 && window->shaper->usery != 0) {
   244         SDL_SetWindowPosition(window,window->shaper->userx,window->shaper->usery);
   245         SDL_SetWindowPosition(window,window->shaper->userx,window->shaper->usery);
   245         window->shaper->userx = 0;
   246         window->shaper->userx = 0;
   246         window->shaper->usery = 0;
   247         window->shaper->usery = 0;
   247     }
   248     }
   248     return result;
   249     return result;