summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--src/gui/setup.cpp4
-rw-r--r--src/gui/setup_joystick.cpp57
-rw-r--r--src/gui/setup_joystick.h6
-rw-r--r--src/gui/setup_video.cpp78
-rw-r--r--src/gui/setup_video.h16
-rw-r--r--src/joystick.cpp20
-rw-r--r--src/joystick.h39
8 files changed, 190 insertions, 40 deletions
diff --git a/ChangeLog b/ChangeLog
index a886518b..a6f5e4ab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2006-08-26 Pascal Ganaye <pascalganaye@users.sourceforge.net>
+
+ * src/joystick.h, src/joystick.cpp, src/gui/setup.cpp,
+ src/gui/setup_joystick.h, src/gui/setup_video.cpp,
+ src/gui/setup_joystick.cpp, src/gui/setup_video.h: Added sliders to
+ the video section of the setup window to configure the laziness and
+ radius of the scrolling behaviour. Added a checkbox to the joystick
+ section to allow enabling/disabling the joystick (patch applied by
+ Bjørn Lindeijer).
+
2006-08-26 Bjørn Lindeijer <bjorn@lindeijer.nl>
* src/gui/ministatus.cpp, src/gui/ministatus.h: Applied patch by mrha
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index 73b22e5a..1fe22ea6 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -43,7 +43,7 @@ Setup::Setup():
Window("Setup")
{
int width = 230;
- int height = 185;
+ int height = 225;
setContentSize(width, height);
const char *buttonNames[] = {
@@ -58,7 +58,7 @@ Setup::Setup():
}
TabbedContainer *panel = new TabbedContainer();
- panel->setDimension(gcn::Rectangle(5, 5, 220, 150));
+ panel->setDimension(gcn::Rectangle(5, 5, 220, 185));
panel->setOpaque(false);
SetupTab *tab;
diff --git a/src/gui/setup_joystick.cpp b/src/gui/setup_joystick.cpp
index 36b0ee20..d9212728 100644
--- a/src/gui/setup_joystick.cpp
+++ b/src/gui/setup_joystick.cpp
@@ -26,22 +26,31 @@
#include <guichan/widgets/label.hpp>
#include "button.h"
-
+#include "checkbox.h"
+#include "../configuration.h"
#include "../joystick.h"
extern Joystick *joystick;
Setup_Joystick::Setup_Joystick():
mCalibrateLabel(new gcn::Label("Press the button to start calibration")),
- mCalibrateButton(new Button("Calibrate", "calibrate", this))
+ mCalibrateButton(new Button("Calibrate", "calibrate", this)),
+ mJoystickEnabled(new CheckBox("Enable joystick"))
{
setOpaque(false);
+ mJoystickEnabled->setPosition(10, 10);
+ mCalibrateLabel->setPosition(10, 25);
+ mCalibrateButton->setPosition(10, 30 + mCalibrateLabel->getHeight());
+
+ mOriginalJoystickEnabled = (joystick ? joystick->isEnabled() : false);
+ mJoystickEnabled->setMarked(mOriginalJoystickEnabled);
- mCalibrateLabel->setPosition(5, 10);
- mCalibrateButton->setPosition(10, 20 + mCalibrateLabel->getHeight());
+ mJoystickEnabled->setEventId("joystickEnabled");
+ mJoystickEnabled->addActionListener(this);
add(mCalibrateLabel);
add(mCalibrateButton);
+ add(mJoystickEnabled);
}
void Setup_Joystick::action(const std::string &event, gcn::Widget *widget)
@@ -50,13 +59,37 @@ void Setup_Joystick::action(const std::string &event, gcn::Widget *widget)
return;
}
- if (joystick->isCalibrating()) {
- mCalibrateButton->setCaption("Calibrate");
- mCalibrateLabel->setCaption("Press the button to start calibration");
- joystick->finishCalibration();
- } else {
- mCalibrateButton->setCaption("Stop");
- mCalibrateLabel->setCaption("Rotate the stick");
- joystick->startCalibration();
+ if (event == "joystickEnabled")
+ {
+ joystick->setEnabled(mJoystickEnabled->isMarked());
+ }
+ else
+ {
+ if (joystick->isCalibrating()) {
+ mCalibrateButton->setCaption("Calibrate");
+ mCalibrateLabel->setCaption(
+ "Press the button to start calibration");
+ joystick->finishCalibration();
+ } else {
+ mCalibrateButton->setCaption("Stop");
+ mCalibrateLabel->setCaption("Rotate the stick");
+ joystick->startCalibration();
+ }
}
}
+
+void Setup_Joystick::cancel()
+{
+ if (joystick)
+ {
+ joystick->setEnabled(mOriginalJoystickEnabled);
+ }
+ mJoystickEnabled->setMarked(mOriginalJoystickEnabled);
+}
+
+void Setup_Joystick::apply()
+{
+ config.setValue("joystickEnabled",
+ joystick ? joystick->isEnabled() : false);
+}
+
diff --git a/src/gui/setup_joystick.h b/src/gui/setup_joystick.h
index da773c8f..4cc2b3d9 100644
--- a/src/gui/setup_joystick.h
+++ b/src/gui/setup_joystick.h
@@ -35,14 +35,16 @@ class Setup_Joystick : public SetupTab, public gcn::ActionListener
public:
Setup_Joystick();
- void apply() {}
- void cancel() {}
+ void apply();
+ void cancel();
void action(const std::string& eventId, gcn::Widget* widget);
private:
gcn::Label *mCalibrateLabel;
gcn::Button *mCalibrateButton;
+ bool mOriginalJoystickEnabled;
+ gcn::CheckBox *mJoystickEnabled;
};
#endif
diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp
index 9eb94520..fc2c0c78 100644
--- a/src/gui/setup_video.cpp
+++ b/src/gui/setup_video.cpp
@@ -114,7 +114,13 @@ Setup_Video::Setup_Video():
mAlphaSlider(new Slider(0.2, 1.0)),
mFpsCheckBox(new CheckBox("FPS Limit: ")),
mFpsSlider(new Slider(10, 200)),
- mFpsField(new TextField())
+ mFpsField(new TextField()),
+ mOriginalScrollLaziness((int) config.getValue("ScrollLaziness", 0)),
+ mScrollLazinessSlider(new Slider(0, 100)),
+ mScrollLazinessField(new TextField()),
+ mOriginalScrollRadius((int) config.getValue("ScrollRadius", 0)),
+ mScrollRadiusSlider(new Slider(0, 100)),
+ mScrollRadiusField(new TextField())
{
setOpaque(false);
@@ -152,12 +158,36 @@ Setup_Video::Setup_Video():
mAlphaSlider->setEventId("guialpha");
mFpsCheckBox->setEventId("fpslimitcheckbox");
mFpsSlider->setEventId("fpslimitslider");
+ mScrollRadiusSlider->setEventId("scrollradiusslider");
+ mScrollRadiusField->setEventId("scrollradiusfield");
+ mScrollLazinessSlider->setEventId("scrolllazinessslider");
+ mScrollLazinessField->setEventId("scrolllazinessfield");
mCustomCursorCheckBox->addActionListener(this);
mAlphaSlider->addActionListener(this);
mFpsCheckBox->addActionListener(this);
mFpsSlider->addActionListener(this);
mFpsField->addKeyListener(this);
+ mScrollRadiusSlider->addActionListener(this);
+ mScrollRadiusField->addKeyListener(this);
+ mScrollLazinessSlider->addActionListener(this);
+ mScrollLazinessField->addKeyListener(this);
+
+ mScrollRadiusSlider->setDimension(gcn::Rectangle(10, 120, 75, 10));
+ gcn::Label *scrollRadiusLabel = new gcn::Label("Scroll radius");
+ scrollRadiusLabel->setPosition(90, 120);
+ mScrollRadiusField->setPosition(180, 120);
+ mScrollRadiusField->setWidth(30);
+ mScrollRadiusField->setText(toString(mOriginalScrollRadius));
+ mScrollRadiusSlider->setValue(mOriginalScrollRadius);
+
+ mScrollLazinessSlider->setDimension(gcn::Rectangle(10, 140, 75, 10));
+ gcn::Label *scrollLazinessLabel = new gcn::Label("Scroll laziness");
+ scrollLazinessLabel->setPosition(90, 140);
+ mScrollLazinessField->setPosition(180, 140);
+ mScrollLazinessField->setWidth(30);
+ mScrollLazinessField->setText(toString(mOriginalScrollLaziness));
+ mScrollLazinessSlider->setValue(mOriginalScrollLaziness);
add(scrollArea);
add(mFsCheckBox);
@@ -168,6 +198,12 @@ Setup_Video::Setup_Video():
add(mFpsCheckBox);
add(mFpsSlider);
add(mFpsField);
+ add(mScrollRadiusSlider);
+ add(scrollRadiusLabel);
+ add(mScrollRadiusField);
+ add(mScrollLazinessSlider);
+ add(scrollLazinessLabel);
+ add(mScrollLazinessField);
}
Setup_Video::~Setup_Video()
@@ -224,6 +260,27 @@ void Setup_Video::apply()
mOpenGLEnabled = config.getValue("opengl", 0);
}
+int
+Setup_Video::updateSlider(gcn::Slider *slider, gcn::TextField *field,
+ const std::string &configName)
+{
+ int value;
+ std::stringstream temp(field->getText());
+ temp >> value;
+ if (value < slider->getScaleStart())
+ {
+ value = (int) slider->getScaleStart();
+ }
+ else if (value > slider->getScaleEnd())
+ {
+ value = (int) slider->getScaleEnd();
+ }
+ field->setText(toString(value));
+ slider->setValue(value);
+ config.setValue(configName, value);
+ return value;
+}
+
void Setup_Video::cancel()
{
mFsCheckBox->setMarked(mFullScreenEnabled);
@@ -231,6 +288,11 @@ void Setup_Video::cancel()
mCustomCursorCheckBox->setMarked(mCustomCursorEnabled);
mAlphaSlider->setValue(mOpacity);
+ mScrollRadiusField->setText(toString(mOriginalScrollRadius));
+ mScrollLazinessField->setText(toString(mOriginalScrollLaziness));
+ updateSlider(mScrollRadiusSlider, mScrollRadiusField, "ScrollRadius");
+ updateSlider(mScrollLazinessSlider, mScrollLazinessField, "ScrollLaziness");
+
config.setValue("screen", mFullScreenEnabled ? 1 : 0);
config.setValue("customcursor", mCustomCursorEnabled ? 1 : 0);
config.setValue("guialpha", mOpacity);
@@ -253,6 +315,18 @@ void Setup_Video::action(const std::string &event, gcn::Widget *widget)
mFps = (int)mFpsSlider->getValue();
mFpsField->setText(toString(mFps));
}
+ else if (event == "scrollradiusslider")
+ {
+ int val = (int)mScrollRadiusSlider->getValue();
+ mScrollRadiusField->setText(toString(val));
+ config.setValue("ScrollRadius", val);
+ }
+ else if (event == "scrolllazinessslider")
+ {
+ int val = (int)mScrollLazinessSlider->getValue();
+ mScrollLazinessField->setText(toString(val));
+ config.setValue("ScrollLaziness", val);
+ }
else if (event == "fpslimitcheckbox")
{
if (mFpsCheckBox->isMarked())
@@ -292,4 +366,6 @@ void Setup_Video::keyPress(const gcn::Key &key)
mFpsField->setText("");
mFps = 0;
}
+ updateSlider(mScrollRadiusSlider, mScrollRadiusField, "ScrollRadius");
+ updateSlider(mScrollLazinessSlider, mScrollLazinessField, "ScrollLaziness");
}
diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h
index 9aef8834..3b5c00a5 100644
--- a/src/gui/setup_video.h
+++ b/src/gui/setup_video.h
@@ -59,10 +59,26 @@ class Setup_Video : public SetupTab, public gcn::ActionListener,
gcn::CheckBox *mFsCheckBox;
gcn::CheckBox *mOpenGLCheckBox;
gcn::CheckBox *mCustomCursorCheckBox;
+
gcn::Slider *mAlphaSlider;
gcn::CheckBox *mFpsCheckBox;
gcn::Slider *mFpsSlider;
gcn::TextField *mFpsField;
+
+ int mOriginalScrollLaziness;
+ gcn::Slider *mScrollLazinessSlider;
+ gcn::TextField *mScrollLazinessField;
+
+ int mOriginalScrollRadius;
+ gcn::Slider *mScrollRadiusSlider;
+ gcn::TextField *mScrollRadiusField;
+
+ void
+ updateSliders(bool originalValues);
+
+ int
+ updateSlider(gcn::Slider *slider, gcn::TextField *field,
+ const std::string &configName);
};
#endif
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;
}
diff --git a/src/joystick.h b/src/joystick.h
index ebdfabeb..f0759add 100644
--- a/src/joystick.h
+++ b/src/joystick.h
@@ -30,12 +30,12 @@ class Joystick
{
public:
/**
- * Number of buttons we can handle
+ * Number of buttons we can handle.
*/
static const unsigned char MAX_BUTTONS = 6;
/**
- * Directions, to be used as bitmask values
+ * Directions, to be used as bitmask values.
*/
static const char UP = 1;
static const char DOWN = 2;
@@ -43,12 +43,12 @@ class Joystick
static const char RIGHT = 8;
/**
- * Initializes the joystick subsystem
+ * Initializes the joystick subsystem.
*/
static void init();
/**
- * Returns the number of available joysticks
+ * Returns the number of available joysticks.
*/
static int getNumberOfJoysticks() { return joystickCount; }
@@ -60,21 +60,33 @@ class Joystick
~Joystick();
+ bool
+ isEnabled() const { return mEnabled; }
+
+ void
+ setEnabled(bool enabled) { mEnabled = enabled; }
+
/**
* Updates the direction and button information.
*/
- void update();
+ void
+ update();
+
+ void
+ startCalibration();
+
+ void
+ finishCalibration();
- void startCalibration();
- void finishCalibration();
- bool isCalibrating() { return mCalibrating; };
+ bool
+ isCalibrating() const { return mCalibrating; }
- bool buttonPressed(unsigned char no);
+ bool buttonPressed(unsigned char no) const;
- bool isUp() { return mDirection & UP; };
- bool isDown() { return mDirection & DOWN; };
- bool isLeft() { return mDirection & LEFT; };
- bool isRight() { return mDirection & RIGHT; };
+ bool isUp() const { return mDirection & UP; };
+ bool isDown() const { return mDirection & DOWN; };
+ bool isLeft() const { return mDirection & LEFT; };
+ bool isRight() const { return mDirection & RIGHT; };
protected:
unsigned char mDirection;
@@ -83,6 +95,7 @@ class Joystick
int mUpTolerance, mDownTolerance, mLeftTolerance, mRightTolerance;
bool mCalibrating;
+ bool mEnabled;
static int joystickCount;