do touchscreen input more properly

This commit is contained in:
Arisotura 2024-10-31 22:10:25 +01:00
parent 1b8daa0465
commit f3bd58f75e
4 changed files with 34 additions and 14 deletions

View File

@ -147,6 +147,9 @@ public:
int getJoystickID() { return joystickID; }
SDL_Joystick* getJoystick() { return joystick; }
void touchScreen(int x, int y);
void releaseScreen();
private:
static int lastSep(const std::string& path);
std::string getAssetPath(bool gba, const std::string& configpath, const std::string& ext, const std::string& file);
@ -328,6 +331,9 @@ private:
melonDS::u32 inputMask;
bool isTouching;
melonDS::u16 touchX, touchY;
friend class EmuThread;
friend class MainWindow;
};

View File

@ -74,6 +74,10 @@ void EmuInstance::inputInit()
hotkeyMask = 0;
lastHotkeyMask = 0;
isTouching = false;
touchX = 0;
touchY = 0;
joystick = nullptr;
controller = nullptr;
hasRumble = false;
@ -353,3 +357,15 @@ void EmuInstance::inputProcess()
hotkeyRelease = lastHotkeyMask & ~hotkeyMask;
lastHotkeyMask = hotkeyMask;
}
void EmuInstance::touchScreen(int x, int y)
{
touchX = x;
touchY = y;
isTouching = true;
}
void EmuInstance::releaseScreen()
{
isTouching = false;
}

View File

@ -251,6 +251,11 @@ void EmuThread::run()
// process input and hotkeys
emuInstance->nds->SetKeyMask(emuInstance->inputMask);
if (emuInstance->isTouching)
emuInstance->nds->TouchScreen(emuInstance->touchX, emuInstance->touchY);
else
emuInstance->nds->ReleaseScreen();
if (emuInstance->hotkeyPressed(HK_Lid))
{
bool lid = !emuInstance->nds->IsLidClosed();

View File

@ -258,8 +258,7 @@ void ScreenPanel::mousePressEvent(QMouseEvent* event)
if (layout.GetTouchCoords(x, y, false))
{
touching = true;
assert(emuInstance->getNDS() != nullptr);
emuInstance->getNDS()->TouchScreen(x, y);
emuInstance->touchScreen(x, y);
}
}
@ -272,8 +271,7 @@ void ScreenPanel::mouseReleaseEvent(QMouseEvent* event)
if (touching)
{
touching = false;
assert(emuInstance->getNDS() != nullptr);
emuInstance->getNDS()->ReleaseScreen();
emuInstance->releaseScreen();
}
}
@ -292,8 +290,7 @@ void ScreenPanel::mouseMoveEvent(QMouseEvent* event)
if (layout.GetTouchCoords(x, y, true))
{
assert(emuInstance->getNDS() != nullptr);
emuInstance->getNDS()->TouchScreen(x, y);
emuInstance->touchScreen(x, y);
}
}
@ -318,16 +315,14 @@ void ScreenPanel::tabletEvent(QTabletEvent* event)
if (layout.GetTouchCoords(x, y, event->type()==QEvent::TabletMove))
{
touching = true;
assert(emuInstance->getNDS() != nullptr);
emuInstance->getNDS()->TouchScreen(x, y);
emuInstance->touchScreen(x, y);
}
}
break;
case QEvent::TabletRelease:
if (touching)
{
assert(emuInstance->getNDS() != nullptr);
emuInstance->getNDS()->ReleaseScreen();
emuInstance->releaseScreen();
touching = false;
}
break;
@ -365,16 +360,14 @@ void ScreenPanel::touchEvent(QTouchEvent* event)
if (layout.GetTouchCoords(x, y, event->type()==QEvent::TouchUpdate))
{
touching = true;
assert(emuInstance->getNDS() != nullptr);
emuInstance->getNDS()->TouchScreen(x, y);
emuInstance->touchScreen(x, y);
}
}
break;
case QEvent::TouchEnd:
if (touching)
{
assert(emuInstance->getNDS() != nullptr);
emuInstance->getNDS()->ReleaseScreen();
emuInstance->releaseScreen();
touching = false;
}
break;