Changeset 338 for trunk/src


Ignore:
Timestamp:
09/22/14 23:54:01 (11 years ago)
Author:
epyon
Message:
  • io_events for controllers
Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/io_event.cc

    r319 r338  
    66
    77#include "nv/core/io_event.hh"
     8
     9#include "nv/core/logging.hh"
    810
    911using namespace nv;
     
    4042        NV_RETURN_COVERED_DEFAULT( "EV_UNKNOWN" );
    4143        };
     44}
     45
     46void nv::log_event( const io_event& e )
     47{
     48        NV_LOG( LOG_INFO, "Event: " << get_io_event_name( e.type ) );
    4249}
    4350
  • trunk/src/sdl/sdl_input.cc

    r336 r338  
    1515{
    1616        if ( ! SDL_WasInit( SDL_INIT_JOYSTICK ) ) SDL_InitSubSystem( SDL_INIT_JOYSTICK );
     17        if ( ! SDL_WasInit( SDL_INIT_GAMECONTROLLER ) ) SDL_InitSubSystem( SDL_INIT_GAMECONTROLLER );
    1718}
    1819
     
    140141}
    141142
     143static bool sdl_pad_button_event_to_io_event( const SDL_ControllerButtonEvent& cb, io_event& cevent )
     144{
     145        cevent.type            = EV_PAD_BUTTON;
     146        cevent.pbutton.id      = cb.which;
     147        cevent.pbutton.button  = cb.button;
     148        cevent.pbutton.pressed = (cb.type == SDL_PRESSED);
     149        return true;
     150}
     151
     152static bool sdl_pad_axis_event_to_io_event( const SDL_ControllerAxisEvent& ca, io_event& cevent )
     153{
     154        cevent.type          = EV_PAD_AXIS;
     155        cevent.paxis.id      = ca.which;
     156        cevent.paxis.axis    = ca.axis;
     157        cevent.paxis.value   = ca.value;
     158        return true;
     159}
     160
     161
    142162static bool sdl_joy_button_event_to_io_event( const SDL_JoyButtonEvent& jb, io_event& jevent )
    143163{
     
    202222        case SDL_SYSWMEVENT      : ioevent.type = EV_SYSTEM; return true;
    203223        case SDL_QUIT            : ioevent.type = EV_QUIT;   return true;
     224        case SDL_CONTROLLERAXISMOTION : return sdl_pad_axis_event_to_io_event( e.caxis, ioevent );
     225        case SDL_CONTROLLERBUTTONDOWN : return sdl_pad_button_event_to_io_event( e.cbutton, ioevent );
     226        case SDL_CONTROLLERBUTTONUP   :
    204227        case SDL_JOYAXISMOTION   : return sdl_joy_axis_event_to_io_event( e.jaxis, ioevent );
    205228        case SDL_JOYBALLMOTION   : return sdl_joy_ball_event_to_io_event( e.jball, ioevent );
Note: See TracChangeset for help on using the changeset viewer.