| 1 | package SDL2::events 0.01 { | ||
| 2 | use SDL2::Utils; | ||
| 3 | use experimental 'signatures'; | ||
| 4 | # | ||
| 5 | use SDL2::stdinc; | ||
| 6 | use SDL2::error; | ||
| 7 | use SDL2::video; | ||
| 8 | use SDL2::keyboard; | ||
| 9 | use SDL2::mouse; | ||
| 10 | use SDL2::joystick; | ||
| 11 | use SDL2::gamecontroller; | ||
| 12 | use SDL2::quit; | ||
| 13 | use SDL2::gesture; | ||
| 14 | use SDL2::touch; | ||
| 15 | # | ||
| 16 | use SDL2::version; # Not in upstream header but required for SDL_version | ||
| 17 | use SDL2::syswm; # Header is not included by default but let's make life easy on folks | ||
| 18 | |||
| 19 | # | ||
| 20 | define events => [ [ SDL_RELEASED => 0 ], [ SDL_PRESSED => 1 ] ]; | ||
| 21 | enum SDL_EventType => [ | ||
| 22 | [ SDL_FIRSTEVENT => 0 ], [ SDL_QUIT => 0x100 ], | ||
| 23 | |||
| 24 | # These application events have special meaning on iOS, see README-ios.md for details | ||
| 25 | qw[SDL_APP_TERMINATING | ||
| 26 | SDL_APP_LOWMEMORY | ||
| 27 | SDL_APP_WILLENTERBACKGROUND | ||
| 28 | SDL_APP_DIDENTERBACKGROUND | ||
| 29 | SDL_APP_WILLENTERFOREGROUND | ||
| 30 | SDL_APP_DIDENTERFOREGROUND], | ||
| 31 | # | ||
| 32 | 'SDL_LOCALECHANGED', | ||
| 33 | |||
| 34 | #Display events | ||
| 35 | [ SDL_DISPLAYEVENT => 0x150 ], | ||
| 36 | |||
| 37 | # Window events | ||
| 38 | [ SDL_WINDOWEVENT => 0x200 ], 'SDL_SYSWMEVENT', | ||
| 39 | |||
| 40 | # Keyboard events | ||
| 41 | [ SDL_KEYDOWN => 0x300 ], qw[SDL_KEYUP | ||
| 42 | SDL_TEXTEDITING | ||
| 43 | SDL_TEXTINPUT | ||
| 44 | SDL_KEYMAPCHANGED], | ||
| 45 | |||
| 46 | # Mouse events | ||
| 47 | [ SDL_MOUSEMOTION => 0x400 ], qw[SDL_MOUSEBUTTONDOWN | ||
| 48 | SDL_MOUSEBUTTONUP | ||
| 49 | SDL_MOUSEWHEEL], | ||
| 50 | |||
| 51 | # Joystick events | ||
| 52 | [ SDL_JOYAXISMOTION => 0x600 ], qw[SDL_JOYBALLMOTION | ||
| 53 | SDL_JOYHATMOTION | ||
| 54 | SDL_JOYBUTTONDOWN | ||
| 55 | SDL_JOYBUTTONUP | ||
| 56 | SDL_JOYDEVICEADDED | ||
| 57 | SDL_JOYDEVICEREMOVED], | ||
| 58 | |||
| 59 | # Game controller events | ||
| 60 | [ SDL_CONTROLLERAXISMOTION => 0x650 ], qw[SDL_CONTROLLERBUTTONDOWN | ||
| 61 | SDL_CONTROLLERBUTTONUP | ||
| 62 | SDL_CONTROLLERDEVICEADDED | ||
| 63 | SDL_CONTROLLERDEVICEREMOVED | ||
| 64 | SDL_CONTROLLERDEVICEREMAPPED | ||
| 65 | SDL_CONTROLLERTOUCHPADDOWN | ||
| 66 | SDL_CONTROLLERTOUCHPADMOTION | ||
| 67 | SDL_CONTROLLERTOUCHPADUP | ||
| 68 | SDL_CONTROLLERSENSORUPDATE], | ||
| 69 | |||
| 70 | # Touch events | ||
| 71 | [ SDL_FINGERDOWN => 0x700 ], qw[SDL_FINGERUP | ||
| 72 | SDL_FINGERMOTION], | ||
| 73 | |||
| 74 | # Gesture events | ||
| 75 | [ SDL_DOLLARGESTURE => 0x800 ], qw[SDL_DOLLARRECORD | ||
| 76 | SDL_MULTIGESTURE], | ||
| 77 | |||
| 78 | # Clipboard events | ||
| 79 | [ SDL_CLIPBOARDUPDATE => 0x900 ], | ||
| 80 | |||
| 81 | # Drag and drop events | ||
| 82 | [ SDL_DROPFILE => 0x1000 ], qw[SDL_DROPTEXT | ||
| 83 | SDL_DROPBEGIN | ||
| 84 | SDL_DROPCOMPLETE], | ||
| 85 | |||
| 86 | # Audio hotplug events | ||
| 87 | [ SDL_AUDIODEVICEADDED => 0x1100 ], 'SDL_AUDIODEVICEREMOVED', | ||
| 88 | |||
| 89 | # Sensor events | ||
| 90 | [ SDL_SENSORUPDATE => 0x1200 ], | ||
| 91 | |||
| 92 | # Render events | ||
| 93 | [ SDL_RENDER_TARGETS_RESET => 0x2000 ], 'SDL_RENDER_DEVICE_RESET', | ||
| 94 | |||
| 95 | # Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use, | ||
| 96 | # and should be allocated with SDL_RegisterEvents() | ||
| 97 | [ SDL_USEREVENT => 0x8000 ], | ||
| 98 | |||
| 99 | # This last event is only for bounding internal arrays | ||
| 100 | [ SDL_LASTEVENT => 0xFFFF ] | ||
| 101 | ]; | ||
| 102 | |||
| 103 | package SDL2::CommonEvent { | ||
| 104 | use SDL2::Utils; | ||
| 105 | our $TYPE = has | ||
| 106 | type => 'uint32', | ||
| 107 | timestamp => 'uint32'; | ||
| 108 | }; | ||
| 109 | |||
| 110 | package SDL2::DisplayEvent { | ||
| 111 | use SDL2::Utils; | ||
| 112 | our $TYPE = has | ||
| 113 | type => 'uint32', | ||
| 114 | timestamp => 'uint32', | ||
| 115 | display => 'uint32', | ||
| 116 | event => 'uint8', | ||
| 117 | padding1 => 'uint8', | ||
| 118 | padding2 => 'uint8', | ||
| 119 | padding3 => 'uint8', | ||
| 120 | data1 => 'sint32'; | ||
| 121 | }; | ||
| 122 | |||
| 123 | package SDL2::WindowEvent { | ||
| 124 | use SDL2::Utils; | ||
| 125 | our $TYPE = has | ||
| 126 | type => 'uint32', | ||
| 127 | timestamp => 'uint32', | ||
| 128 | windowID => 'uint32', | ||
| 129 | event => 'uint8', | ||
| 130 | padding1 => 'uint8', | ||
| 131 | padding2 => 'uint8', | ||
| 132 | padding3 => 'uint8', | ||
| 133 | data1 => 'sint32', | ||
| 134 | data2 => 'sint32'; | ||
| 135 | }; | ||
| 136 | |||
| 137 | package SDL2::KeyboardEvent { | ||
| 138 | use SDL2::Utils; | ||
| 139 | |||
| 140 | #use SDL2::Keysym; | ||
| 141 | our $TYPE = has | ||
| 142 | type => 'uint32', | ||
| 143 | timestamp => 'uint32', | ||
| 144 | windowId => 'uint32', | ||
| 145 | state => 'uint8', | ||
| 146 | repeat => 'uint8', | ||
| 147 | padding2 => 'uint8', | ||
| 148 | padding3 => 'uint8', | ||
| 149 | keysym => 'SDL_Keysym'; | ||
| 150 | }; | ||
| 151 | # | ||
| 152 | define events => [ [ SDL_TEXTEDITINGEVENT_TEXT_SIZE => 32 ] ]; | ||
| 153 | |||
| 154 | package SDL2::TextEditingEvent { | ||
| 155 | use SDL2::Utils; | ||
| 156 | our $TYPE = has | ||
| 157 | type => 'uint32', | ||
| 158 | timestamp => 'uint32', | ||
| 159 | windowId => 'uint32', | ||
| 160 | text => 'char[' . SDL2::FFI::SDL_TEXTEDITINGEVENT_TEXT_SIZE() . ']', | ||
| 161 | start => 'sint32', | ||
| 162 | length => 'sint32'; | ||
| 163 | }; | ||
| 164 | define events => [ [ SDL_TEXTINPUTEVENT_TEXT_SIZE => 32 ] ]; | ||
| 165 | |||
| 166 | package SDL2::TextInputEvent { | ||
| 167 | use SDL2::Utils; | ||
| 168 | our $TYPE = has | ||
| 169 | type => 'uint32', | ||
| 170 | timestamp => 'uint32', | ||
| 171 | windowId => 'uint32', | ||
| 172 | text => 'char[' . SDL2::FFI::SDL_TEXTINPUTEVENT_TEXT_SIZE() . ']'; | ||
| 173 | }; | ||
| 174 | |||
| 175 | package SDL2::MouseMotionEvent { | ||
| 176 | use SDL2::Utils; | ||
| 177 | our $TYPE = has | ||
| 178 | type => 'uint32', | ||
| 179 | timestamp => 'uint32', | ||
| 180 | windowId => 'uint32', | ||
| 181 | which => 'uint32', | ||
| 182 | state => 'uint32', | ||
| 183 | x => 'sint32', | ||
| 184 | y => 'sint32', | ||
| 185 | xrel => 'sint32', | ||
| 186 | yrel => 'sint32'; | ||
| 187 | }; | ||
| 188 | |||
| 189 | package SDL2::MouseButtonEvent { | ||
| 190 | use SDL2::Utils; | ||
| 191 | our $TYPE = has | ||
| 192 | type => 'uint32', | ||
| 193 | timestamp => 'uint32', | ||
| 194 | windowID => 'uint32', | ||
| 195 | which => 'uint32', | ||
| 196 | button => 'uint8', | ||
| 197 | state => 'uint8', | ||
| 198 | clicks => 'uint8', | ||
| 199 | padding1 => 'uint8', | ||
| 200 | x => 'sint32', | ||
| 201 | y => 'sint32'; | ||
| 202 | }; | ||
| 203 | |||
| 204 | package SDL2::MouseWheelEvent { | ||
| 205 | use SDL2::Utils; | ||
| 206 | our $TYPE = has | ||
| 207 | type => 'uint32', | ||
| 208 | timestamp => 'uint32', | ||
| 209 | windowId => 'uint32', | ||
| 210 | which => 'uint32', | ||
| 211 | x => 'sint32', | ||
| 212 | y => 'sint32', | ||
| 213 | direction => 'uint32'; | ||
| 214 | }; | ||
| 215 | |||
| 216 | package SDL2::JoyAxisEvent { | ||
| 217 | use SDL2::Utils; | ||
| 218 | our $TYPE = has | ||
| 219 | type => 'uint32', | ||
| 220 | timestamp => 'uint32', | ||
| 221 | which => 'SDL_JoystickID', | ||
| 222 | axis => 'uint8', | ||
| 223 | padding1 => 'uint8', | ||
| 224 | padding2 => 'uint8', | ||
| 225 | padding3 => 'uint8', | ||
| 226 | value => 'sint16', | ||
| 227 | padding4 => 'uint16'; | ||
| 228 | }; | ||
| 229 | |||
| 230 | package SDL2::JoyBallEvent { | ||
| 231 | use SDL2::Utils; | ||
| 232 | our $TYPE = has | ||
| 233 | type => 'uint32', | ||
| 234 | timestamp => 'uint32', | ||
| 235 | which => 'SDL_JoystickID', | ||
| 236 | ball => 'uint8', | ||
| 237 | padding1 => 'uint8', | ||
| 238 | padding2 => 'uint8', | ||
| 239 | padding3 => 'uint8', | ||
| 240 | xrel => 'sint16', | ||
| 241 | yrel => 'sint16'; | ||
| 242 | }; | ||
| 243 | |||
| 244 | package SDL2::JoyHatEvent { | ||
| 245 | use SDL2::Utils; | ||
| 246 | our $TYPE = has | ||
| 247 | type => 'uint32', | ||
| 248 | timestamp => 'uint32', | ||
| 249 | which => 'SDL_JoystickID', | ||
| 250 | hat => 'uint8', | ||
| 251 | value => 'uint8', | ||
| 252 | padding1 => 'uint8', | ||
| 253 | padding2 => 'uint8'; | ||
| 254 | }; | ||
| 255 | |||
| 256 | package SDL2::JoyButtonEvent { | ||
| 257 | use SDL2::Utils; | ||
| 258 | our $TYPE = has | ||
| 259 | type => 'uint32', | ||
| 260 | timestamp => 'uint32', | ||
| 261 | which => 'SDL_JoystickID', | ||
| 262 | button => 'uint8', | ||
| 263 | state => 'uint8', | ||
| 264 | padding1 => 'uint8', | ||
| 265 | padding2 => 'uint8'; | ||
| 266 | }; | ||
| 267 | |||
| 268 | package SDL2::JoyDeviceEvent { | ||
| 269 | use SDL2::Utils; | ||
| 270 | our $TYPE = has | ||
| 271 | type => 'uint32', | ||
| 272 | timestamp => 'uint32', | ||
| 273 | which => 'sint32'; | ||
| 274 | }; | ||
| 275 | |||
| 276 | package SDL2::ControllerAxisEvent { | ||
| 277 | use SDL2::Utils; | ||
| 278 | our $TYPE = has | ||
| 279 | type => 'uint32', | ||
| 280 | timestamp => 'uint32', | ||
| 281 | which => 'SDL_JoystickID', | ||
| 282 | axis => 'uint8', | ||
| 283 | padding1 => 'uint8', | ||
| 284 | padding2 => 'uint8', | ||
| 285 | padding3 => 'uint8', | ||
| 286 | value => 'sint16', | ||
| 287 | padding4 => 'uint8'; | ||
| 288 | }; | ||
| 289 | |||
| 290 | package SDL2::ControllerButtonEvent { | ||
| 291 | use SDL2::Utils; | ||
| 292 | our $TYPE = has | ||
| 293 | type => 'uint32', | ||
| 294 | timestamp => 'uint32', | ||
| 295 | which => 'SDL_JoystickID', | ||
| 296 | button => 'uint8', | ||
| 297 | state => 'uint8', | ||
| 298 | padding1 => 'uint8', | ||
| 299 | padding2 => 'uint8'; | ||
| 300 | }; | ||
| 301 | |||
| 302 | package SDL2::ControllerDeviceEvent { | ||
| 303 | use SDL2::Utils; | ||
| 304 | our $TYPE = has | ||
| 305 | type => 'uint32', | ||
| 306 | timestamp => 'uint32', | ||
| 307 | which => 'sint32'; | ||
| 308 | }; | ||
| 309 | |||
| 310 | package SDL2::ControllerTouchpadEvent { | ||
| 311 | use SDL2::Utils; | ||
| 312 | our $TYPE = has | ||
| 313 | type => 'uint32', | ||
| 314 | timestamp => 'uint32', | ||
| 315 | which => 'SDL_JoystickID', | ||
| 316 | touchpad => 'sint32', | ||
| 317 | finger => 'sint32', | ||
| 318 | x => 'float', | ||
| 319 | y => 'float', | ||
| 320 | pressure => 'float'; | ||
| 321 | }; | ||
| 322 | |||
| 323 | package SDL2::ControllerSensorEvent { | ||
| 324 | use SDL2::Utils; | ||
| 325 | our $TYPE = has | ||
| 326 | type => 'uint32', | ||
| 327 | timestamp => 'uint32', | ||
| 328 | which => 'SDL_JoystickID', | ||
| 329 | sensor => 'sint32', | ||
| 330 | data => 'float[3]'; | ||
| 331 | }; | ||
| 332 | |||
| 333 | package SDL2::AudioDeviceEvent { | ||
| 334 | use SDL2::Utils; | ||
| 335 | our $TYPE = has | ||
| 336 | type => 'uint32', | ||
| 337 | timestamp => 'uint32', | ||
| 338 | which => 'uint32', | ||
| 339 | iscapture => 'uint8', | ||
| 340 | padding1 => 'uint8', | ||
| 341 | padding2 => 'uint8', | ||
| 342 | padding3 => 'uint8'; | ||
| 343 | }; | ||
| 344 | |||
| 345 | package SDL2::TouchFingerEvent { | ||
| 346 | use SDL2::Utils; | ||
| 347 | |||
| 348 | #ffi->type( 'sint64' => 'SDL_TouchID' ); | ||
| 349 | our $TYPE = has | ||
| 350 | type => 'uint32', | ||
| 351 | timestamp => 'uint32', | ||
| 352 | touchId => 'SDL_TouchID', | ||
| 353 | fingerId => 'SDL_FingerID', | ||
| 354 | x => 'float', | ||
| 355 | y => 'float', | ||
| 356 | dx => 'float', | ||
| 357 | dy => 'float', | ||
| 358 | pressure => 'float', | ||
| 359 | windowID => 'uint32'; | ||
| 360 | }; | ||
| 361 | |||
| 362 | package SDL2::MultiGestureEvent { | ||
| 363 | use SDL2::Utils; | ||
| 364 | our $TYPE = has | ||
| 365 | type => 'uint32', | ||
| 366 | timestamp => 'uint32', | ||
| 367 | touchId => 'SDL_TouchID', | ||
| 368 | dTheta => 'float', | ||
| 369 | dDist => 'float', | ||
| 370 | x => 'float', | ||
| 371 | y => 'float', | ||
| 372 | numFingers => 'uint16', | ||
| 373 | padding => 'uint16'; | ||
| 374 | }; | ||
| 375 | |||
| 376 | package SDL2::DollarGestureEvent { | ||
| 377 | use SDL2::Utils; | ||
| 378 | |||
| 379 | #ffi->type( 'sint64' => 'SDL_GestureID' ); | ||
| 380 | our $TYPE = has | ||
| 381 | type => 'uint32', | ||
| 382 | timestamp => 'uint32', | ||
| 383 | touchId => 'SDL_TouchID', | ||
| 384 | gestureId => 'SDL_GestureID', | ||
| 385 | numFingers => 'uint32', | ||
| 386 | error => 'float', | ||
| 387 | x => 'float', | ||
| 388 | y => 'float'; | ||
| 389 | }; | ||
| 390 | |||
| 391 | package SDL2::DropEvent { | ||
| 392 | use SDL2::Utils; | ||
| 393 | our $TYPE = has | ||
| 394 | type => 'uint32', | ||
| 395 | timestamp => 'uint32', | ||
| 396 | file => 'string(1024)', #'char[1024]', # char * | ||
| 397 | windowID => 'uint32'; | ||
| 398 | }; | ||
| 399 | |||
| 400 | package SDL2::SensorEvent { | ||
| 401 | use SDL2::Utils; | ||
| 402 | our $TYPE = has | ||
| 403 | type => 'uint32', | ||
| 404 | timestamp => 'uint32', | ||
| 405 | which => 'sint32', | ||
| 406 | data => 'float[6]'; | ||
| 407 | }; | ||
| 408 | |||
| 409 | package SDL2::QuitEvent { | ||
| 410 | use SDL2::Utils; | ||
| 411 | our $TYPE = has type => 'uint32', timestamp => 'uint32'; | ||
| 412 | }; | ||
| 413 | |||
| 414 | package SDL2::OSEvent { | ||
| 415 | use SDL2::Utils; | ||
| 416 | our $TYPE = has type => 'uint32', timestamp => 'uint32'; | ||
| 417 | }; | ||
| 418 | |||
| 419 | package SDL2::UserEvent { | ||
| 420 | use SDL2::Utils; | ||
| 421 | our $TYPE = has | ||
| 422 | type => 'uint32', | ||
| 423 | timestamp => 'uint32', | ||
| 424 | windowID => 'uint32', | ||
| 425 | code => 'sint32', | ||
| 426 | data1 => 'opaque', # void * | ||
| 427 | data2 => 'opaque'; # void * | ||
| 428 | }; | ||
| 429 | |||
| 430 | package SDL2::SysWMEvent 0.01 { | ||
| 431 | use SDL2::Utils; | ||
| 432 | our $TYPE = has # TODO: Complex! | ||
| 433 | type => 'uint32', | ||
| 434 | timestamp => 'uint32', | ||
| 435 | _msg => 'opaque' # SDL_SysWMmsg * | ||
| 436 | ; | ||
| 437 | |||
| 438 | sub msg { | ||
| 439 | ffi->cast( 'opaque', 'SDL_SysWMmsg', $_[0]->_msg ); | ||
| 440 | } | ||
| 441 | }; | ||
| 442 | |||
| 443 | package SDL2::Event { | ||
| 444 | use SDL2::Utils; | ||
| 445 | is 'Union'; | ||
| 446 | our $TYPE = has | ||
| 447 | type => 'uint32', | ||
| 448 | common => 'SDL_CommonEvent', | ||
| 449 | display => 'SDL_DisplayEvent', | ||
| 450 | window => 'SDL_WindowEvent', | ||
| 451 | key => 'SDL_KeyboardEvent', | ||
| 452 | edit => 'SDL_TextEditingEvent', | ||
| 453 | text => 'SDL_TextInputEvent', | ||
| 454 | motion => 'SDL_MouseMotionEvent', | ||
| 455 | button => 'SDL_MouseButtonEvent', | ||
| 456 | wheel => 'SDL_MouseWheelEvent', | ||
| 457 | jaxis => 'SDL_JoyAxisEvent', | ||
| 458 | jball => 'SDL_JoyBallEvent', | ||
| 459 | jhat => 'SDL_JoyHatEvent', | ||
| 460 | jbutton => 'SDL_JoyButtonEvent', | ||
| 461 | jdevice => 'SDL_JoyDeviceEvent', | ||
| 462 | caxis => 'SDL_ControllerAxisEvent', | ||
| 463 | cbutton => 'SDL_ControllerButtonEvent', | ||
| 464 | cdevice => 'SDL_ControllerDeviceEvent', | ||
| 465 | ctouchpad => 'SDL_ControllerTouchpadEvent', | ||
| 466 | csensor => 'SDL_ControllerSensorEvent', | ||
| 467 | adevice => 'SDL_AudioDeviceEvent', | ||
| 468 | sensor => 'SDL_SensorEvent', | ||
| 469 | quit => 'SDL_QuitEvent', | ||
| 470 | user => 'SDL_UserEvent', | ||
| 471 | syswm => 'SDL_SysWMEvent', # broken? | ||
| 472 | tfinger => 'SDL_TouchFingerEvent', | ||
| 473 | mgesture => 'SDL_MultiGestureEvent', | ||
| 474 | dgesture => 'SDL_DollarGestureEvent', | ||
| 475 | drop => 'SDL_DropEvent', | ||
| 476 | padding => 'uint8[56]'; | ||
| 477 | }; | ||
| 478 | attach events => { SDL_PumpEvents => [ [] ] }; | ||
| 479 | enum SDL_eventaction => [qw[SDL_ADDEVENT SDL_PEEKEVENT SDL_GETEVENT ]]; | ||
| 480 | attach events => { | ||
| 481 | SDL_PeepEvents => [ | ||
| 482 | [ 'SDL_Event', 'int', 'SDL_eventaction', 'uint32', 'uint32' ] => 'int' => | ||
| 483 | sub ( $inner, @etc ) { SDL2::FFI::SDL_Yield(); $inner->(@etc) } | ||
| 484 | ], | ||
| 485 | SDL_HasEvent => [ | ||
| 486 | ['uint32'] => 'bool' => sub ( $inner, @etc ) { SDL2::FFI::SDL_Yield(); $inner->(@etc) } | ||
| 487 | ], | ||
| 488 | SDL_HasEvents => [ | ||
| 489 | [ 'uint32', 'uint32' ] => 'bool' => | ||
| 490 | sub ( $inner, @etc ) { SDL2::FFI::SDL_Yield(); $inner->(@etc) } | ||
| 491 | ], | ||
| 492 | SDL_FlushEvent => | ||
| 493 | [ ['uint32'] => sub ( $inner, @etc ) { SDL2::FFI::SDL_Yield(); $inner->(@etc) } ], | ||
| 494 | SDL_FlushEvents => [ | ||
| 495 | [ 'uint32', 'uint32' ] => | ||
| 496 | sub ( $inner, @etc ) { SDL2::FFI::SDL_Yield(); $inner->(@etc) } | ||
| 497 | ], | ||
| 498 | SDL_PollEvent => [ | ||
| 499 | ['SDL_Event'] => 'int' => | ||
| 500 | sub ( $inner, @etc ) { SDL2::FFI::SDL_Yield(); $inner->(@etc) } | ||
| 501 | ], | ||
| 502 | SDL_WaitEvent => [ | ||
| 503 | ['SDL_Event'] => 'int' => | ||
| 504 | sub ( $inner, @etc ) { SDL2::FFI::SDL_Yield(); $inner->(@etc) } | ||
| 505 | ], | ||
| 506 | SDL_WaitEventTimeout => [ | ||
| 507 | [ 'SDL_Event', 'int' ] => 'int' => | ||
| 508 | sub ( $inner, @etc ) { SDL2::FFI::SDL_Yield(); $inner->(@etc) } | ||
| 509 | ], | ||
| 510 | SDL_PushEvent => [ | ||
| 511 | ['SDL_Event'] => 'int' => | ||
| 512 | sub ( $inner, @etc ) { SDL2::FFI::SDL_Yield(); $inner->(@etc) } | ||
| 513 | ] | ||
| 514 | }; | ||
| 515 | ffi->type( '(opaque,opaque)->int' => 'SDL_EventFilter' ); | ||
| 516 | attach events => { | ||
| 517 | SDL_SetEventFilter => [ [ 'SDL_EventFilter', 'opaque' ] ], | ||
| 518 | SDL_GetEventFilter => [ [ 'SDL_EventFilter', 'opaque*' ], 'SDL_bool' ], | ||
| 519 | SDL_AddEventWatch => [ [ 'SDL_EventFilter', 'opaque' ] ], | ||
| 520 | SDL_DelEventWatch => [ [ 'SDL_EventFilter', 'opaque' ] ], | ||
| 521 | SDL_FilterEvents => [ [ 'SDL_EventFilter', 'opaque' ] ] | ||
| 522 | }; | ||
| 523 | define eventState => | ||
| 524 | [ [ SDL_QUERY => -1 ], [ SDL_IGNORE => 0 ], [ SDL_DISABLE => 0 ], [ SDL_ENABLE => 1 ] ]; | ||
| 525 | attach events => { SDL_EventState => [ [ 'uint32', 'int' ], 'uint8' ] }; | ||
| 526 | define events => [ | ||
| 527 | [ SDL_GetEventState => | ||
| 528 | sub ($type) { SDL2::FFI::SDL_EventState( $type, SDL2::FFI::SDL_QUERY() ) } | ||
| 529 | ] | ||
| 530 | ]; | ||
| 531 | attach events => { SDL_RegisterEvents => [ ['int'], 'uint32' ] }; | ||
| 532 | |||
| 533 | =encoding utf-8 | ||
| 534 | |||
| 535 | =head1 NAME | ||
| 536 | |||
| 537 | SDL2::events - SDL Event Handling | ||
| 538 | |||
| 539 | =head1 SYNOPSIS | ||
| 540 | |||
| 541 | use SDL2 qw[:events]; | ||
| 542 | |||
| 543 | =head1 DESCRIPTION | ||
| 544 | |||
| 545 | SDL2::events represents the library's version as three levels: major, minor, | ||
| 546 | and patch level. | ||
| 547 | |||
| 548 | =head1 Functions | ||
| 549 | |||
| 550 | These functions might be imported by name or with the C<:events> tag. | ||
| 551 | |||
| 552 | =head2 C<SDL_PumpEvents( )> | ||
| 553 | |||
| 554 | Pump the event loop, gathering events from the input devices. | ||
| 555 | |||
| 556 | SDL_PumpEvents( ); | ||
| 557 | |||
| 558 | This function updates the event queue and internal input device state. | ||
| 559 | |||
| 560 | B<WARNING>: This should only be run in the thread that initialized the video | ||
| 561 | subsystem, and for extra safety, you should consider only doing those things on | ||
| 562 | the main thread in any case. | ||
| 563 | |||
| 564 | C<SDL_PumpEvents( )> gathers all the pending input information from devices and | ||
| 565 | places it in the event queue. Without calls to C<SDL_PumpEvents( )> no events | ||
| 566 | would ever be placed on the queue. Often the need for calls to | ||
| 567 | C<SDL_PumpEvents( )> is hidden from the user since L<< C<SDL_PollEvent( ... | ||
| 568 | )>|/C<SDL_PollEvent( ... )> >> and L<< C<SDL_WaitEvent( ... | ||
| 569 | )>|/C<SDL_WaitEvent( ... )> >> implicitly call C<SDL_PumpEvents( )>. However, | ||
| 570 | if you are not polling or waiting for events (e.g. you are filtering them), | ||
| 571 | then you must call C<SDL_PumpEvents( )> to force an event queue update. | ||
| 572 | |||
| 573 | =head2 C<SDL_PeepEvents( ... )> | ||
| 574 | |||
| 575 | Check the event queue for messages and optionally return them. | ||
| 576 | |||
| 577 | C<action> may be any of the following: | ||
| 578 | |||
| 579 | =over | ||
| 580 | |||
| 581 | =item C<SDL_ADDEVENT>: up to C<numevents> events will be added to the back of the event queue | ||
| 582 | |||
| 583 | =item C<SDL_PEEKEVENT>: C<numevents> events at the front of the event queue, within the specified minimum and maximum type, will be returned to the caller and will _not_ be removed from the queue | ||
| 584 | |||
| 585 | =item C<SDL_GETEVENT>: up to C<numevents> events at the front of the event queue, within the specified minimum and maximum type, will be returned to the caller and will be removed from the queue | ||
| 586 | |||
| 587 | =back | ||
| 588 | |||
| 589 | You may have to call L<< C<SDL_PumpEvents( )>|/C<SDL_PumpEvents( )> >> before | ||
| 590 | calling this function. Otherwise, the events may not be ready to be filtered | ||
| 591 | when you call L<< C<SDL_PeepEvents( )>|/C<SDL_PumpEvents( )> >>. | ||
| 592 | |||
| 593 | This function is thread-safe. | ||
| 594 | |||
| 595 | Expected parameters include: | ||
| 596 | |||
| 597 | =over | ||
| 598 | |||
| 599 | =item C<events> - destination buffer for the retrieved events | ||
| 600 | |||
| 601 | =item C<numevents> - if action is C<SDL_ADDEVENT>, the number of events to add back to the event queue; if action is C<SDL_PEEKEVENT> or C<SDL_GETEVENT>, the maximum number of events to retrieve | ||
| 602 | |||
| 603 | =item C<action> - action to take | ||
| 604 | |||
| 605 | =item C<minType> - minimum value of the event type to be considered; C<SDL_FIRSTEVENT> is a safe choice | ||
| 606 | |||
| 607 | =item C<maxType> - maximum value of the event type to be considered; C<SDL_LASTEVENT> is a safe choice | ||
| 608 | |||
| 609 | =back | ||
| 610 | |||
| 611 | Returns the number of events actually stored or a negative error code on | ||
| 612 | failure; call C<SDL_GetError( )> for more information. | ||
| 613 | |||
| 614 | =head2 C<SDL_HasEvent( ... )> | ||
| 615 | |||
| 616 | Check for the existence of a certain event type in the event queue. | ||
| 617 | |||
| 618 | If you need to check for a range of event types, use C<SDL_HasEvents( )> | ||
| 619 | instead. | ||
| 620 | |||
| 621 | Expected parameters include: | ||
| 622 | |||
| 623 | =over | ||
| 624 | |||
| 625 | =item C<type> - the type of event to be queried; see SDL_EventType for details | ||
| 626 | |||
| 627 | =back | ||
| 628 | |||
| 629 | Returns C<SDL_TRUE> if events matching C<type> are present, or C<SDL_FALSE> if | ||
| 630 | events matching C<type> are not present. | ||
| 631 | |||
| 632 | =head2 C<SDL_HasEvents( ... )> | ||
| 633 | |||
| 634 | Check for the existence of certain event types in the event queue. | ||
| 635 | |||
| 636 | If you need to check for a single event type, use C<SDL_HasEvent( )> instead. | ||
| 637 | |||
| 638 | Expected parameters include: | ||
| 639 | |||
| 640 | =over | ||
| 641 | |||
| 642 | =item C<minType> - the low end of event type to be queried, inclusive; see C<SDL_EventType> for details | ||
| 643 | |||
| 644 | =item C<maxType> - the high end of event type to be queried, inclusive; see C<SDL_EventType> for details | ||
| 645 | |||
| 646 | =back | ||
| 647 | |||
| 648 | Returns C<SDL_TRUE> if events with type >= C<minType> and <= C<maxType> are | ||
| 649 | present, or C<SDL_FALSE> if not. | ||
| 650 | |||
| 651 | =head2 C<SDL_FlushEvent( ... )> | ||
| 652 | |||
| 653 | Clear events of a specific type from the event queue. | ||
| 654 | |||
| 655 | This will unconditionally remove any events from the queue that match C<type>. | ||
| 656 | If you need to remove a range of event types, use C<SDL_FlushEvents( )> | ||
| 657 | instead. | ||
| 658 | |||
| 659 | It's also normal to just ignore events you don't care about in your event loop | ||
| 660 | without calling this function. | ||
| 661 | |||
| 662 | This function only affects currently queued events. If you want to make sure | ||
| 663 | that all pending OS events are flushed, you can call C<SDL_PumpEvents( )> on | ||
| 664 | the main thread immediately before the flush call. | ||
| 665 | |||
| 666 | Expected parameters include: | ||
| 667 | |||
| 668 | =over | ||
| 669 | |||
| 670 | =item C<type> - the type of event to be cleared; see C<SDL_EventType> for details | ||
| 671 | |||
| 672 | =back | ||
| 673 | |||
| 674 | =head2 C<SDL_FlushEvents( ... )> | ||
| 675 | |||
| 676 | Clear events of a range of types from the event queue. | ||
| 677 | |||
| 678 | This will unconditionally remove any events from the queue that are in the | ||
| 679 | range of C<minType> to C<maxType>, inclusive. If you need to remove a single | ||
| 680 | event type, use C<SDL_FlushEvent( )> instead. | ||
| 681 | |||
| 682 | It's also normal to just ignore events you don't care about in your event loop | ||
| 683 | without calling this function. | ||
| 684 | |||
| 685 | This function only affects currently queued events. If you want to make sure | ||
| 686 | that all pending OS events are flushed, you can call C<SDL_PumpEvents( )> on | ||
| 687 | the main thread immediately before the flush call. | ||
| 688 | |||
| 689 | Expected parameters include: | ||
| 690 | |||
| 691 | =over | ||
| 692 | |||
| 693 | =item C<minType> - the low end of event type to be cleared, inclusive; see C<SDL_EventType> for details | ||
| 694 | |||
| 695 | =item C<maxType> - the high end of event type to be cleared, inclusive; see C<SDL_EventType> for details | ||
| 696 | |||
| 697 | =back | ||
| 698 | |||
| 699 | =head2 C<SDL_PollEvent( ... )> | ||
| 700 | |||
| 701 | Poll for currently pending events. | ||
| 702 | |||
| 703 | If C<event> is not C<undef>, the next event is removed from the queue and | ||
| 704 | stored in the L<SDL2::Event> structure pointed to by C<event>. The C<1> | ||
| 705 | returned refers to this event, immediately stored in the SDL Event structure -- | ||
| 706 | not an event to follow. | ||
| 707 | |||
| 708 | If C<event> is C<undef>, it simply returns C<1> if there is an event in the | ||
| 709 | queue, but will not remove it from the queue. | ||
| 710 | |||
| 711 | As this function implicitly calls C<SDL_PumpEvents( )>, you can only call this | ||
| 712 | function in the thread that set the video mode. | ||
| 713 | |||
| 714 | C<SDL_PollEvent( ... )> is the favored way of receiving system events since it | ||
| 715 | can be done from the main loop and does not suspend the main loop while waiting | ||
| 716 | on an event to be posted. | ||
| 717 | |||
| 718 | The common practice is to fully process the event queue once every frame, | ||
| 719 | usually as a first step before updating the game's state: | ||
| 720 | |||
| 721 | while (game_is_still_running()) { | ||
| 722 | while (SDL_PollEvent(\my $event)) { # poll until all events are handled! | ||
| 723 | # decide what to do with this event. | ||
| 724 | } | ||
| 725 | # update game state, draw the current frame | ||
| 726 | } | ||
| 727 | |||
| 728 | Expected parameters include: | ||
| 729 | |||
| 730 | =over | ||
| 731 | |||
| 732 | =item C<event> - the L<SDL2::Event> structure to be filled with the next event from the queue, or C<undef> | ||
| 733 | |||
| 734 | =back | ||
| 735 | |||
| 736 | Returns C<1> if there is a pending event or C<0> if there are none available. | ||
| 737 | |||
| 738 | =head2 C<SDL_WaitEvent( ... )> | ||
| 739 | |||
| 740 | Wait indefinitely for the next available event. | ||
| 741 | |||
| 742 | If C<event> is not C<undef>, the next event is removed from the queue and | ||
| 743 | stored in the L<SDL2::Event> structure pointed to by C<event>. | ||
| 744 | |||
| 745 | As this function implicitly calls C<SDL_PumpEvents( )>, you can only call this | ||
| 746 | function in the thread that initialized the video subsystem. | ||
| 747 | |||
| 748 | Expected parameters include: | ||
| 749 | |||
| 750 | =over | ||
| 751 | |||
| 752 | =item C<event> - the L<SDL2::Event> structure to be filled in with the next event from the queue, or C<undef> | ||
| 753 | |||
| 754 | =back | ||
| 755 | |||
| 756 | Returns C<1> on success or C<0> if there was an error while waiting for events; | ||
| 757 | call C<SDL_GetError( )> for more information. | ||
| 758 | |||
| 759 | =head2 C<SDL_WaitEventTimeout( ... )> | ||
| 760 | |||
| 761 | Wait until the specified timeout (in milliseconds) for the next available | ||
| 762 | event. | ||
| 763 | |||
| 764 | If C<event> is not C<>, the next event is removed from the queue and stored in | ||
| 765 | the L<DL2::Event> structure pointed to by C<event>. | ||
| 766 | |||
| 767 | As this function implicitly calls C<SDL_PumpEvents( )>, you can only call this | ||
| 768 | function in the thread that initialized the video subsystem. | ||
| 769 | |||
| 770 | Expected parameters include: | ||
| 771 | |||
| 772 | =over | ||
| 773 | |||
| 774 | =item C<event> - the L<SDL2::Event> structure to be filled in with the next event from the queue, or C<undef> | ||
| 775 | |||
| 776 | =item C<timeout> - the maximum number of milliseconds to wait for the next available event | ||
| 777 | |||
| 778 | =back | ||
| 779 | |||
| 780 | Returns C<1> on success or C<0> if there was an error while waiting for events; | ||
| 781 | call C<SDL_GetError( )> for more information. This also returns C<0> if the | ||
| 782 | timeout elapsed without an event arriving. | ||
| 783 | |||
| 784 | =head2 C<SDL_PushEvent( ... )> | ||
| 785 | |||
| 786 | Add an event to the event queue. | ||
| 787 | |||
| 788 | The event queue can actually be used as a two way communication channel. Not | ||
| 789 | only can events be read from the queue, but the user can also push their own | ||
| 790 | events onto it. C<event> is a pointer to the event structure you wish to push | ||
| 791 | onto the queue. The event is copied into the queue, and the caller may dispose | ||
| 792 | of the memory pointed to after C<SDL_PushEvent( )> returns. | ||
| 793 | |||
| 794 | Note: Pushing device input events onto the queue doesn't modify the state of | ||
| 795 | the device within SDL. | ||
| 796 | |||
| 797 | This function is thread-safe, and can be called from other threads safely. | ||
| 798 | |||
| 799 | Note: Events pushed onto the queue with C<SDL_PushEvent( )> get passed through | ||
| 800 | the event filter but events added with C<SDL_PeepEvents( )> do not. | ||
| 801 | |||
| 802 | For pushing application-specific events, please use C<SDL_RegisterEvents( )> to | ||
| 803 | get an event type that does not conflict with other code that also wants its | ||
| 804 | own custom event types. | ||
| 805 | |||
| 806 | Expected parameters include: | ||
| 807 | |||
| 808 | =over | ||
| 809 | |||
| 810 | =item C<event> - the L<SDL2::Event> to be added to the queue | ||
| 811 | |||
| 812 | =back | ||
| 813 | |||
| 814 | Returns C<1> on success, C<0> if the event was filtered, or a negative error | ||
| 815 | code on failure; call C<SDL_GetError( )> for more information. A common reason | ||
| 816 | for error is the event queue being full. | ||
| 817 | |||
| 818 | =head2 C<SDL_SetEventFilter( ... )> | ||
| 819 | |||
| 820 | Set up a filter to process all events before they change internal state and are | ||
| 821 | posted to the internal event queue. | ||
| 822 | |||
| 823 | If the filter function returns 1 when called, then the event will be added to | ||
| 824 | the internal queue. If it returns C<0>, then the event will be dropped from the | ||
| 825 | queue, but the internal state will still be updated. This allows selective | ||
| 826 | filtering of dynamically arriving events. | ||
| 827 | |||
| 828 | B<WARNING>: Be very careful of what you do in the event filter function, as it | ||
| 829 | may run in a different thread! | ||
| 830 | |||
| 831 | On platforms that support it, if the quit event is generated by an interrupt | ||
| 832 | signal (e.g. pressing Ctrl-C), it will be delivered to the application at the | ||
| 833 | next event poll. | ||
| 834 | |||
| 835 | There is one caveat when dealing with the C<SDL_QuitEvent> event type. The | ||
| 836 | event filter is only called when the window manager desires to close the | ||
| 837 | application window. If the event filter returns C<1>, then the window will be | ||
| 838 | closed, otherwise the window will remain open if possible. | ||
| 839 | |||
| 840 | Note: Disabled events never make it to the event filter function; see | ||
| 841 | C<SDL_EventState( )>. | ||
| 842 | |||
| 843 | Note: If you just want to inspect events without filtering, you should use | ||
| 844 | C<SDL_AddEventWatch( )> instead. | ||
| 845 | |||
| 846 | Note: Events pushed onto the queue with C<SDL_PushEvent( )> get passed through | ||
| 847 | the event filter, but events pushed onto the queue with C<SDL_PeepEvents( )> do | ||
| 848 | not. | ||
| 849 | |||
| 850 | Expected parameters include: | ||
| 851 | |||
| 852 | =over | ||
| 853 | |||
| 854 | =item C<filter> - An C<SDL_EventFilter> function to call when an event happens param userdata a pointer that is passed to C<filter> | ||
| 855 | |||
| 856 | =item C<userdata> - a pointer that is passed to C<filter> | ||
| 857 | |||
| 858 | =back | ||
| 859 | |||
| 860 | =head2 C<SDL_GetEventFilter( ... )> | ||
| 861 | |||
| 862 | Query the current event filter. | ||
| 863 | |||
| 864 | This function can be used to "chain" filters, by saving the existing filter | ||
| 865 | before replacing it with a function that will call that saved filter. | ||
| 866 | |||
| 867 | Expected parameters include: | ||
| 868 | |||
| 869 | =over | ||
| 870 | |||
| 871 | =item C<filter> - the current callback function will be stored here | ||
| 872 | |||
| 873 | =item C<userdata> - the pointer that is passed to the current event filter will be stored here | ||
| 874 | |||
| 875 | =back | ||
| 876 | |||
| 877 | Returns C<SDL_TRUE> on success or C<SDL_FALSE> if there is no event filter set. | ||
| 878 | |||
| 879 | =head2 C<SDL_AddEventWatch( ... )> | ||
| 880 | |||
| 881 | Add a callback to be triggered when an event is added to the event queue. | ||
| 882 | |||
| 883 | C<filter> will be called when an event happens, and its return value is | ||
| 884 | ignored. | ||
| 885 | |||
| 886 | B<WARNING>: Be very careful of what you do in the event filter function, as it | ||
| 887 | may run in a different thread! | ||
| 888 | |||
| 889 | If the quit event is generated by a signal (e.g. C<SIGINT>), it will bypass the | ||
| 890 | internal queue and be delivered to the watch callback immediately, and arrive | ||
| 891 | at the next event poll. | ||
| 892 | |||
| 893 | Note: the callback is called for events posted by the user through | ||
| 894 | C<SDL_PushEvent( )>, but not for disabled events, nor for events by a filter | ||
| 895 | callback set with C<SDL_SetEventFilter( )>, nor for events posted by the user | ||
| 896 | through C<SDL_PeepEvents( )>. | ||
| 897 | |||
| 898 | Expected parameters include: | ||
| 899 | |||
| 900 | =over | ||
| 901 | |||
| 902 | =item C<filter> - an C<SDL_EventFilter> function to call when an event happens. | ||
| 903 | |||
| 904 | =item C<userdata> - a pointer that is passed to C<filter> | ||
| 905 | |||
| 906 | =back | ||
| 907 | |||
| 908 | =head2 C<SDL_DelEventWatch( ... )> | ||
| 909 | |||
| 910 | Remove an event watch callback added with C<SDL_AddEventWatch( )>. | ||
| 911 | |||
| 912 | This function takes the same input as C<SDL_AddEventWatch( )> to identify and | ||
| 913 | delete the corresponding callback. | ||
| 914 | |||
| 915 | Expected parameters include: | ||
| 916 | |||
| 917 | =over | ||
| 918 | |||
| 919 | =item C<filter> - the function originally passed to C<SDL_AddEventWatch( )> | ||
| 920 | |||
| 921 | =item C<userdata> - the pointer originally passed to C<SDL_AddEventWatch( )> | ||
| 922 | |||
| 923 | =back | ||
| 924 | |||
| 925 | =head2 C<SDL_FilterEvents( ... )> | ||
| 926 | |||
| 927 | Run a specific filter function on the current event queue, removing any events | ||
| 928 | for which the filter returns C<0>. | ||
| 929 | |||
| 930 | See C<SDL_SetEventFilter( )> for more information. Unlike C<SDL_SetEventFilter( | ||
| 931 | )>, this function does not change the filter permanently, it only uses the | ||
| 932 | supplied filter until this function returns. | ||
| 933 | |||
| 934 | Expected parameters include: | ||
| 935 | |||
| 936 | =over | ||
| 937 | |||
| 938 | =item C<filter> - the C<SDL_EventFilter> function to call when an event happens | ||
| 939 | |||
| 940 | =item C<userdata> - a pointer that is passed to C<filter> | ||
| 941 | |||
| 942 | =back | ||
| 943 | |||
| 944 | =head2 C<SDL_EventState( ... )> | ||
| 945 | |||
| 946 | Set the state of processing events by type. | ||
| 947 | |||
| 948 | C<state> may be any of the following: | ||
| 949 | |||
| 950 | =over | ||
| 951 | |||
| 952 | =item - C<SDL_QUERY>: returns the current processing state of the specified event | ||
| 953 | |||
| 954 | =item - C<SDL_IGNORE> (aka C<SDL_DISABLE>): the event will automatically be dropped from the event queue and will not be filtered | ||
| 955 | |||
| 956 | =item - C<SDL_ENABLE>: the event will be processed normally | ||
| 957 | |||
| 958 | =back | ||
| 959 | |||
| 960 | Expected parameters include: | ||
| 961 | |||
| 962 | =over | ||
| 963 | |||
| 964 | =item C<type> - the type of event; see C<SDL_EventType> for details | ||
| 965 | |||
| 966 | =item C<state> - how to process the event | ||
| 967 | |||
| 968 | =back | ||
| 969 | |||
| 970 | Returns C<SDL_DISABLE> or C<SDL_ENABLE>, representing the processing state of | ||
| 971 | the event before this function makes any changes to it. | ||
| 972 | |||
| 973 | =head2 C<SDL_GetEventState( ... )> | ||
| 974 | |||
| 975 | Queries for the current processing state of the specified event. | ||
| 976 | |||
| 977 | Expected parameters include: | ||
| 978 | |||
| 979 | =over | ||
| 980 | |||
| 981 | =item C<type> - the type of event; see C<SDL_EventType> for details | ||
| 982 | |||
| 983 | =back | ||
| 984 | |||
| 985 | Returns C<SDL_DISABLE> or C<SDL_ENABLE>, representing the processing state of | ||
| 986 | the event before this function makes any changes to it. | ||
| 987 | |||
| 988 | =head2 C<SDL_RegisterEvents( ... )> | ||
| 989 | |||
| 990 | Allocate a set of user-defined events, and return the beginning event number | ||
| 991 | for that set of events. | ||
| 992 | |||
| 993 | Calling this function with `numevents` <= 0 is an error and will return | ||
| 994 | C<(Uint32)-1>. | ||
| 995 | |||
| 996 | Note, C<(Uint32)-1> means the maximum unsigned 32-bit integer value (or | ||
| 997 | C<0xFFFFFFFF>), but is clearer to write. | ||
| 998 | |||
| 999 | Expected parameters include: | ||
| 1000 | |||
| 1001 | =over | ||
| 1002 | |||
| 1003 | =item C<numevents> - the number of events to be allocated | ||
| 1004 | |||
| 1005 | =back | ||
| 1006 | |||
| 1007 | Returns the beginning event number, or C<(Uint32)-1> if there are not enough | ||
| 1008 | user-defined events left. | ||
| 1009 | |||
| 1010 | =head1 Defined Values and Enumerations | ||
| 1011 | |||
| 1012 | These may be imported by name or with the given tag. | ||
| 1013 | |||
| 1014 | =head2 Event States | ||
| 1015 | |||
| 1016 | General keyboard/mouse state definitions. These may be imported with the | ||
| 1017 | C<:eventstate> tag. | ||
| 1018 | |||
| 1019 | =over | ||
| 1020 | |||
| 1021 | =item C<SDL_RELEASED> | ||
| 1022 | |||
| 1023 | =item C<SDL_PRESSED> | ||
| 1024 | |||
| 1025 | =back | ||
| 1026 | |||
| 1027 | =head2 C<SDL_EventType> | ||
| 1028 | |||
| 1029 | The types of events that can be delivered. This enumerations may be imported | ||
| 1030 | with the C<:eventType> tag. | ||
| 1031 | |||
| 1032 | =over | ||
| 1033 | |||
| 1034 | =item C<SDL_FIRSTEVENT> - Unused | ||
| 1035 | |||
| 1036 | =back | ||
| 1037 | |||
| 1038 | Application events | ||
| 1039 | |||
| 1040 | =over | ||
| 1041 | |||
| 1042 | =item C<SDL_QUIT> - User-requested quit | ||
| 1043 | |||
| 1044 | =back | ||
| 1045 | |||
| 1046 | These application events have special meaning on iOS, see C<README-ios.md> for | ||
| 1047 | details. | ||
| 1048 | |||
| 1049 | =over | ||
| 1050 | |||
| 1051 | =item C<SDL_APP_TERMINATING> - The application is being terminated by the OS | ||
| 1052 | |||
| 1053 | Called on iOS in C<applicationWillTerminate()> | ||
| 1054 | |||
| 1055 | Called on Android in C<onDestroy()> | ||
| 1056 | |||
| 1057 | =item C<SDL_APP_LOWMEMORY> - The application is low on memory, free memory if possible. | ||
| 1058 | |||
| 1059 | Called on iOS in C<applicationDidReceiveMemoryWarning()> | ||
| 1060 | |||
| 1061 | Called on Android in C<onLowMemory()> | ||
| 1062 | |||
| 1063 | =item C<SDL_APP_WILLENTERBACKGROUND> - The application is about to enter the background | ||
| 1064 | |||
| 1065 | Called on iOS in C<applicationWillResignActive()> | ||
| 1066 | |||
| 1067 | Called on Android in C<onPause()> | ||
| 1068 | |||
| 1069 | =item C<SDL_APP_DIDENTERBACKGROUND> - The application did enter the background and may not get CPU for some time | ||
| 1070 | |||
| 1071 | Called on iOS in C<applicationDidEnterBackground()> | ||
| 1072 | |||
| 1073 | Called on Android in C<onPause()> | ||
| 1074 | |||
| 1075 | =item C<SDL_APP_WILLENTERFOREGROUND> - The application is about to enter the foreground | ||
| 1076 | |||
| 1077 | Called on iOS in C<applicationWillEnterForeground()> | ||
| 1078 | |||
| 1079 | Called on Android in C<onResume()> | ||
| 1080 | |||
| 1081 | =item C<SDL_APP_DIDENTERFOREGROUND> - The application is now interactive | ||
| 1082 | |||
| 1083 | Called on iOS in C<applicationDidBecomeActive()> | ||
| 1084 | |||
| 1085 | Called on Android in C<onResume()> | ||
| 1086 | |||
| 1087 | =item C<SDL_LOCALECHANGED> - The user's locale preferences have changed. | ||
| 1088 | |||
| 1089 | =back | ||
| 1090 | |||
| 1091 | Display events | ||
| 1092 | |||
| 1093 | =over | ||
| 1094 | |||
| 1095 | =item C<SDL_DISPLAYEVENT> - Display state change | ||
| 1096 | |||
| 1097 | =back | ||
| 1098 | |||
| 1099 | Window events | ||
| 1100 | |||
| 1101 | =over | ||
| 1102 | |||
| 1103 | =item C<SDL_WINDOWEVENT> - Window state change | ||
| 1104 | |||
| 1105 | =item C<SDL_SYSWMEVENT> - System specific event | ||
| 1106 | |||
| 1107 | =back | ||
| 1108 | |||
| 1109 | Keyboard events | ||
| 1110 | |||
| 1111 | =over | ||
| 1112 | |||
| 1113 | =item C<SDL_KEYDOWN> - Key pressed | ||
| 1114 | |||
| 1115 | =item C<SDL_KEYUP> - Key released | ||
| 1116 | |||
| 1117 | =item C<SDL_TEXTEDITING> - Keyboard text editing (composition) | ||
| 1118 | |||
| 1119 | =item C<SDL_TEXTINPUT> - Keyboard text input | ||
| 1120 | |||
| 1121 | =item C<SDL_KEYMAPCHANGED> - Keymap changed due to a system event such as an input language or keyboard layout change | ||
| 1122 | |||
| 1123 | =back | ||
| 1124 | |||
| 1125 | Mouse events | ||
| 1126 | |||
| 1127 | =over | ||
| 1128 | |||
| 1129 | =item C<SDL_MOUSEMOTION> - Mouse moved | ||
| 1130 | |||
| 1131 | =item C<SDL_MOUSEBUTTONDOWN> - Mouse button pressed | ||
| 1132 | |||
| 1133 | =item C<SDL_MOUSEBUTTONUP> - Mouse button released | ||
| 1134 | |||
| 1135 | =item C<SDL_MOUSEWHEEL> - Mouse wheel motion | ||
| 1136 | |||
| 1137 | =back | ||
| 1138 | |||
| 1139 | Joystick events | ||
| 1140 | |||
| 1141 | =over | ||
| 1142 | |||
| 1143 | =item C<SDL_JOYAXISMOTION> - Joystick axis motion | ||
| 1144 | |||
| 1145 | =item C<SDL_JOYBALLMOTION> - Joystick trackball motion | ||
| 1146 | |||
| 1147 | =item C<SDL_JOYHATMOTION> - Joystick hat position change | ||
| 1148 | |||
| 1149 | =item C<SDL_JOYBUTTONDOWN> - Joystick button pressed | ||
| 1150 | |||
| 1151 | =item C<SDL_JOYBUTTONUP> - Joystick button released | ||
| 1152 | |||
| 1153 | =item C<SDL_JOYDEVICEADDED> - A new joystick has been inserted into the system | ||
| 1154 | |||
| 1155 | =item C<SDL_JOYDEVICEREMOVED> - An opened joystick has been removed | ||
| 1156 | |||
| 1157 | =back | ||
| 1158 | |||
| 1159 | Game controller events | ||
| 1160 | |||
| 1161 | =over | ||
| 1162 | |||
| 1163 | =item C<SDL_CONTROLLERAXISMOTION> - Game controller axis motion | ||
| 1164 | |||
| 1165 | =item C<SDL_CONTROLLERBUTTONDOWN> - Game controller button pressed | ||
| 1166 | |||
| 1167 | =item C<SDL_CONTROLLERBUTTONUP> - Game controller button released | ||
| 1168 | |||
| 1169 | =item C<SDL_CONTROLLERDEVICEADDED> - A new Game controller has been inserted into the system | ||
| 1170 | |||
| 1171 | =item C<SDL_CONTROLLERDEVICEREMOVED> - An opened Game controller has been removed | ||
| 1172 | |||
| 1173 | =item C<SDL_CONTROLLERDEVICEREMAPPED> - The controller mapping was updated | ||
| 1174 | |||
| 1175 | =item C<SDL_CONTROLLERTOUCHPADDOWN> - Game controller touchpad was touched | ||
| 1176 | |||
| 1177 | =item C<SDL_CONTROLLERTOUCHPADMOTION> - Game controller touchpad finger was moved | ||
| 1178 | |||
| 1179 | =item C<SDL_CONTROLLERTOUCHPADUP> - Game controller touchpad finger was lifted | ||
| 1180 | |||
| 1181 | =item C<SDL_CONTROLLERSENSORUPDATE> - Game controller sensor was updated | ||
| 1182 | |||
| 1183 | =back | ||
| 1184 | |||
| 1185 | Touch events | ||
| 1186 | |||
| 1187 | =over | ||
| 1188 | |||
| 1189 | =item C<SDL_FINGERDOWN> | ||
| 1190 | |||
| 1191 | =item C<SDL_FINGERUP> | ||
| 1192 | |||
| 1193 | =item C<SDL_FINGERMOTION> | ||
| 1194 | |||
| 1195 | =back | ||
| 1196 | |||
| 1197 | Gesture events | ||
| 1198 | |||
| 1199 | =over | ||
| 1200 | |||
| 1201 | =item C<SDL_DOLLARGESTURE> | ||
| 1202 | |||
| 1203 | =item C<SDL_DOLLARRECORD> | ||
| 1204 | |||
| 1205 | =item C<SDL_MULTIGESTURE> | ||
| 1206 | |||
| 1207 | =back | ||
| 1208 | |||
| 1209 | Clipboard events | ||
| 1210 | |||
| 1211 | =over | ||
| 1212 | |||
| 1213 | =item C<SDL_CLIPBOARDUPDATE> - The clipboard changed | ||
| 1214 | |||
| 1215 | =back | ||
| 1216 | |||
| 1217 | Drag and drop events | ||
| 1218 | |||
| 1219 | =over | ||
| 1220 | |||
| 1221 | =item C<SDL_DROPFILE> - The system requests a file open | ||
| 1222 | |||
| 1223 | =item C<SDL_DROPTEXT> - text/plain drag-and-drop event | ||
| 1224 | |||
| 1225 | =item C<SDL_DROPBEGIN> - A new set of drops is beginning (NULL filename) | ||
| 1226 | |||
| 1227 | =item C<SDL_DROPCOMPLETE> - Current set of drops is now complete (NULL filename) | ||
| 1228 | |||
| 1229 | =back | ||
| 1230 | |||
| 1231 | Audio hotplug events | ||
| 1232 | |||
| 1233 | =over | ||
| 1234 | |||
| 1235 | =item C<SDL_AUDIODEVICEADDED> - A new audio device is available | ||
| 1236 | |||
| 1237 | =item C<SDL_AUDIODEVICEREMOVED> - An audio device has been removed | ||
| 1238 | |||
| 1239 | =back | ||
| 1240 | |||
| 1241 | Sensor events | ||
| 1242 | |||
| 1243 | =over | ||
| 1244 | |||
| 1245 | =item C<SDL_SENSORUPDATE> - A sensor was updated | ||
| 1246 | |||
| 1247 | =back | ||
| 1248 | |||
| 1249 | Render events | ||
| 1250 | |||
| 1251 | =over | ||
| 1252 | |||
| 1253 | =item C<SDL_RENDER_TARGETS_RESET> - The render targets have been reset and their contents need to be updated | ||
| 1254 | |||
| 1255 | =item C<SDL_RENDER_DEVICE_RESET> - The device has been reset and all textures need to be recreated | ||
| 1256 | |||
| 1257 | =back | ||
| 1258 | |||
| 1259 | Events C<SDL_USEREVENT> through C<SDL_LASTEVENT> are for your use, and should | ||
| 1260 | be allocated with C<SDL_RegisterEvents( ... )> | ||
| 1261 | |||
| 1262 | =over | ||
| 1263 | |||
| 1264 | =item C<SDL_USEREVENT> | ||
| 1265 | |||
| 1266 | =back | ||
| 1267 | |||
| 1268 | This last event is only for bounding internal arrays | ||
| 1269 | |||
| 1270 | =over | ||
| 1271 | |||
| 1272 | =item C<SDL_LASTEVENT> | ||
| 1273 | |||
| 1274 | =back | ||
| 1275 | |||
| 1276 | =head2 C<SDL_eventaction> | ||
| 1277 | |||
| 1278 | This enumeration may be imported with the C<:eventaction> tag. | ||
| 1279 | |||
| 1280 | =over | ||
| 1281 | |||
| 1282 | =item C<SDL_ADDEVENT> | ||
| 1283 | |||
| 1284 | =item C<SDL_PEEKEVENT> | ||
| 1285 | |||
| 1286 | =item C<SDL_GETEVENT> | ||
| 1287 | |||
| 1288 | =back | ||
| 1289 | |||
| 1290 | =head2 C<SDL_EventFilter> | ||
| 1291 | |||
| 1292 | A function pointer used for callbacks that watch the event queue. | ||
| 1293 | |||
| 1294 | Parameters to expect: | ||
| 1295 | |||
| 1296 | =over | ||
| 1297 | |||
| 1298 | =item C<userdata> - what was passed as C<userdata> to C<SDL_SetEventFilter( )> or C<SDL_AddEventWatch>, etc. | ||
| 1299 | |||
| 1300 | =item C<event> - the event that triggered the callback | ||
| 1301 | |||
| 1302 | =back | ||
| 1303 | |||
| 1304 | Your callback should return C<1> to permit event to be added to the queue, and | ||
| 1305 | C<0> to disallow it. When used with C<SDL_AddEventWatch>, the return value is | ||
| 1306 | ignored. | ||
| 1307 | |||
| 1308 | =head2 Event State | ||
| 1309 | |||
| 1310 | These values may be imported with the C<eventState> tag. | ||
| 1311 | |||
| 1312 | =over | ||
| 1313 | |||
| 1314 | =item C<SDL_QUERY> - returns the current processing state of the specified event | ||
| 1315 | |||
| 1316 | =item C<SDL_IGNORE> - aka C<SDL_DISABLE>; the event will automatically be dropped from the event queue and will not be filtered | ||
| 1317 | |||
| 1318 | =item C<SDL_DISABLE> - aka C<SDL_IGNORE> | ||
| 1319 | |||
| 1320 | =item C<SDL_ENABLE> - the event will be processed normally | ||
| 1321 | |||
| 1322 | =back | ||
| 1323 | |||
| 1324 | =head1 LICENSE | ||
| 1325 | |||
| 1326 | Copyright (C) Sanko Robinson. | ||
| 1327 | |||
| 1328 | This library is free software; you can redistribute it and/or modify it under | ||
| 1329 | the terms found in the Artistic License 2. Other copyrights, terms, and | ||
| 1330 | conditions may apply to data transmitted through this module. | ||
| 1331 | |||
| 1332 | =head1 AUTHOR | ||
| 1333 | |||
| 1334 | Sanko Robinson E<lt>sanko@cpan.orgE<gt> | ||
| 1335 | |||
| 1336 | =begin stopwords | ||
| 1337 | |||
| 1338 | userdata aka numevents hotplug | ||
| 1339 | |||
| 1340 | =end stopwords | ||
| 1341 | |||
| 1342 | =cut | ||
| 1343 | |||
| 1344 | }; | ||
| 1345 | 1; |