summaryrefslogtreecommitdiff
path: root/src/joystick.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-01-17 20:45:26 +0300
committerAndrei Karas <akaras@inbox.ru>2013-01-17 22:19:41 +0300
commitb86c930c9c18c95cf3e838ce56bf3b06cb5ca782 (patch)
tree2f64ba00fd43b21ae0c4975b99483b0c0f0ce2fa /src/joystick.cpp
parentbc9712cfb34a891a64bd28b76df0f9f4e5d01513 (diff)
downloadplus-b86c930c9c18c95cf3e838ce56bf3b06cb5ca782.tar.gz
plus-b86c930c9c18c95cf3e838ce56bf3b06cb5ca782.tar.bz2
plus-b86c930c9c18c95cf3e838ce56bf3b06cb5ca782.tar.xz
plus-b86c930c9c18c95cf3e838ce56bf3b06cb5ca782.zip
Add detect joystick button in settings page.
This need to detect joystick changes.
Diffstat (limited to 'src/joystick.cpp')
-rw-r--r--src/joystick.cpp51
1 files changed, 32 insertions, 19 deletions
diff --git a/src/joystick.cpp b/src/joystick.cpp
index 1d3d5a147..3b88e5668 100644
--- a/src/joystick.cpp
+++ b/src/joystick.cpp
@@ -32,25 +32,6 @@
int Joystick::joystickCount = 0;
bool Joystick::mEnabled = false;
-void Joystick::init()
-{
- SDL_InitSubSystem(SDL_INIT_JOYSTICK);
- SDL_JoystickEventState(SDL_ENABLE);
- joystickCount = SDL_NumJoysticks();
- logger->log("%i joysticks/gamepads found", joystickCount);
- for (int i = 0; i < joystickCount; i++)
- logger->log("- %s", SDL_JoystickName(i));
-
- mEnabled = config.getBoolValue("joystickEnabled");
-
- if (Joystick::getNumberOfJoysticks() > 0)
- {
- joystick = new Joystick(config.getIntValue("selectedJoystick"));
- if (mEnabled)
- joystick->open();
- }
-}
-
Joystick::Joystick(const int no):
mDirection(0),
mJoystick(nullptr),
@@ -74,8 +55,34 @@ Joystick::~Joystick()
close();
}
+void Joystick::init()
+{
+ SDL_InitSubSystem(SDL_INIT_JOYSTICK);
+ SDL_JoystickEventState(SDL_ENABLE);
+ joystickCount = SDL_NumJoysticks();
+ logger->log("%i joysticks/gamepads found", joystickCount);
+ for (int i = 0; i < joystickCount; i++)
+ logger->log("- %s", SDL_JoystickName(i));
+
+ mEnabled = config.getBoolValue("joystickEnabled");
+
+ if (joystickCount > 0)
+ {
+ joystick = new Joystick(config.getIntValue("selectedJoystick"));
+ if (mEnabled)
+ joystick->open();
+ }
+}
+
bool Joystick::open()
{
+ if (mNumber >= joystickCount)
+ mNumber = joystickCount - 1;
+ if (mNumber < 0)
+ {
+ logger->log("error: incorrect joystick selection");
+ return false;
+ }
logger->log("open joystick %d", mNumber);
mJoystick = SDL_JoystickOpen(mNumber);
@@ -120,6 +127,12 @@ void Joystick::close()
}
}
+void Joystick::reload()
+{
+ joystickCount = SDL_NumJoysticks();
+ setNumber(mNumber);
+}
+
void Joystick::setNumber(const int n)
{
if (mJoystick)