Changeset 184 for trunk/src


Ignore:
Timestamp:
08/01/13 01:36:03 (12 years ago)
Author:
epyon
Message:
  • io_event - full support for all joystick events
  • gl_window - full implementation for all joystick events
Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gl/gl_device.cc

    r171 r184  
    2525        m_info = NULL;
    2626
    27         if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
     27        if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK ) < 0 )
    2828        {
    2929                NV_LOG( LOG_CRITICAL, "Video initialization failed: " << SDL_GetError( ) );
  • trunk/src/gl/gl_window.cc

    r172 r184  
    132132}
    133133
     134static bool sdl_joy_button_event_to_io_event( const SDL_JoyButtonEvent& jb, io_event& jevent )
     135{
     136        jevent.type            = EV_JOY_BUTTON;
     137        jevent.jbutton.id      = jb.which;
     138        jevent.jbutton.button  = jb.button;
     139        jevent.jbutton.pressed = (jb.type == SDL_PRESSED);
     140        return true;
     141}
     142
     143static bool sdl_joy_axis_event_to_io_event( const SDL_JoyAxisEvent& ja, io_event& jevent )
     144{
     145        jevent.type          = EV_JOY_AXIS;
     146        jevent.jaxis.id      = ja.which;
     147        jevent.jaxis.axis    = ja.axis;
     148        jevent.jaxis.value   = ja.value;
     149        return true;
     150}
     151
     152static bool sdl_joy_hat_event_to_io_event( const SDL_JoyHatEvent& jh, io_event& jevent )
     153{
     154        jevent.type          = EV_JOY_HAT;
     155        jevent.jhat.id       = jh.which;
     156        jevent.jhat.hat      = jh.hat;
     157        jevent.jhat.value    = jh.value;
     158        return true;
     159}
     160
     161static bool sdl_joy_ball_event_to_io_event( const SDL_JoyBallEvent& jb, io_event& jevent )
     162{
     163        jevent.type          = EV_JOY_HAT;
     164        jevent.jball.id      = jb.which;
     165        jevent.jball.ball    = jb.ball;
     166        jevent.jball.rx      = jb.xrel;
     167        jevent.jball.ry      = jb.yrel;
     168        return true;
     169}
     170
    134171static bool sdl_event_to_io_event( const SDL_Event& e, io_event& ioevent )
    135172{
     
    156193        case SDL_SYSWMEVENT      : ioevent.type = EV_SYSTEM; return true;
    157194        case SDL_QUIT            : ioevent.type = EV_QUIT;   return true;
    158         case SDL_JOYAXISMOTION   : return false;
    159         case SDL_JOYBALLMOTION   : return false;
    160         case SDL_JOYHATMOTION    : return false;
    161         case SDL_JOYBUTTONDOWN   : return false;
    162         case SDL_JOYBUTTONUP     : return false;
     195        case SDL_JOYAXISMOTION   : return sdl_joy_axis_event_to_io_event( e.jaxis, ioevent );
     196        case SDL_JOYBALLMOTION   : return sdl_joy_ball_event_to_io_event( e.jball, ioevent );
     197        case SDL_JOYHATMOTION    : return sdl_joy_hat_event_to_io_event( e.jhat, ioevent );
     198        case SDL_JOYBUTTONDOWN   : return sdl_joy_button_event_to_io_event( e.jbutton, ioevent );
     199        case SDL_JOYBUTTONUP     : return sdl_joy_button_event_to_io_event( e.jbutton, ioevent );
    163200        default : return false;
    164201        }
     
    183220        }
    184221
     222//      NV_LOG( LOG_INFO, "Joystick count : " << SDL_NumJoysticks() );
     223//      SDL_Joystick* j = SDL_JoystickOpen(0);
     224//      if (j)
     225//      {
     226//              NV_LOG( LOG_INFO, "Joystick Name: " << SDL_JoystickNameForIndex(0) );
     227//              NV_LOG( LOG_INFO, "Joystick Number of Axes: " << SDL_JoystickNumAxes(j));
     228//              NV_LOG( LOG_INFO, "Joystick Number of Buttons: " << SDL_JoystickNumButtons(j));
     229//              NV_LOG( LOG_INFO, "Joystick Number of Balls: " << SDL_JoystickNumBalls(j));
     230//      }
     231
     232
    185233        m_context = new gl_context( m_device, m_handle );
    186234        m_context->set_viewport( nv::ivec4( 0, 0, m_width, m_height ) );
  • trunk/src/io_event.cc

    r121 r184  
    9494        db->create_type<mouse_move_event>("mouse_move_event").fields( mouse_move_fields );
    9595
     96        type_field joy_button_fields[] = {
     97                type_field( "id",      &joy_button_event::id ),
     98                type_field( "button",  &joy_button_event::button ),
     99                type_field( "pressed", &joy_button_event::pressed ),
     100        };
     101        db->create_type<joy_button_event>("joy_button_event").fields( joy_button_fields );
     102
     103        type_field joy_axis_fields[] = {
     104                type_field( "id",      &joy_axis_event::id ),
     105                type_field( "axis",    &joy_axis_event::axis ),
     106                type_field( "value",   &joy_axis_event::value ),
     107        };
     108        db->create_type<joy_axis_event>("joy_axis_event").fields( joy_axis_fields );
     109
     110        type_field joy_hat_fields[] = {
     111                type_field( "id",      &joy_hat_event::id ),
     112                type_field( "hat",     &joy_hat_event::hat ),
     113                type_field( "value",   &joy_hat_event::value ),
     114        };
     115        db->create_type<joy_hat_event>("joy_hat_event").fields( joy_hat_fields );
     116
     117        type_field joy_ball_fields[] = {
     118                type_field( "id",      &joy_ball_event::id ),
     119                type_field( "ball",    &joy_ball_event::ball ),
     120                type_field( "rx",      &joy_ball_event::rx ),
     121                type_field( "ry",      &joy_ball_event::ry ),
     122        };
     123        db->create_type<joy_ball_event>("joy_ball_event").fields( joy_ball_fields );
     124
    96125        type_field system_fields[] = {
    97126                type_field( "sys_type", &system_event::sys_type ),
Note: See TracChangeset for help on using the changeset viewer.