Commit 4b1601e1 authored by thrust26's avatar thrust26
Browse files

reversed controller button reaction (now on UP), fixes #567

prevent button read for up after long press
parent 00451d44
......@@ -721,7 +721,7 @@ void PhysicalJoystickHandler::handleBtnEvent(int stick, int button, bool pressed
j->buttonLast[stick] = pressed ? button : JOY_CTRL_NONE;
// Handle buttons which switch eventhandler state
if(pressed && myHandler.changeStateByEvent(j->joyMap.get(EventMode::kEmulationMode, button)))
if(!pressed && myHandler.changeStateByEvent(j->joyMap.get(EventMode::kEmulationMode, button)))
return;
// Determine which mode we're in, then send the event to the appropriate place
......
......@@ -276,7 +276,7 @@ void ContextMenu::handleKeyDown(StellaKey key, StellaMod mod, bool repeated)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ContextMenu::handleJoyDown(int stick, int button, bool longPress)
void ContextMenu::handleJoyUp(int stick, int button)
{
handleEvent(instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button));
}
......
......@@ -87,7 +87,7 @@ class ContextMenu : public Dialog, public CommandSender
bool handleMouseClicks(int x, int y, MouseButton b) override;
void handleMouseWheel(int x, int y, int direction) override;
void handleKeyDown(StellaKey key, StellaMod mod, bool repeated) override;
void handleJoyDown(int stick, int button, bool longPress) override;
void handleJoyUp(int stick, int button) override;
void handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int button) override;
bool handleJoyHat(int stick, int hat, JoyHatDir vahdirlue, int button) override;
void handleEvent(Event::Type e);
......
......@@ -572,26 +572,32 @@ bool Dialog::handleMouseClicks(int x, int y, MouseButton b)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleJoyDown(int stick, int button, bool longPress)
{
Event::Type e =
instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button);
// Unless a widget has claimed all responsibility for data, we assume
// that if an event exists for the given data, it should have priority.
if(!handleNavEvent(e) && _focusedWidget)
// Focused widget receives joystick events
if(_focusedWidget)
{
Event::Type e =
instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button);
if(_focusedWidget->wantsRaw() || e == Event::NoType)
_focusedWidget->handleJoyDown(stick, button, longPress);
else
_focusedWidget->handleEvent(e);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleJoyUp(int stick, int button)
{
// Focused widget receives joystick events
if(_focusedWidget)
_focusedWidget->handleJoyUp(stick, button);
Event::Type e =
instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button);
// Unless a widget has claimed all responsibility for data, we assume
// that if an event exists for the given data, it should have priority.
if (!handleNavEvent(e) && _focusedWidget)
{
if (_focusedWidget->wantsRaw() || e == Event::NoType)
_focusedWidget->handleJoyUp(stick, button);
else
_focusedWidget->handleEvent(e);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
......
......@@ -66,6 +66,7 @@ void DialogContainer::updateTime(uInt64 time)
// Joystick has been pressed long
if(myCurrentButtonDown.stick != -1 && myButtonLongPressTime < myTime)
{
myButtonLongPress = true;
activeDialog->handleJoyDown(myCurrentButtonDown.stick, myCurrentButtonDown.button, true);
myButtonLongPressTime = myButtonRepeatTime = myTime + _REPEAT_NONE;
}
......@@ -302,7 +303,10 @@ void DialogContainer::handleJoyBtnEvent(int stick, int button, bool pressed)
myCurrentButtonDown.stick = myCurrentButtonDown.button = -1;
myButtonRepeatTime = myButtonLongPressTime = 0;
}
activeDialog->handleJoyUp(stick, button);
if (myButtonLongPress)
myButtonLongPress = false;
else
activeDialog->handleJoyUp(stick, button);
}
}
......
......@@ -206,6 +206,7 @@ class DialogContainer
} myCurrentButtonDown;
uInt64 myButtonRepeatTime{0};
uInt64 myButtonLongPressTime{0};
bool myButtonLongPress{false};
// For continuous 'joy axis down' events
struct {
......
......@@ -404,6 +404,14 @@ void LauncherDialog::handleKeyDown(StellaKey key, StellaMod mod, bool repeated)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::handleJoyDown(int stick, int button, bool longPress)
{
myEventHandled = false;
myList->setFlags(Widget::FLAG_WANTS_RAWDATA); // allow handling long button press
Dialog::handleJoyDown(stick, button, longPress);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::handleJoyUp(int stick, int button)
{
// open power-up options and settings for 2nd and 4th button if not mapped otherwise
Event::Type e = instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button);
......@@ -413,19 +421,9 @@ void LauncherDialog::handleJoyDown(int stick, int button, bool longPress)
myGlobalProps->open();
if (button == 3 && (e == Event::Event::UITabPrev || e == Event::NoType))
openSettings();
else
{
myEventHandled = false;
myList->setFlags(Widget::FLAG_WANTS_RAWDATA); // allow handling long button press
Dialog::handleJoyDown(stick, button, longPress);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::handleJoyUp(int stick, int button)
{
if (!myEventHandled)
else if (!myEventHandled)
Dialog::handleJoyUp(stick, button);
myList->clearFlags(Widget::FLAG_WANTS_RAWDATA); // stop allowing to handle long button press
}
......
......@@ -279,12 +279,6 @@ void ListWidget::handleJoyDown(int stick, int button, bool longPress)
{
if (longPress)
sendCommand(ListWidget::kLongButtonPressCmd, _selectedItem, _id);
Event::Type e = _boss->instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button);
// handle UISelect event on button up
if(e != Event::UISelect)
handleEvent(e);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
......@@ -292,9 +286,7 @@ void ListWidget::handleJoyUp(int stick, int button)
{
Event::Type e = _boss->instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button);
// handle UISelect event on button up
if(e == Event::UISelect)
handleEvent(e);
handleEvent(e);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment