summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorewewukek <ewewukek@gmail.com>2024-01-10 23:11:14 +0300
committerFedja Beader <fedja@protonmail.ch>2024-05-14 01:14:04 +0000
commit78f73fbc427d449a9fbfb35461ff22eac309486b (patch)
treee7602d61b2646c624e69fb17cd66882381fd5529 /src/gui/widgets
parent9e3a03079cfa530fd3885e36d3f7214ec2348818 (diff)
downloadmv-78f73fbc427d449a9fbfb35461ff22eac309486b.tar.gz
mv-78f73fbc427d449a9fbfb35461ff22eac309486b.tar.bz2
mv-78f73fbc427d449a9fbfb35461ff22eac309486b.tar.xz
mv-78f73fbc427d449a9fbfb35461ff22eac309486b.zip
Add a slider to joystick settings to set axis tolerance
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/tabs/setup_joystick.cpp36
-rw-r--r--src/gui/widgets/tabs/setup_joystick.h3
2 files changed, 34 insertions, 5 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;
};