Cleanup touch. Fix back touchscreen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
diff --git a/src/video/vita/SDL_vitatouch.c b/src/video/vita/SDL_vitatouch.c
index f101d35..47770db 100644
--- a/src/video/vita/SDL_vitatouch.c
+++ b/src/video/vita/SDL_vitatouch.c
@@ -35,13 +35,13 @@
SceTouchData touch_old[SCE_TOUCH_PORT_MAX_NUM];
SceTouchData touch[SCE_TOUCH_PORT_MAX_NUM];
-SceTouchPanelInfo panelinfo[SCE_TOUCH_PORT_MAX_NUM];
+SDL_FRect area_info[SCE_TOUCH_PORT_MAX_NUM];
+SDL_FRect display_info[SCE_TOUCH_PORT_MAX_NUM];
-float aAWidth[SCE_TOUCH_PORT_MAX_NUM];
-float aAHeight[SCE_TOUCH_PORT_MAX_NUM];
-float dispWidth[SCE_TOUCH_PORT_MAX_NUM];
-float dispHeight[SCE_TOUCH_PORT_MAX_NUM];
-float forcerange[SCE_TOUCH_PORT_MAX_NUM];
+struct{
+ float min;
+ float range;
+} force_info[SCE_TOUCH_PORT_MAX_NUM];
void
VITA_InitTouch(void)
@@ -51,14 +51,22 @@ VITA_InitTouch(void)
sceTouchEnableTouchForce(SCE_TOUCH_PORT_FRONT);
sceTouchEnableTouchForce(SCE_TOUCH_PORT_BACK);
- SceTouchPanelInfo panelinfo[SCE_TOUCH_PORT_MAX_NUM];
for(int port = 0; port < SCE_TOUCH_PORT_MAX_NUM; port++) {
- sceTouchGetPanelInfo(port, &panelinfo[port]);
- aAWidth[port] = (float)(panelinfo[port].maxAaX - panelinfo[port].minAaX);
- aAHeight[port] = (float)(panelinfo[port].maxAaY - panelinfo[port].minAaY);
- dispWidth[port] = (float)(panelinfo[port].maxDispX - panelinfo[port].minDispX);
- dispHeight[port] = (float)(panelinfo[port].maxDispY - panelinfo[port].minDispY);
- forcerange[port] = (float)(panelinfo[port].maxForce - panelinfo[port].minForce);
+ SceTouchPanelInfo panelinfo;
+ sceTouchGetPanelInfo(port, &panelinfo);
+
+ area_info[port].x = (float)panelinfo.minAaX;
+ area_info[port].y = (float)panelinfo.minAaY;
+ area_info[port].w = (float)(panelinfo.maxAaX - panelinfo.minAaX);
+ area_info[port].h = (float)(panelinfo.maxAaY - panelinfo.minAaY);
+
+ display_info[port].x = (float)panelinfo.minDispX;
+ display_info[port].y = (float)panelinfo.minDispY;
+ display_info[port].w = (float)(panelinfo.maxDispX - panelinfo.minDispX);
+ display_info[port].h = (float)(panelinfo.maxDispY - panelinfo.minDispY);
+
+ force_info[port].min = (float)panelinfo.minForce;
+ force_info[port].range = (float)(panelinfo.maxForce - panelinfo.minForce);
}
// Support passing both front and back touch devices in events
@@ -96,7 +104,7 @@ VITA_PollTouch(void)
float x = 0;
float y = 0;
VITA_ConvertTouchXYToSDLXY(&x, &y, touch[port].report[i].x, touch[port].report[i].y, port);
- float force = (touch[port].report[i].force - panelinfo[port].minForce) / forcerange[port];
+ float force = (touch[port].report[i].force - force_info[port].min) / force_info[port].range;
finger_id = (SDL_FingerID) touch[port].report[i].id;
// Send an initial touch
@@ -133,7 +141,7 @@ VITA_PollTouch(void)
float x = 0;
float y = 0;
VITA_ConvertTouchXYToSDLXY(&x, &y, touch_old[port].report[i].x, touch_old[port].report[i].y, port);
- float force = (touch_old[port].report[i].force - panelinfo[port].minForce) / forcerange[port];
+ float force = (touch_old[port].report[i].force - force_info[port].min) / force_info[port].range;
finger_id = (SDL_FingerID) touch_old[port].report[i].id;
// Finger released from screen
SDL_SendTouch((SDL_TouchID)port,
@@ -150,25 +158,25 @@ VITA_PollTouch(void)
}
void VITA_ConvertTouchXYToSDLXY(float *sdl_x, float *sdl_y, int vita_x, int vita_y, int port) {
- float x = 0;
- float y = 0;
+ float x = 0.f;
+ float y = 0.f;
+ SDL_FRect rect;
+
if (port == SCE_TOUCH_PORT_FRONT) {
- x = (vita_x - panelinfo[port].minDispX) / dispWidth[port];
- y = (vita_y - panelinfo[port].minDispY) / dispHeight[port];
+ rect = display_info[port];
} else {
- x = (vita_x - panelinfo[port].minAaX) / aAWidth[port];
- y = (vita_y - panelinfo[port].minAaY) / aAHeight[port];
- }
- if (x < 0.0) {
- x = 0.0;
- } else if (x > 1.0) {
- x = 1.0;
- }
- if (y < 0.0) {
- y = 0.0;
- } else if (y > 1.0) {
- y = 1.0;
+ rect = area_info[port];
}
+
+ x = (vita_x - rect.x) / rect.w;
+ y = (vita_y - rect.y) / rect.h;
+
+ x = SDL_max(x, 0.0);
+ x = SDL_min(x, 1.0);
+
+ y = SDL_max(y, 0.0);
+ y = SDL_min(y, 1.0);
+
*sdl_x = x;
*sdl_y = y;
}