summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/defaults.cpp1
-rw-r--r--src/gui/setup_joystick.cpp15
-rw-r--r--src/gui/setup_joystick.h1
-rw-r--r--src/joystick.cpp50
-rw-r--r--src/joystick.h7
5 files changed, 51 insertions, 23 deletions
diff --git a/src/defaults.cpp b/src/defaults.cpp
index 76438a1e2..f18e0f432 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -223,6 +223,7 @@ DefaultsData* getConfigDefaults()
AddDEF(configData, "pvpAttackType", 0);
AddDEF(configData, "lang", "");
AddDEF(configData, "selectedJoystick", 0);
+ AddDEF(configData, "useInactiveJoystick", false);
return configData;
}
diff --git a/src/gui/setup_joystick.cpp b/src/gui/setup_joystick.cpp
index f0899be3f..7899247e3 100644
--- a/src/gui/setup_joystick.cpp
+++ b/src/gui/setup_joystick.cpp
@@ -70,7 +70,10 @@ Setup_Joystick::Setup_Joystick():
mCalibrateLabel(new Label(_("Press the button to start calibration"))),
mCalibrateButton(new Button(_("Calibrate"), "calibrate", this)),
mJoystickEnabled(new CheckBox(_("Enable joystick"))),
- mNamesModel(new NamesModel())
+ mNamesModel(new NamesModel()),
+ mNamesDropDown(new DropDown(mNamesModel)),
+ mUseInactiveCheckBox(new CheckBox(_("Use joystick if client "
+ "window inactive"), config.getBoolValue("useInactiveJoystick")))
{
setName(_("Joystick"));
@@ -82,7 +85,6 @@ Setup_Joystick::Setup_Joystick():
mJoystickEnabled->addActionListener(this);
mCalibrateButton->setEnabled(mOriginalJoystickEnabled);
- mNamesDropDown = new DropDown(mNamesModel);
mNamesDropDown->setActionEventId("name");
mNamesDropDown->addActionListener(this);
@@ -104,8 +106,9 @@ Setup_Joystick::Setup_Joystick():
place(0, 0, mJoystickEnabled);
place(0, 1, mNamesDropDown);
- place(0, 2, mCalibrateLabel);
- place(0, 3, mCalibrateButton);
+ place(0, 2, mUseInactiveCheckBox);
+ place(0, 3, mCalibrateLabel);
+ place(0, 4, mCalibrateButton);
setDimension(gcn::Rectangle(0, 0, 365, 75));
}
@@ -180,4 +183,8 @@ void Setup_Joystick::apply()
config.setValue("joystickEnabled",
joystick ? joystick->isEnabled() : false);
+
+ config.setValue("useInactiveJoystick", mUseInactiveCheckBox->isSelected());
+ if (joystick)
+ joystick->setUseInactive(mUseInactiveCheckBox->isSelected());
}
diff --git a/src/gui/setup_joystick.h b/src/gui/setup_joystick.h
index e0a3a143f..5bd72cdad 100644
--- a/src/gui/setup_joystick.h
+++ b/src/gui/setup_joystick.h
@@ -54,6 +54,7 @@ class Setup_Joystick : public SetupTab
gcn::CheckBox *mJoystickEnabled;
NamesModel *mNamesModel;
DropDown *mNamesDropDown;
+ gcn::CheckBox *mUseInactiveCheckBox;
};
#endif
diff --git a/src/joystick.cpp b/src/joystick.cpp
index 3084a5ae6..bc4572370 100644
--- a/src/joystick.cpp
+++ b/src/joystick.cpp
@@ -20,8 +20,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "configuration.h"
#include "joystick.h"
+
+#include "client.h"
+#include "configuration.h"
#include "logger.h"
#include "debug.h"
@@ -57,7 +59,8 @@ Joystick::Joystick(int no):
mRightTolerance(0),
mCalibrating(false),
mCalibrated(false),
- mButtonsNumber(MAX_BUTTONS)
+ mButtonsNumber(MAX_BUTTONS),
+ mUseInactive(false)
{
if (no >= joystickCount)
no = joystickCount;
@@ -102,6 +105,7 @@ bool Joystick::open()
mDownTolerance = config.getIntValue("downTolerance" + toString(mNumber));
mLeftTolerance = config.getIntValue("leftTolerance" + toString(mNumber));
mRightTolerance = config.getIntValue("rightTolerance" + toString(mNumber));
+ mUseInactive = config.getBoolValue("useInactiveJoystick");
return true;
}
@@ -144,23 +148,31 @@ void Joystick::update()
if (!mEnabled || !mCalibrated)
return;
- // X-Axis
- int position = SDL_JoystickGetAxis(mJoystick, 0);
- if (position >= mRightTolerance)
- mDirection |= RIGHT;
- else if (position <= mLeftTolerance)
- mDirection |= LEFT;
-
- // Y-Axis
- position = SDL_JoystickGetAxis(mJoystick, 1);
- if (position <= mUpTolerance)
- mDirection |= UP;
- else if (position >= mDownTolerance)
- mDirection |= DOWN;
-
- // Buttons
- for (int i = 0; i < mButtonsNumber; i++)
- mButtons[i] = (SDL_JoystickGetButton(mJoystick, i) == 1);
+ if (mUseInactive || Client::getInputFocused())
+ {
+ // X-Axis
+ int position = SDL_JoystickGetAxis(mJoystick, 0);
+ if (position >= mRightTolerance)
+ mDirection |= RIGHT;
+ else if (position <= mLeftTolerance)
+ mDirection |= LEFT;
+
+ // Y-Axis
+ position = SDL_JoystickGetAxis(mJoystick, 1);
+ if (position <= mUpTolerance)
+ mDirection |= UP;
+ else if (position >= mDownTolerance)
+ mDirection |= DOWN;
+
+ // Buttons
+ for (int i = 0; i < mButtonsNumber; i++)
+ mButtons[i] = (SDL_JoystickGetButton(mJoystick, i) == 1);
+ }
+ else
+ {
+ for (int i = 0; i < mButtonsNumber; i++)
+ mButtons[i] = false;
+ }
}
void Joystick::startCalibration()
diff --git a/src/joystick.h b/src/joystick.h
index 6a8a1a1b9..16f4b9bd3 100644
--- a/src/joystick.h
+++ b/src/joystick.h
@@ -25,6 +25,9 @@
#include <SDL.h>
+#include <string>
+#include <vector>
+
class Joystick
{
public:
@@ -109,6 +112,9 @@ class Joystick
int getNumber() const
{ return mNumber; }
+ void setUseInactive(bool b)
+ { mUseInactive = b; }
+
protected:
unsigned char mDirection;
bool mButtons[MAX_BUTTONS];
@@ -122,6 +128,7 @@ class Joystick
int mNumber;
bool mCalibrated;
int mButtonsNumber;
+ bool mUseInactive;
/**
* Is joystick support enabled.