X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fgui%2Fgamepad.cpp;h=6ca2329a02cf20ab737bdca253cdc37bb7552f43;hb=5c28b6dbf7aa20441c8a51f484f4f64b1966f7e3;hp=ba8a551037b044ec7b0239ab6dd0248ed63fd976;hpb=f63cd569374c4fbcd872bb8a67c94788da29c3a8;p=virtualjaguar diff --git a/src/gui/gamepad.cpp b/src/gui/gamepad.cpp index ba8a551..6ca2329 100644 --- a/src/gui/gamepad.cpp +++ b/src/gui/gamepad.cpp @@ -12,19 +12,81 @@ // #include "gamepad.h" +#include "log.h" + + +// Class member initialization +/*static*/ int Gamepad::numJoysticks = 0; +/*static*/ SDL_Joystick * Gamepad::pad[8]; +/*static*/ int Gamepad::numButtons[8]; +/*static*/ int Gamepad::numHats[8]; +/*static*/ bool Gamepad::button[8][256]; +/*static*/ uint8_t Gamepad::hat[8][32]; + + +Gamepad::Gamepad(void)//: numJoysticks(0) +{ + AllocateJoysticks(); +} + + +Gamepad::~Gamepad(void) +{ + DeallocateJoysticks(); +} + + +void Gamepad::AllocateJoysticks(void) +{ +// DeallocateJoysticks(); + numJoysticks = SDL_NumJoysticks(); + + // Sanity check + if (numJoysticks > 8) + numJoysticks = 8; + + for(int i=0; i> 3; - int hatDirection = hatMask[buttonID & JOY_HATBUT_MASK]; + uint8_t hatDirection = hatMask[buttonID & JOY_HATBUT_MASK]; +// uint8 direction = SDL_JoystickGetHat(pad[joystickID], hatNumber); +// return ( + return (hat[joystickID][hatNumber] & hatDirection ? true : false); } // Default == failure @@ -32,14 +94,77 @@ bool Gamepad::GetState(int joystickID, int buttonID) } +int Gamepad::CheckButtonPressed(void) +{ + // This translates the hat direction to a mask index. + int hatNum[16] = { -1, 0, 1, -1, 2, -1, -1, -1, + 3, -1, -1, -1, -1, -1, -1, -1 }; + + // Return single button ID being pressed (if any) + for(int i=0; i