added more event constants and their tests
Tobias Leich [Sun, 8 Nov 2009 15:59:59 +0000 (16:59 +0100)]
lib/SDL/Constants.pm
lib/SDL/Events.pm
src/Core/Events.xs
src/Core/objects/JoyButtonEvent.xs
src/Core/objects/KeyboardEvent.xs
src/Core/objects/MouseButtonEvent.xs
t/core_events.t

index 1120260..5e61223 100644 (file)
@@ -202,6 +202,7 @@ our @EXPORT=qw(
        SDLK_y
        SDLK_z
        SDL_ACTIVEEVENT
+       SDL_ACTIVEEVENTMASK
        SDL_ALLEVENTS
        SDL_ANYFORMAT
        SDL_ADDEVENT
@@ -268,6 +269,8 @@ our @EXPORT=qw(
        SDL_MOUSEBUTTONDOWN
        SDL_MOUSEBUTTONUP
        SDL_MOUSEMOTION
+       SDL_NOEVENT
+       SDL_NUMEVENTS
        SDL_OPENGL
        SDL_OPENGLBLIT
        SDL_PEEKEVENT
@@ -276,6 +279,14 @@ our @EXPORT=qw(
        SDL_QUERY
        SDL_QUIT
        SDL_RELEASED
+       SDL_EVENT_RESERVEDA
+       SDL_EVENT_RESERVEDB
+       SDL_EVENT_RESERVED2
+       SDL_EVENT_RESERVED3
+       SDL_EVENT_RESERVED4
+       SDL_EVENT_RESERVED5
+       SDL_EVENT_RESERVED6
+       SDL_EVENT_RESERVED7
        SDL_RESIZABLE
        SDL_RLEACCEL
        SDL_RLEACCELOK
@@ -283,6 +294,7 @@ our @EXPORT=qw(
        SDL_SRCCOLORKEY
        SDL_SWSURFACE
        SDL_SYSWMEVENT
+       SDL_USEREVENT
        SDL_UYVY_OVERLAY
        SDL_VIDEOEXPOSE
        SDL_VIDEORESIZE
@@ -489,6 +501,7 @@ use constant {
     SDLK_z            => 122,
     
     SDL_ACTIVEEVENT         => 1,
+       SDL_ACTIVEEVENTMASK     => 1 << 1,
        SDL_ADDEVENT            => 0,
        SDL_ALLEVENTS           => 0xFFFFFFFF,
     SDL_ANYFORMAT           => 268435456,
@@ -508,7 +521,17 @@ use constant {
     SDL_BUTTON_WHEELDOWN => 16,
     
     SDL_DOUBLEBUF => 1073741824,
+       
     SDL_ENABLE => 1,
+    SDL_EVENT_RESERVEDA     => 14,
+    SDL_EVENT_RESERVEDB     => 15,
+    SDL_EVENT_RESERVED2     => 18,
+    SDL_EVENT_RESERVED3     => 19,
+    SDL_EVENT_RESERVED4     => 20,
+    SDL_EVENT_RESERVED5     => 21,
+    SDL_EVENT_RESERVED6     => 22,
+    SDL_EVENT_RESERVED7     => 23,
+       
     SDL_FULLSCREEN => -2147483648,
     
        SDL_GETEVENT            => 2,
@@ -555,20 +578,23 @@ use constant {
     
     SDL_IYUV_OVERLAY => 1448433993,
     
-    SDL_JOYAXISMOTION => 7,
-    SDL_JOYBALLMOTION => 8,
-    SDL_JOYBUTTONDOWN => 10,
-    SDL_JOYBUTTONUP   => 11,
-    SDL_JOYHATMOTION  => 9,
+    SDL_JOYAXISMOTION       => 7,
+    SDL_JOYBALLMOTION       => 8,
+    SDL_JOYBUTTONDOWN       => 10,
+    SDL_JOYBUTTONUP         => 11,
+    SDL_JOYHATMOTION        => 9,
     
-    SDL_KEYDOWN => 2,
-    SDL_KEYUP   => 3,
+    SDL_KEYDOWN             => 2,
+    SDL_KEYUP               => 3,
     
     SDL_MIX_MAXVOLUME => 128,
     
-    SDL_MOUSEBUTTONDOWN => 5,
-    SDL_MOUSEBUTTONUP   => 6,
-    SDL_MOUSEMOTION     => 4,
+    SDL_MOUSEBUTTONDOWN     => 5,
+    SDL_MOUSEBUTTONUP       => 6,
+    SDL_MOUSEMOTION         => 4,
+       
+    SDL_NOEVENT             => 0,
+       SDL_NUMEVENTS           => 32,
     
     SDL_OPENGL     => 2,
     SDL_OPENGLBLIT => 10,
@@ -578,7 +604,7 @@ use constant {
     SDL_PRESSED => 1,
        
     SDL_QUERY => -1,
-    SDL_QUIT => 12,
+    SDL_QUIT                => 12,
        
     SDL_RELEASED => 0,
     SDL_RESIZABLE => 16,
@@ -588,12 +614,13 @@ use constant {
     SDL_SRCALPHA => 65536,
     SDL_SRCCOLORKEY => 4096,
     SDL_SWSURFACE => 0,
-    SDL_SYSWMEVENT => 13,
+    SDL_SYSWMEVENT          => 13,
        
-    SDL_UYVY_OVERLAY => 1498831189,
+       SDL_USEREVENT           => 24,
+    SDL_UYVY_OVERLAY        => 1498831189,
        
-    SDL_VIDEOEXPOSE => 17,
-    SDL_VIDEORESIZE => 16,
+    SDL_VIDEOEXPOSE         => 17,
+    SDL_VIDEORESIZE         => 16,
        
     SDL_YUY2_OVERLAY => 844715353,
     SDL_YV12_OVERLAY => 842094169,
index a293a83..7f25ef4 100644 (file)
@@ -6,4 +6,11 @@ require DynaLoader;
 our @ISA = qw(Exporter DynaLoader);
 bootstrap SDL::Events;
 
+our @EXPORT=qw(SDL_EVENTMASK);
+
+sub SDL_EVENTMASK
+{
+       return 1 << shift;
+}
+
 1;
index 8602c1e..24be987 100644 (file)
@@ -45,6 +45,8 @@ int
 events_poll_event( event )
        SDL_Event *event
        CODE:
+               RETVAL = -1;
+               if ( &event != NULL )
                RETVAL = SDL_PollEvent(event);
        OUTPUT:
                RETVAL
@@ -53,6 +55,8 @@ int
 events_push_event(event)
        SDL_Event *event
        CODE:
+               RETVAL = -1;
+               if ( &event != NULL )
                RETVAL = SDL_PushEvent(event);
        OUTPUT:
                RETVAL
index 304389d..ae6e01d 100644 (file)
@@ -29,7 +29,7 @@ jbevent_new ( CLASS )
        char* CLASS
        CODE:
                RETVAL = safemalloc(sizeof(SDL_JoyButtonEvent));
-               RETVAL->type = SDL_JOYBUTTONDOWN | SDL_JOYBUTTONUP;
+               RETVAL->type = SDL_JOYBUTTONDOWN;
        OUTPUT:
                RETVAL
 
index a1be0b1..2889808 100644 (file)
@@ -28,7 +28,7 @@ kbevent_new ( CLASS )
        char* CLASS
        CODE:
                RETVAL = safemalloc(sizeof(SDL_KeyboardEvent));
-               RETVAL->type = SDL_KEYDOWN | SDL_KEYUP;
+               RETVAL->type = SDL_KEYDOWN;
        OUTPUT:
                RETVAL
 
index d3b01d5..724c144 100644 (file)
@@ -30,7 +30,7 @@ mbevent_new ( CLASS )
        char* CLASS
        CODE:
                RETVAL = safemalloc(sizeof(SDL_MouseButtonEvent));
-               RETVAL->type = SDL_MOUSEBUTTONDOWN | SDL_MOUSEBUTTONUP;
+               RETVAL->type = SDL_MOUSEBUTTONDOWN;
        OUTPUT:
                RETVAL
 
index a4a9bcf..e7d2553 100644 (file)
@@ -19,7 +19,7 @@ use SDL::UserEvent;
 use SDL::Video;
 use Test::More;
 
-plan ( tests => 51 );
+plan ( tests => 90 );
 
 my @done =qw/
 pump_events 
@@ -110,7 +110,51 @@ isa_ok( $wrevent, 'SDL::ResizeEvent',      '[SDL::ResizeEvent::new] is creating
 isa_ok( $wmevent, 'SDL::SysWMEvent',       '[SDL::SysWMEvent::new] is creating an SysWMEvent');
 isa_ok( $uevent,  'SDL::UserEvent',        '[SDL::UserEvent::new] is creating an UserEvent');
 
-is( $uevent->type, 0x0018, '[SDL::UserEvent->type] returns correctly');
+# checking constants
+is(SDL_NOEVENT,          0, 'Constant SDL_NOEVENT');         # Unused
+is(SDL_ACTIVEEVENT,      1, 'Constant SDL_ACTIVEVENT');      # Application loses/gains visibility
+is(SDL_KEYDOWN,          2, 'Constant SDL_KEYDOWN');         # Keys pressed
+is(SDL_KEYUP,            3, 'Constant SDL_KEYUP');           # Keys released
+is(SDL_MOUSEMOTION,      4, 'Constant SDL_MOUSEMOTION');     # Mouse moved
+is(SDL_MOUSEBUTTONDOWN,  5, 'Constant SDL_MOUSEBUTTONDOWN'); # Mouse button pressed
+is(SDL_MOUSEBUTTONUP,    6, 'Constant SDL_MOUSEBUTTONUP');   # Mouse button released
+is(SDL_JOYAXISMOTION,    7, 'Constant SDL_JOYAXISMOTION');   # Joystick axis motion
+is(SDL_JOYBALLMOTION,    8, 'Constant SDL_JOYBALLMOTION');   # Joystick trackball motion
+is(SDL_JOYHATMOTION,     9, 'Constant SDL_JOYHATMOTION');    # Joystick hat position change
+is(SDL_JOYBUTTONDOWN,   10, 'Constant SDL_JOYBUTTONDOWN');   # Joystick button pressed
+is(SDL_JOYBUTTONUP,     11, 'Constant SDL_JOYBUTTONUP');     # Joystick button released
+is(SDL_QUIT,            12, 'Constant SDL_QUIT');            # User-requested quit
+is(SDL_SYSWMEVENT,      13, 'Constant SDL_SYSWMEVENT');      # System specific event
+is(SDL_EVENT_RESERVEDA, 14, 'Constant SDL_EVENT_RESERVEDA'); # Reserved for future use..
+is(SDL_EVENT_RESERVEDB, 15, 'Constant SDL_EVENT_RESERVEDB'); # Reserved for future use..
+is(SDL_VIDEORESIZE,     16, 'Constant SDL_VIDEORESIZE');     # User resized video mode
+is(SDL_VIDEOEXPOSE,     17, 'Constant SDL_VIDEOEXPOSE');     # Screen needs to be redrawn
+is(SDL_EVENT_RESERVED2, 18, 'Constant SDL_EVENT_RESERVED2'); # Reserved for future use..
+is(SDL_EVENT_RESERVED3, 19, 'Constant SDL_EVENT_RESERVED3'); # Reserved for future use..
+is(SDL_EVENT_RESERVED4, 20, 'Constant SDL_EVENT_RESERVED4'); # Reserved for future use..
+is(SDL_EVENT_RESERVED5, 21, 'Constant SDL_EVENT_RESERVED5'); # Reserved for future use..
+is(SDL_EVENT_RESERVED6, 22, 'Constant SDL_EVENT_RESERVED6'); # Reserved for future use..
+is(SDL_EVENT_RESERVED7, 23, 'Constant SDL_EVENT_RESERVED7'); # Reserved for future use..
+is(SDL_USEREVENT,       24, 'Constant SDL_USEREVENT');
+is(SDL_NUMEVENTS,       32, 'Constant SDL_NUMEVENTS');
+
+# checking eventmasks
+is(SDL_ACTIVEEVENTMASK,  SDL_EVENTMASK(SDL_ACTIVEEVENT), 'Constant SDL_ACTIVEVENTMASK');
+
+#is($event->type,   SDL_EVENT, '[SDL::Event->type] returns correctly');
+is($aevent->type,  SDL_ACTIVEEVENT, '[SDL::ActiveEvent->type] returns correctly'); 
+is($weevent->type, SDL_VIDEOEXPOSE, '[SDL::ExposeEvent->type] returns correctly'); 
+is($jaevent->type, SDL_JOYAXISMOTION, '[SDL::JoyAxisEvent->type] returns correctly'); 
+is($jtevent->type, SDL_JOYBALLMOTION, '[SDL::JoyBallEvent->type] returns correctly'); 
+is((($jbevent->type == SDL_JOYBUTTONDOWN) || ($jbevent->type == SDL_JOYBUTTONUP)), 1, '[SDL::JoyButtonEvent->type] returns correctly'); 
+is($jhevent->type, SDL_JOYHATMOTION, '[SDL::JoyHatEvent->type] returns correctly'); 
+is((($kbevent->type == SDL_KEYUP) || ($kbevent->type == SDL_KEYDOWN)), 1, '[SDL::KeyboardEvent->type] returns correctly'); 
+is((($mbevent->type == SDL_MOUSEBUTTONDOWN) || ($mbevent->type == SDL_MOUSEBUTTONUP)), 1, '[SDL::MouseButtonEvent->type] returns correctly'); 
+is($mmevent->type, SDL_MOUSEMOTION, '[SDL::MouseMotionEvent->type] returns correctly'); 
+is($qevent->type,  SDL_QUIT, '[SDL::QuitEvent->type] returns correctly'); 
+is($wrevent->type, SDL_VIDEORESIZE, '[SDL::ResizeEvent->type] returns correctly'); 
+is($wmevent->type, SDL_SYSWMEVENT, '[SDL::SysWMEvent->type] returns correctly'); 
+is($uevent->type,  SDL_USEREVENT, '[SDL::UserEvent->type] returns correctly'); 
 
 $uevent->code(200);
 is( $uevent->code, 200, '[SDL::UserEvent->code] is set correctly');