SDL_shape.c File Reference
`#include "../SDL_internal.h"`
`#include "SDL.h"`
`#include "SDL_assert.h"`
`#include "SDL_video.h"`
`#include "SDL_sysvideo.h"`
`#include "SDL_pixels.h"`
`#include "SDL_surface.h"`
`#include "SDL_shape.h"`
`#include "SDL_shape_internals.h"`
Include dependency graph for SDL_shape.c:

Go to the source code of this file.

## Functions

SDL_Window * | SDL_CreateShapedWindow (const char *title, unsigned int x, unsigned int y, unsigned int w, unsigned int h, Uint32 flags)
| Create a window that can be shaped with the specified position, dimensions, and flags. More...
SDL_bool | SDL_IsShapedWindow (const SDL_Window *window)
| Return whether the given window is a shaped window. More...
void | SDL_CalculateShapeBitmap (SDL_WindowShapeMode mode, SDL_Surface *shape, Uint8 *bitmap, Uint8 ppb)
static SDL_ShapeTree * | RecursivelyCalculateShapeTree (SDL_WindowShapeMode mode, SDL_Surface *mask, SDL_Rect dimensions)
SDL_ShapeTree * | SDL_CalculateShapeTree (SDL_WindowShapeMode mode, SDL_Surface *shape)
void | SDL_TraverseShapeTree (SDL_ShapeTree *tree, SDL_TraversalFunction function, void *closure)
void | SDL_FreeShapeTree (SDL_ShapeTree **shape_tree)
int | SDL_SetWindowShape (SDL_Window *window, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode)
| Set the shape and parameters of a shaped window. More...
static SDL_bool | SDL_WindowHasAShape (SDL_Window *window)
int | SDL_GetShapedWindowMode (SDL_Window *window, SDL_WindowShapeMode *shape_mode)
| Get the shape parameters of a shaped window. More...

## Function Documentation

## RecursivelyCalculateShapeTree()

static SDL_ShapeTree* RecursivelyCalculateShapeTree | ( | SDL_WindowShapeMode | mode,
|  | SDL_Surface * | mask,
|  | SDL_Rect | dimensions
| ) |  |

static

Definition at line 127 of file SDL_shape.c.

References SDL_PixelFormat::Amask, SDL_Color::b, SDL_WindowShapeParams::binarizationCutoff, SDL_PixelFormat::BytesPerPixel, SDL_ShapeUnion::children, SDL_WindowShapeParams::colorKey, SDL_ShapeTree::data, SDL_QuadTreeChildren::downleft, SDL_QuadTreeChildren::downright, SDL_Surface::format, SDL_Color::g, SDL_Rect::h, SDL_ShapeTree::kind, SDL_WindowShapeMode::mode, NULL, OpaqueShape, SDL_WindowShapeMode::parameters, SDL_Surface::pitch, SDL_Surface::pixels, QuadShape, SDL_Color::r, SDL_FALSE, SDL_GetRGBA, SDL_malloc, SDL_TRUE, SDL_ShapeUnion::shape, ShapeModeBinarizeAlpha, ShapeModeColorKey, ShapeModeDefault, ShapeModeReverseBinarizeAlpha, TransparentShape, SDL_QuadTreeChildren::upleft, SDL_QuadTreeChildren::upright, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_CalculateShapeTree().

{
int x = 0,y = 0;
Uint8* pixel = NULL;
Uint32 pixel_value = 0;
Uint8 r = 0,g = 0,b = 0,a = 0;
SDL_bool pixel_opaque = SDL_FALSE;
int last_opaque = -1;
SDL_Color key;
SDL_ShapeTree* result = (SDL_ShapeTree*)SDL_malloc(sizeof(SDL_ShapeTree));
SDL_Rect next = {0,0,0,0};
for(y=dimensions.y;y<dimensions.y + dimensions.h;y++) {
for(x=dimensions.x;x<dimensions.x + dimensions.w;x++) {
pixel_value = 0;
pixel = (Uint8 *)(mask->pixels) + (y*mask->pitch) + (x*mask->format->BytesPerPixel);
switch(mask->format->BytesPerPixel) {
case(1):
pixel_value = *(Uint8*)pixel;
break;
case(2):
pixel_value = *(Uint16*)pixel;
break;
case(3):
pixel_value = *(Uint32*)pixel & (~mask->format->Amask);
break;
case(4):
pixel_value = *(Uint32*)pixel;
break;
}
SDL_GetRGBA(pixel_value,mask->format,&r,&g,&b,&a);
switch(mode.mode) {
case(ShapeModeDefault):
pixel_opaque = (a >= 1 ? SDL_TRUE : SDL_FALSE);
break;
case(ShapeModeBinarizeAlpha):
pixel_opaque = (a >= mode.parameters.binarizationCutoff ? SDL_TRUE : SDL_FALSE);
break;
case(ShapeModeReverseBinarizeAlpha):
pixel_opaque = (a <= mode.parameters.binarizationCutoff ? SDL_TRUE : SDL_FALSE);
break;
case(ShapeModeColorKey):
key = mode.parameters.colorKey;
pixel_opaque = ((key.r != r || key.g != g || key.b != b) ? SDL_TRUE : SDL_FALSE);
break;
}
if(last_opaque == -1)
last_opaque = pixel_opaque;
if(last_opaque != pixel_opaque) {
const int halfwidth = dimensions.w / 2;
const int halfheight = dimensions.h / 2;
result->kind = QuadShape;
next.x = dimensions.x;
next.y = dimensions.y;
next.w = halfwidth;
next.h = halfheight;
result->data.children.upleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
next.x = dimensions.x + halfwidth;
next.w = dimensions.w - halfwidth;
result->data.children.upright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
next.x = dimensions.x;
next.w = halfwidth;
next.y = dimensions.y + halfheight;
next.h = dimensions.h - halfheight;
result->data.children.downleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
next.x = dimensions.x + halfwidth;
next.w = dimensions.w - halfwidth;
result->data.children.downright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
return result;
}
}
}
/* If we never recursed, all the pixels in this quadrant have the same "value". */
result->kind = (last_opaque == SDL_TRUE ? OpaqueShape : TransparentShape);
result->data.shape = dimensions;
return result;
}
r
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
SDL_Color
Definition: SDL_pixels.h:295
SDL_TRUE
Definition: SDL_stdinc.h:142
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
SDL_Color::g
Uint8 g
Definition: SDL_pixels.h:298
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
SDL_PixelFormat::BytesPerPixel
Uint8 BytesPerPixel
Definition: SDL_pixels.h:320
SDL_QuadTreeChildren::upright
struct SDL_ShapeTree * upright
Definition: SDL_shape_internals.h:39
SDL_FALSE
Definition: SDL_stdinc.h:141
ShapeModeColorKey
A color key is applied.
Definition: SDL_shape.h:88
OpaqueShape
Definition: SDL_shape_internals.h:47
SDL_Color::b
Uint8 b
Definition: SDL_pixels.h:299
SDL_ShapeTree::data
SDL_ShapeUnion data
Definition: SDL_shape_internals.h:51
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:181
key
GLuint64 key
Definition: gl2ext.h:2192
SDL_Color::r
Uint8 r
Definition: SDL_pixels.h:297
SDL_Surface::pixels
void * pixels
Definition: SDL_surface.h:75
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:157
QuadShape
Definition: SDL_shape_internals.h:47
ShapeModeDefault
The default mode, a binarized alpha cutoff of 1.
Definition: SDL_shape.h:82
SDL_WindowShapeMode::parameters
SDL_WindowShapeParams parameters
Window-shape parameters.
Definition: SDL_shape.h:105
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
TransparentShape
Definition: SDL_shape_internals.h:47
SDL_Rect::x
int x
Definition: SDL_rect.h:66
SDL_Rect::w
int w
Definition: SDL_rect.h:67
SDL_GetRGBA
#define SDL_GetRGBA
Definition: SDL_dynapi_overrides.h:289
NULL
#define NULL
Definition: begin_code.h:164
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:139
ShapeModeBinarizeAlpha
A binarized alpha cutoff with a given integer value.
Definition: SDL_shape.h:84
SDL_Surface::format
SDL_PixelFormat * format
Definition: SDL_surface.h:72
SDL_ShapeUnion::shape
SDL_Rect shape
Definition: SDL_shape_internals.h:44
SDL_Rect::h
int h
Definition: SDL_rect.h:67
SDL_WindowShapeParams::colorKey
SDL_Color colorKey
Definition: SDL_shape.h:97
ShapeModeReverseBinarizeAlpha
A binarized alpha cutoff with a given integer value, but with the opposite comparison.
Definition: SDL_shape.h:86
SDL_ShapeTree
Definition: SDL_shape_internals.h:49
SDL_QuadTreeChildren::upleft
struct SDL_ShapeTree * upleft
Definition: SDL_shape_internals.h:39
SDL_Surface::pitch
int pitch
Definition: SDL_surface.h:74
Uint16
uint16_t Uint16
Definition: SDL_stdinc.h:169
SDL_WindowShapeParams::binarizationCutoff
Uint8 binarizationCutoff
A cutoff alpha value for binarization of the window shape&#39;s alpha channel.
Definition: SDL_shape.h:96
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374
SDL_PixelFormat::Amask
Uint32 Amask
Definition: SDL_pixels.h:325
RecursivelyCalculateShapeTree
static SDL_ShapeTree * RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode, SDL_Surface *mask, SDL_Rect dimensions)
Definition: SDL_shape.c:127
SDL_ShapeTree::kind
SDL_ShapeKind kind
Definition: SDL_shape_internals.h:50
SDL_WindowShapeMode::mode
WindowShapeMode mode
The mode of these window-shape parameters.
Definition: SDL_shape.h:103
a
GLboolean GLboolean GLboolean GLboolean a
Definition: SDL_opengl_glext.h:1109
g
GLboolean GLboolean g
Definition: SDL_opengl_glext.h:1109
b
GLboolean GLboolean GLboolean b
Definition: SDL_opengl_glext.h:1109
SDL_QuadTreeChildren::downright
struct SDL_ShapeTree * downright
Definition: SDL_shape_internals.h:39
SDL_Rect::y
int y
Definition: SDL_rect.h:66
SDL_ShapeUnion::children
SDL_QuadTreeChildren children
Definition: SDL_shape_internals.h:43
SDL_Rect
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64
SDL_QuadTreeChildren::downleft
struct SDL_ShapeTree * downleft
Definition: SDL_shape_internals.h:39

## SDL_CalculateShapeBitmap()

void SDL_CalculateShapeBitmap | ( | SDL_WindowShapeMode | mode,
|  | SDL_Surface * | shape,
|  | Uint8 * | bitmap,
|  | Uint8 | ppb
| ) |  |

Definition at line 71 of file SDL_shape.c.

References SDL_PixelFormat::Amask, SDL_Color::b, SDL_WindowShapeParams::binarizationCutoff, SDL_PixelFormat::BytesPerPixel, SDL_WindowShapeParams::colorKey, SDL_Surface::format, SDL_Color::g, SDL_Surface::h, SDL_WindowShapeMode::mode, NULL, SDL_WindowShapeMode::parameters, SDL_Surface::pitch, SDL_Surface::pixels, SDL_Color::r, SDL_GetRGBA, SDL_LockSurface, SDL_MUSTLOCK, SDL_UnlockSurface, ShapeModeBinarizeAlpha, ShapeModeColorKey, ShapeModeDefault, ShapeModeReverseBinarizeAlpha, and SDL_Surface::w.

{
int x = 0;
int y = 0;
Uint8 r = 0,g = 0,b = 0,alpha = 0;
Uint8* pixel = NULL;
Uint32 pixel_value = 0,mask_value = 0;
int bytes_per_scanline = (shape->w + (ppb - 1)) / ppb;
Uint8 *bitmap_scanline;
SDL_Color key;
if(SDL_MUSTLOCK(shape))
SDL_LockSurface(shape);
for(y = 0;y<shape->h;y++) {
bitmap_scanline = bitmap + y * bytes_per_scanline;
for(x=0;x<shape->w;x++) {
alpha = 0;
pixel_value = 0;
pixel = (Uint8 *)(shape->pixels) + (y*shape->pitch) + (x*shape->format->BytesPerPixel);
switch(shape->format->BytesPerPixel) {
case(1):
pixel_value = *(Uint8*)pixel;
break;
case(2):
pixel_value = *(Uint16*)pixel;
break;
case(3):
pixel_value = *(Uint32*)pixel & (~shape->format->Amask);
break;
case(4):
pixel_value = *(Uint32*)pixel;
break;
}
SDL_GetRGBA(pixel_value,shape->format,&r,&g,&b,&alpha);
switch(mode.mode) {
case(ShapeModeDefault):
mask_value = (alpha >= 1 ? 1 : 0);
break;
case(ShapeModeBinarizeAlpha):
mask_value = (alpha >= mode.parameters.binarizationCutoff ? 1 : 0);
break;
case(ShapeModeReverseBinarizeAlpha):
mask_value = (alpha <= mode.parameters.binarizationCutoff ? 1 : 0);
break;
case(ShapeModeColorKey):
key = mode.parameters.colorKey;
mask_value = ((key.r != r || key.g != g || key.b != b) ? 1 : 0);
break;
}
bitmap_scanline[x / ppb] |= mask_value << (x % ppb);
}
}
if(SDL_MUSTLOCK(shape))
SDL_UnlockSurface(shape);
}
bitmap
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
Definition: SDL_opengl_glext.h:4534
r
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
SDL_Color
Definition: SDL_pixels.h:295
SDL_UnlockSurface
#define SDL_UnlockSurface
Definition: SDL_dynapi_overrides.h:449
SDL_Color::g
Uint8 g
Definition: SDL_pixels.h:298
SDL_Surface::h
int h
Definition: SDL_surface.h:73
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
SDL_PixelFormat::BytesPerPixel
Uint8 BytesPerPixel
Definition: SDL_pixels.h:320
ShapeModeColorKey
A color key is applied.
Definition: SDL_shape.h:88
SDL_Color::b
Uint8 b
Definition: SDL_pixels.h:299
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:181
SDL_Surface::w
int w
Definition: SDL_surface.h:73
alpha
GLfloat GLfloat GLfloat alpha
Definition: SDL_opengl_glext.h:412
key
GLuint64 key
Definition: gl2ext.h:2192
SDL_Color::r
Uint8 r
Definition: SDL_pixels.h:297
SDL_Surface::pixels
void * pixels
Definition: SDL_surface.h:75
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:157
ShapeModeDefault
The default mode, a binarized alpha cutoff of 1.
Definition: SDL_shape.h:82
SDL_WindowShapeMode::parameters
SDL_WindowShapeParams parameters
Window-shape parameters.
Definition: SDL_shape.h:105
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
SDL_GetRGBA
#define SDL_GetRGBA
Definition: SDL_dynapi_overrides.h:289
NULL
#define NULL
Definition: begin_code.h:164
ShapeModeBinarizeAlpha
A binarized alpha cutoff with a given integer value.
Definition: SDL_shape.h:84
SDL_Surface::format
SDL_PixelFormat * format
Definition: SDL_surface.h:72
SDL_LockSurface
#define SDL_LockSurface
Definition: SDL_dynapi_overrides.h:448
SDL_MUSTLOCK
#define SDL_MUSTLOCK(S)
Definition: SDL_surface.h:61
SDL_WindowShapeParams::colorKey
SDL_Color colorKey
Definition: SDL_shape.h:97
ShapeModeReverseBinarizeAlpha
A binarized alpha cutoff with a given integer value, but with the opposite comparison.
Definition: SDL_shape.h:86
SDL_Surface::pitch
int pitch
Definition: SDL_surface.h:74
Uint16
uint16_t Uint16
Definition: SDL_stdinc.h:169
SDL_WindowShapeParams::binarizationCutoff
Uint8 binarizationCutoff
A cutoff alpha value for binarization of the window shape&#39;s alpha channel.
Definition: SDL_shape.h:96
SDL_PixelFormat::Amask
Uint32 Amask
Definition: SDL_pixels.h:325
SDL_WindowShapeMode::mode
WindowShapeMode mode
The mode of these window-shape parameters.
Definition: SDL_shape.h:103
g
GLboolean GLboolean g
Definition: SDL_opengl_glext.h:1109
b
GLboolean GLboolean GLboolean b
Definition: SDL_opengl_glext.h:1109

## SDL_CalculateShapeTree()

SDL_ShapeTree* SDL_CalculateShapeTree | ( | SDL_WindowShapeMode | mode,
|  | SDL_Surface * | shape
| ) |  |

Definition at line 213 of file SDL_shape.c.

References SDL_Rect::h, SDL_Surface::h, NULL, RecursivelyCalculateShapeTree(), SDL_LockSurface, SDL_MUSTLOCK, SDL_UnlockSurface, SDL_Rect::w, SDL_Surface::w, SDL_Rect::x, and SDL_Rect::y.

{
SDL_Rect dimensions;
SDL_ShapeTree* result = NULL;
dimensions.x = 0;
dimensions.y = 0;
dimensions.w = shape->w;
dimensions.h = shape->h;
if(SDL_MUSTLOCK(shape))
SDL_LockSurface(shape);
result = RecursivelyCalculateShapeTree(mode,shape,dimensions);
if(SDL_MUSTLOCK(shape))
SDL_UnlockSurface(shape);
return result;
}
SDL_UnlockSurface
#define SDL_UnlockSurface
Definition: SDL_dynapi_overrides.h:449
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
SDL_Surface::h
int h
Definition: SDL_surface.h:73
SDL_Surface::w
int w
Definition: SDL_surface.h:73
SDL_Rect::x
int x
Definition: SDL_rect.h:66
SDL_Rect::w
int w
Definition: SDL_rect.h:67
NULL
#define NULL
Definition: begin_code.h:164
SDL_LockSurface
#define SDL_LockSurface
Definition: SDL_dynapi_overrides.h:448
SDL_MUSTLOCK
#define SDL_MUSTLOCK(S)
Definition: SDL_surface.h:61
SDL_Rect::h
int h
Definition: SDL_rect.h:67
SDL_ShapeTree
Definition: SDL_shape_internals.h:49
RecursivelyCalculateShapeTree
static SDL_ShapeTree * RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode, SDL_Surface *mask, SDL_Rect dimensions)
Definition: SDL_shape.c:127
SDL_Rect::y
int y
Definition: SDL_rect.h:66
SDL_Rect
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

## SDL_CreateShapedWindow()

SDL_Window* SDL_CreateShapedWindow | ( | const char * | title,
|  | unsigned int | x,
|  | unsigned int | y,
|  | unsigned int | w,
|  | unsigned int | h,
|  | Uint32 | flags
| ) |  |

Create a window that can be shaped with the specified position, dimensions, and flags.

Parameters

  title | The title of the window, in UTF-8 encoding.
  x | The x position of the window, SDL_WINDOWPOS_CENTERED, or SDL_WINDOWPOS_UNDEFINED.
  y | The y position of the window, SDL_WINDOWPOS_CENTERED, or SDL_WINDOWPOS_UNDEFINED.
  w | The width of the window.
  h | The height of the window.
  flags | The flags for the window, a mask of SDL_WINDOW_BORDERLESS with any of the following: SDL_WINDOW_OPENGL, SDL_WINDOW_INPUT_GRABBED, SDL_WINDOW_HIDDEN, SDL_WINDOW_RESIZABLE, SDL_WINDOW_MAXIMIZED, SDL_WINDOW_MINIMIZED, SDL_WINDOW_BORDERLESS is always set, and SDL_WINDOW_FULLSCREEN is always unset.

Returns
  The window created, or NULL if window creation failed.

See also
  SDL_DestroyWindow()

Definition at line 33 of file SDL_shape.c.

References SDL_WindowShapeParams::binarizationCutoff, SDL_ShapeDriver::CreateShaper, SDL_WindowShaper::hasshape, SDL_WindowShaper::mode, SDL_WindowShapeMode::mode, NULL, SDL_WindowShapeMode::parameters, SDL_CreateWindow, SDL_DestroyWindow, SDL_FALSE, SDL_GetVideoDevice(), SDL_WINDOW_BORDERLESS, SDL_WINDOW_FULLSCREEN, SDL_WINDOW_RESIZABLE, SDL_VideoDevice::shape_driver, ShapeModeDefault, SDL_Window::shaper, SDL_WindowShaper::userx, and SDL_WindowShaper::usery.

{
SDL_Window *result = NULL;
result = SDL_CreateWindow(title,-1000,-1000,w,h,(flags | SDL_WINDOW_BORDERLESS) & (~SDL_WINDOW_FULLSCREEN) & (~SDL_WINDOW_RESIZABLE) /* & (~SDL_WINDOW_SHOWN) */);
if(result != NULL) {
if (SDL_GetVideoDevice()->shape_driver.CreateShaper == NULL) {
SDL_DestroyWindow(result);
return NULL;
}
result->shaper = SDL_GetVideoDevice()->shape_driver.CreateShaper(result);
if(result->shaper != NULL) {
result->shaper->userx = x;
result->shaper->usery = y;
result->shaper->mode.mode = ShapeModeDefault;
result->shaper->mode.parameters.binarizationCutoff = 1;
result->shaper->hasshape = SDL_FALSE;
return result;
}
else {
SDL_DestroyWindow(result);
return NULL;
}
}
else
return NULL;
}
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
SDL_WindowShaper::hasshape
SDL_bool hasshape
Definition: SDL_sysvideo.h:52
SDL_FALSE
Definition: SDL_stdinc.h:141
h
GLfloat GLfloat GLfloat GLfloat h
Definition: SDL_opengl_glext.h:1946
SDL_CreateWindow
#define SDL_CreateWindow
Definition: SDL_dynapi_overrides.h:514
SDL_WindowShaper::mode
SDL_WindowShapeMode mode
Definition: SDL_sysvideo.h:49
SDL_Window::shaper
SDL_WindowShaper * shaper
Definition: SDL_sysvideo.h:104
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:731
ShapeModeDefault
The default mode, a binarized alpha cutoff of 1.
Definition: SDL_shape.h:82
SDL_WindowShapeMode::parameters
SDL_WindowShapeParams parameters
Window-shape parameters.
Definition: SDL_shape.h:105
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
SDL_WindowShaper::userx
Uint32 userx
Definition: SDL_sysvideo.h:46
SDL_WindowShaper::usery
Uint32 usery
Definition: SDL_sysvideo.h:46
NULL
#define NULL
Definition: begin_code.h:164
SDL_WINDOW_RESIZABLE
Definition: SDL_video.h:105
SDL_WINDOW_BORDERLESS
Definition: SDL_video.h:104
flags
GLbitfield flags
Definition: SDL_opengl_glext.h:1480
SDL_ShapeDriver::CreateShaper
SDL_WindowShaper *(* CreateShaper)(SDL_Window *window)
Definition: SDL_sysvideo.h:60
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:73
SDL_WINDOW_FULLSCREEN
Definition: SDL_video.h:100
SDL_GetVideoDevice
SDL_VideoDevice * SDL_GetVideoDevice(void)
Definition: SDL_video.c:586
SDL_VideoDevice::shape_driver
SDL_ShapeDriver shape_driver
Definition: SDL_sysvideo.h:244
SDL_WindowShapeParams::binarizationCutoff
Uint8 binarizationCutoff
A cutoff alpha value for binarization of the window shape&#39;s alpha channel.
Definition: SDL_shape.h:96
SDL_WindowShapeMode::mode
WindowShapeMode mode
The mode of these window-shape parameters.
Definition: SDL_shape.h:103
SDL_DestroyWindow
#define SDL_DestroyWindow
Definition: SDL_dynapi_overrides.h:549

## SDL_FreeShapeTree()

void SDL_FreeShapeTree | ( | SDL_ShapeTree ** | shape_tree | ) |

Definition at line 246 of file SDL_shape.c.

References NULL, QuadShape, SDL_free, and SDL_FreeShapeTree().

Referenced by SDL_FreeShapeTree().

{
if((*shape_tree)->kind == QuadShape) {
SDL_FreeShapeTree((SDL_ShapeTree **)(char*)&(*shape_tree)->data.children.upleft);
SDL_FreeShapeTree((SDL_ShapeTree **)(char*)&(*shape_tree)->data.children.upright);
SDL_FreeShapeTree((SDL_ShapeTree **)(char*)&(*shape_tree)->data.children.downleft);
SDL_FreeShapeTree((SDL_ShapeTree **)(char*)&(*shape_tree)->data.children.downright);
}
SDL_free(*shape_tree);
*shape_tree = NULL;
}
SDL_FreeShapeTree
void SDL_FreeShapeTree(SDL_ShapeTree **shape_tree)
Definition: SDL_shape.c:246
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
QuadShape
Definition: SDL_shape_internals.h:47
NULL
#define NULL
Definition: begin_code.h:164
SDL_ShapeTree
Definition: SDL_shape_internals.h:49

## SDL_GetShapedWindowMode()

int SDL_GetShapedWindowMode | ( | SDL_Window * | window,
|  | SDL_WindowShapeMode * | shape_mode
| ) |  |

Get the shape parameters of a shaped window.

Parameters

  window | The shaped window whose parameters should be retrieved.
  shape_mode | An empty shape-mode structure to fill, or NULL to check whether the window has a shape.

Returns
  0 if the window has a shape and, provided shape_mode was not NULL, shape_mode has been filled with the mode data, SDL_NONSHAPEABLE_WINDOW if the SDL_Window given is not a shaped window, or SDL_WINDOW_LACKS_SHAPE if the SDL_Window given is a shapeable window currently lacking a shape.

See also
  SDL_WindowShapeMode
  SDL_SetWindowShape

Definition at line 290 of file SDL_shape.c.

References SDL_WindowShaper::mode, NULL, SDL_IsShapedWindow(), SDL_NONSHAPEABLE_WINDOW, SDL_WINDOW_LACKS_SHAPE, SDL_WindowHasAShape(), and SDL_Window::shaper.

{
if(window != NULL && SDL_IsShapedWindow(window)) {
if(shape_mode == NULL) {
if(SDL_WindowHasAShape(window))
/* The window given has a shape. */
return 0;
else
/* The window given is shapeable but lacks a shape. */
return SDL_WINDOW_LACKS_SHAPE;
}
else {
*shape_mode = window->shaper->mode;
return 0;
}
}
else
/* The window given is not a valid shapeable window. */
return SDL_NONSHAPEABLE_WINDOW;
}
SDL_IsShapedWindow
SDL_bool SDL_IsShapedWindow(const SDL_Window *window)
Return whether the given window is a shaped window.
Definition: SDL_shape.c:61
SDL_WindowHasAShape
static SDL_bool SDL_WindowHasAShape(SDL_Window *window)
Definition: SDL_shape.c:282
SDL_WindowShaper::mode
SDL_WindowShapeMode mode
Definition: SDL_sysvideo.h:49
SDL_Window::shaper
SDL_WindowShaper * shaper
Definition: SDL_sysvideo.h:104
SDL_NONSHAPEABLE_WINDOW
#define SDL_NONSHAPEABLE_WINDOW
Definition: SDL_shape.h:42
SDL_WINDOW_LACKS_SHAPE
#define SDL_WINDOW_LACKS_SHAPE
Definition: SDL_shape.h:44
NULL
#define NULL
Definition: begin_code.h:164

## SDL_IsShapedWindow()

SDL_bool SDL_IsShapedWindow | ( | const SDL_Window * | window | ) |

Return whether the given window is a shaped window.

Parameters

  window | The window to query for being shaped.

Returns
  SDL_TRUE if the window is a window that can be shaped, SDL_FALSE if the window is unshaped or NULL.

See also
  SDL_CreateShapedWindow

Definition at line 61 of file SDL_shape.c.

References NULL, SDL_FALSE, and SDL_Window::shaper.

Referenced by SDL_GetShapedWindowMode(), SDL_SetWindowShape(), and SDL_WindowHasAShape().

{
if(window == NULL)
return SDL_FALSE;
else
return (SDL_bool)(window->shaper != NULL);
}
SDL_FALSE
Definition: SDL_stdinc.h:141
SDL_Window::shaper
SDL_WindowShaper * shaper
Definition: SDL_sysvideo.h:104
NULL
#define NULL
Definition: begin_code.h:164
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:139

## SDL_SetWindowShape()

int SDL_SetWindowShape | ( | SDL_Window * | window,
|  | SDL_Surface * | shape,
|  | SDL_WindowShapeMode * | shape_mode
| ) |  |

Set the shape and parameters of a shaped window.

Parameters

  window | The shaped window whose parameters should be set.
  shape | A surface encoding the desired shape for the window.
  shape_mode | The parameters to set for the shaped window.

Returns
  0 on success, SDL_INVALID_SHAPE_ARGUMENT on an invalid shape argument, or SDL_NONSHAPEABLE_WINDOW if the SDL_Window given does not reference a valid shaped window.

See also
  SDL_WindowShapeMode
  SDL_GetShapedWindowMode.

Definition at line 259 of file SDL_shape.c.

References SDL_WindowShaper::hasshape, SDL_WindowShaper::mode, NULL, SDL_GetVideoDevice(), SDL_INVALID_SHAPE_ARGUMENT, SDL_IsShapedWindow(), SDL_NONSHAPEABLE_WINDOW, SDL_SetWindowPosition, SDL_TRUE, SDL_ShapeDriver::SetWindowShape, SDL_VideoDevice::shape_driver, SDL_Window::shaper, SDL_WindowShaper::userx, and SDL_WindowShaper::usery.

{
int result;
if(window == NULL || !SDL_IsShapedWindow(window))
/* The window given was not a shapeable window. */
return SDL_NONSHAPEABLE_WINDOW;
if(shape == NULL)
/* Invalid shape argument. */
return SDL_INVALID_SHAPE_ARGUMENT;
if(shape_mode != NULL)
window->shaper->mode = *shape_mode;
result = SDL_GetVideoDevice()->shape_driver.SetWindowShape(window->shaper,shape,shape_mode);
window->shaper->hasshape = SDL_TRUE;
if(window->shaper->userx != 0 && window->shaper->usery != 0) {
SDL_SetWindowPosition(window,window->shaper->userx,window->shaper->usery);
window->shaper->userx = 0;
window->shaper->usery = 0;
}
return result;
}
SDL_TRUE
Definition: SDL_stdinc.h:142
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
SDL_WindowShaper::hasshape
SDL_bool hasshape
Definition: SDL_sysvideo.h:52
SDL_IsShapedWindow
SDL_bool SDL_IsShapedWindow(const SDL_Window *window)
Return whether the given window is a shaped window.
Definition: SDL_shape.c:61
SDL_INVALID_SHAPE_ARGUMENT
#define SDL_INVALID_SHAPE_ARGUMENT
Definition: SDL_shape.h:43
SDL_ShapeDriver::SetWindowShape
int(* SetWindowShape)(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode)
Definition: SDL_sysvideo.h:61
SDL_WindowShaper::mode
SDL_WindowShapeMode mode
Definition: SDL_sysvideo.h:49
SDL_Window::shaper
SDL_WindowShaper * shaper
Definition: SDL_sysvideo.h:104
SDL_NONSHAPEABLE_WINDOW
#define SDL_NONSHAPEABLE_WINDOW
Definition: SDL_shape.h:42
SDL_WindowShaper::userx
Uint32 userx
Definition: SDL_sysvideo.h:46
SDL_WindowShaper::usery
Uint32 usery
Definition: SDL_sysvideo.h:46
NULL
#define NULL
Definition: begin_code.h:164
SDL_GetVideoDevice
SDL_VideoDevice * SDL_GetVideoDevice(void)
Definition: SDL_video.c:586
SDL_VideoDevice::shape_driver
SDL_ShapeDriver shape_driver
Definition: SDL_sysvideo.h:244
SDL_SetWindowPosition
#define SDL_SetWindowPosition
Definition: SDL_dynapi_overrides.h:524

## SDL_TraverseShapeTree()

void SDL_TraverseShapeTree | ( | SDL_ShapeTree * | tree,
|  | SDL_TraversalFunction | function,
|  | void * | closure
| ) |  |

Definition at line 232 of file SDL_shape.c.

References SDL_ShapeUnion::children, SDL_ShapeTree::data, SDL_QuadTreeChildren::downleft, SDL_QuadTreeChildren::downright, SDL_ShapeTree::kind, NULL, QuadShape, SDL_assert, SDL_TraverseShapeTree(), SDL_QuadTreeChildren::upleft, and SDL_QuadTreeChildren::upright.

Referenced by SDL_TraverseShapeTree().

{
SDL_assert(tree != NULL);
if(tree->kind == QuadShape) {
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.downleft,function,closure);
SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downright,function,closure);
}
else
function(tree,closure);
}
SDL_QuadTreeChildren::upright
struct SDL_ShapeTree * upright
Definition: SDL_shape_internals.h:39
SDL_ShapeTree::data
SDL_ShapeUnion data
Definition: SDL_shape_internals.h:51
QuadShape
Definition: SDL_shape_internals.h:47
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:169
NULL
#define NULL
Definition: begin_code.h:164
SDL_TraverseShapeTree
void SDL_TraverseShapeTree(SDL_ShapeTree *tree, SDL_TraversalFunction function, void *closure)
Definition: SDL_shape.c:232
SDL_ShapeTree
Definition: SDL_shape_internals.h:49
SDL_QuadTreeChildren::upleft
struct SDL_ShapeTree * upleft
Definition: SDL_shape_internals.h:39
SDL_ShapeTree::kind
SDL_ShapeKind kind
Definition: SDL_shape_internals.h:50
SDL_QuadTreeChildren::downright
struct SDL_ShapeTree * downright
Definition: SDL_shape_internals.h:39
SDL_ShapeUnion::children
SDL_QuadTreeChildren children
Definition: SDL_shape_internals.h:43
SDL_QuadTreeChildren::downleft
struct SDL_ShapeTree * downleft
Definition: SDL_shape_internals.h:39

## SDL_WindowHasAShape()

static SDL_bool SDL_WindowHasAShape | ( | SDL_Window * | window | ) |

static

Definition at line 282 of file SDL_shape.c.

References SDL_WindowShaper::hasshape, NULL, SDL_FALSE, SDL_IsShapedWindow(), and SDL_Window::shaper.

Referenced by SDL_GetShapedWindowMode().

{
if (window == NULL || !SDL_IsShapedWindow(window))
return SDL_FALSE;
return window->shaper->hasshape;
}
SDL_WindowShaper::hasshape
SDL_bool hasshape
Definition: SDL_sysvideo.h:52
SDL_FALSE
Definition: SDL_stdinc.h:141
SDL_IsShapedWindow
SDL_bool SDL_IsShapedWindow(const SDL_Window *window)
Return whether the given window is a shaped window.
Definition: SDL_shape.c:61
SDL_Window::shaper
SDL_WindowShaper * shaper
Definition: SDL_sysvideo.h:104
NULL
#define NULL
Definition: begin_code.h:164