mirror of https://github.com/OpenRCT2/OpenRCT2.git
Merge pull request #2520 from samdroid-apps/touch-as-cursor-try-2
Handle touch events
This commit is contained in:
commit
5d8cd60c8c
|
@ -41,6 +41,8 @@
|
||||||
|
|
||||||
#define INVALID_HANDLE -1
|
#define INVALID_HANDLE -1
|
||||||
|
|
||||||
|
#define TOUCH_DOUBLE_TIMEOUT 300
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int width, height;
|
int width, height;
|
||||||
} resolution;
|
} resolution;
|
||||||
|
@ -69,6 +71,8 @@ typedef struct {
|
||||||
unsigned char left, middle, right, any;
|
unsigned char left, middle, right, any;
|
||||||
int wheel;
|
int wheel;
|
||||||
int old;
|
int old;
|
||||||
|
bool touch, touchIsDouble;
|
||||||
|
unsigned int touchDownTimestamp;
|
||||||
} openrct2_cursor;
|
} openrct2_cursor;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|
|
@ -426,6 +426,7 @@ void platform_process_messages()
|
||||||
gCursorState.middle &= ~CURSOR_CHANGED;
|
gCursorState.middle &= ~CURSOR_CHANGED;
|
||||||
gCursorState.right &= ~CURSOR_CHANGED;
|
gCursorState.right &= ~CURSOR_CHANGED;
|
||||||
gCursorState.old = 0;
|
gCursorState.old = 0;
|
||||||
|
gCursorState.touch = false;
|
||||||
|
|
||||||
while (SDL_PollEvent(&e)) {
|
while (SDL_PollEvent(&e)) {
|
||||||
switch (e.type) {
|
switch (e.type) {
|
||||||
|
@ -466,6 +467,13 @@ void platform_process_messages()
|
||||||
gCursorState.x = (int)(e.motion.x / gConfigGeneral.window_scale);
|
gCursorState.x = (int)(e.motion.x / gConfigGeneral.window_scale);
|
||||||
gCursorState.y = (int)(e.motion.y / gConfigGeneral.window_scale);
|
gCursorState.y = (int)(e.motion.y / gConfigGeneral.window_scale);
|
||||||
break;
|
break;
|
||||||
|
case SDL_FINGERMOTION:
|
||||||
|
RCT2_GLOBAL(0x0142406C, int) = (int)(e.tfinger.x / gConfigGeneral.window_scale);
|
||||||
|
RCT2_GLOBAL(0x01424070, int) = (int)(e.tfinger.y / gConfigGeneral.window_scale);
|
||||||
|
|
||||||
|
gCursorState.x = (int)(e.tfinger.x / gConfigGeneral.window_scale);
|
||||||
|
gCursorState.y = (int)(e.tfinger.y / gConfigGeneral.window_scale);
|
||||||
|
break;
|
||||||
case SDL_MOUSEWHEEL:
|
case SDL_MOUSEWHEEL:
|
||||||
if (gConsoleOpen) {
|
if (gConsoleOpen) {
|
||||||
console_scroll(e.wheel.y);
|
console_scroll(e.wheel.y);
|
||||||
|
@ -492,6 +500,25 @@ void platform_process_messages()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case SDL_FINGERDOWN:
|
||||||
|
RCT2_GLOBAL(0x01424318, int) = (int)(e.tfinger.x / gConfigGeneral.window_scale);
|
||||||
|
RCT2_GLOBAL(0x0142431C, int) = (int)(e.tfinger.y / gConfigGeneral.window_scale);
|
||||||
|
|
||||||
|
gCursorState.touchIsDouble = (!gCursorState.touchIsDouble
|
||||||
|
&& e.tfinger.timestamp - gCursorState.touchDownTimestamp < TOUCH_DOUBLE_TIMEOUT);
|
||||||
|
|
||||||
|
if (gCursorState.touchIsDouble) {
|
||||||
|
store_mouse_input(3);
|
||||||
|
gCursorState.right = CURSOR_PRESSED;
|
||||||
|
gCursorState.old = 2;
|
||||||
|
} else {
|
||||||
|
store_mouse_input(1);
|
||||||
|
gCursorState.left = CURSOR_PRESSED;
|
||||||
|
gCursorState.old = 1;
|
||||||
|
}
|
||||||
|
gCursorState.touch = true;
|
||||||
|
gCursorState.touchDownTimestamp = e.tfinger.timestamp;
|
||||||
|
break;
|
||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
RCT2_GLOBAL(0x01424318, int) = (int)(e.button.x / gConfigGeneral.window_scale);
|
RCT2_GLOBAL(0x01424318, int) = (int)(e.button.x / gConfigGeneral.window_scale);
|
||||||
RCT2_GLOBAL(0x0142431C, int) = (int)(e.button.y / gConfigGeneral.window_scale);
|
RCT2_GLOBAL(0x0142431C, int) = (int)(e.button.y / gConfigGeneral.window_scale);
|
||||||
|
@ -511,6 +538,21 @@ void platform_process_messages()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case SDL_FINGERUP:
|
||||||
|
RCT2_GLOBAL(0x01424318, int) = (int)(e.tfinger.x / gConfigGeneral.window_scale);
|
||||||
|
RCT2_GLOBAL(0x0142431C, int) = (int)(e.tfinger.y / gConfigGeneral.window_scale);
|
||||||
|
|
||||||
|
if (gCursorState.touchIsDouble) {
|
||||||
|
store_mouse_input(4);
|
||||||
|
gCursorState.left = CURSOR_RELEASED;
|
||||||
|
gCursorState.old = 4;
|
||||||
|
} else {
|
||||||
|
store_mouse_input(2);
|
||||||
|
gCursorState.left = CURSOR_RELEASED;
|
||||||
|
gCursorState.old = 3;
|
||||||
|
}
|
||||||
|
gCursorState.touch = true;
|
||||||
|
break;
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
if (gTextInputCompositionActive) break;
|
if (gTextInputCompositionActive) break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue