do touchscreen input more properly
Some checks are pending
macOS / ${{ matrix.arch }} (arm64) (push) Waiting to run
macOS / ${{ matrix.arch }} (x86_64) (push) Waiting to run
macOS / Universal binary (push) Blocked by required conditions
Ubuntu / x86_64 (push) Waiting to run
Ubuntu / aarch64 (push) Waiting to run
Windows / build (push) Waiting to run

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; } int getJoystickID() { return joystickID; }
SDL_Joystick* getJoystick() { return joystick; } SDL_Joystick* getJoystick() { return joystick; }
void touchScreen(int x, int y);
void releaseScreen();
private: private:
static int lastSep(const std::string& path); static int lastSep(const std::string& path);
std::string getAssetPath(bool gba, const std::string& configpath, const std::string& ext, const std::string& file); 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; melonDS::u32 inputMask;
bool isTouching;
melonDS::u16 touchX, touchY;
friend class EmuThread; friend class EmuThread;
friend class MainWindow; friend class MainWindow;
}; };

View File

@ -74,6 +74,10 @@ void EmuInstance::inputInit()
hotkeyMask = 0; hotkeyMask = 0;
lastHotkeyMask = 0; lastHotkeyMask = 0;
isTouching = false;
touchX = 0;
touchY = 0;
joystick = nullptr; joystick = nullptr;
controller = nullptr; controller = nullptr;
hasRumble = false; hasRumble = false;
@ -353,3 +357,15 @@ void EmuInstance::inputProcess()
hotkeyRelease = lastHotkeyMask & ~hotkeyMask; hotkeyRelease = lastHotkeyMask & ~hotkeyMask;
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 // process input and hotkeys
emuInstance->nds->SetKeyMask(emuInstance->inputMask); emuInstance->nds->SetKeyMask(emuInstance->inputMask);
if (emuInstance->isTouching)
emuInstance->nds->TouchScreen(emuInstance->touchX, emuInstance->touchY);
else
emuInstance->nds->ReleaseScreen();
if (emuInstance->hotkeyPressed(HK_Lid)) if (emuInstance->hotkeyPressed(HK_Lid))
{ {
bool lid = !emuInstance->nds->IsLidClosed(); bool lid = !emuInstance->nds->IsLidClosed();

View File

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