e8972aa824
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
42 lines
908 B
C++
42 lines
908 B
C++
#include "StdAfx.h"
|
|
#include "frontends/sa2/gamepad.h"
|
|
|
|
#include "Log.h"
|
|
|
|
#define AXIS_MIN -32768
|
|
#define AXIS_MAX 32767
|
|
|
|
|
|
Gamepad::Gamepad(const int index)
|
|
: myButtonCodes(2), myAxisCodes(2)
|
|
{
|
|
myController.reset(SDL_GameControllerOpen(index), SDL_GameControllerClose);
|
|
myButtonCodes[0] = SDL_CONTROLLER_BUTTON_A;
|
|
myButtonCodes[1] = SDL_CONTROLLER_BUTTON_B;
|
|
myAxisCodes[0] = SDL_CONTROLLER_AXIS_LEFTX;
|
|
myAxisCodes[1] = SDL_CONTROLLER_AXIS_LEFTY;
|
|
}
|
|
|
|
bool Gamepad::getButton(int i) const
|
|
{
|
|
int value = 0;
|
|
if (myController)
|
|
{
|
|
value = SDL_GameControllerGetButton(myController.get(), myButtonCodes[i]);
|
|
}
|
|
return value != 0;
|
|
}
|
|
|
|
int Gamepad::getAxis(int i) const
|
|
{
|
|
if (myController)
|
|
{
|
|
const int value = SDL_GameControllerGetAxis(myController.get(), myAxisCodes[i]);
|
|
int pdl = 255 * (value - AXIS_MIN) / (AXIS_MAX - AXIS_MIN);
|
|
return pdl;
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|