From 65e94b56c9b7b0f69911ba37fe1a22f22e9ba09e Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Thu, 27 Nov 2008 21:46:48 +0100 Subject: 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. --- src/joystick.h | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'src/joystick.h') 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 -- cgit v1.2.3-70-g09d2