summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorewewukek <ewewukek@gmail.com>2024-01-10 23:11:14 +0300
committerewewukek <ewewukek@gmail.com>2024-03-27 13:18:30 +0300
commit55f9902343eff790c420ca3724c02e95664a9d25 (patch)
treee28e36935c70c6f9397f818ed35b6138d36df973
parent531cf122d42900453102862caf94119c60d7f077 (diff)
downloadmanaverse-55f9902343eff790c420ca3724c02e95664a9d25.tar.gz
manaverse-55f9902343eff790c420ca3724c02e95664a9d25.tar.bz2
manaverse-55f9902343eff790c420ca3724c02e95664a9d25.tar.xz
manaverse-55f9902343eff790c420ca3724c02e95664a9d25.zip
Add a slider to joystick settings to set axis tolerance
-rw-r--r--src/gui/widgets/tabs/setup_joystick.cpp36
-rw-r--r--src/gui/widgets/tabs/setup_joystick.h3
-rw-r--r--src/input/joystick.cpp6
-rw-r--r--src/input/joystick.h3
4 files changed, 40 insertions, 8 deletions
diff --git a/src/gui/widgets/tabs/setup_joystick.cpp b/src/gui/widgets/tabs/setup_joystick.cpp
index ab623b901..16c248c48 100644
--- a/src/gui/widgets/tabs/setup_joystick.cpp
+++ b/src/gui/widgets/tabs/setup_joystick.cpp
@@ -35,6 +35,7 @@
#include "gui/widgets/dropdown.h"
#include "gui/widgets/label.h"
#include "gui/widgets/layouthelper.h"
+#include "gui/widgets/slider.h"
#include "utils/delete2.h"
#include "utils/gettext.h"
@@ -58,6 +59,8 @@ Setup_Joystick::Setup_Joystick(const Widget2 *const widget) :
mNamesModel(new NamesModel),
mNamesDropDown(new DropDown(this, mNamesModel,
false, Modal_false, nullptr, std::string())),
+ mToleranceLabel(new Label(this)),
+ mToleranceSlider(new Slider(this, 1000, 32767, 1000)),
mUseInactiveCheckBox(new CheckBox(this,
// TRANSLATORS: joystick settings tab checkbox
_("Use joystick if client window inactive"),
@@ -75,8 +78,17 @@ Setup_Joystick::Setup_Joystick(const Widget2 *const widget) :
mJoystickEnabled->addActionListener(this);
mCalibrateButton->setEnabled(mOriginalJoystickEnabled);
+ int tolerance = config.getIntValue("joystickTolerance");
+ mToleranceSlider->setValue(tolerance);
+ // TRANSLATORS: joystick settings tab label
+ mToleranceLabel->setCaption(_("Axis tolerance: ") + strprintf("%d", tolerance));
+ mToleranceLabel->setWidth(150);
+ mToleranceLabel->setHeight(20);
+
mNamesDropDown->setActionEventId("name");
mNamesDropDown->addActionListener(this);
+ mToleranceSlider->setActionEventId("toleranceslider");
+ mToleranceSlider->addActionListener(this);
if (joystick != nullptr)
{
@@ -96,12 +108,16 @@ Setup_Joystick::Setup_Joystick(const Widget2 *const widget) :
place(0, 0, mJoystickEnabled, 1, 1);
place(0, 1, mNamesDropDown, 1, 1);
- place(0, 2, mUseInactiveCheckBox, 1, 1);
- place(0, 3, mDetectButton, 1, 1);
- place(0, 4, mCalibrateLabel, 1, 1);
- place(0, 5, mCalibrateButton, 1, 1);
- setDimension(Rect(0, 0, 365, 75));
+ place(0, 2, mToleranceSlider, 1, 1);
+ place(1, 2, mToleranceLabel, 1, 1).setPadding(3);
+
+ place(0, 3, mUseInactiveCheckBox, 1, 1);
+ place(0, 4, mDetectButton, 1, 1);
+ place(0, 5, mCalibrateLabel, 1, 1);
+ place(0, 6, mCalibrateButton, 1, 1);
+
+ setDimension(Rect(0, 0, 365, 95));
}
Setup_Joystick::~Setup_Joystick()
@@ -121,6 +137,12 @@ void Setup_Joystick::action(const ActionEvent &event)
if (joystick != nullptr)
joystick->setNumber(mNamesDropDown->getSelected());
}
+ else if (source == mToleranceSlider)
+ {
+ int tolerance = mToleranceSlider->getValue();
+ // TRANSLATORS: joystick settings tab label
+ mToleranceLabel->setCaption(_("Axis tolerance: ") + strprintf("%d", tolerance));
+ }
else if (source == mDetectButton)
{
Joystick::detect();
@@ -188,4 +210,8 @@ void Setup_Joystick::apply()
config.setValue("useInactiveJoystick", mUseInactiveCheckBox->isSelected());
joystick->setUseInactive(mUseInactiveCheckBox->isSelected());
+
+ int tolerance = mToleranceSlider->getValue();
+ config.setValue("joystickTolerance", tolerance);
+ joystick->setTolerance(tolerance);
}
diff --git a/src/gui/widgets/tabs/setup_joystick.h b/src/gui/widgets/tabs/setup_joystick.h
index 174cd82b2..8e347d0f6 100644
--- a/src/gui/widgets/tabs/setup_joystick.h
+++ b/src/gui/widgets/tabs/setup_joystick.h
@@ -31,6 +31,7 @@ class CheckBox;
class DropDown;
class Label;
class NamesModel;
+class Slider;
class Setup_Joystick final : public SetupTab
{
@@ -56,6 +57,8 @@ class Setup_Joystick final : public SetupTab
CheckBox *mJoystickEnabled A_NONNULLPOINTER;
NamesModel *mNamesModel A_NONNULLPOINTER;
DropDown *mNamesDropDown A_NONNULLPOINTER;
+ Label *mToleranceLabel A_NONNULLPOINTER;
+ Slider *mToleranceSlider A_NONNULLPOINTER;
CheckBox *mUseInactiveCheckBox A_NONNULLPOINTER;
bool mOriginalJoystickEnabled A_NONNULLPOINTER;
};
diff --git a/src/input/joystick.cpp b/src/input/joystick.cpp
index 5396adadc..48b4488b0 100644
--- a/src/input/joystick.cpp
+++ b/src/input/joystick.cpp
@@ -198,12 +198,12 @@ bool Joystick::open()
#ifdef __SWITCH__
config.setValue("joystick" + toString(mNumber) + "calibrated", true);
- config.setValue("joystickTolerance" + toString(mNumber), 10000);
+ config.setValue("joystickTolerance", 10000);
#endif
mCalibrated = config.getValueBool("joystick"
+ toString(mNumber) + "calibrated", false);
- mTolerance = config.getIntValue("joystickTolerance" + toString(mNumber));
+ mTolerance = config.getIntValue("joystickTolerance");
mUseInactive = config.getBoolValue("useInactiveJoystick");
return true;
@@ -341,7 +341,7 @@ void Joystick::finishCalibration()
mCalibrated = true;
mCalibrating = false;
config.setValue("joystick" + toString(mNumber) + "calibrated", true);
- config.setValue("joystickTolerance" + toString(mNumber), mTolerance);
+ config.setValue("joystickTolerance", mTolerance);
}
bool Joystick::buttonPressed(const unsigned char no) const
diff --git a/src/input/joystick.h b/src/input/joystick.h
index 3587d1ba0..198b6fe9e 100644
--- a/src/input/joystick.h
+++ b/src/input/joystick.h
@@ -122,6 +122,9 @@ class Joystick final
int getNumber() const noexcept2 A_WARN_UNUSED
{ return mNumber; }
+ void setTolerance(const int tolerance)
+ { mTolerance = tolerance; }
+
void setUseInactive(const bool b)
{ mUseInactive = b; }