diff options
author | Jonathan Gray | 2003-01-20 16:29:26 +0000 |
---|---|---|
committer | Jonathan Gray | 2003-01-20 16:29:26 +0000 |
commit | 473cbb843749e2e373ab0dd48aba2498d3fa56f6 (patch) | |
tree | 8100a0624b074d4984982dddbb0b19527206ef26 /backends/sdl | |
parent | 1043ec1df97cc0f6184a1ecd0960732d3b76e05a (diff) | |
download | scummvm-rg350-473cbb843749e2e373ab0dd48aba2498d3fa56f6.tar.gz scummvm-rg350-473cbb843749e2e373ab0dd48aba2498d3fa56f6.tar.bz2 scummvm-rg350-473cbb843749e2e373ab0dd48aba2498d3fa56f6.zip |
start of joystick support, just selects first joystick for now and only maps first two buttons to first two mouse buttons. Will add more button mappings and a -j options to specify joystick in future
svn-id: r6528
Diffstat (limited to 'backends/sdl')
-rw-r--r-- | backends/sdl/sdl-common.cpp | 55 | ||||
-rw-r--r-- | backends/sdl/sdl-common.h | 4 |
2 files changed, 58 insertions, 1 deletions
diff --git a/backends/sdl/sdl-common.cpp b/backends/sdl/sdl-common.cpp index a4cb7ba341..6e7882db7e 100644 --- a/backends/sdl/sdl-common.cpp +++ b/backends/sdl/sdl-common.cpp @@ -42,7 +42,7 @@ OSystem *OSystem_SDL_Common::create(int gfx_mode, bool full_screen) { syst->_mode = gfx_mode; syst->_full_screen = full_screen; - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) ==-1) { + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK) ==-1) { error("Could not initialize SDL: %s.\n", SDL_GetError()); } @@ -62,6 +62,12 @@ OSystem *OSystem_SDL_Common::create(int gfx_mode, bool full_screen) { atexit(atexit_proc); #endif + // enable joystick + if (SDL_NumJoysticks() > 0) { + printf("Using joystick: %s\n", SDL_JoystickName(0)); + syst->init_joystick(); + } + return syst; } @@ -85,6 +91,7 @@ OSystem_SDL_Common::OSystem_SDL_Common() // reset mouse state memset(&km, 0, sizeof(km)); + } OSystem_SDL_Common::~OSystem_SDL_Common() @@ -640,6 +647,52 @@ bool OSystem_SDL_Common::poll_event(Event *event) { event->mouse.y /= _scaleFactor; return true; + case SDL_JOYBUTTONDOWN: + if (ev.jbutton.button == 0) { + event->event_code = EVENT_LBUTTONDOWN; + } + if (ev.jbutton.button == 1) { + event->event_code = EVENT_RBUTTONDOWN; + } + return true; + + case SDL_JOYBUTTONUP: + if (ev.jbutton.button == 0) { + event->event_code = EVENT_LBUTTONUP; + } + if (ev.jbutton.button == 1) { + event->event_code = EVENT_RBUTTONUP; + } + return true; + + case SDL_JOYAXISMOTION: + if ( ev.jaxis.axis == 0) { + if (ev.jaxis.value < -3200) { // left + km.x_vel = -1; + km.x_down_count = 1; + } else if (ev.jaxis.value > 3200) { // right + km.x_vel = 1; + km.x_down_count = 1; + } else { // neither + km.x_vel = 0; + km.x_down_count = 0; + } + + + } else if (ev.jaxis.axis == 1) { + if (ev.jaxis.value < -3200) { // up + km.y_vel = -1; + km.y_down_count = 1; + } else if (ev.jaxis.value > 3200) { // down + km.y_vel = 1; + km.y_down_count = 1; + } else { + km.y_vel = 0; + km.y_down_count = 0; + } + } + return true; + case SDL_QUIT: quit(); } diff --git a/backends/sdl/sdl-common.h b/backends/sdl/sdl-common.h index b4e2b324db..e0d4d37a28 100644 --- a/backends/sdl/sdl-common.h +++ b/backends/sdl/sdl-common.h @@ -181,6 +181,9 @@ protected: MousePos() : x(0), y(0), w(0), h(0) {} }; + // joystick + SDL_Joystick *_joystick; + bool _mouseVisible; bool _mouseDrawn; byte *_mouseData; @@ -214,6 +217,7 @@ protected: void setup_icon(); void kbd_mouse(); + void init_joystick() { _joystick = SDL_JoystickOpen(0); } static OSystem_SDL_Common *create(); }; |