From f30e19a2ec8dff11180a7a101a1368eb4a2d6d08 Mon Sep 17 00:00:00 2001 From: StapleButter Date: Sun, 17 Sep 2017 23:36:28 +0200 Subject: [PATCH] touchscreen input --- src/libui_sdl/main.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 52c8117a..5cbe7508 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -41,6 +41,8 @@ int EmuRunning; SDL_mutex* ScreenMutex; uiDrawBitmap* ScreenBitmap = NULL; +bool Touching = false; + void AudioCallback(void* data, Uint8* stream, int len) { @@ -51,6 +53,8 @@ int EmuThreadFunc(void* burp) { NDS::Init(); + Touching = false; + // DS: // 547.060546875 samples per frame // 32823.6328125 samples per second @@ -173,7 +177,33 @@ void OnAreaMouseEvent(uiAreaHandler* handler, uiArea* area, uiAreaMouseEvent* ev { int x = (int)evt->X; int y = (int)evt->Y; - printf("mouse: %08X %d,%d\n", (u32)evt->Held1To64, x, y); + + if (Touching && (evt->Up == 1)) + { + Touching = false; + NDS::ReleaseKey(16+6); + NDS::ReleaseScreen(); + } + else if (!Touching && (evt->Down == 1) && (y >= 192)) + { + Touching = true; + NDS::PressKey(16+6); + // TODO: scaling/offset as needed + } + + if (Touching) + { + // TODO: scaling, here too + y -= 192; + + // clamp + if (x < 0) x = 0; + else if (x > 255) x = 255; + if (y < 0) y = 0; + else if (y > 191) y = 191; + + NDS::TouchScreen(x, y); + } } void OnAreaMouseCrossed(uiAreaHandler* handler, uiArea* area, int left)