From 45bd7a8b75ebd8227ec4a09e427a66b1bb2796d1 Mon Sep 17 00:00:00 2001 From: rsn8887 Date: Sun, 19 Feb 2017 20:14:51 -0600 Subject: SDL: Fix erratic analog pointer + control options Fixes erratic speeds in analog pointer motion Implemented option to set analog/keyboard pointer speed and control the analog joystick deadzone. The deadzone option appears only if the build supports analog joystick (via JOY_ANALOG define) --- gui/options.cpp | 119 +++++++++++++++++---- gui/options.h | 9 +- gui/themes/default.inc | 76 ++++++++++--- gui/themes/scummclassic.zip | Bin 127529 -> 128803 bytes gui/themes/scummclassic/classic_layout.stx | 22 ++++ gui/themes/scummclassic/classic_layout_lowres.stx | 22 ++++ gui/themes/scummmodern.zip | Bin 1647069 -> 1648343 bytes gui/themes/scummmodern/scummmodern_layout.stx | 22 ++++ .../scummmodern/scummmodern_layout_lowres.stx | 22 ++++ gui/widgets/tab.cpp | 10 ++ gui/widgets/tab.h | 2 + 11 files changed, 267 insertions(+), 37 deletions(-) (limited to 'gui') diff --git a/gui/options.cpp b/gui/options.cpp index 53fba2f371..955f655f6c 100644 --- a/gui/options.cpp +++ b/gui/options.cpp @@ -78,7 +78,9 @@ enum { kExtraPathClearCmd = 'clex', kChoosePluginsDirCmd = 'chpl', kChooseThemeCmd = 'chtf', - kUpdatesCheckCmd = 'updc' + kUpdatesCheckCmd = 'updc', + kKbdMouseSpeedChanged = 'kmsc', + kJoystickDeadzoneChanged= 'jodc' }; enum { @@ -120,6 +122,8 @@ static const char *savePeriodLabels[] = { _s("Never"), _s("every 5 mins"), _s("e static const int savePeriodValues[] = { 0, 5 * 60, 10 * 60, 15 * 60, 30 * 60, -1 }; static const char *outputRateLabels[] = { _s(""), _s("8 kHz"), _s("11 kHz"), _s("22 kHz"), _s("44 kHz"), _s("48 kHz"), 0 }; static const int outputRateValues[] = { 0, 8000, 11025, 22050, 44100, 48000, -1 }; +static const char *kbdMouseSpeedLabels[] = { _s("3"), _s("5"), _s("8"), _s("10"), _s("13"), _s("15"), _s("18"), _s("20"), 0 }; +static const int kbdMouseSpeedValues[] = { 0, 1, 2, 3, 4, 5, 6, 7, -1 }; OptionsDialog::OptionsDialog(const Common::String &domain, int x, int y, int w, int h) : Dialog(x, y, w, h), _domain(domain), _graphicsTabId(-1), _midiTabId(-1), _pathsTabId(-1), _tabWidget(0) { @@ -140,6 +144,12 @@ void OptionsDialog::init() { _onscreenCheckbox = 0; _touchpadCheckbox = 0; _swapMenuAndBackBtnsCheckbox = 0; + _kbdMouseSpeedDesc = 0; + _kbdMouseSpeedSlider = 0; + _kbdMouseSpeedLabel = 0; + _joystickDeadzoneDesc = 0; + _joystickDeadzoneSlider = 0; + _joystickDeadzoneLabel = 0; _enableGraphicSettings = false; _gfxPopUp = 0; _gfxPopUpDesc = 0; @@ -229,6 +239,24 @@ void OptionsDialog::build() { _swapMenuAndBackBtnsCheckbox->setState(state); } } + if (g_system->hasFeature(OSystem::kFeatureKbdMouseSpeed)) { + if (ConfMan.hasKey("kbdmouse_speed", _domain)) { + int value = ConfMan.getInt("kbdmouse_speed", _domain); + if (_kbdMouseSpeedSlider && value < sizeof(kbdMouseSpeedLabels)) { + _kbdMouseSpeedSlider->setValue(value); + _kbdMouseSpeedLabel->setLabel(kbdMouseSpeedLabels[value]); + } + } + } + if (g_system->hasFeature(OSystem::kFeatureJoystickDeadzone)) { + if (ConfMan.hasKey("joystick_deadzone", _domain)) { + int value = ConfMan.getInt("joystick_deadzone", _domain); + if (_joystickDeadzoneSlider != 0) { + _joystickDeadzoneSlider->setValue(value); + _joystickDeadzoneLabel->setValue(value); + } + } + } // Graphic options if (_fullscreenCheckbox) { @@ -424,6 +452,16 @@ void OptionsDialog::apply() { g_system->setFeatureState(OSystem::kFeatureSwapMenuAndBackButtons, _swapMenuAndBackBtnsCheckbox->getState()); } } + if (g_system->hasFeature(OSystem::kFeatureKbdMouseSpeed)) { + if (ConfMan.getInt("kbdmouse_speed", _domain) != _kbdMouseSpeedSlider->getValue()) { + ConfMan.setInt("kbdmouse_speed", _kbdMouseSpeedSlider->getValue(), _domain); + } + } + if (g_system->hasFeature(OSystem::kFeatureJoystickDeadzone)) { + if (ConfMan.getInt("joystick_deadzone", _domain) != _joystickDeadzoneSlider->getValue()) { + ConfMan.setInt("joystick_deadzone", _joystickDeadzoneSlider->getValue(), _domain); + } + } } // Graphic options @@ -737,6 +775,14 @@ void OptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data _soundFontClearButton->setEnabled(false); draw(); break; + case kKbdMouseSpeedChanged: + _kbdMouseSpeedLabel->setLabel(kbdMouseSpeedLabels[_kbdMouseSpeedSlider->getValue()]); + _kbdMouseSpeedLabel->draw(); + break; + case kJoystickDeadzoneChanged: + _joystickDeadzoneLabel->setValue(_joystickDeadzoneSlider->getValue()); + _joystickDeadzoneLabel->draw(); + break; case kApplyCmd: apply(); break; @@ -878,21 +924,46 @@ void OptionsDialog::setSubtitleSettingsState(bool enabled) { _subSpeedLabel->setEnabled(ena); } - void OptionsDialog::addControlControls(GuiObject *boss, const Common::String &prefix) { - // Show On-Screen control - if (g_system->hasFeature(OSystem::kFeatureOnScreenControl)) - _onscreenCheckbox = new CheckboxWidget(boss, prefix + "grOnScreenCheckbox", _("Show On-screen control")); - - // Touchpad Mouse mode - if (g_system->hasFeature(OSystem::kFeatureTouchpadMode)) - _touchpadCheckbox = new CheckboxWidget(boss, prefix + "grTouchpadCheckbox", _("Touchpad mouse mode")); +void OptionsDialog::addControlControls(GuiObject *boss, const Common::String &prefix) { + // Show On-Screen control + if (g_system->hasFeature(OSystem::kFeatureOnScreenControl)) + _onscreenCheckbox = new CheckboxWidget(boss, prefix + "grOnScreenCheckbox", _("Show On-screen control")); - // Swap menu and back buttons - if (g_system->hasFeature(OSystem::kFeatureSwapMenuAndBackButtons)) - _swapMenuAndBackBtnsCheckbox = new CheckboxWidget(boss, prefix + "grSwapMenuAndBackBtnsCheckbox", _("Swap Menu and Back buttons")); - - _enableControlSettings = true; - } + // Touchpad Mouse mode + if (g_system->hasFeature(OSystem::kFeatureTouchpadMode)) + _touchpadCheckbox = new CheckboxWidget(boss, prefix + "grTouchpadCheckbox", _("Touchpad mouse mode")); + + // Swap menu and back buttons + if (g_system->hasFeature(OSystem::kFeatureSwapMenuAndBackButtons)) + _swapMenuAndBackBtnsCheckbox = new CheckboxWidget(boss, prefix + "grSwapMenuAndBackBtnsCheckbox", _("Swap Menu and Back buttons")); + + // Keyboard and joystick mouse speed + if (g_system->hasFeature(OSystem::kFeatureKbdMouseSpeed)) { + if (g_system->getOverlayWidth() > 320) + _kbdMouseSpeedDesc = new StaticTextWidget(boss, prefix + "grKbdMouseSpeedDesc", _("Mouse Speed:"), _("Speed multiplier for mouse emulation")); + else + _kbdMouseSpeedDesc = new StaticTextWidget(boss, prefix + "grKbdMouseSpeedDesc", _c("Mouse Speed:", "lowres"), _("Speed multiplier for mouse emulation")); + _kbdMouseSpeedSlider = new SliderWidget(boss, prefix + "grKbdMouseSpeedSlider", _("Speed multiplier for mouse emulation"), kKbdMouseSpeedChanged); + _kbdMouseSpeedLabel = new StaticTextWidget(boss, prefix + "grKbdMouseSpeedLabel", " "); + _kbdMouseSpeedSlider->setMinValue(0); + _kbdMouseSpeedSlider->setMaxValue(7); + _kbdMouseSpeedLabel->setFlags(WIDGET_CLEARBG); + } + + // Joystick deadzone + if (g_system->hasFeature(OSystem::kFeatureJoystickDeadzone)) { + if (g_system->getOverlayWidth() > 320) + _joystickDeadzoneDesc = new StaticTextWidget(boss, prefix + "grJoystickDeadzoneDesc", _("Joy Deadzone:"), _("Analog Joystick Deadzone")); + else + _joystickDeadzoneDesc = new StaticTextWidget(boss, prefix + "grJoystickDeadzoneDesc", _c("Joy Deadzone:", "lowres"), _("Analog Joystick Deadzone")); + _joystickDeadzoneSlider = new SliderWidget(boss, prefix + "grJoystickDeadzoneSlider", _("Analog Joystick Deadzone"), kJoystickDeadzoneChanged); + _joystickDeadzoneLabel = new StaticTextWidget(boss, prefix + "grJoystickDeadzoneLabel", " "); + _joystickDeadzoneSlider->setMinValue(1); + _joystickDeadzoneSlider->setMaxValue(10); + _joystickDeadzoneLabel->setFlags(WIDGET_CLEARBG); + } + _enableControlSettings = true; +} void OptionsDialog::addGraphicControls(GuiObject *boss, const Common::String &prefix) { const OSystem::GraphicsMode *gm = g_system->getSupportedGraphicsModes(); @@ -1343,14 +1414,16 @@ void GlobalOptionsDialog::build() { TabWidget *tab = new TabWidget(this, "GlobalOptions.TabWidget"); // - // The control tab (currently visible only for AndroidSDL platform, visibility checking by features + // The control tab (currently visible only for AndroidSDL, SDL, and Vita platform, visibility checking by features // if (g_system->hasFeature(OSystem::kFeatureTouchpadMode) || g_system->hasFeature(OSystem::kFeatureOnScreenControl) || - g_system->hasFeature(OSystem::kFeatureSwapMenuAndBackButtons)) { + g_system->hasFeature(OSystem::kFeatureSwapMenuAndBackButtons) || + g_system->hasFeature(OSystem::kFeatureKbdMouseSpeed) || + g_system->hasFeature(OSystem::kFeatureJoystickDeadzone)) { tab->addTab(_("Control")); addControlControls(tab, "GlobalOptions_Control."); - } + } // // 1) The graphics tab @@ -1927,8 +2000,14 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 #ifdef USE_LIBCURL case kPopUpItemSelectedCmd: { - //update container's scrollbar - reflowLayout(); + //update container's scrollbar and make sure tabs are not re-arranged + if (_tabWidget) { + int oldFirstVisible = _tabWidget->getFirstVisible(); + reflowLayout(); + _tabWidget->setFirstVisible(oldFirstVisible); + } else { + reflowLayout(); + } break; } case kConfigureStorageCmd: diff --git a/gui/options.h b/gui/options.h index 6b6cb92378..2f628315e4 100644 --- a/gui/options.h +++ b/gui/options.h @@ -123,7 +123,14 @@ private: CheckboxWidget *_touchpadCheckbox; CheckboxWidget *_onscreenCheckbox; CheckboxWidget *_swapMenuAndBackBtnsCheckbox; - + + StaticTextWidget *_kbdMouseSpeedDesc; + SliderWidget *_kbdMouseSpeedSlider; + StaticTextWidget *_kbdMouseSpeedLabel; + StaticTextWidget *_joystickDeadzoneDesc; + SliderWidget *_joystickDeadzoneSlider; + StaticTextWidget *_joystickDeadzoneLabel; + // // Graphics controls // diff --git a/gui/themes/default.inc b/gui/themes/default.inc index d8baae8d0e..f967067adc 100644 --- a/gui/themes/default.inc +++ b/gui/themes/default.inc @@ -813,17 +813,39 @@ const char *defaultXML1 = "" "" "" "" -"" -"" -"" +"" +"" -"" -"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" "" "" "" @@ -2368,17 +2390,39 @@ const char *defaultXML1 = "" "" "" "" -"" -"" -"" +"" +"" -"" -"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" "" "" "" diff --git a/gui/themes/scummclassic.zip b/gui/themes/scummclassic.zip index d90289a4be..e84768b497 100644 Binary files a/gui/themes/scummclassic.zip and b/gui/themes/scummclassic.zip differ diff --git a/gui/themes/scummclassic/classic_layout.stx b/gui/themes/scummclassic/classic_layout.stx index aa91cdb35f..75ffee20cd 100644 --- a/gui/themes/scummclassic/classic_layout.stx +++ b/gui/themes/scummclassic/classic_layout.stx @@ -249,6 +249,28 @@ + + + + + + + + + + diff --git a/gui/themes/scummclassic/classic_layout_lowres.stx b/gui/themes/scummclassic/classic_layout_lowres.stx index c925a39d18..e46db3e94b 100644 --- a/gui/themes/scummclassic/classic_layout_lowres.stx +++ b/gui/themes/scummclassic/classic_layout_lowres.stx @@ -246,6 +246,28 @@ + + + + + + + + + + diff --git a/gui/themes/scummmodern.zip b/gui/themes/scummmodern.zip index f10102503e..ed1e3c0c58 100644 Binary files a/gui/themes/scummmodern.zip and b/gui/themes/scummmodern.zip differ diff --git a/gui/themes/scummmodern/scummmodern_layout.stx b/gui/themes/scummmodern/scummmodern_layout.stx index 80b913a3a4..754bc251d9 100644 --- a/gui/themes/scummmodern/scummmodern_layout.stx +++ b/gui/themes/scummmodern/scummmodern_layout.stx @@ -263,6 +263,28 @@ + + + + + + + + + + diff --git a/gui/themes/scummmodern/scummmodern_layout_lowres.stx b/gui/themes/scummmodern/scummmodern_layout_lowres.stx index 308ba44b7e..eadb305414 100644 --- a/gui/themes/scummmodern/scummmodern_layout_lowres.stx +++ b/gui/themes/scummmodern/scummmodern_layout_lowres.stx @@ -244,6 +244,28 @@ + + + + + + + + + + diff --git a/gui/widgets/tab.cpp b/gui/widgets/tab.cpp index cf9dd5d962..8e8c6b48a1 100644 --- a/gui/widgets/tab.cpp +++ b/gui/widgets/tab.cpp @@ -277,6 +277,16 @@ void TabWidget::adjustTabs(int value) { setActiveTab(tabID); } +int TabWidget::getFirstVisible() { + return _firstVisibleTab; +} + +void TabWidget::setFirstVisible(int tabID) { + assert(0 <= tabID && tabID < (int)_tabs.size()); + _firstVisibleTab = tabID; + _boss->draw(); +} + void TabWidget::reflowLayout() { Widget::reflowLayout(); diff --git a/gui/widgets/tab.h b/gui/widgets/tab.h index 17b85986b5..4516c3c831 100644 --- a/gui/widgets/tab.h +++ b/gui/widgets/tab.h @@ -101,6 +101,8 @@ public: virtual void handleMouseDown(int x, int y, int button, int clickCount); virtual bool handleKeyDown(Common::KeyState state); virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); + virtual int getFirstVisible(); + virtual void setFirstVisible(int tabID); virtual void reflowLayout(); -- cgit v1.2.3