add touchscreen input

This commit is contained in:
Arisotura 2023-03-27 21:01:05 +02:00
parent 2d131dd755
commit b59de12ce4
4 changed files with 46 additions and 8 deletions

View File

@ -36,6 +36,9 @@ u32 HotkeyPress, HotkeyRelease;
u32 InputMask;
bool Touching;
int TouchX, TouchY;
void Init()
{
@ -48,6 +51,10 @@ void Init()
ExtHotkeyMask = 0;
HotkeyMask = 0;
LastHotkeyMask = 0;
Touching = false;
TouchX = 0;
TouchY = 0;
}
@ -190,6 +197,18 @@ void ExtHotkeyPress(int id)
ExtHotkeyMask |= (1<<id);
}
void TouchScreen(int x, int y)
{
TouchX = x;
TouchY = y;
Touching = true;
}
void ReleaseScreen()
{
Touching = false;
}
void Process()
{
SDL_JoystickUpdate();

View File

@ -32,6 +32,9 @@ extern SDL_Joystick* Joystick;
extern u32 InputMask;
extern bool Touching;
extern int TouchX, TouchY;
void Init();
// set joystickID before calling openJoystick()
@ -43,6 +46,9 @@ void KeyRelease(QKeyEvent* event);
void ExtHotkeyPress(int id);
void TouchScreen(int x, int y);
void ReleaseScreen();
void Process();
bool HotkeyDown(int id);

View File

@ -196,6 +196,8 @@ struct InputFrame
{
u32 FrameNum;
u32 KeyMask;
u32 Touching;
u32 TouchX, TouchY;
};
std::queue<InputFrame> InputQueue;
@ -471,6 +473,9 @@ void StartLocal()
InputFrame frame;
frame.FrameNum = i;
frame.KeyMask = 0xFFF;
frame.Touching = 0;
frame.TouchX = 0;
frame.TouchY = 0;
InputQueue.push(frame);
}
@ -843,7 +848,10 @@ void ProcessInput()
InputFrame frame;
frame.FrameNum = NDS::NumFrames + lag;
frame.KeyMask = Input::InputMask;
// TODO: touchscreen input and other shit!
frame.Touching = Input::Touching ? 1:0;
frame.TouchX = Input::TouchX;
frame.TouchY = Input::TouchY;
// TODO: other shit! (some hotkeys for example?)
InputQueue.push(frame);
@ -884,6 +892,9 @@ void ProcessInput()
// apply this input frame
if (frame.KeyMask != 0xFFF) printf("[%08d] INPUT=%08X (%08d) (backlog=%d)\n", NDS::NumFrames, frame.KeyMask, frame.FrameNum, InputQueue.size());
NDS::SetKeyMask(frame.KeyMask);
if (frame.Touching) NDS::TouchScreen(frame.TouchX, frame.TouchY);
else NDS::ReleaseScreen();
InputQueue.pop();
}

View File

@ -479,6 +479,8 @@ void EmuThread::run()
else
{
NDS::SetKeyMask(Input::InputMask);
if (Input::Touching) NDS::TouchScreen(Input::TouchX, Input::TouchY);
else NDS::ReleaseScreen();
}
if (Input::HotkeyPressed(HK_Lid))
@ -923,7 +925,7 @@ void ScreenHandler::screenOnMousePress(QMouseEvent* event)
if (Frontend::GetTouchCoords(x, y, false))
{
touching = true;
NDS::TouchScreen(x, y);
Input::TouchScreen(x, y);
}
}
@ -935,7 +937,7 @@ void ScreenHandler::screenOnMouseRelease(QMouseEvent* event)
if (touching)
{
touching = false;
NDS::ReleaseScreen();
Input::ReleaseScreen();
}
}
@ -952,7 +954,7 @@ void ScreenHandler::screenOnMouseMove(QMouseEvent* event)
int y = event->pos().y();
if (Frontend::GetTouchCoords(x, y, true))
NDS::TouchScreen(x, y);
Input::TouchScreen(x, y);
}
void ScreenHandler::screenHandleTablet(QTabletEvent* event)
@ -970,14 +972,14 @@ void ScreenHandler::screenHandleTablet(QTabletEvent* event)
if (Frontend::GetTouchCoords(x, y, event->type()==QEvent::TabletMove))
{
touching = true;
NDS::TouchScreen(x, y);
Input::TouchScreen(x, y);
}
}
break;
case QEvent::TabletRelease:
if (touching)
{
NDS::ReleaseScreen();
Input::ReleaseScreen();
touching = false;
}
break;
@ -1003,14 +1005,14 @@ void ScreenHandler::screenHandleTouch(QTouchEvent* event)
if (Frontend::GetTouchCoords(x, y, event->type()==QEvent::TouchUpdate))
{
touching = true;
NDS::TouchScreen(x, y);
Input::TouchScreen(x, y);
}
}
break;
case QEvent::TouchEnd:
if (touching)
{
NDS::ReleaseScreen();
Input::ReleaseScreen();
touching = false;
}
break;