| 1 | package SDL2::shape 0.01 { | ||
| 2 | use SDL2::Utils; | ||
| 3 | use experimental 'signatures'; | ||
| 4 | # | ||
| 5 | use SDL2::stdinc; | ||
| 6 | use SDL2::pixels; | ||
| 7 | use SDL2::rect; | ||
| 8 | use SDL2::surface; | ||
| 9 | use SDL2::video; | ||
| 10 | # | ||
| 11 | define shape => [ | ||
| 12 | [ SDL_NONSHAPEABLE_WINDOW => -1 ], | ||
| 13 | [ SDL_INVALID_SHAPE_ARGUMENT => -2 ], | ||
| 14 | [ SDL_WINDOW_LACKS_SHAPE => -3 ] | ||
| 15 | ]; | ||
| 16 | attach shape => { | ||
| 17 | SDL_CreateShapedWindow => | ||
| 18 | [ [ 'string', 'uint', 'uint', 'uint', 'uint', 'uint32' ], 'SDL_Window' ], | ||
| 19 | SDL_IsShapedWindow => [ ['SDL_Window'], 'SDL_bool' ] | ||
| 20 | }; | ||
| 21 | enum WindowShapeMode => [ | ||
| 22 | qw[ShapeModeDefault | ||
| 23 | ShapeModeBinarizeAlpha | ||
| 24 | ShapeModeReverseBinarizeAlpha | ||
| 25 | ShapeModeColorKey] | ||
| 26 | ]; | ||
| 27 | define shape => [ | ||
| 28 | [ SDL_SHAPEMODEALPHA => sub ($mode) { | ||
| 29 | ( $mode == SDL2::FFI::ShapeModeDefault() || | ||
| 30 | $mode == SDL2::FFI::ShapeModeBinarizeAlpha() || | ||
| 31 | $mode == SDL2::FFI::ShapeModeReverseBinarizeAlpha() ) | ||
| 32 | } | ||
| 33 | ], | ||
| 34 | ]; | ||
| 35 | |||
| 36 | package SDL2::WindowShapeParams { | ||
| 37 | use SDL2::Utils; | ||
| 38 | use FFI::C::UnionDef; | ||
| 39 | is 'Union'; | ||
| 40 | our $TYPE = has binarizationCutoff => 'uint8', colorKey => 'SDL_Color'; | ||
| 41 | }; | ||
| 42 | |||
| 43 | package SDL2::WindowShapeMode { | ||
| 44 | use SDL2::Utils; | ||
| 45 | our $TYPE = has | ||
| 46 | mode => 'WindowShapeMode', | ||
| 47 | parameters => 'SDL_WindowShapeParams'; | ||
| 48 | }; | ||
| 49 | attach shape => { | ||
| 50 | SDL_SetWindowShape => [ [ 'SDL_Window', 'SDL_Surface', 'SDL_WindowShapeMode' ], 'int' ], | ||
| 51 | SDL_GetShapedWindowMode => [ [ 'SDL_Window', 'SDL_WindowShapeMode' ], 'int' ] | ||
| 52 | }; | ||
| 53 | |||
| 54 | =encoding utf-8 | ||
| 55 | |||
| 56 | =head1 NAME | ||
| 57 | |||
| 58 | SDL2::shape - Functions for the Shaped Window API | ||
| 59 | |||
| 60 | =head1 SYNOPSIS | ||
| 61 | |||
| 62 | use SDL2 qw[:shape]; | ||
| 63 | |||
| 64 | =head1 DESCRIPTION | ||
| 65 | |||
| 66 | SDL2::shape exposes functions which allow you to create windows with custom | ||
| 67 | shapes. | ||
| 68 | |||
| 69 | =head1 Functions | ||
| 70 | |||
| 71 | These functions may be imported by name or with the C<:shape> tag. | ||
| 72 | |||
| 73 | =head2 C<SDL_CreateShapedWindow( ... )> | ||
| 74 | |||
| 75 | Create a window that can be shaped with the specified position, dimensions, and | ||
| 76 | flags. | ||
| 77 | |||
| 78 | Expected parameters include: | ||
| 79 | |||
| 80 | =over | ||
| 81 | |||
| 82 | =item C<title> - The title of the window, in UTF-8 encoding | ||
| 83 | |||
| 84 | =item C<x> - The x position of the window, C<SDL_WINDOWPOS_CENTERED>, or C<SDL_WINDOWPOS_UNDEFINED> | ||
| 85 | |||
| 86 | =item C<y> - The y position of the window, C<SDL_WINDOWPOS_CENTERED>, or C<DL_WINDOWPOS_UNDEFINED>. | ||
| 87 | |||
| 88 | =item C<w> - The width of the window. | ||
| 89 | |||
| 90 | =item C<h> - The height of the window. | ||
| 91 | |||
| 92 | =item C<flags> | ||
| 93 | |||
| 94 | The flags for the window, a mask of C<SDL_WINDOW_BORDERLESS> with any of the | ||
| 95 | following: C<SDL_WINDOW_OPENGL>, C<SDL_WINDOW_INPUT_GRABBED>, | ||
| 96 | C<DL_WINDOW_HIDDEN>, C<SDL_WINDOW_RESIZABLE>, C<SDL_WINDOW_MAXIMIZED>, | ||
| 97 | C<SDL_WINDOW_MINIMIZED>. | ||
| 98 | |||
| 99 | C<SDL_WINDOW_BORDERLESS> is always set, and C<SDL_WINDOW_FULLSCREEN> is always | ||
| 100 | unset. | ||
| 101 | |||
| 102 | =back | ||
| 103 | |||
| 104 | Returns the window created, or C<undef> if window creation failed. | ||
| 105 | |||
| 106 | =head2 C<SDL_IsShapedWindow( ... )> | ||
| 107 | |||
| 108 | Return whether the given window is a shaped window. | ||
| 109 | |||
| 110 | Expected parameters include: | ||
| 111 | |||
| 112 | =over | ||
| 113 | |||
| 114 | =item C<window> - the window to query for being shaped | ||
| 115 | |||
| 116 | =back | ||
| 117 | |||
| 118 | Returns C<SDL_TRUE> if the window is a window that can be shaped, C<SDL_FALSE> | ||
| 119 | if the window is unshaped or C<undef>. | ||
| 120 | |||
| 121 | =head2 C<SDL_SetWindowShape( ... )> | ||
| 122 | |||
| 123 | Set the shape and parameters of a shaped window. | ||
| 124 | |||
| 125 | Expected parameters include: | ||
| 126 | |||
| 127 | =over | ||
| 128 | |||
| 129 | =item C<window> - the shaped window whose parameters should be set | ||
| 130 | |||
| 131 | =item C<shape> - a surface encoding the desired shape for the window | ||
| 132 | |||
| 133 | =item C<shape_mode> - the parameters to set for the shaped window | ||
| 134 | |||
| 135 | =back | ||
| 136 | |||
| 137 | Returns C<0> on success, C<SDL_INVALID_SHAPE_ARGUMENT> on an invalid shape | ||
| 138 | argument, or C<SDL_NONSHAPEABLE_WINDOW> if the L<SDL2::Window> given does not | ||
| 139 | reference a valid shaped window. | ||
| 140 | |||
| 141 | =head2 C<SDL_GetShapedWindowMode( ... )> | ||
| 142 | |||
| 143 | Get the shape parameters of a shaped window. | ||
| 144 | |||
| 145 | Expected parameters include: | ||
| 146 | |||
| 147 | =over | ||
| 148 | |||
| 149 | =item C<window> - the shaped window whose parameters should be retrieved | ||
| 150 | |||
| 151 | =item C<shape_mode> - an empty shape-mode structure to fill, or C<undef> to check whether the window has a shape | ||
| 152 | |||
| 153 | =back | ||
| 154 | |||
| 155 | Returns C<0> if the window has a shape and, provided shape_mode was not | ||
| 156 | C<undef>, C<shape_mode> has been filled with the mode data, | ||
| 157 | C<SDL_NONSHAPEABLE_WINDOW> if the L<SDL2::Window> given is not a shaped window, | ||
| 158 | or C<SDL_WINDOW_LACKS_SHAPE> if the L<SDL2::Window> given is a shapeable window | ||
| 159 | currently lacking a shape. | ||
| 160 | |||
| 161 | =head1 Defined Variables and Enumerations | ||
| 162 | |||
| 163 | Variables may be imported by name or with the C<:shape> tag. | ||
| 164 | |||
| 165 | =over | ||
| 166 | |||
| 167 | =item C<SDL_NONSHAPEABLE_WINDOW> | ||
| 168 | |||
| 169 | =item C<SDL_INVALID_SHAPE_ARGUMENT> | ||
| 170 | |||
| 171 | =item C<SDL_WINDOW_LACKS_SHAPE> | ||
| 172 | |||
| 173 | =back | ||
| 174 | |||
| 175 | =head2 C<WindowShapeMode> | ||
| 176 | |||
| 177 | An enum denoting the specific type of contents present in an | ||
| 178 | C<SDL_WindowShapeParams> union. These may be imported with the | ||
| 179 | C<:windowShapeMode> tag. | ||
| 180 | |||
| 181 | =over | ||
| 182 | |||
| 183 | =item C<ShapeModeDefault> - The default mode, a binarized alpha cutoff of 1 | ||
| 184 | |||
| 185 | =item C<ShapeModeBinarizeAlpha> - A binarized alpha cutoff with a given integer value | ||
| 186 | |||
| 187 | =item C<ShapeModeReverseBinarizeAlpha> - A binarized alpha cutoff with a given integer value, but with the opposite comparison | ||
| 188 | |||
| 189 | =item C<ShapeModeColorKey> - A color key is applied. | ||
| 190 | |||
| 191 | =back | ||
| 192 | |||
| 193 | =head1 LICENSE | ||
| 194 | |||
| 195 | Copyright (C) Sanko Robinson. | ||
| 196 | |||
| 197 | This library is free software; you can redistribute it and/or modify it under | ||
| 198 | the terms found in the Artistic License 2. Other copyrights, terms, and | ||
| 199 | conditions may apply to data transmitted through this module. | ||
| 200 | |||
| 201 | =head1 AUTHOR | ||
| 202 | |||
| 203 | Sanko Robinson E<lt>sanko@cpan.orgE<gt> | ||
| 204 | |||
| 205 | =begin stopwords | ||
| 206 | |||
| 207 | binarized | ||
| 208 | |||
| 209 | =end stopwords | ||
| 210 | |||
| 211 | =cut | ||
| 212 | |||
| 213 | }; | ||
| 214 | 1; |