Commit f4b4b47a authored by Eli Gottlieb's avatar Eli Gottlieb

Fixed overwriting of SDL_shape.c in merge.

parent 56d94ad5
...@@ -22,15 +22,15 @@ ...@@ -22,15 +22,15 @@
#include "SDL_config.h" #include "SDL_config.h"
#include "SDL.h" #include "SDL.h"
#include "SDL_assert.h"
#include "SDL_video.h" #include "SDL_video.h"
#include "SDL_sysvideo.h" #include "SDL_sysvideo.h"
#include "SDL_pixels.h" #include "SDL_pixels.h"
#include "SDL_surface.h" #include "SDL_surface.h"
#include "SDL_shape.h" #include "SDL_shape.h"
#include "../src/video/SDL_shape_internals.h" #include "SDL_shape_internals.h"
SDL_Window* SDL_Window* SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) {
SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) {
SDL_Window *result = SDL_CreateWindow(title,x,y,w,h,SDL_WINDOW_BORDERLESS | flags & !SDL_WINDOW_FULLSCREEN & !SDL_WINDOW_SHOWN); SDL_Window *result = SDL_CreateWindow(title,x,y,w,h,SDL_WINDOW_BORDERLESS | flags & !SDL_WINDOW_FULLSCREEN & !SDL_WINDOW_SHOWN);
if(result != NULL) { if(result != NULL) {
result->shaper = result->display->device->shape_driver.CreateShaper(result); result->shaper = result->display->device->shape_driver.CreateShaper(result);
...@@ -50,8 +50,7 @@ SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned ...@@ -50,8 +50,7 @@ SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned
return NULL; return NULL;
} }
SDL_bool SDL_bool SDL_IsShapedWindow(const SDL_Window *window) {
SDL_IsShapedWindow(const SDL_Window *window) {
if(window == NULL) if(window == NULL)
return SDL_FALSE; return SDL_FALSE;
else else
...@@ -59,8 +58,7 @@ SDL_IsShapedWindow(const SDL_Window *window) { ...@@ -59,8 +58,7 @@ SDL_IsShapedWindow(const SDL_Window *window) {
} }
/* REQUIRES that bitmap point to a w-by-h bitmap with ppb pixels-per-byte. */ /* REQUIRES that bitmap point to a w-by-h bitmap with ppb pixels-per-byte. */
void void SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode,SDL_Surface *shape,Uint8* bitmap,Uint8 ppb) {
SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode,SDL_Surface *shape,Uint8* bitmap,Uint8 ppb) {
int x = 0; int x = 0;
int y = 0; int y = 0;
Uint8 r = 0,g = 0,b = 0,alpha = 0; Uint8 r = 0,g = 0,b = 0,alpha = 0;
...@@ -113,19 +111,18 @@ SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode,SDL_Surface *shape,Uint8* bitm ...@@ -113,19 +111,18 @@ SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode,SDL_Surface *shape,Uint8* bitm
SDL_UnlockSurface(shape); SDL_UnlockSurface(shape);
} }
SDL_ShapeTree* SDL_ShapeTree* RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* mask,SDL_Rect dimensions) {
RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* mask,SDL_bool invert,SDL_Rect dimensions) {
int x = 0,y = 0; int x = 0,y = 0;
Uint8* pixel = NULL; Uint8* pixel = NULL;
Uint32 pixel_value = 0; Uint32 pixel_value = 0;
Uint8 r = 0,g = 0,b = 0,a = 0; Uint8 r = 0,g = 0,b = 0,a = 0;
SDL_bool pixel_transparent = SDL_FALSE; SDL_bool pixel_opaque = SDL_FALSE;
int last_transparent = -1; int last_opaque = -1;
SDL_Color key; SDL_Color key;
SDL_ShapeTree* result = (SDL_ShapeTree*)SDL_malloc(sizeof(SDL_ShapeTree)); SDL_ShapeTree* result = (SDL_ShapeTree*)SDL_malloc(sizeof(SDL_ShapeTree));
SDL_Rect next = {0,0,0,0}; SDL_Rect next = {0,0,0,0};
for(y=dimensions.y;y<dimensions.h;y++) for(y=dimensions.y;y<dimensions.y + dimensions.h;y++)
for(x=dimensions.x;x<dimensions.w;x++) { for(x=dimensions.x;x<dimensions.x + dimensions.w;x++) {
pixel_value = 0; pixel_value = 0;
pixel = (Uint8 *)(mask->pixels) + (y*mask->pitch) + (x*mask->format->BytesPerPixel); pixel = (Uint8 *)(mask->pixels) + (y*mask->pitch) + (x*mask->format->BytesPerPixel);
switch(mask->format->BytesPerPixel) { switch(mask->format->BytesPerPixel) {
...@@ -145,24 +142,22 @@ RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* mask,SDL_boo ...@@ -145,24 +142,22 @@ RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* mask,SDL_boo
SDL_GetRGBA(pixel_value,mask->format,&r,&g,&b,&a); SDL_GetRGBA(pixel_value,mask->format,&r,&g,&b,&a);
switch(mode.mode) { switch(mode.mode) {
case(ShapeModeDefault): case(ShapeModeDefault):
pixel_transparent = (SDL_bool)(a >= 1 ? !invert : invert); pixel_opaque = (a >= 1 ? SDL_TRUE : SDL_FALSE);
break; break;
case(ShapeModeBinarizeAlpha): case(ShapeModeBinarizeAlpha):
pixel_transparent = (SDL_bool)(a >= mode.parameters.binarizationCutoff ? !invert : invert); pixel_opaque = (a >= mode.parameters.binarizationCutoff ? SDL_TRUE : SDL_FALSE);
break; break;
case(ShapeModeReverseBinarizeAlpha): case(ShapeModeReverseBinarizeAlpha):
pixel_transparent = (SDL_bool)(a <= mode.parameters.binarizationCutoff ? !invert : invert); pixel_opaque = (a <= mode.parameters.binarizationCutoff ? SDL_TRUE : SDL_FALSE);
break; break;
case(ShapeModeColorKey): case(ShapeModeColorKey):
key = mode.parameters.colorKey; key = mode.parameters.colorKey;
pixel_transparent = (SDL_bool)((key.r == r && key.g == g && key.b == b) ? !invert : invert); pixel_opaque = ((key.r == r && key.g == g && key.b == b) ? SDL_TRUE : SDL_FALSE);
break; break;
} }
if(last_transparent == -1) { if(last_opaque == -1)
last_transparent = pixel_transparent; last_opaque = pixel_opaque;
break; if(last_opaque != pixel_opaque) {
}
if(last_transparent != pixel_transparent) {
result->kind = QuadShape; result->kind = QuadShape;
//These will stay the same. //These will stay the same.
next.w = dimensions.w / 2; next.w = dimensions.w / 2;
...@@ -170,39 +165,38 @@ RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* mask,SDL_boo ...@@ -170,39 +165,38 @@ RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* mask,SDL_boo
//These will change from recursion to recursion. //These will change from recursion to recursion.
next.x = dimensions.x; next.x = dimensions.x;
next.y = dimensions.y; next.y = dimensions.y;
result->data.children.upleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); result->data.children.upleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
next.x = dimensions.w / 2 + 1; next.x = dimensions.w / 2;
//Unneeded: next.y = dimensions.y; //Unneeded: next.y = dimensions.y;
result->data.children.upright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); result->data.children.upright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
next.x = dimensions.x; next.x = dimensions.x;
next.y = dimensions.h / 2 + 1; next.y = dimensions.h / 2;
result->data.children.downleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); result->data.children.downleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
next.x = dimensions.w / 2 + 1; next.x = dimensions.w / 2;
//Unneeded: next.y = dimensions.h / 2 + 1; //Unneeded: next.y = dimensions.h / 2 + 1;
result->data.children.downright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); result->data.children.downright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
return result; return result;
} }
} }
//If we never recursed, all the pixels in this quadrant have the same "value". //If we never recursed, all the pixels in this quadrant have the same "value".
result->kind = (last_transparent == SDL_FALSE ? OpaqueShape : TransparentShape); result->kind = (last_opaque == SDL_TRUE ? OpaqueShape : TransparentShape);
result->data.shape = dimensions; result->data.shape = dimensions;
return result; return result;
} }
SDL_ShapeTree* SDL_ShapeTree* SDL_CalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* shape) {
SDL_CalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* shape,SDL_bool invert) {
SDL_Rect dimensions = {0,0,shape->w,shape->h}; SDL_Rect dimensions = {0,0,shape->w,shape->h};
SDL_ShapeTree* result = NULL; SDL_ShapeTree* result = NULL;
if(SDL_MUSTLOCK(shape)) if(SDL_MUSTLOCK(shape))
SDL_LockSurface(shape); SDL_LockSurface(shape);
result = RecursivelyCalculateShapeTree(mode,shape,invert,dimensions); result = RecursivelyCalculateShapeTree(mode,shape,dimensions);
if(SDL_MUSTLOCK(shape)) if(SDL_MUSTLOCK(shape))
SDL_UnlockSurface(shape); SDL_UnlockSurface(shape);
return result; return result;
} }
void void SDL_TraverseShapeTree(SDL_ShapeTree *tree,SDL_TraversalFunction function,void* closure) {
SDL_TraverseShapeTree(SDL_ShapeTree *tree,void(*function)(SDL_ShapeTree*,void*),void* closure) { SDL_assert(tree != NULL);
if(tree->kind == QuadShape) { if(tree->kind == QuadShape) {
SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upleft,function,closure); SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upleft,function,closure);
SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upright,function,closure); SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upright,function,closure);
...@@ -213,8 +207,7 @@ SDL_TraverseShapeTree(SDL_ShapeTree *tree,void(*function)(SDL_ShapeTree*,void*), ...@@ -213,8 +207,7 @@ SDL_TraverseShapeTree(SDL_ShapeTree *tree,void(*function)(SDL_ShapeTree*,void*),
function(tree,closure); function(tree,closure);
} }
void void SDL_FreeShapeTree(SDL_ShapeTree** shapeTree) {
SDL_FreeShapeTree(SDL_ShapeTree** shapeTree) {
if((*shapeTree)->kind == QuadShape) { if((*shapeTree)->kind == QuadShape) {
SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.upleft); SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.upleft);
SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.upright); SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.upright);
...@@ -225,8 +218,7 @@ SDL_FreeShapeTree(SDL_ShapeTree** shapeTree) { ...@@ -225,8 +218,7 @@ SDL_FreeShapeTree(SDL_ShapeTree** shapeTree) {
*shapeTree = NULL; *shapeTree = NULL;
} }
int int SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
int result; int result;
if(window == NULL || !SDL_IsShapedWindow(window)) if(window == NULL || !SDL_IsShapedWindow(window))
//The window given was not a shapeable window. //The window given was not a shapeable window.
...@@ -247,15 +239,13 @@ SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *sh ...@@ -247,15 +239,13 @@ SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *sh
return result; return result;
} }
SDL_bool SDL_bool SDL_WindowHasAShape(SDL_Window *window) {
SDL_WindowHasAShape(SDL_Window *window) { if (window == NULL || !SDL_IsShapedWindow(window))
if (window == NULL && !SDL_IsShapedWindow(window))
return SDL_FALSE; return SDL_FALSE;
return window->shaper->hasshape; return window->shaper->hasshape;
} }
int int SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shapeMode) {
SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shapeMode) {
if(window != NULL && SDL_IsShapedWindow(window)) { if(window != NULL && SDL_IsShapedWindow(window)) {
if(shapeMode == NULL) { if(shapeMode == NULL) {
if(SDL_WindowHasAShape(window)) if(SDL_WindowHasAShape(window))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment