transform touch events to virtual size

This commit is contained in:
olebeck 2025-07-03 00:00:37 +02:00
parent 875b52dac6
commit bada87b975
4 changed files with 55 additions and 7 deletions

View File

@ -57,6 +57,8 @@
#ifdef __vita__
#include "vita/config.h"
#include <psp2/appmgr.h>
#include <psp2/kernel/clib.h>
#endif
DECOMP_SIZE_ASSERT(IsleApp, 0x8c)
@ -262,6 +264,21 @@ void IsleApp::SetupVideoFlags(
SDL_AppResult SDL_AppInit(void** appstate, int argc, char** argv)
{
#ifdef __vita__
SceAppUtilInitParam appUtilInitParam = {0};
SceAppUtilBootParam appUtilBootParam = {0};
sceAppUtilInit(&appUtilInitParam, &appUtilBootParam);
SceAppUtilAppEventParam eventParam = {0};
sceAppUtilReceiveAppEvent(&eventParam);
if (eventParam.type == 0x05) {
char buffer[2048];
sceAppUtilAppEventParseLiveArea(&eventParam, buffer);
if (strstr(buffer, "-config")) {
sceAppMgrLoadExec("app0:/isle-config.self", NULL, NULL);
}
}
#endif
*appstate = NULL;
SDL_SetHint(SDL_HINT_MOUSE_TOUCH_EVENTS, "0");
@ -407,6 +424,9 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event)
case SDL_EVENT_MOUSE_MOTION:
case SDL_EVENT_MOUSE_BUTTON_DOWN:
case SDL_EVENT_MOUSE_BUTTON_UP:
case SDL_EVENT_FINGER_MOTION:
case SDL_EVENT_FINGER_DOWN:
case SDL_EVENT_FINGER_UP:
IDirect3DRMMiniwinDevice* device = GetD3DRMMiniwinDevice();
if (device && !device->ConvertEventToRenderCoordinates(event)) {
SDL_Log("Failed to convert event coordinates: %s", SDL_GetError());

View File

@ -150,14 +150,13 @@ ViewportTransform CalculateViewportTransform(int virtualW, int virtualH, int win
void Direct3DRMDevice2Impl::Resize()
{
int width, height;
SDL_GetWindowSizeInPixels(DDWindow, &width, &height);
SDL_GetWindowSizeInPixels(DDWindow, &m_windowWidth, &m_windowHeight);
#ifdef __3DS__
width = 320; // We are on the lower screen
height = 240;
m_windowWidth = 320; // We are on the lower screen
m_windowHeight = 240;
#endif
m_viewportTransform = CalculateViewportTransform(m_virtualWidth, m_virtualHeight, width, height);
m_renderer->Resize(width, height, m_viewportTransform);
m_viewportTransform = CalculateViewportTransform(m_virtualWidth, m_virtualHeight, m_windowWidth, m_windowHeight);
m_renderer->Resize(m_windowWidth, m_windowHeight, m_viewportTransform);
for (int i = 0; i < m_viewports->GetSize(); i++) {
IDirect3DRMViewport* viewport;
m_viewports->GetElement(i, &viewport);
@ -182,7 +181,18 @@ bool Direct3DRMDevice2Impl::ConvertEventToRenderCoordinates(SDL_Event* event)
event->motion.x = static_cast<Sint32>(x);
event->motion.y = static_cast<Sint32>(y);
break;
} break;
}
case SDL_EVENT_FINGER_MOTION:
case SDL_EVENT_FINGER_DOWN:
case SDL_EVENT_FINGER_UP: {
int rawX = event->tfinger.x * m_windowWidth;
int rawY = event->tfinger.y * m_windowHeight;
float x = (rawX - m_viewportTransform.offsetX) / m_viewportTransform.scale;
float y = (rawY - m_viewportTransform.offsetY) / m_viewportTransform.scale;
event->tfinger.x = x / m_virtualWidth;
event->tfinger.y = y / m_virtualHeight;
break;
}
}
return true;

View File

@ -40,6 +40,8 @@ struct Direct3DRMDevice2Impl : public Direct3DRMObjectBaseImpl<IDirect3DRMDevice
private:
void Resize();
int32_t m_windowWidth;
int32_t m_windowHeight;
uint32_t m_virtualWidth;
uint32_t m_virtualHeight;
ViewportTransform m_viewportTransform;

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<livearea style="pspemu" format-ver="01.00" content-rev="1">
<livearea-background>
<image>bg.png</image>
</livearea-background>
<gate>
<startup-image>startup.png</startup-image>
</gate>
<frame id="frame1" multi="o" autoflip="0" rev="1">
<liveitem>
<target>psla:-config</target>
<background valign="bottom" align="center">config.png</background>
</liveitem>
</frame>
</livearea>