aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorrsn88872018-01-27 18:29:05 -0600
committerrsn88872018-01-27 19:02:59 -0600
commit68274d1cc66fe3a8f6df2a2064a4a03d1a0678f6 (patch)
tree341b031ada2536ea7ed0d56a261cf90301a7bcc8 /backends
parent6080d633397397d3ddb06cf3fb7517fc484c01f8 (diff)
downloadscummvm-rg350-68274d1cc66fe3a8f6df2a2064a4a03d1a0678f6.tar.gz
scummvm-rg350-68274d1cc66fe3a8f6df2a2064a4a03d1a0678f6.tar.bz2
scummvm-rg350-68274d1cc66fe3a8f6df2a2064a4a03d1a0678f6.zip
PSP2: Improve direct touch accuracy
Diffstat (limited to 'backends')
-rw-r--r--backends/events/psp2sdl/psp2sdl-events.cpp107
-rw-r--r--backends/graphics/psp2sdl/psp2sdl-graphics.cpp44
2 files changed, 87 insertions, 64 deletions
diff --git a/backends/events/psp2sdl/psp2sdl-events.cpp b/backends/events/psp2sdl/psp2sdl-events.cpp
index 3f447b7435..0c0df37015 100644
--- a/backends/events/psp2sdl/psp2sdl-events.cpp
+++ b/backends/events/psp2sdl/psp2sdl-events.cpp
@@ -239,58 +239,71 @@ void PSP2EventSource::preprocessFingerMotion(SDL_Event *event) {
}
void PSP2EventSource::convertTouchXYToGameXY(float touchX, float touchY, int *gameX, int *gameY) {
- int screenWidth = 960;
- int screenHeight = 544;
- // Find touch coordinates in terms of Vita screen pixels
- int screenTouchX = (int) (touchX * (float)screenWidth);
- int screenTouchY = (int) (touchY * (float)screenHeight);
-
- // Find four corners of game screen in Vita screen coordinates
- // This depends on the fullscreen and aspect ratio correction settings (at least on Vita)
-
- int gameXMin = 0;
- int gameXMax = 0;
- int gameYMin = 0;
- int gameYMax = 0;
- float aspectRatio = 4.0 / 3.0;
-
- // vertical
- if (ConfMan.getBool("fullscreen")) {
- gameYMin = 0;
- gameYMax = screenHeight;
+ int screenH = _km.y_max;
+ int screenW = _km.x_max;
+
+ bool fullscreen = ConfMan.getBool("fullscreen");
+ bool aspectRatioCorrection = ConfMan.getBool("aspect_ratio");
+
+ const int dispW = 960;
+ const int dispH = 544;
+
+ int x, y, w, h;
+ float sx, sy;
+ float ratio = (float)screenW / (float)screenH;
+
+ if (aspectRatioCorrection) {
+ ratio = 4.0 / 3.0;
+ }
+
+ if (fullscreen || screenH >= dispH) {
+ h = dispH;
+ if (aspectRatioCorrection) {
+ ratio = ratio * 1.1;
+ }
+ w = h * ratio;
} else {
- if (_km.y_max <= 272) {
- gameYMin = (screenHeight - (_km.y_max * 2)) / 2;
- gameYMax = screenHeight - gameYMin;
+ if (screenH <= dispH / 2 && screenW <= dispW / 2) {
+ // Use Vita hardware 2x scaling if the picture is really small
+ // this uses the current shader and filtering mode
+ h = screenH * 2;
+ w = screenW * 2;
} else {
- gameYMin = (screenHeight - (_km.y_max)) / 2;
- gameYMax = screenHeight - gameYMin;
+ h = screenH;
+ w = screenW;
+ }
+ if (aspectRatioCorrection) {
+ // stretch the height only if it fits, otherwise make the width smaller
+ if (((float)w * (1.0 / ratio)) <= (float)dispH) {
+ h = w * (1.0 / ratio);
+ } else {
+ w = h * ratio;
+ }
}
}
- // horizontal
- if (ConfMan.getBool("aspect_ratio")) {
- aspectRatio = 4.0/3.0;
- } else {
- aspectRatio = (float)_km.x_max / (float)_km.y_max;
+
+ x = (dispW - w) / 2;
+ y = (dispH - h) / 2;
+
+ sy = (float)h / (float)screenH;
+ sx = (float)w / (float)screenW;
+
+ // Find touch coordinates in terms of Vita screen pixels
+ float dispTouchX = (touchX * (float)dispW);
+ float dispTouchY = (touchY * (float)dispH);
+
+ *gameX = (dispTouchX - x) / sx;
+ *gameY = (dispTouchY - y) / sy;
+
+ if (*gameX < 0) {
+ *gameX = 0;
+ } else if (*gameX > _km.x_max) {
+ *gameX = _km.x_max;
}
- gameXMin = (960 - ((float)(gameYMax - gameYMin) * aspectRatio)) / 2;
- gameXMax = 960 - gameXMin;
-
- // find game pixel coordinates corresponding to front panel touch coordinates
- int x = ((screenTouchX - gameXMin) * _km.x_max) / (gameXMax - gameXMin);
- int y = ((screenTouchY - gameYMin) * _km.y_max) / (gameYMax - gameYMin);
-
- if (x < 0) {
- x = 0;
- } else if (x > _km.x_max) {
- x = _km.x_max;
- } else if (y < 0) {
- y = 0;
- } else if (y > _km.y_max) {
- y = _km.y_max;
+ if (*gameY < 0) {
+ *gameY = 0;
+ } else if (*gameY > _km.y_max) {
+ *gameY = _km.y_max;
}
- *gameX = x;
- *gameY = y;
}
-
#endif
diff --git a/backends/graphics/psp2sdl/psp2sdl-graphics.cpp b/backends/graphics/psp2sdl/psp2sdl-graphics.cpp
index 28e1e71332..1947f8f751 100644
--- a/backends/graphics/psp2sdl/psp2sdl-graphics.cpp
+++ b/backends/graphics/psp2sdl/psp2sdl-graphics.cpp
@@ -251,40 +251,50 @@ SDL_Surface *PSP2SdlGraphicsManager::SDL_SetVideoMode(int width, int height, int
}
void PSP2SdlGraphicsManager::SDL_UpdateRects(SDL_Surface *screen, int numrects, SDL_Rect *rects) {
+ int screenH = screen->h;
+ int screenW = screen->w;
+
+ bool fullscreen = _videoMode.fullscreen;
+ bool aspectRatioCorrection = _hardwareAspectRatioCorrection;
+
+ const int dispW = 960;
+ const int dispH = 544;
+
int x, y, w, h;
float sx, sy;
- float ratio = (float)screen->w / (float)screen->h;
+ float ratio = (float)screenW / (float)screenH;
- if ((_videoMode.screenHeight == 200 || _videoMode.screenHeight == 400) && _hardwareAspectRatioCorrection) {
- ratio = ratio * (200.0f / 240.0f);
+ if (aspectRatioCorrection) {
+ ratio = 4.0 / 3.0;
}
- if (_videoMode.fullscreen || screen->h >= 544) {
- h = 544;
+ if (fullscreen || screenH >= dispH) {
+ h = dispH;
w = h * ratio;
} else {
- if (screen->h <= 277 && screen->w <= 480) {
+ if (screenH <= dispH / 2 && screenW <= dispW / 2) {
// Use Vita hardware 2x scaling if the picture is really small
// this uses the current shader and filtering mode
- h = screen->h * 2;
- w = screen->w * 2;
+ h = screenH * 2;
+ w = screenW * 2;
} else {
- h = screen->h;
- w = screen->w;
+ h = screenH;
+ w = screenW;
}
- if ((_videoMode.screenHeight == 200 || _videoMode.screenHeight == 400) && _hardwareAspectRatioCorrection) {
+ if (aspectRatioCorrection) {
// stretch the height only if it fits, otherwise make the width smaller
- if (((float)w * (1.0f / ratio)) <= 544.0f) {
- h = w * (1.0f / ratio);
+ if (((float)w * (1.0 / ratio)) <= (float)dispH) {
+ h = w * (1.0 / ratio);
} else {
w = h * ratio;
}
}
}
-
- x = (960 - w) / 2; y = (544 - h) / 2;
- sx = (float)w / (float)screen->w;
- sy = (float)h / (float)screen->h;
+
+ x = (dispW - w) / 2;
+ y = (dispH - h) / 2;
+ sx = (float)w / (float)screenW;
+ sy = (float)h / (float)screenH;
if (_vitatex_hwscreen) {
vita2d_start_drawing();
vita2d_draw_texture_scale(_vitatex_hwscreen, x, y, sx, sy);