/src/Core/objects/Event.xs

http://github.com/PerlGameDev/SDL · Unknown · 987 lines · 810 code · 177 blank · 0 comment · 0 complexity · ce3da913fb2e0ba03263a9b17fddafda MD5 · raw file

  1. #include "EXTERN.h"
  2. #include "perl.h"
  3. #include "XSUB.h"
  4. #include "ppport.h"
  5. #ifndef aTHX_
  6. #define aTHX_
  7. #endif
  8. #include <SDL.h>
  9. SV* new_data( SV* thing )
  10. {
  11. if ( SvROK( thing ) )
  12. return newRV_inc(SvRV(thing ) );
  13. else
  14. return SvREFCNT_inc(thing);
  15. }
  16. MODULE = SDL::Event PACKAGE = SDL::Event PREFIX = event_
  17. =for documentation
  18. SDL_Event -- General event structure
  19. typedef union{
  20. Uint8 type;
  21. SDL_ActiveEvent active;
  22. SDL_KeyboardEvent key;
  23. SDL_MouseMotionEvent motion;
  24. SDL_MouseButtonEvent button;
  25. SDL_JoyAxisEvent jaxis;
  26. SDL_JoyBallEvent jball;
  27. SDL_JoyHatEvent jhat;
  28. SDL_JoyButtonEvent jbutton;
  29. SDL_ResizeEvent resize;
  30. SDL_ExposeEvent expose;
  31. SDL_QuitEvent quit;
  32. SDL_UserEvent user;
  33. SDL_SysWMEvent syswm;
  34. } SDL_Event;
  35. =cut
  36. SDL_Event *
  37. event_new (CLASS)
  38. char *CLASS
  39. CODE:
  40. RETVAL = (SDL_Event *) safemalloc(sizeof (SDL_Event));
  41. /*set userdata to NULL for now */
  42. (RETVAL->user).data1 =(void *)NULL;
  43. (RETVAL->user).data2 =(void *)NULL;
  44. OUTPUT:
  45. RETVAL
  46. Uint8
  47. event_type ( event, ... )
  48. SDL_Event *event
  49. CODE:
  50. if( items > 1 )
  51. {
  52. event->type = SvUV( ST(1) );
  53. }
  54. RETVAL = event->type;
  55. OUTPUT:
  56. RETVAL
  57. SDL_ActiveEvent *
  58. event_active ( event, ... )
  59. SDL_Event *event
  60. PREINIT:
  61. char *CLASS = "SDL::ActiveEvent";
  62. CODE:
  63. RETVAL = &(event->active);
  64. OUTPUT:
  65. RETVAL
  66. Uint8
  67. event_active_type ( event, ... )
  68. SDL_Event *event
  69. CODE:
  70. SDL_ActiveEvent * a = &(event->active);
  71. if( items > 1 )
  72. {
  73. a->type = SvUV( ST(1) );
  74. }
  75. RETVAL = a->type;
  76. OUTPUT:
  77. RETVAL
  78. Uint8
  79. event_active_gain ( event, ... )
  80. SDL_Event *event
  81. CODE:
  82. SDL_ActiveEvent * a = &(event->active);
  83. if( items > 1 )
  84. {
  85. a->gain = SvUV( ST(1) );
  86. }
  87. RETVAL = a->gain;
  88. OUTPUT:
  89. RETVAL
  90. Uint8
  91. event_active_state ( event, ... )
  92. SDL_Event *event
  93. CODE:
  94. SDL_ActiveEvent * a = &(event->active);
  95. if( items > 1 )
  96. {
  97. a->state = SvUV( ST(1) );
  98. }
  99. RETVAL = a->state;
  100. OUTPUT:
  101. RETVAL
  102. SDL_KeyboardEvent *
  103. event_key ( event, ... )
  104. SDL_Event *event
  105. PREINIT:
  106. char *CLASS = "SDL::KeyboardEvent";
  107. CODE:
  108. RETVAL = &(event->key);
  109. OUTPUT:
  110. RETVAL
  111. Uint8
  112. event_key_type ( event, ... )
  113. SDL_Event *event
  114. CODE:
  115. SDL_KeyboardEvent * a = &(event->key);
  116. if( items > 1 )
  117. {
  118. a->type = SvUV( ST(1) );
  119. }
  120. RETVAL = a->type;
  121. OUTPUT:
  122. RETVAL
  123. Uint8
  124. event_key_state ( event, ... )
  125. SDL_Event *event
  126. CODE:
  127. SDL_KeyboardEvent * a = &(event->key);
  128. if( items > 1 )
  129. {
  130. a->state = SvUV( ST(1) );
  131. }
  132. RETVAL = a->state;
  133. OUTPUT:
  134. RETVAL
  135. SDL_keysym *
  136. event_key_keysym ( event, ... )
  137. SDL_Event *event
  138. PREINIT:
  139. char* CLASS = "SDL::keysym";
  140. CODE:
  141. SDL_KeyboardEvent * a = &(event->key);
  142. if( items > 1 )
  143. {
  144. SDL_keysym * ksp = (SDL_keysym * )SvPV( ST(1), PL_na) ;
  145. a->keysym = *ksp;
  146. }
  147. RETVAL = &(a->keysym);
  148. OUTPUT:
  149. RETVAL
  150. Uint8
  151. event_key_scancode ( event, ... )
  152. SDL_Event *event
  153. CODE:
  154. SDL_KeyboardEvent * a = &(event->key);
  155. SDL_keysym * b = &(a->keysym);
  156. if( items > 1 )
  157. {
  158. b->scancode = SvUV( ST(1) );
  159. }
  160. RETVAL = b->scancode;
  161. OUTPUT:
  162. RETVAL
  163. Uint16
  164. event_key_sym ( event, ... )
  165. SDL_Event *event
  166. CODE:
  167. SDL_KeyboardEvent * a = &(event->key);
  168. SDL_keysym * b = &(a->keysym);
  169. if( items > 1 )
  170. {
  171. b->sym = SvUV( ST(1) );
  172. }
  173. RETVAL = b->sym;
  174. OUTPUT:
  175. RETVAL
  176. Uint16
  177. event_key_mod ( event, ... )
  178. SDL_Event *event
  179. CODE:
  180. SDL_KeyboardEvent * a = &(event->key);
  181. SDL_keysym * b = &(a->keysym);
  182. if( items > 1 )
  183. {
  184. b->mod = SvUV( ST(1) );
  185. }
  186. RETVAL = b->mod;
  187. OUTPUT:
  188. RETVAL
  189. Uint16
  190. event_key_unicode ( event, ... )
  191. SDL_Event *event
  192. CODE:
  193. SDL_KeyboardEvent * a = &(event->key);
  194. SDL_keysym * b = &(a->keysym);
  195. if( items > 1 )
  196. {
  197. b->unicode = SvUV( ST(1) );
  198. }
  199. RETVAL = b->unicode;
  200. OUTPUT:
  201. RETVAL
  202. SDL_MouseMotionEvent *
  203. event_motion ( event, ... )
  204. SDL_Event *event
  205. PREINIT:
  206. char *CLASS = "SDL::MouseMotionEvent";
  207. CODE:
  208. RETVAL = &(event->motion);
  209. OUTPUT:
  210. RETVAL
  211. Uint8
  212. event_motion_type ( event, ... )
  213. SDL_Event *event
  214. CODE:
  215. SDL_MouseMotionEvent * a = &(event->motion);
  216. if( items > 1 )
  217. {
  218. a->type = SvUV( ST(1) );
  219. }
  220. RETVAL = a->type;
  221. OUTPUT:
  222. RETVAL
  223. Uint8
  224. event_motion_state ( event, ... )
  225. SDL_Event *event
  226. CODE:
  227. SDL_MouseMotionEvent * a = &(event->motion);
  228. if( items > 1 )
  229. {
  230. a->state = SvUV( ST(1) );
  231. }
  232. RETVAL = a->state;
  233. OUTPUT:
  234. RETVAL
  235. Uint16
  236. event_motion_x ( event, ... )
  237. SDL_Event *event
  238. CODE:
  239. SDL_MouseMotionEvent * a = &(event->motion);
  240. if( items > 1 )
  241. {
  242. a->x = SvUV( ST(1) );
  243. }
  244. RETVAL = a->x;
  245. OUTPUT:
  246. RETVAL
  247. Uint16
  248. event_motion_y ( event, ... )
  249. SDL_Event *event
  250. CODE:
  251. SDL_MouseMotionEvent * a = &(event->motion);
  252. if( items > 1 )
  253. {
  254. a->y = SvUV( ST(1) );
  255. }
  256. RETVAL = a->y;
  257. OUTPUT:
  258. RETVAL
  259. Sint16
  260. event_motion_xrel ( event, ... )
  261. SDL_Event *event
  262. CODE:
  263. SDL_MouseMotionEvent * a = &(event->motion);
  264. if( items > 1 )
  265. {
  266. a->xrel = SvIV( ST(1) );
  267. }
  268. RETVAL = a->xrel;
  269. OUTPUT:
  270. RETVAL
  271. Sint16
  272. event_motion_yrel ( event, ... )
  273. SDL_Event *event
  274. CODE:
  275. SDL_MouseMotionEvent * a = &(event->motion);
  276. if( items > 1 )
  277. {
  278. a->yrel = SvIV( ST(1) );
  279. }
  280. RETVAL = a->yrel;
  281. OUTPUT:
  282. RETVAL
  283. SDL_MouseButtonEvent *
  284. event_button ( event, ... )
  285. SDL_Event *event
  286. PREINIT:
  287. char *CLASS = "SDL::MouseButtonEvent";
  288. CODE:
  289. RETVAL = &(event->button);
  290. OUTPUT:
  291. RETVAL
  292. Uint8
  293. event_button_type ( event, ... )
  294. SDL_Event *event
  295. CODE:
  296. SDL_MouseButtonEvent * a = &(event->button);
  297. if( items > 1 )
  298. {
  299. a->type = SvUV( ST(1) );
  300. }
  301. RETVAL = a->type;
  302. OUTPUT:
  303. RETVAL
  304. Uint8
  305. event_button_which ( event, ... )
  306. SDL_Event *event
  307. CODE:
  308. SDL_MouseButtonEvent * a = &(event->button);
  309. if( items > 1 )
  310. {
  311. a->which = SvUV( ST(1) );
  312. }
  313. RETVAL = a->which;
  314. OUTPUT:
  315. RETVAL
  316. Uint8
  317. event_button_button ( event, ... )
  318. SDL_Event *event
  319. CODE:
  320. SDL_MouseButtonEvent * a = &(event->button);
  321. if( items > 1 )
  322. {
  323. a->button = SvUV( ST(1) );
  324. }
  325. RETVAL = a->button;
  326. OUTPUT:
  327. RETVAL
  328. Uint8
  329. event_button_state ( event, ... )
  330. SDL_Event *event
  331. CODE:
  332. SDL_MouseButtonEvent * a = &(event->button);
  333. if( items > 1 )
  334. {
  335. a->state = SvUV( ST(1) );
  336. }
  337. RETVAL = a->state;
  338. OUTPUT:
  339. RETVAL
  340. Uint16
  341. event_button_x ( event, ... )
  342. SDL_Event *event
  343. CODE:
  344. SDL_MouseButtonEvent * a = &(event->button);
  345. if( items > 1 )
  346. {
  347. a->x = SvUV( ST(1) );
  348. }
  349. RETVAL = a->x;
  350. OUTPUT:
  351. RETVAL
  352. Uint16
  353. event_button_y ( event, ... )
  354. SDL_Event *event
  355. CODE:
  356. SDL_MouseButtonEvent * a = &(event->button);
  357. if( items > 1 )
  358. {
  359. a->y = SvUV( ST(1) );
  360. }
  361. RETVAL = a->y;
  362. OUTPUT:
  363. RETVAL
  364. SDL_JoyAxisEvent *
  365. event_jaxis ( event, ... )
  366. SDL_Event * event
  367. PREINIT:
  368. char *CLASS = "SDL::JoyAxisEvent";
  369. CODE:
  370. RETVAL = &(event->jaxis);
  371. OUTPUT:
  372. RETVAL
  373. Uint8
  374. event_jaxis_type ( event, ... )
  375. SDL_Event *event
  376. CODE:
  377. SDL_JoyAxisEvent * a = &(event->jaxis);
  378. if( items > 1 )
  379. {
  380. a->type = SvUV( ST(1) );
  381. }
  382. RETVAL = a->type;
  383. OUTPUT:
  384. RETVAL
  385. Uint8
  386. event_jaxis_which ( event, ... )
  387. SDL_Event *event
  388. CODE:
  389. SDL_JoyAxisEvent * a = &(event->jaxis);
  390. if( items > 1 )
  391. {
  392. a->which = SvUV( ST(1) );
  393. }
  394. RETVAL = a->which;
  395. OUTPUT:
  396. RETVAL
  397. Uint8
  398. event_jaxis_axis ( event, ... )
  399. SDL_Event *event
  400. CODE:
  401. SDL_JoyAxisEvent * a = &(event->jaxis);
  402. if( items > 1 )
  403. {
  404. a->axis = SvUV( ST(1) );
  405. }
  406. RETVAL = a->axis;
  407. OUTPUT:
  408. RETVAL
  409. Sint16
  410. event_jaxis_value ( event, ... )
  411. SDL_Event *event
  412. CODE:
  413. SDL_JoyAxisEvent * a = &(event->jaxis);
  414. if( items > 1 )
  415. {
  416. a->value = SvUV( ST(1) );
  417. }
  418. RETVAL = a->value;
  419. OUTPUT:
  420. RETVAL
  421. SDL_JoyBallEvent *
  422. event_jball ( event, ... )
  423. SDL_Event * event
  424. PREINIT:
  425. char *CLASS = "SDL::JoyBallEvent";
  426. CODE:
  427. RETVAL = &(event->jball);
  428. OUTPUT:
  429. RETVAL
  430. Uint8
  431. event_jball_type ( event, ... )
  432. SDL_Event *event
  433. CODE:
  434. SDL_JoyBallEvent * a = &(event->jball);
  435. if( items > 1 )
  436. {
  437. a->type = SvUV( ST(1) );
  438. }
  439. RETVAL = event->type;
  440. OUTPUT:
  441. RETVAL
  442. Uint8
  443. event_jball_which ( event, ... )
  444. SDL_Event *event
  445. CODE:
  446. SDL_JoyBallEvent * a = &(event->jball);
  447. if( items > 1 )
  448. {
  449. a->which = SvUV( ST(1) );
  450. }
  451. RETVAL = a->which;
  452. OUTPUT:
  453. RETVAL
  454. Uint8
  455. event_jball_ball ( event, ... )
  456. SDL_Event *event
  457. CODE:
  458. SDL_JoyBallEvent * a = &(event->jball);
  459. if( items > 1 )
  460. {
  461. a->ball = SvUV( ST(1) );
  462. }
  463. RETVAL = a->ball;
  464. OUTPUT:
  465. RETVAL
  466. Sint16
  467. event_jball_xrel ( event, ... )
  468. SDL_Event *event
  469. CODE:
  470. SDL_JoyBallEvent * a = &(event->jball);
  471. if( items > 1 )
  472. {
  473. a->xrel = SvIV( ST(1) );
  474. }
  475. RETVAL = a->xrel;
  476. OUTPUT:
  477. RETVAL
  478. Sint16
  479. event_jball_yrel ( event, ... )
  480. SDL_Event *event
  481. CODE:
  482. SDL_JoyBallEvent * a = &(event->jball);
  483. if( items > 1 )
  484. {
  485. a->yrel = SvIV( ST(1) );
  486. }
  487. RETVAL = a->yrel;
  488. OUTPUT:
  489. RETVAL
  490. SDL_JoyHatEvent *
  491. event_jhat ( event, ... )
  492. SDL_Event *event
  493. PREINIT:
  494. char *CLASS = "SDL::JoyHatEvent";
  495. CODE:
  496. RETVAL = NULL;
  497. if ( &event != NULL )
  498. RETVAL = &(event->jhat);
  499. OUTPUT:
  500. RETVAL
  501. Uint8
  502. event_jhat_type ( event, ... )
  503. SDL_Event *event
  504. CODE:
  505. SDL_JoyHatEvent * a = &(event->jhat);
  506. if( items > 1 )
  507. {
  508. a->which = SvUV( ST(1) );
  509. }
  510. RETVAL = a->type;
  511. OUTPUT:
  512. RETVAL
  513. Uint8
  514. event_jhat_which ( event, ... )
  515. SDL_Event *event
  516. CODE:
  517. SDL_JoyHatEvent * a = &(event->jhat);
  518. if( items > 1 )
  519. {
  520. a->which = SvUV( ST(1) );
  521. }
  522. RETVAL = a->which;
  523. OUTPUT:
  524. RETVAL
  525. Uint8
  526. event_jhat_hat ( event, ... )
  527. SDL_Event *event
  528. CODE:
  529. SDL_JoyHatEvent * a = &(event->jhat);
  530. if( items > 1 )
  531. {
  532. a->hat = SvUV( ST(1) );
  533. }
  534. RETVAL = a->hat;
  535. OUTPUT:
  536. RETVAL
  537. Uint8
  538. event_jhat_value ( event, ... )
  539. SDL_Event *event
  540. CODE:
  541. SDL_JoyHatEvent * a = &(event->jhat);
  542. if( items > 1 )
  543. {
  544. a->value = SvUV( ST(1) );
  545. }
  546. RETVAL = a->value;
  547. OUTPUT:
  548. RETVAL
  549. SDL_JoyButtonEvent *
  550. event_jbutton ( event, ... )
  551. SDL_Event *event
  552. PREINIT:
  553. char *CLASS = "SDL::JoyButtonEvent";
  554. CODE:
  555. RETVAL = NULL;
  556. if ( &event != NULL )
  557. RETVAL = &(event->jbutton);
  558. OUTPUT:
  559. RETVAL
  560. Uint8
  561. event_jbutton_type ( event, ... )
  562. SDL_Event *event
  563. CODE:
  564. SDL_JoyButtonEvent * a = &(event->jbutton);
  565. if( items > 1 )
  566. {
  567. a->type = SvUV( ST(1) );
  568. }
  569. RETVAL = a->type;
  570. OUTPUT:
  571. RETVAL
  572. Uint8
  573. event_jbutton_which ( event, ... )
  574. SDL_Event *event
  575. CODE:
  576. SDL_JoyButtonEvent * a = &(event->jbutton);
  577. if( items > 1 )
  578. {
  579. a->which = SvUV( ST(1) );
  580. }
  581. RETVAL = a->which;
  582. OUTPUT:
  583. RETVAL
  584. Uint8
  585. event_jbutton_button ( event, ... )
  586. SDL_Event *event
  587. CODE:
  588. SDL_JoyButtonEvent * a = &(event->jbutton);
  589. if( items > 1 )
  590. {
  591. a->button = SvUV( ST(1) );
  592. }
  593. RETVAL = a->button;
  594. OUTPUT:
  595. RETVAL
  596. Uint8
  597. event_jbutton_state ( event, ... )
  598. SDL_Event *event
  599. CODE:
  600. SDL_JoyButtonEvent * a = &(event->jbutton);
  601. if( items > 1 )
  602. {
  603. a->state = SvUV( ST(1) );
  604. }
  605. RETVAL = a->state;
  606. OUTPUT:
  607. RETVAL
  608. SDL_ResizeEvent *
  609. event_resize ( event, ... )
  610. SDL_Event * event
  611. PREINIT:
  612. char *CLASS = "SDL::ResizeEvent";
  613. CODE:
  614. RETVAL = NULL;
  615. if ( &event != NULL )
  616. RETVAL = &(event->resize);
  617. OUTPUT:
  618. RETVAL
  619. Uint8
  620. event_resize_type ( event, ... )
  621. SDL_Event *event
  622. CODE:
  623. SDL_ResizeEvent * a = &(event->resize);
  624. if( items > 1 )
  625. {
  626. a->type = SvUV( ST(1) );
  627. }
  628. RETVAL = a->type;
  629. OUTPUT:
  630. RETVAL
  631. int
  632. event_resize_w ( event, ... )
  633. SDL_Event *event
  634. CODE:
  635. SDL_ResizeEvent * a = &(event->resize);
  636. if( items > 1 )
  637. {
  638. a->w = SvUV( ST(1) );
  639. }
  640. RETVAL = a->w;
  641. OUTPUT:
  642. RETVAL
  643. int
  644. event_resize_h ( event, ... )
  645. SDL_Event *event
  646. CODE:
  647. SDL_ResizeEvent * a = &(event->resize);
  648. if( items > 1 )
  649. {
  650. a->h = SvUV( ST(1) );
  651. }
  652. RETVAL = a->h;
  653. OUTPUT:
  654. RETVAL
  655. SDL_ExposeEvent *
  656. event_expose ( event, ... )
  657. SDL_Event * event
  658. PREINIT:
  659. char *CLASS = "SDL::ExposeEvent";
  660. CODE:
  661. RETVAL = &(event->expose);
  662. OUTPUT:
  663. RETVAL
  664. Uint8
  665. event_expose_type ( event, ... )
  666. SDL_Event *event
  667. CODE:
  668. SDL_ExposeEvent * a = &(event->expose);
  669. if( items > 1 )
  670. {
  671. a->type = SvUV( ST(1) );
  672. }
  673. RETVAL = a->type;
  674. OUTPUT:
  675. RETVAL
  676. SDL_QuitEvent *
  677. event_quit ( event, ... )
  678. SDL_Event * event
  679. PREINIT:
  680. char *CLASS = "SDL::QuitEvent";
  681. CODE:
  682. RETVAL = &(event->quit);
  683. OUTPUT:
  684. RETVAL
  685. Uint8
  686. event_quit_type ( event, ... )
  687. SDL_Event *event
  688. CODE:
  689. SDL_QuitEvent * a = &(event->quit);
  690. if( items > 1 )
  691. {
  692. a->type = SvUV( ST(1) );
  693. }
  694. RETVAL = a->type;
  695. OUTPUT:
  696. RETVAL
  697. SDL_UserEvent *
  698. event_user ( event, ... )
  699. SDL_Event * event
  700. PREINIT:
  701. char *CLASS = "SDL::UserEvent";
  702. CODE:
  703. RETVAL = &(event->user);
  704. OUTPUT:
  705. RETVAL
  706. Uint8
  707. event_user_type ( event, ... )
  708. SDL_Event *event
  709. CODE:
  710. SDL_UserEvent * a = &(event->user);
  711. if( items > 1 )
  712. {
  713. a->type = SvUV( ST(1) );
  714. }
  715. RETVAL = a->type;
  716. OUTPUT:
  717. RETVAL
  718. int
  719. event_user_code ( event, ... )
  720. SDL_Event *event
  721. CODE:
  722. SDL_UserEvent * a = &(event->user);
  723. if( items > 1 )
  724. {
  725. a->code = SvUV( ST(1) );
  726. }
  727. RETVAL = (int)a->code;
  728. OUTPUT:
  729. RETVAL
  730. SV*
  731. event_user_data1 ( event, ... )
  732. SDL_Event *event
  733. PPCODE:
  734. SDL_UserEvent * a = &(event->user);
  735. if ( items > 1)
  736. a->data1 = new_data( ST(1) );
  737. if (!a->data1)
  738. XSRETURN_EMPTY;
  739. ST(0) = a->data1;
  740. XSRETURN(1);
  741. SV*
  742. event_user_data2 ( event, ... )
  743. SDL_Event *event
  744. PPCODE:
  745. SDL_UserEvent * a = &(event->user);
  746. if ( items > 1)
  747. a->data2 = new_data( ST(1) );
  748. if (!a->data2)
  749. XSRETURN_EMPTY;
  750. ST(0) = a->data2;
  751. XSRETURN(1);
  752. SDL_SysWMEvent *
  753. event_syswm ( event, ... )
  754. SDL_Event * event
  755. PREINIT:
  756. char *CLASS = "SDL::SysWMEvent";
  757. CODE:
  758. RETVAL = &(event->syswm);
  759. OUTPUT:
  760. RETVAL
  761. Uint8
  762. event_syswm_type ( event, ... )
  763. SDL_Event *event
  764. CODE:
  765. SDL_SysWMEvent * a = &(event->syswm);
  766. if( items > 1 )
  767. {
  768. a->type = SvUV( ST(1) );
  769. }
  770. RETVAL = a->type;
  771. OUTPUT:
  772. RETVAL
  773. SDL_SysWMmsg *
  774. event_syswm_msg ( event, ... )
  775. SDL_Event *event
  776. PREINIT:
  777. char* CLASS = "SDL::SysWMmsg";
  778. CODE:
  779. SDL_SysWMEvent * a = &(event->syswm);
  780. if( items > 1 )
  781. {
  782. SDL_SysWMmsg * sysm = (SDL_SysWMmsg * )SvPV( ST(1), PL_na) ;
  783. a->msg = sysm;
  784. }
  785. RETVAL = a->msg;
  786. OUTPUT:
  787. RETVAL
  788. void
  789. event_DESTROY(bag)
  790. SV* bag
  791. CODE:
  792. if( sv_isobject(bag) && (SvTYPE(SvRV(bag)) == SVt_PVMG) ) {
  793. void** pointers = (void**)INT2PTR(void *, SvIV((SV *)SvRV( bag )));
  794. SDL_Event* self = (SDL_Event*)(pointers[0]);
  795. if (PERL_GET_CONTEXT == pointers[1]) {
  796. /*warn("Freed surface %p and pixels %p \n", surface, surface->pixels); */
  797. if(self->type == SDL_USEREVENT) {
  798. if( (self->user).data1 != NULL )
  799. SvREFCNT_dec( (self->user).data1);
  800. if( (self->user).data2 != NULL )
  801. SvREFCNT_dec( (self->user).data2);
  802. }
  803. safefree(self);
  804. safefree(pointers);
  805. }
  806. } else if (bag == 0) {
  807. XSRETURN(0);
  808. } else {
  809. XSRETURN_UNDEF;
  810. }