From be3b639a879a5a8eb73b2e652683da222796af44 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sat, 26 Aug 2006 20:19:39 +0000 Subject: Applied patch by Pascal, adding sliders to configure the scrolling behaviour and a checkbox to enable or disable the joystick. --- src/joystick.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/joystick.cpp') diff --git a/src/joystick.cpp b/src/joystick.cpp index bb6e887b..a5dab4f4 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -59,10 +59,11 @@ Joystick::Joystick(int no): logger->log("Hats: %i", SDL_JoystickNumHats(mJoystick)); logger->log("Buttons: %i", SDL_JoystickNumButtons(mJoystick)); - mUpTolerance = (int)config.getValue("upTolerance", 100); - mDownTolerance = (int)config.getValue("downTolerance", 100); - mLeftTolerance = (int)config.getValue("leftTolerance", 100); - mRightTolerance = (int)config.getValue("rightTolerance", 100); + mEnabled = (int) config.getValue("joystickEnabled", 0) != 0; + mUpTolerance = (int) config.getValue("upTolerance", 100); + mDownTolerance = (int) config.getValue("downTolerance", 100); + mLeftTolerance = (int) config.getValue("leftTolerance", 100); + mRightTolerance = (int) config.getValue("rightTolerance", 100); } Joystick::~Joystick() @@ -73,6 +74,7 @@ Joystick::~Joystick() void Joystick::update() { mDirection = 0; + SDL_JoystickUpdate(); // When calibrating, don't bother the outside with our state @@ -81,6 +83,8 @@ void Joystick::update() return; }; + if (!mEnabled) return; + // X-Axis int position = SDL_JoystickGetAxis(mJoystick, 0); if (position >= mRightTolerance) @@ -144,7 +148,6 @@ void Joystick::doCalibration() } } - void Joystick::finishCalibration() { config.setValue("leftTolerance", mLeftTolerance); @@ -154,10 +157,7 @@ void Joystick::finishCalibration() mCalibrating = false; } -bool Joystick::buttonPressed(unsigned char no) +bool Joystick::buttonPressed(unsigned char no) const { - if (no > MAX_BUTTONS) - return false; - - return mButtons[no]; + return (no < MAX_BUTTONS) ? mButtons[no] : false; } -- cgit v1.2.3-70-g09d2