make controller repeats configurable in UIDialog

This commit is contained in:
Thomas Jentzsch 2019-08-10 17:45:50 +02:00
parent ce10108660
commit 1ecf55ffc0
6 changed files with 156 additions and 49 deletions

View File

@ -108,6 +108,15 @@ void EventHandler::initialize()
// Set number of lines a mousewheel will scroll // Set number of lines a mousewheel will scroll
ScrollBarWidget::setWheelLines(myOSystem.settings().getInt("mwheel")); ScrollBarWidget::setWheelLines(myOSystem.settings().getInt("mwheel"));
// Mouse double click
DialogContainer::setDoubleClickDelay(myOSystem.settings().getInt("mdouble"));
// Input delay
DialogContainer::setControllerDelay(myOSystem.settings().getInt("inpDelay"));
// Input rate
DialogContainer::setControllerRate(myOSystem.settings().getInt("inpRate"));
#endif #endif
// Integer to string conversions (for HEX) use upper or lower-case // Integer to string conversions (for HEX) use upper or lower-case
@ -1157,7 +1166,6 @@ bool EventHandler::addJoyHatMapping(Event::Type event, EventMode mode,
#endif #endif
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::eraseMapping(Event::Type event, EventMode mode) void EventHandler::eraseMapping(Event::Type event, EventMode mode)
{ {

View File

@ -135,6 +135,9 @@ Settings::Settings()
setPermanent("hidpi", "false"); setPermanent("hidpi", "false");
setPermanent("listdelay", "300"); setPermanent("listdelay", "300");
setPermanent("mwheel", "4"); setPermanent("mwheel", "4");
setPermanent("mdouble", "500");
setPermanent("ctrldelay", "400");
setPermanent("ctrlrate", "20");
setPermanent("basic_settings", false); setPermanent("basic_settings", false);
setPermanent("dialogpos", 0); setPermanent("dialogpos", 0);
@ -487,6 +490,9 @@ void Settings::usage() const
<< " (300-1000)\n" << " (300-1000)\n"
<< " -mwheel <lines> Number of lines the mouse wheel will scroll in\n" << " -mwheel <lines> Number of lines the mouse wheel will scroll in\n"
<< " UI\n" << " UI\n"
<< " -mdouble <speed> Mouse double click speed in UI\n"
<< " -ctrldelay <delay> Delay before controller input is repeated in UI\n"
<< " -ctrlrate <rate> Rate per second of repeated controller input in UI\n"
<< " -basic_settings <0|1> Display only a basic settings dialog\n" << " -basic_settings <0|1> Display only a basic settings dialog\n"
<< " -romdir <dir> Directory from which to load ROM files\n" << " -romdir <dir> Directory from which to load ROM files\n"
<< " -avoxport <name> The name of the serial port where an AtariVox is\n" << " -avoxport <name> The name of the serial port where an AtariVox is\n"

View File

@ -34,6 +34,9 @@ DialogContainer::DialogContainer(OSystem& osystem)
myAxisRepeatTime(0), myAxisRepeatTime(0),
myHatRepeatTime(0) myHatRepeatTime(0)
{ {
_DOUBLE_CLICK_DELAY = osystem.settings().getInt("mdouble");
_REPEAT_INITIAL_DELAY = osystem.settings().getInt("ctrldelay");
setControllerRate(osystem.settings().getInt("ctrlrate"));
reset(); reset();
} }
@ -55,14 +58,14 @@ void DialogContainer::updateTime(uInt64 time)
activeDialog->handleMouseDown(myCurrentMouseDown.x - activeDialog->_x, activeDialog->handleMouseDown(myCurrentMouseDown.x - activeDialog->_x,
myCurrentMouseDown.y - activeDialog->_y, myCurrentMouseDown.y - activeDialog->_y,
myCurrentMouseDown.b, 1); myCurrentMouseDown.b, 1);
myClickRepeatTime = myTime + kRepeatSustainDelay; myClickRepeatTime = myTime + _REPEAT_SUSTAIN_DELAY;
} }
// Joystick button still pressed // Joystick button still pressed
if(myCurrentButtonDown.stick != -1 && myButtonRepeatTime < myTime) if(myCurrentButtonDown.stick != -1 && myButtonRepeatTime < myTime)
{ {
activeDialog->handleJoyDown(myCurrentButtonDown.stick, myCurrentButtonDown.button); activeDialog->handleJoyDown(myCurrentButtonDown.stick, myCurrentButtonDown.button);
myButtonRepeatTime = myTime + kRepeatSustainDelay; myButtonRepeatTime = myTime + _REPEAT_SUSTAIN_DELAY;
} }
// Joystick axis still pressed // Joystick axis still pressed
@ -70,7 +73,7 @@ void DialogContainer::updateTime(uInt64 time)
{ {
activeDialog->handleJoyAxis(myCurrentAxisDown.stick, myCurrentAxisDown.axis, activeDialog->handleJoyAxis(myCurrentAxisDown.stick, myCurrentAxisDown.axis,
myCurrentAxisDown.value); myCurrentAxisDown.value);
myAxisRepeatTime = myTime + kRepeatSustainDelay; myAxisRepeatTime = myTime + _REPEAT_SUSTAIN_DELAY;
} }
// Joystick hat still pressed // Joystick hat still pressed
@ -78,7 +81,7 @@ void DialogContainer::updateTime(uInt64 time)
{ {
activeDialog->handleJoyHat(myCurrentHatDown.stick, myCurrentHatDown.hat, activeDialog->handleJoyHat(myCurrentHatDown.stick, myCurrentHatDown.hat,
myCurrentHatDown.value); myCurrentHatDown.value);
myHatRepeatTime = myTime + kRepeatSustainDelay; myHatRepeatTime = myTime + _REPEAT_SUSTAIN_DELAY;
} }
} }
@ -219,7 +222,7 @@ void DialogContainer::handleMouseButtonEvent(MouseButton b, bool pressed,
myLastClick.count = 0; myLastClick.count = 0;
} }
if(myLastClick.count && (myTime < myLastClick.time + kDoubleClickDelay) if(myLastClick.count && (myTime < myLastClick.time + _DOUBLE_CLICK_DELAY)
&& std::abs(myLastClick.x - x) < 3 && std::abs(myLastClick.x - x) < 3
&& std::abs(myLastClick.y - y) < 3) && std::abs(myLastClick.y - y) < 3)
{ {
@ -240,7 +243,7 @@ void DialogContainer::handleMouseButtonEvent(MouseButton b, bool pressed,
myCurrentMouseDown.x = x; myCurrentMouseDown.x = x;
myCurrentMouseDown.y = y; myCurrentMouseDown.y = y;
myCurrentMouseDown.b = b; myCurrentMouseDown.b = b;
myClickRepeatTime = myTime + kRepeatInitialDelay; myClickRepeatTime = myTime + _REPEAT_INITIAL_DELAY;
} }
else else
myCurrentMouseDown.b = MouseButton::NONE; myCurrentMouseDown.b = MouseButton::NONE;
@ -284,7 +287,7 @@ void DialogContainer::handleJoyBtnEvent(int stick, int button, bool pressed)
{ {
myCurrentButtonDown.stick = stick; myCurrentButtonDown.stick = stick;
myCurrentButtonDown.button = button; myCurrentButtonDown.button = button;
myButtonRepeatTime = myTime + (activeDialog->repeatEnabled() ? kRepeatInitialDelay : kRepeatNone); myButtonRepeatTime = myTime + (activeDialog->repeatEnabled() ? _REPEAT_INITIAL_DELAY : kRepeatNone);
activeDialog->handleJoyDown(stick, button); activeDialog->handleJoyDown(stick, button);
} }
@ -323,7 +326,7 @@ void DialogContainer::handleJoyAxisEvent(int stick, int axis, int value, int but
myCurrentAxisDown.stick = stick; myCurrentAxisDown.stick = stick;
myCurrentAxisDown.axis = axis; myCurrentAxisDown.axis = axis;
myCurrentAxisDown.value = value; myCurrentAxisDown.value = value;
myAxisRepeatTime = myTime + (activeDialog->repeatEnabled() ? kRepeatInitialDelay : kRepeatNone); myAxisRepeatTime = myTime + (activeDialog->repeatEnabled() ? _REPEAT_INITIAL_DELAY : kRepeatNone);
} }
activeDialog->handleJoyAxis(stick, axis, value, button); activeDialog->handleJoyAxis(stick, axis, value, button);
} }
@ -349,8 +352,7 @@ void DialogContainer::handleJoyHatEvent(int stick, int hat, JoyHat value, int bu
myCurrentHatDown.stick = stick; myCurrentHatDown.stick = stick;
myCurrentHatDown.hat = hat; myCurrentHatDown.hat = hat;
myCurrentHatDown.value = value; myCurrentHatDown.value = value;
myHatRepeatTime = myTime + (activeDialog->repeatEnabled() ? kRepeatInitialDelay : kRepeatNone); myHatRepeatTime = myTime + (activeDialog->repeatEnabled() ? _REPEAT_INITIAL_DELAY : kRepeatNone);
//myHatRepeatTime = myTime + kRepeatInitialDelay;
} }
activeDialog->handleJoyHat(stick, hat, value, button); activeDialog->handleJoyHat(stick, hat, value, button);
} }
@ -367,3 +369,9 @@ void DialogContainer::reset()
myCurrentAxisDown.stick = myCurrentAxisDown.axis = -1; myCurrentAxisDown.stick = myCurrentAxisDown.axis = -1;
myCurrentHatDown.stick = myCurrentHatDown.hat = -1; myCurrentHatDown.stick = myCurrentHatDown.hat = -1;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt64 DialogContainer::_DOUBLE_CLICK_DELAY = 500;
uInt64 DialogContainer::_REPEAT_INITIAL_DELAY = 400;
uInt64 DialogContainer::_REPEAT_SUSTAIN_DELAY = 50;

View File

@ -155,6 +155,13 @@ class DialogContainer
*/ */
virtual Dialog* baseDialog() = 0; virtual Dialog* baseDialog() = 0;
/**
Set input speeds
*/
static void setDoubleClickDelay(int delay) { _DOUBLE_CLICK_DELAY = delay; }
static void setControllerDelay(int delay) { _REPEAT_INITIAL_DELAY = delay; }
static void setControllerRate(int rate) { _REPEAT_SUSTAIN_DELAY = 1000 / rate; }
private: private:
void reset(); void reset();
@ -174,15 +181,16 @@ class DialogContainer
private: private:
enum { enum {
kDoubleClickDelay = 500,
kRepeatInitialDelay = 400,
kRepeatSustainDelay = 50,
kRepeatNone = 1 << 24 // loooong kRepeatNone = 1 << 24 // loooong
}; };
// Indicates the most current time (in milliseconds) as set by updateTime() // Indicates the most current time (in milliseconds) as set by updateTime()
uInt64 myTime; uInt64 myTime;
static uInt64 _DOUBLE_CLICK_DELAY;
static uInt64 _REPEAT_INITIAL_DELAY;
static uInt64 _REPEAT_SUSTAIN_DELAY;
// For continuous 'mouse down' events // For continuous 'mouse down' events
struct { struct {
int x; int x;

View File

@ -71,7 +71,7 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent,
// 1) Misc. options // 1) Misc. options
wid.clear(); wid.clear();
tabID = myTab->addTab(" Look & Feel "); tabID = myTab->addTab(" Look & Feel ");
lwidth = font.getStringWidth("Mouse wheel scroll "); lwidth = font.getStringWidth("Controller repeat delay ");
pwidth = font.getStringWidth("Right bottom"); pwidth = font.getStringWidth("Right bottom");
xpos = HBORDER; ypos = VBORDER; xpos = HBORDER; ypos = VBORDER;
@ -94,7 +94,7 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent,
VarList::push_back(items, "Right bottom", 3); VarList::push_back(items, "Right bottom", 3);
VarList::push_back(items, "Left bottom", 4); VarList::push_back(items, "Left bottom", 4);
myPositionPopup = new PopUpWidget(myTab, font, xpos, ypos, pwidth, lineHeight, myPositionPopup = new PopUpWidget(myTab, font, xpos, ypos, pwidth, lineHeight,
items, "Dialogs position ", lwidth); items, "Dialogs position ", lwidth);
wid.push_back(myPositionPopup); wid.push_back(myPositionPopup);
ypos += lineHeight + V_GAP; ypos += lineHeight + V_GAP;
@ -105,24 +105,57 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent,
// Delay between quick-selecting characters in ListWidget // Delay between quick-selecting characters in ListWidget
int swidth = myPalettePopup->getWidth() - lwidth; int swidth = myPalettePopup->getWidth() - lwidth;
myListDelayPopup = new SliderWidget(myTab, font, xpos, ypos, swidth, lineHeight, myListDelaySlider = new SliderWidget(myTab, font, xpos, ypos, swidth, lineHeight,
"List input delay ", 0, kListDelay, "List input delay ", 0, kListDelay,
font.getStringWidth("1 second")); font.getStringWidth("1 second"));
myListDelayPopup->setMinValue(0); myListDelaySlider->setMinValue(0);
myListDelayPopup->setMaxValue(1000); myListDelaySlider->setMaxValue(1000);
myListDelayPopup->setStepValue(50); myListDelaySlider->setStepValue(50);
myListDelayPopup->setTickmarkIntervals(5); myListDelaySlider->setTickmarkIntervals(5);
wid.push_back(myListDelayPopup); wid.push_back(myListDelaySlider);
ypos += lineHeight + V_GAP; ypos += lineHeight + V_GAP;
// Number of lines a mouse wheel will scroll // Number of lines a mouse wheel will scroll
myWheelLinesPopup = new SliderWidget(myTab, font, xpos, ypos, swidth, lineHeight, myWheelLinesSlider = new SliderWidget(myTab, font, xpos, ypos, swidth, lineHeight,
"Mouse wheel scroll ", 0, kMouseWheel, "Mouse wheel scroll ", 0, kMouseWheel,
font.getStringWidth("10 lines")); font.getStringWidth("10 lines"));
myWheelLinesPopup->setMinValue(1); myWheelLinesSlider->setMinValue(1);
myWheelLinesPopup->setMaxValue(10); myWheelLinesSlider->setMaxValue(10);
myWheelLinesPopup->setTickmarkIntervals(3); myWheelLinesSlider->setTickmarkIntervals(3);
wid.push_back(myWheelLinesPopup); wid.push_back(myWheelLinesSlider);
ypos += lineHeight + V_GAP;
// Mouse double click speed
myDoubleClickSlider = new SliderWidget(myTab, font, xpos, ypos, swidth, lineHeight,
"Double-click speed ", 0, 0,
font.getStringWidth("900 ms"), " ms");
myDoubleClickSlider->setMinValue(100);
myDoubleClickSlider->setMaxValue(900);
myDoubleClickSlider->setStepValue(50);
myDoubleClickSlider->setTickmarkIntervals(8);
wid.push_back(myDoubleClickSlider);
ypos += lineHeight + V_GAP;
// Initial delay before controller input will start repeating
myControllerDelaySlider = new SliderWidget(myTab, font, xpos, ypos, swidth, lineHeight,
"Controller repeat delay ", 0, kControllerDelay,
font.getStringWidth("1 second"));
myControllerDelaySlider->setMinValue(200);
myControllerDelaySlider->setMaxValue(1000);
myControllerDelaySlider->setStepValue(100);
myControllerDelaySlider->setTickmarkIntervals(4);
wid.push_back(myControllerDelaySlider);
ypos += lineHeight + V_GAP;
// Controller repeat rate
myControllerRateSlider = new SliderWidget(myTab, font, xpos, ypos, swidth, lineHeight,
"Controller repeat rate ", 0, 0,
font.getStringWidth("30 repeats/s"), " repeats/s");
myControllerRateSlider->setMinValue(2);
myControllerRateSlider->setMaxValue(30);
myControllerRateSlider->setStepValue(1);
myControllerRateSlider->setTickmarkIntervals(14);
wid.push_back(myControllerRateSlider);
// Add message concerning usage // Add message concerning usage
ypos = myTab->getHeight() - 5 - fontHeight - ifont.getFontHeight() - 10; ypos = myTab->getHeight() - 5 - fontHeight - ifont.getFontHeight() - 10;
@ -300,11 +333,23 @@ void UIDialog::loadConfig()
// Listwidget quick delay // Listwidget quick delay
int delay = settings.getInt("listdelay"); int delay = settings.getInt("listdelay");
myListDelayPopup->setValue(delay); myListDelaySlider->setValue(delay);
// Mouse wheel lines // Mouse wheel lines
int mw = settings.getInt("mwheel"); int mw = settings.getInt("mwheel");
myWheelLinesPopup->setValue(mw); myWheelLinesSlider->setValue(mw);
// Mouse double click
int md = settings.getInt("mdouble");
myDoubleClickSlider->setValue(md);
// Controller input delay
int cs = settings.getInt("ctrldelay");
myControllerDelaySlider->setValue(cs);
// Controller input rate
int cr = settings.getInt("ctrlrate");
myControllerRateSlider->setValue(cr);
handleRomViewer(); handleRomViewer();
@ -350,12 +395,24 @@ void UIDialog::saveConfig()
settings.setValue("dialogpos", myPositionPopup->getSelectedTag().toString()); settings.setValue("dialogpos", myPositionPopup->getSelectedTag().toString());
// Listwidget quick delay // Listwidget quick delay
settings.setValue("listdelay", myListDelayPopup->getValue()); settings.setValue("listdelay", myListDelaySlider->getValue());
ListWidget::setQuickSelectDelay(myListDelayPopup->getValue()); ListWidget::setQuickSelectDelay(myListDelaySlider->getValue());
// Mouse wheel lines // Mouse wheel lines
settings.setValue("mwheel", myWheelLinesPopup->getValue()); settings.setValue("mwheel", myWheelLinesSlider->getValue());
ScrollBarWidget::setWheelLines(myWheelLinesPopup->getValue()); ScrollBarWidget::setWheelLines(myWheelLinesSlider->getValue());
// Mouse double click
settings.setValue("mdouble", myDoubleClickSlider->getValue());
DialogContainer::setDoubleClickDelay(myDoubleClickSlider->getValue());
// Controller input delay
settings.setValue("ctrldelay", myControllerDelaySlider->getValue());
DialogContainer::setControllerDelay(myControllerDelaySlider->getValue());
// Controller input rate
settings.setValue("ctrlrate", myControllerRateSlider->getValue());
DialogContainer::setControllerRate(myControllerRateSlider->getValue());
// Flush changes to disk and inform the OSystem // Flush changes to disk and inform the OSystem
instance().saveConfig(); instance().saveConfig();
@ -371,8 +428,11 @@ void UIDialog::setDefaults()
myPalettePopup->setSelected("standard"); myPalettePopup->setSelected("standard");
myHidpiWidget->setState(false); myHidpiWidget->setState(false);
myPositionPopup->setSelected("0"); myPositionPopup->setSelected("0");
myListDelayPopup->setValue(300); myListDelaySlider->setValue(300);
myWheelLinesPopup->setValue(4); myWheelLinesSlider->setValue(4);
myDoubleClickSlider->setValue(500);
myControllerDelaySlider->setValue(400);
myControllerRateSlider->setValue(20);
break; break;
case 1: // Launcher options case 1: // Launcher options
{ {
@ -410,26 +470,39 @@ void UIDialog::handleCommand(CommandSender* sender, int cmd, int data, int id)
break; break;
case kListDelay: case kListDelay:
if(myListDelayPopup->getValue() == 0) if(myListDelaySlider->getValue() == 0)
{ {
myListDelayPopup->setValueLabel("Off"); myListDelaySlider->setValueLabel("Off");
myListDelayPopup->setValueUnit(""); myListDelaySlider->setValueUnit("");
} }
else if(myListDelayPopup->getValue() == 1000) else if(myListDelaySlider->getValue() == 1000)
{ {
myListDelayPopup->setValueLabel("1"); myListDelaySlider->setValueLabel("1");
myListDelayPopup->setValueUnit(" second"); myListDelaySlider->setValueUnit(" second");
} }
else else
{ {
myListDelayPopup->setValueUnit(" ms"); myListDelaySlider->setValueUnit(" ms");
} }
break; break;
case kMouseWheel: case kMouseWheel:
if(myWheelLinesPopup->getValue() == 1) if(myWheelLinesSlider->getValue() == 1)
myWheelLinesPopup->setValueUnit(" line"); myWheelLinesSlider->setValueUnit(" line");
else else
myWheelLinesPopup->setValueUnit(" lines"); myWheelLinesSlider->setValueUnit(" lines");
break;
case kControllerDelay:
if(myControllerDelaySlider->getValue() == 1000)
{
myControllerDelaySlider->setValueLabel("1");
myControllerDelaySlider->setValueUnit(" second");
}
else
{
myControllerDelaySlider->setValueUnit(" ms");
}
break; break;
case kChooseRomDirCmd: case kChooseRomDirCmd:

View File

@ -41,6 +41,7 @@ class UIDialog : public Dialog, public CommandSender
{ {
kListDelay = 'UILd', kListDelay = 'UILd',
kMouseWheel = 'UIMw', kMouseWheel = 'UIMw',
kControllerDelay = 'UIcd',
kChooseRomDirCmd = 'LOrm', // rom select kChooseRomDirCmd = 'LOrm', // rom select
kLauncherSize = 'UIls', kLauncherSize = 'UIls',
kRomViewer = 'UIRv', kRomViewer = 'UIRv',
@ -65,8 +66,11 @@ class UIDialog : public Dialog, public CommandSender
PopUpWidget* myPalettePopup; PopUpWidget* myPalettePopup;
CheckboxWidget* myHidpiWidget; CheckboxWidget* myHidpiWidget;
PopUpWidget* myPositionPopup; PopUpWidget* myPositionPopup;
SliderWidget* myListDelayPopup; SliderWidget* myListDelaySlider;
SliderWidget* myWheelLinesPopup; SliderWidget* myWheelLinesSlider;
SliderWidget* myControllerRateSlider;
SliderWidget* myControllerDelaySlider;
SliderWidget* myDoubleClickSlider;
unique_ptr<BrowserDialog> myBrowser; unique_ptr<BrowserDialog> myBrowser;