SDL_shape.h File Reference
`#include "SDL_stdinc.h"`
`#include "SDL_pixels.h"`
`#include "SDL_rect.h"`
`#include "SDL_surface.h"`
`#include "SDL_video.h"`
`#include "begin_code.h"`
`#include "close_code.h"`
Include dependency graph for SDL_shape.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Data Structures

union | SDL_WindowShapeParams
| A union containing parameters for shaped windows. More...
struct | SDL_WindowShapeMode
| A struct that tags the SDL_WindowShapeParams union with an enum describing the type of its contents. More...

## Macros

#define | SDL_NONSHAPEABLE_WINDOW -1
#define | SDL_INVALID_SHAPE_ARGUMENT -2
#define | SDL_WINDOW_LACKS_SHAPE -3
#define | SDL_SHAPEMODEALPHA(mode) (mode == ShapeModeDefault || mode == ShapeModeBinarizeAlpha || mode == ShapeModeReverseBinarizeAlpha)

## Enumerations

enum | WindowShapeMode { ShapeModeDefault, ShapeModeBinarizeAlpha, ShapeModeReverseBinarizeAlpha, ShapeModeColorKey }
| An enum denoting the specific type of contents present in an SDL_WindowShapeParams union. More...

## 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...
int | SDL_SetWindowShape (SDL_Window *window, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode)
| Set the shape and parameters of a shaped window. More...
int | SDL_GetShapedWindowMode (SDL_Window *window, SDL_WindowShapeMode *shape_mode)
| Get the shape parameters of a shaped window. More...

## Detailed Description

Header file for the shaped window API.

Definition in file SDL_shape.h.

## Macro Definition Documentation

## SDL_INVALID_SHAPE_ARGUMENT

#define SDL_INVALID_SHAPE_ARGUMENT -2

Definition at line 43 of file SDL_shape.h.

Referenced by SDL_SetWindowShape().

## SDL_NONSHAPEABLE_WINDOW

#define SDL_NONSHAPEABLE_WINDOW -1

Definition at line 42 of file SDL_shape.h.

Referenced by SDL_GetShapedWindowMode(), and SDL_SetWindowShape().

## SDL_SHAPEMODEALPHA

#define SDL_SHAPEMODEALPHA | ( |  | mode | ) | (mode == ShapeModeDefault || mode == ShapeModeBinarizeAlpha || mode == ShapeModeReverseBinarizeAlpha)

Definition at line 91 of file SDL_shape.h.

## SDL_WINDOW_LACKS_SHAPE

#define SDL_WINDOW_LACKS_SHAPE -3

Definition at line 44 of file SDL_shape.h.

Referenced by SDL_GetShapedWindowMode().

## Enumeration Type Documentation

## WindowShapeMode

enum WindowShapeMode

An enum denoting the specific type of contents present in an SDL_WindowShapeParams union.

Enumerator
ShapeModeDefault | The default mode, a binarized alpha cutoff of 1.
ShapeModeBinarizeAlpha | A binarized alpha cutoff with a given integer value.
ShapeModeReverseBinarizeAlpha | A binarized alpha cutoff with a given integer value, but with the opposite comparison.
ShapeModeColorKey | A color key is applied.

Definition at line 80 of file SDL_shape.h.

{
/** \brief The default mode, a binarized alpha cutoff of 1. */
ShapeModeDefault,
/** \brief A binarized alpha cutoff with a given integer value. */
ShapeModeBinarizeAlpha,
/** \brief A binarized alpha cutoff with a given integer value, but with the opposite comparison. */
ShapeModeReverseBinarizeAlpha,
/** \brief A color key is applied. */
ShapeModeColorKey
} WindowShapeMode;
ShapeModeColorKey
A color key is applied.
Definition: SDL_shape.h:88
WindowShapeMode
WindowShapeMode
An enum denoting the specific type of contents present in an SDL_WindowShapeParams union...
Definition: SDL_shape.h:80
ShapeModeDefault
The default mode, a binarized alpha cutoff of 1.
Definition: SDL_shape.h:82
ShapeModeBinarizeAlpha
A binarized alpha cutoff with a given integer value.
Definition: SDL_shape.h:84
ShapeModeReverseBinarizeAlpha
A binarized alpha cutoff with a given integer value, but with the opposite comparison.
Definition: SDL_shape.h:86

## Function Documentation

## 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_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