summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorewewukek <ewewukek@gmail.com>2024-01-10 23:26:42 +0300
committerewewukek <ewewukek@gmail.com>2024-03-27 13:18:30 +0300
commit7c6feeb44a614985ea957c5ca431e331fd41d216 (patch)
tree6d8882113443407975c5af9ce22a90c6bd972fd6 /src
parent9802c54b0a5094d5f118a2a21d1518fa8fe245b8 (diff)
downloadmanaverse-7c6feeb44a614985ea957c5ca431e331fd41d216.tar.gz
manaverse-7c6feeb44a614985ea957c5ca431e331fd41d216.tar.bz2
manaverse-7c6feeb44a614985ea957c5ca431e331fd41d216.tar.xz
manaverse-7c6feeb44a614985ea957c5ca431e331fd41d216.zip
Switch joystick axis tolerance type to float
Diffstat (limited to 'src')
-rw-r--r--src/defaults.cpp2
-rw-r--r--src/gui/widgets/tabs/setup_joystick.cpp14
-rw-r--r--src/input/joystick.cpp12
-rw-r--r--src/input/joystick.h13
4 files changed, 26 insertions, 15 deletions
diff --git a/src/defaults.cpp b/src/defaults.cpp
index 30c5f3caf..462a278c3 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -194,7 +194,7 @@ void setConfigDefaults(Configuration &cfg)
#else
AddDEF("joystickEnabled", false);
#endif
- AddDEF("joystickTolerance", 10000);
+ AddDEF("joystickTolerance", 0.1F);
AddDEF("logNpcInGui", true);
AddDEF("download-music", true);
AddDEF("guialpha", 0.8F);
diff --git a/src/gui/widgets/tabs/setup_joystick.cpp b/src/gui/widgets/tabs/setup_joystick.cpp
index 3542f39a5..c7ece8c7a 100644
--- a/src/gui/widgets/tabs/setup_joystick.cpp
+++ b/src/gui/widgets/tabs/setup_joystick.cpp
@@ -54,7 +54,7 @@ Setup_Joystick::Setup_Joystick(const Widget2 *const widget) :
mNamesDropDown(new DropDown(this, mNamesModel,
false, Modal_false, nullptr, std::string())),
mToleranceLabel(new Label(this)),
- mToleranceSlider(new Slider(this, 1000, 32767, 1000)),
+ mToleranceSlider(new Slider(this, 0.01, 1, 0.01)),
mUseInactiveCheckBox(new CheckBox(this,
// TRANSLATORS: joystick settings tab checkbox
_("Use joystick if client window inactive"),
@@ -71,10 +71,11 @@ Setup_Joystick::Setup_Joystick(const Widget2 *const widget) :
mJoystickEnabled->setActionEventId("joystick");
mJoystickEnabled->addActionListener(this);
- int tolerance = config.getIntValue("joystickTolerance");
+ float tolerance = config.getFloatValue("joystickTolerance");
mToleranceSlider->setValue(tolerance);
// TRANSLATORS: joystick settings tab label
- mToleranceLabel->setCaption(_("Axis tolerance: ") + strprintf("%d", tolerance));
+ mToleranceLabel->setCaption(_("Axis tolerance: ")
+ + strprintf("%.2f", tolerance));
mToleranceLabel->setWidth(150);
mToleranceLabel->setHeight(20);
@@ -130,9 +131,10 @@ void Setup_Joystick::action(const ActionEvent &event)
}
else if (source == mToleranceSlider)
{
- int tolerance = mToleranceSlider->getValue();
+ float tolerance = mToleranceSlider->getValue();
// TRANSLATORS: joystick settings tab label
- mToleranceLabel->setCaption(_("Axis tolerance: ") + strprintf("%d", tolerance));
+ mToleranceLabel->setCaption(_("Axis tolerance: ")
+ + strprintf("%.2f", tolerance));
}
else if (source == mDetectButton)
{
@@ -177,7 +179,7 @@ void Setup_Joystick::apply()
config.setValue("useInactiveJoystick", mUseInactiveCheckBox->isSelected());
joystick->setUseInactive(mUseInactiveCheckBox->isSelected());
- int tolerance = mToleranceSlider->getValue();
+ float tolerance = mToleranceSlider->getValue();
config.setValue("joystickTolerance", tolerance);
joystick->setTolerance(tolerance);
}
diff --git a/src/input/joystick.cpp b/src/input/joystick.cpp
index 4bcb070d3..0ab6102c5 100644
--- a/src/input/joystick.cpp
+++ b/src/input/joystick.cpp
@@ -195,9 +195,9 @@ bool Joystick::open()
mButtonsNumber = MAX_BUTTONS;
#ifdef __SWITCH__
- config.setValue("joystickTolerance", 10000);
+ config.setValue("joystickTolerance", 0.1F);
#endif
- mTolerance = config.getIntValue("joystickTolerance");
+ mTolerance = config.getFloatValue("joystickTolerance");
mUseInactive = config.getBoolValue("useInactiveJoystick");
return true;
@@ -243,16 +243,16 @@ void Joystick::logic()
{
// X-Axis
int position = SDL_JoystickGetAxis(mJoystick, 0);
- if (position >= mTolerance)
+ if (position >= mTolerance * SDL_JOYSTICK_AXIS_MAX)
mDirection |= RIGHT;
- else if (position <= -mTolerance)
+ else if (position <= mTolerance * SDL_JOYSTICK_AXIS_MIN)
mDirection |= LEFT;
// Y-Axis
position = SDL_JoystickGetAxis(mJoystick, 1);
- if (position <= -mTolerance)
+ if (position <= mTolerance * SDL_JOYSTICK_AXIS_MIN)
mDirection |= UP;
- else if (position >= mTolerance)
+ else if (position >= mTolerance * SDL_JOYSTICK_AXIS_MAX)
mDirection |= DOWN;
#ifdef DEBUG_JOYSTICK
diff --git a/src/input/joystick.h b/src/input/joystick.h
index d90420395..32fdddf2e 100644
--- a/src/input/joystick.h
+++ b/src/input/joystick.h
@@ -31,6 +31,15 @@ PRAGMA48(GCC diagnostic ignored "-Wshadow")
#include <SDL_events.h>
PRAGMA48(GCC diagnostic pop)
+// defined first in SDL 2.0.6
+// not available on older distros
+#ifndef SDL_JOYSTICK_AXIS_MIN
+#define SDL_JOYSTICK_AXIS_MIN -32768
+#endif
+#ifndef SDL_JOYSTICK_AXIS_MAX
+#define SDL_JOYSTICK_AXIS_MAX 32767
+#endif
+
class Joystick final
{
public:
@@ -115,7 +124,7 @@ class Joystick final
int getNumber() const noexcept2 A_WARN_UNUSED
{ return mNumber; }
- void setTolerance(const int tolerance)
+ void setTolerance(const float tolerance)
{ mTolerance = tolerance; }
void setUseInactive(const bool b)
@@ -144,7 +153,7 @@ class Joystick final
SDL_Joystick *mJoystick;
- int mTolerance;
+ float mTolerance;
int mNumber;
int mButtonsNumber;
bool mUseInactive;