SDL  2.0
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_WindowSDL_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_ShapeTreeRecursivelyCalculateShapeTree (SDL_WindowShapeMode mode, SDL_Surface *mask, SDL_Rect dimensions)
 
SDL_ShapeTreeSDL_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

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

Definition at line 121 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().

121  {
122  int x = 0,y = 0;
123  Uint8* pixel = NULL;
124  Uint32 pixel_value = 0;
125  Uint8 r = 0,g = 0,b = 0,a = 0;
126  SDL_bool pixel_opaque = SDL_FALSE;
127  int last_opaque = -1;
128  SDL_Color key;
130  SDL_Rect next = {0,0,0,0};
131 
132  for(y=dimensions.y;y<dimensions.y + dimensions.h;y++) {
133  for(x=dimensions.x;x<dimensions.x + dimensions.w;x++) {
134  pixel_value = 0;
135  pixel = (Uint8 *)(mask->pixels) + (y*mask->pitch) + (x*mask->format->BytesPerPixel);
136  switch(mask->format->BytesPerPixel) {
137  case(1):
138  pixel_value = *(Uint8*)pixel;
139  break;
140  case(2):
141  pixel_value = *(Uint16*)pixel;
142  break;
143  case(3):
144  pixel_value = *(Uint32*)pixel & (~mask->format->Amask);
145  break;
146  case(4):
147  pixel_value = *(Uint32*)pixel;
148  break;
149  }
150  SDL_GetRGBA(pixel_value,mask->format,&r,&g,&b,&a);
151  switch(mode.mode) {
152  case(ShapeModeDefault):
153  pixel_opaque = (a >= 1 ? SDL_TRUE : SDL_FALSE);
154  break;
156  pixel_opaque = (a >= mode.parameters.binarizationCutoff ? SDL_TRUE : SDL_FALSE);
157  break;
159  pixel_opaque = (a <= mode.parameters.binarizationCutoff ? SDL_TRUE : SDL_FALSE);
160  break;
161  case(ShapeModeColorKey):
162  key = mode.parameters.colorKey;
163  pixel_opaque = ((key.r != r || key.g != g || key.b != b) ? SDL_TRUE : SDL_FALSE);
164  break;
165  }
166  if(last_opaque == -1)
167  last_opaque = pixel_opaque;
168  if(last_opaque != pixel_opaque) {
169  const int halfwidth = dimensions.w / 2;
170  const int halfheight = dimensions.h / 2;
171 
172  result->kind = QuadShape;
173 
174  next.x = dimensions.x;
175  next.y = dimensions.y;
176  next.w = halfwidth;
177  next.h = halfheight;
178  result->data.children.upleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
179 
180  next.x = dimensions.x + halfwidth;
181  next.w = dimensions.w - halfwidth;
182  result->data.children.upright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
183 
184  next.x = dimensions.x;
185  next.w = halfwidth;
186  next.y = dimensions.y + halfheight;
187  next.h = dimensions.h - halfheight;
188  result->data.children.downleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
189 
190  next.x = dimensions.x + halfwidth;
191  next.w = dimensions.w - halfwidth;
192  result->data.children.downright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
193 
194  return result;
195  }
196  }
197  }
198 
199 
200  /* If we never recursed, all the pixels in this quadrant have the same "value". */
201  result->kind = (last_opaque == SDL_TRUE ? OpaqueShape : TransparentShape);
202  result->data.shape = dimensions;
203  return result;
204 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2072
GLuint64EXT * result
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:155
Uint8 g
Definition: SDL_pixels.h:282
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
Uint8 BytesPerPixel
Definition: SDL_pixels.h:304
struct SDL_ShapeTree * upright
A color key is applied.
Definition: SDL_shape.h:87
Uint8 b
Definition: SDL_pixels.h:283
SDL_ShapeUnion data
SDL_bool
Definition: SDL_stdinc.h:126
GLboolean GLboolean g
Uint8 r
Definition: SDL_pixels.h:281
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1567
void * pixels
Definition: SDL_surface.h:75
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
The default mode, a binarized alpha cutoff of 1.
Definition: SDL_shape.h:81
SDL_WindowShapeParams parameters
Window-shape parameters.
Definition: SDL_shape.h:104
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
#define SDL_GetRGBA
#define NULL
Definition: begin_code.h:143
A binarized alpha cutoff with a given integer value.
Definition: SDL_shape.h:83
SDL_PixelFormat * format
Definition: SDL_surface.h:72
int h
Definition: SDL_rect.h:67
SDL_Color colorKey
Definition: SDL_shape.h:96
A binarized alpha cutoff with a given integer value, but with the opposite comparison.
Definition: SDL_shape.h:85
struct SDL_ShapeTree * upleft
uint16_t Uint16
An unsigned 16-bit integer type.
Definition: SDL_stdinc.h:147
Uint8 binarizationCutoff
a cutoff alpha value for binarization of the window shape&#39;s alpha channel.
Definition: SDL_shape.h:95
#define SDL_malloc
static SDL_ShapeTree * RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode, SDL_Surface *mask, SDL_Rect dimensions)
Definition: SDL_shape.c:121
SDL_ShapeKind kind
WindowShapeMode mode
The mode of these window-shape parameters.
Definition: SDL_shape.h:102
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean GLboolean b
struct SDL_ShapeTree * downright
int y
Definition: SDL_rect.h:66
SDL_QuadTreeChildren children
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64
struct SDL_ShapeTree * downleft
void SDL_CalculateShapeBitmap ( SDL_WindowShapeMode  mode,
SDL_Surface shape,
Uint8 bitmap,
Uint8  ppb 
)

Definition at line 67 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.

68 {
69  int x = 0;
70  int y = 0;
71  Uint8 r = 0,g = 0,b = 0,alpha = 0;
72  Uint8* pixel = NULL;
73  Uint32 bitmap_pixel,pixel_value = 0,mask_value = 0;
74  SDL_Color key;
75  if(SDL_MUSTLOCK(shape))
76  SDL_LockSurface(shape);
77  for(y = 0;y<shape->h;y++) {
78  for(x=0;x<shape->w;x++) {
79  alpha = 0;
80  pixel_value = 0;
81  pixel = (Uint8 *)(shape->pixels) + (y*shape->pitch) + (x*shape->format->BytesPerPixel);
82  switch(shape->format->BytesPerPixel) {
83  case(1):
84  pixel_value = *(Uint8*)pixel;
85  break;
86  case(2):
87  pixel_value = *(Uint16*)pixel;
88  break;
89  case(3):
90  pixel_value = *(Uint32*)pixel & (~shape->format->Amask);
91  break;
92  case(4):
93  pixel_value = *(Uint32*)pixel;
94  break;
95  }
96  SDL_GetRGBA(pixel_value,shape->format,&r,&g,&b,&alpha);
97  bitmap_pixel = y*shape->w + x;
98  switch(mode.mode) {
99  case(ShapeModeDefault):
100  mask_value = (alpha >= 1 ? 1 : 0);
101  break;
103  mask_value = (alpha >= mode.parameters.binarizationCutoff ? 1 : 0);
104  break;
106  mask_value = (alpha <= mode.parameters.binarizationCutoff ? 1 : 0);
107  break;
108  case(ShapeModeColorKey):
109  key = mode.parameters.colorKey;
110  mask_value = ((key.r != r || key.g != g || key.b != b) ? 1 : 0);
111  break;
112  }
113  bitmap[bitmap_pixel / ppb] |= mask_value << (7 - ((ppb - 1) - (bitmap_pixel % ppb)));
114  }
115  }
116  if(SDL_MUSTLOCK(shape))
117  SDL_UnlockSurface(shape);
118 }
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
#define SDL_UnlockSurface
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2072
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:155
Uint8 g
Definition: SDL_pixels.h:282
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
Uint8 BytesPerPixel
Definition: SDL_pixels.h:304
A color key is applied.
Definition: SDL_shape.h:87
Uint8 b
Definition: SDL_pixels.h:283
GLfloat GLfloat GLfloat alpha
GLboolean GLboolean g
Uint8 r
Definition: SDL_pixels.h:281
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1567
void * pixels
Definition: SDL_surface.h:75
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
The default mode, a binarized alpha cutoff of 1.
Definition: SDL_shape.h:81
SDL_WindowShapeParams parameters
Window-shape parameters.
Definition: SDL_shape.h:104
#define SDL_GetRGBA
#define NULL
Definition: begin_code.h:143
A binarized alpha cutoff with a given integer value.
Definition: SDL_shape.h:83
SDL_PixelFormat * format
Definition: SDL_surface.h:72
#define SDL_LockSurface
#define SDL_MUSTLOCK(S)
Definition: SDL_surface.h:61
SDL_Color colorKey
Definition: SDL_shape.h:96
A binarized alpha cutoff with a given integer value, but with the opposite comparison.
Definition: SDL_shape.h:85
uint16_t Uint16
An unsigned 16-bit integer type.
Definition: SDL_stdinc.h:147
Uint8 binarizationCutoff
a cutoff alpha value for binarization of the window shape&#39;s alpha channel.
Definition: SDL_shape.h:95
WindowShapeMode mode
The mode of these window-shape parameters.
Definition: SDL_shape.h:102
GLboolean GLboolean GLboolean b
SDL_ShapeTree* SDL_CalculateShapeTree ( SDL_WindowShapeMode  mode,
SDL_Surface shape 
)

Definition at line 207 of file SDL_shape.c.

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

208 {
209  SDL_Rect dimensions = {0,0,shape->w,shape->h};
211  if(SDL_MUSTLOCK(shape))
212  SDL_LockSurface(shape);
213  result = RecursivelyCalculateShapeTree(mode,shape,dimensions);
214  if(SDL_MUSTLOCK(shape))
215  SDL_UnlockSurface(shape);
216  return result;
217 }
#define SDL_UnlockSurface
GLuint64EXT * result
#define NULL
Definition: begin_code.h:143
#define SDL_LockSurface
#define SDL_MUSTLOCK(S)
Definition: SDL_surface.h:61
static SDL_ShapeTree * RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode, SDL_Surface *mask, SDL_Rect dimensions)
Definition: SDL_shape.c:121
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64
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
titleThe title of the window, in UTF-8 encoding.
xThe x position of the window, SDL_WINDOWPOS_CENTERED, or SDL_WINDOWPOS_UNDEFINED.
yThe y position of the window, SDL_WINDOWPOS_CENTERED, or SDL_WINDOWPOS_UNDEFINED.
wThe width of the window.
hThe height of the window.
flagsThe 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.

34 {
36  result = SDL_CreateWindow(title,-1000,-1000,w,h,(flags | SDL_WINDOW_BORDERLESS) & (~SDL_WINDOW_FULLSCREEN) & (~SDL_WINDOW_RESIZABLE) /* & (~SDL_WINDOW_SHOWN) */);
37  if(result != NULL) {
39  if(result->shaper != NULL) {
40  result->shaper->userx = x;
41  result->shaper->usery = y;
42  result->shaper->mode.mode = ShapeModeDefault;
44  result->shaper->hasshape = SDL_FALSE;
45  return result;
46  }
47  else {
48  SDL_DestroyWindow(result);
49  return NULL;
50  }
51  }
52  else
53  return NULL;
54 }
GLuint64EXT * result
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
SDL_bool hasshape
Definition: SDL_sysvideo.h:50
#define SDL_CreateWindow
SDL_WindowShapeMode mode
Definition: SDL_sysvideo.h:47
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1567
SDL_WindowShaper * shaper
Definition: SDL_sysvideo.h:99
The default mode, a binarized alpha cutoff of 1.
Definition: SDL_shape.h:81
SDL_WindowShapeParams parameters
Window-shape parameters.
Definition: SDL_shape.h:104
#define NULL
Definition: begin_code.h:143
SDL_WindowShaper *(* CreateShaper)(SDL_Window *window)
Definition: SDL_sysvideo.h:58
The type used to identify a window.
Definition: SDL_sysvideo.h:71
SDL_VideoDevice * SDL_GetVideoDevice(void)
Definition: SDL_video.c:573
SDL_ShapeDriver shape_driver
Definition: SDL_sysvideo.h:224
Uint8 binarizationCutoff
a cutoff alpha value for binarization of the window shape&#39;s alpha channel.
Definition: SDL_shape.h:95
GLbitfield flags
GLubyte GLubyte GLubyte GLubyte w
WindowShapeMode mode
The mode of these window-shape parameters.
Definition: SDL_shape.h:102
#define SDL_DestroyWindow
GLfloat GLfloat GLfloat GLfloat h
void SDL_FreeShapeTree ( SDL_ShapeTree **  shape_tree)

Definition at line 234 of file SDL_shape.c.

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

Referenced by SDL_FreeShapeTree().

235 {
236  if((*shape_tree)->kind == QuadShape) {
237  SDL_FreeShapeTree((SDL_ShapeTree **)&(*shape_tree)->data.children.upleft);
238  SDL_FreeShapeTree((SDL_ShapeTree **)&(*shape_tree)->data.children.upright);
239  SDL_FreeShapeTree((SDL_ShapeTree **)&(*shape_tree)->data.children.downleft);
240  SDL_FreeShapeTree((SDL_ShapeTree **)&(*shape_tree)->data.children.downright);
241  }
242  SDL_free(*shape_tree);
243  *shape_tree = NULL;
244 }
void SDL_FreeShapeTree(SDL_ShapeTree **shape_tree)
Definition: SDL_shape.c:234
void SDL_free(void *mem)
#define NULL
Definition: begin_code.h:143
int SDL_GetShapedWindowMode ( SDL_Window window,
SDL_WindowShapeMode shape_mode 
)

Get the shape parameters of a shaped window.

Parameters
windowThe shaped window whose parameters should be retrieved.
shape_modeAn 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 278 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.

279 {
280  if(window != NULL && SDL_IsShapedWindow(window)) {
281  if(shape_mode == NULL) {
282  if(SDL_WindowHasAShape(window))
283  /* The window given has a shape. */
284  return 0;
285  else
286  /* The window given is shapeable but lacks a shape. */
287  return SDL_WINDOW_LACKS_SHAPE;
288  }
289  else {
290  *shape_mode = window->shaper->mode;
291  return 0;
292  }
293  }
294  else
295  /* The window given is not a valid shapeable window. */
297 }
SDL_bool SDL_IsShapedWindow(const SDL_Window *window)
Return whether the given window is a shaped window.
Definition: SDL_shape.c:57
static SDL_bool SDL_WindowHasAShape(SDL_Window *window)
Definition: SDL_shape.c:270
SDL_WindowShapeMode mode
Definition: SDL_sysvideo.h:47
SDL_WindowShaper * shaper
Definition: SDL_sysvideo.h:99
#define SDL_NONSHAPEABLE_WINDOW
Definition: SDL_shape.h:42
#define SDL_WINDOW_LACKS_SHAPE
Definition: SDL_shape.h:44
#define NULL
Definition: begin_code.h:143
SDL_bool SDL_IsShapedWindow ( const SDL_Window window)

Return whether the given window is a shaped window.

Parameters
windowThe 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 57 of file SDL_shape.c.

References NULL, SDL_FALSE, and SDL_Window::shaper.

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

58 {
59  if(window == NULL)
60  return SDL_FALSE;
61  else
62  return (SDL_bool)(window->shaper != NULL);
63 }
SDL_bool
Definition: SDL_stdinc.h:126
SDL_WindowShaper * shaper
Definition: SDL_sysvideo.h:99
#define NULL
Definition: begin_code.h:143
int SDL_SetWindowShape ( SDL_Window window,
SDL_Surface shape,
SDL_WindowShapeMode shape_mode 
)

Set the shape and parameters of a shaped window.

Parameters
windowThe shaped window whose parameters should be set.
shapeA surface encoding the desired shape for the window.
shape_modeThe parameters to set for the shaped window.
Returns
0 on success, SDL_INVALID_SHAPE_ARGUMENT on invalid 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 247 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.

248 {
249  int result;
250  if(window == NULL || !SDL_IsShapedWindow(window))
251  /* The window given was not a shapeable window. */
253  if(shape == NULL)
254  /* Invalid shape argument. */
256 
257  if(shape_mode != NULL)
258  window->shaper->mode = *shape_mode;
259  result = SDL_GetVideoDevice()->shape_driver.SetWindowShape(window->shaper,shape,shape_mode);
260  window->shaper->hasshape = SDL_TRUE;
261  if(window->shaper->userx != 0 && window->shaper->usery != 0) {
262  SDL_SetWindowPosition(window,window->shaper->userx,window->shaper->usery);
263  window->shaper->userx = 0;
264  window->shaper->usery = 0;
265  }
266  return result;
267 }
GLuint64EXT * result
SDL_bool hasshape
Definition: SDL_sysvideo.h:50
SDL_bool SDL_IsShapedWindow(const SDL_Window *window)
Return whether the given window is a shaped window.
Definition: SDL_shape.c:57
#define SDL_INVALID_SHAPE_ARGUMENT
Definition: SDL_shape.h:43
int(* SetWindowShape)(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode)
Definition: SDL_sysvideo.h:59
SDL_WindowShapeMode mode
Definition: SDL_sysvideo.h:47
SDL_WindowShaper * shaper
Definition: SDL_sysvideo.h:99
#define SDL_NONSHAPEABLE_WINDOW
Definition: SDL_shape.h:42
#define NULL
Definition: begin_code.h:143
SDL_VideoDevice * SDL_GetVideoDevice(void)
Definition: SDL_video.c:573
SDL_ShapeDriver shape_driver
Definition: SDL_sysvideo.h:224
#define SDL_SetWindowPosition
void SDL_TraverseShapeTree ( SDL_ShapeTree tree,
SDL_TraversalFunction  function,
void closure 
)

Definition at line 220 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().

221 {
222  SDL_assert(tree != NULL);
223  if(tree->kind == QuadShape) {
224  SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upleft,function,closure);
225  SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upright,function,closure);
226  SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downleft,function,closure);
227  SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downright,function,closure);
228  }
229  else
230  function(tree,closure);
231 }
struct SDL_ShapeTree * upright
SDL_ShapeUnion data
#define SDL_assert(condition)
Definition: SDL_assert.h:167
#define NULL
Definition: begin_code.h:143
void SDL_TraverseShapeTree(SDL_ShapeTree *tree, SDL_TraversalFunction function, void *closure)
Definition: SDL_shape.c:220
struct SDL_ShapeTree * upleft
SDL_ShapeKind kind
struct SDL_ShapeTree * downright
SDL_QuadTreeChildren children
struct SDL_ShapeTree * downleft
static SDL_bool SDL_WindowHasAShape ( SDL_Window window)
static

Definition at line 270 of file SDL_shape.c.

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

Referenced by SDL_GetShapedWindowMode().

271 {
272  if (window == NULL || !SDL_IsShapedWindow(window))
273  return SDL_FALSE;
274  return window->shaper->hasshape;
275 }
SDL_bool hasshape
Definition: SDL_sysvideo.h:50
SDL_bool SDL_IsShapedWindow(const SDL_Window *window)
Return whether the given window is a shaped window.
Definition: SDL_shape.c:57
SDL_WindowShaper * shaper
Definition: SDL_sysvideo.h:99
#define NULL
Definition: begin_code.h:143