commit 8e2a21539f3840375f86f1c571957f92d4d5df33
Author: Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Sun Aug 28 16:45:42 2022 -0600
Commit: Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Sun Aug 28 16:45:42 2022 -0600
First pass at touchscreen for support for libretro
---
platform/libretro/libretro.cpp | 21 ++++++++++++++++++++-
platform/libretro/libretrohost.cpp | 10 ++++++++--
platform/libretro/setInput.h | 7 ++++++-
3 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/platform/libretro/libretro.cpp b/platform/libretro/libretro.cpp
index 301ea78..0bb3cdf 100644
--- a/platform/libretro/libretro.cpp
+++ b/platform/libretro/libretro.cpp
@@ -219,7 +219,26 @@ EXPORT void retro_run()
}
}
- setInputState(currKDown, currKHeld);
+ int16_t picoMouseX = 0;
+ int16_t picoMouseY = 0;
+ uint8_t mouseBtnState = 0;
+ int16_t pressed = input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_PRESSED);
+ if (_memory->drawState.devkitMode && pressed) {
+ int16_t pointX = input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X);
+ int16_t pointY = input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y);
+
+ if (pointX > -32768 && pointX < 32767) {
+ picoMouseX = pointX * 64 / 32768 + 64;
+ picoMouseY = pointY * 64 / 32768 + 64;
+ //printf("adjusted: %d, %d : %d\n", picoMouseX, picoMouseY, pressed);
+
+ if (pressed) {
+ mouseBtnState = 1;
+ }
+ }
+ }
+
+ setInputState(currKDown, currKHeld, picoMouseX, picoMouseY, mouseBtnState);
_vm->UpdateAndDraw();
kHeld = currKHeld;
diff --git a/platform/libretro/libretrohost.cpp b/platform/libretro/libretrohost.cpp
index 7cf4652..1833f3c 100644
--- a/platform/libretro/libretrohost.cpp
+++ b/platform/libretro/libretrohost.cpp
@@ -20,10 +20,16 @@ static uint8_t stubCurrKDown;
static uint8_t stubCurrKHeld;
static bool stubCurrKBdown = false;
static std::string stubCurrKBkey = "";
+static int16_t stubMouseX;
+static int16_t stubMouseY;
+static uint8_t stubMouseBtns;
-void setInputState(uint8_t kDown, uint8_t kHeld) {
+void setInputState(uint8_t kDown, uint8_t kHeld, int16_t mouseX, int16_t mouseY, uint8_t mouseBtns) {
stubCurrKDown = kDown;
stubCurrKHeld = kHeld;
+ stubMouseX = mouseX;
+ stubMouseY = mouseY;
+ stubMouseBtns = mouseBtns;
}
@@ -54,7 +60,7 @@ void Host::forceStretch(StretchOption newStretch) {
InputState_t Host::scanInput(){
- return InputState_t {stubCurrKDown, stubCurrKHeld, 0, 0, 0, stubCurrKBdown, stubCurrKBkey};
+ return InputState_t {stubCurrKDown, stubCurrKHeld, stubMouseX, stubMouseY, stubMouseBtns, stubCurrKBdown, stubCurrKBkey};
}
bool Host::shouldQuit() {
diff --git a/platform/libretro/setInput.h b/platform/libretro/setInput.h
index fcc6577..d9ad8a2 100644
--- a/platform/libretro/setInput.h
+++ b/platform/libretro/setInput.h
@@ -1 +1,6 @@
-void setInputState(uint8_t kDown, uint8_t kHeld);
+void setInputState(
+ uint8_t kDown,
+ uint8_t kHeld,
+ int16_t mouseX,
+ int16_t mouseY,
+ uint8_t mouseBtnState);