summaryrefslogtreecommitdiff
path: root/src/joystick.h
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2008-11-27 21:46:48 +0100
committerBjørn Lindeijer <bjorn@lindeijer.nl>2008-11-27 21:47:49 +0100
commit65e94b56c9b7b0f69911ba37fe1a22f22e9ba09e (patch)
treec4037f2e53442107f4b421d23db5625559755df8 /src/joystick.h
parent8ca7a933eb5d2b900ceb11fd8008941d59566666 (diff)
downloadmana-65e94b56c9b7b0f69911ba37fe1a22f22e9ba09e.tar.gz
mana-65e94b56c9b7b0f69911ba37fe1a22f22e9ba09e.tar.bz2
mana-65e94b56c9b7b0f69911ba37fe1a22f22e9ba09e.tar.xz
mana-65e94b56c9b7b0f69911ba37fe1a22f22e9ba09e.zip
Make sure to initialize joystick enabled state
Joystick enabled state could end up uninitialized on unsuccesfully trying to open a joystick. In addition, the enabled state wasn't actually used in the accessor methods for the joystick buttons.
Diffstat (limited to 'src/joystick.h')
-rw-r--r--src/joystick.h35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/joystick.h b/src/joystick.h
index 4cc1babd..ee029915 100644
--- a/src/joystick.h
+++ b/src/joystick.h
@@ -35,7 +35,12 @@ class Joystick
/**
* Directions, to be used as bitmask values.
*/
- enum { UP = 1, DOWN = 2, LEFT = 4, RIGHT = 8 };
+ enum {
+ UP = 1,
+ DOWN = 2,
+ LEFT = 4,
+ RIGHT = 8
+ };
/**
* Initializes the joystick subsystem.
@@ -55,33 +60,27 @@ class Joystick
~Joystick();
- bool
- isEnabled() const { return mEnabled; }
+ bool isEnabled() const { return mEnabled; }
- void
- setEnabled(bool enabled) { mEnabled = enabled; }
+ void setEnabled(bool enabled) { mEnabled = enabled; }
/**
* Updates the direction and button information.
*/
- void
- update();
+ void update();
- void
- startCalibration();
+ void startCalibration();
- void
- finishCalibration();
+ void finishCalibration();
- bool
- isCalibrating() const { return mCalibrating; }
+ bool isCalibrating() const { return mCalibrating; }
bool buttonPressed(unsigned char no) const;
- bool isUp() const { return mDirection & UP; };
- bool isDown() const { return mDirection & DOWN; };
- bool isLeft() const { return mDirection & LEFT; };
- bool isRight() const { return mDirection & RIGHT; };
+ bool isUp() const { return mEnabled && (mDirection & UP); };
+ bool isDown() const { return mEnabled && (mDirection & DOWN); };
+ bool isLeft() const { return mEnabled && (mDirection & LEFT); };
+ bool isRight() const { return mEnabled && (mDirection & RIGHT); };
protected:
unsigned char mDirection;
@@ -97,4 +96,4 @@ class Joystick
void doCalibration();
};
-#endif
+#endif // _TMW_JOYSTICK_H