change touchscreen control method
This commit is contained in:
parent
21aec548af
commit
339fc41327
178
src/dinput.cc
178
src/dinput.cc
|
@ -1,4 +1,6 @@
|
||||||
#include "dinput.h"
|
#include "dinput.h"
|
||||||
|
#include "display_monitor.h"
|
||||||
|
#include "game_mouse.h"
|
||||||
|
|
||||||
namespace fallout {
|
namespace fallout {
|
||||||
|
|
||||||
|
@ -67,57 +69,6 @@ bool mouseDeviceUnacquire()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0x4E053C
|
|
||||||
bool mouseDeviceGetData(MouseData* mouseState)
|
|
||||||
{
|
|
||||||
if (gLastInputType == INPUT_TYPE_TOUCH) {
|
|
||||||
mouseState->x = gTouchMouseDeltaX;
|
|
||||||
mouseState->y = gTouchMouseDeltaY;
|
|
||||||
mouseState->buttons[0] = 0;
|
|
||||||
mouseState->buttons[1] = 0;
|
|
||||||
mouseState->wheelX = 0;
|
|
||||||
mouseState->wheelY = 0;
|
|
||||||
gTouchMouseDeltaX = 0;
|
|
||||||
gTouchMouseDeltaY = 0;
|
|
||||||
|
|
||||||
if (gTouchFingers == 0) {
|
|
||||||
if (SDL_GetTicks() - gTouchGestureLastTouchUpTimestamp > 150) {
|
|
||||||
if (!gTouchGestureHandled) {
|
|
||||||
if (gTouchGestureTaps == 2) {
|
|
||||||
mouseState->buttons[0] = 1;
|
|
||||||
gTouchGestureHandled = true;
|
|
||||||
} else if (gTouchGestureTaps == 3) {
|
|
||||||
mouseState->buttons[1] = 1;
|
|
||||||
gTouchGestureHandled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (gTouchFingers == 1) {
|
|
||||||
if (SDL_GetTicks() - gTouchGestureLastTouchDownTimestamp > 150) {
|
|
||||||
if (gTouchGestureTaps == 1) {
|
|
||||||
mouseState->buttons[0] = 1;
|
|
||||||
gTouchGestureHandled = true;
|
|
||||||
} else if (gTouchGestureTaps == 2) {
|
|
||||||
mouseState->buttons[1] = 1;
|
|
||||||
gTouchGestureHandled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Uint32 buttons = SDL_GetRelativeMouseState(&(mouseState->x), &(mouseState->y));
|
|
||||||
mouseState->buttons[0] = (buttons & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0;
|
|
||||||
mouseState->buttons[1] = (buttons & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
|
|
||||||
mouseState->wheelX = gMouseWheelDeltaX;
|
|
||||||
mouseState->wheelY = gMouseWheelDeltaY;
|
|
||||||
|
|
||||||
gMouseWheelDeltaX = 0;
|
|
||||||
gMouseWheelDeltaY = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 0x4E05A8
|
// 0x4E05A8
|
||||||
bool keyboardDeviceAcquire()
|
bool keyboardDeviceAcquire()
|
||||||
{
|
{
|
||||||
|
@ -192,44 +143,119 @@ void handleMouseEvent(SDL_Event* event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool em_mode = false;
|
||||||
|
static SDL_FingerID lastTouchId = -1;
|
||||||
|
static Uint32 lastType = -1;
|
||||||
|
|
||||||
|
static bool longPressed = false;
|
||||||
|
static bool clicked = false;
|
||||||
|
|
||||||
|
bool mouseDeviceGetData(MouseData* mouseState)
|
||||||
|
{
|
||||||
|
if (gLastInputType == INPUT_TYPE_TOUCH) {
|
||||||
|
mouseState->x = gTouchMouseDeltaX;
|
||||||
|
mouseState->y = gTouchMouseDeltaY;
|
||||||
|
mouseState->buttons[0] = 0;
|
||||||
|
mouseState->buttons[1] = 0;
|
||||||
|
mouseState->wheelX = 0;
|
||||||
|
mouseState->wheelY = 0;
|
||||||
|
gTouchMouseDeltaX = 0;
|
||||||
|
gTouchMouseDeltaY = 0;
|
||||||
|
|
||||||
|
if (lastType == SDL_FINGERDOWN && SDL_GetTicks() - gTouchGestureLastTouchUpTimestamp > 250) {
|
||||||
|
longPressed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (longPressed) {
|
||||||
|
mouseState->buttons[0] = 1;
|
||||||
|
clicked = false;
|
||||||
|
} else if (clicked) {
|
||||||
|
clicked = false;
|
||||||
|
if (em_mode) {
|
||||||
|
mouseState->x = gTouchMouseDeltaX;
|
||||||
|
mouseState->y = gTouchMouseDeltaY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gTouchMouseLastX < screenGetWidth() / 4) {
|
||||||
|
mouseState->buttons[1] = 1;
|
||||||
|
} else {
|
||||||
|
mouseState->buttons[0] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Uint32 buttons = SDL_GetRelativeMouseState(&(mouseState->x), &(mouseState->y));
|
||||||
|
mouseState->buttons[0] = (buttons & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0;
|
||||||
|
mouseState->buttons[1] = (buttons & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
|
||||||
|
mouseState->wheelX = gMouseWheelDeltaX;
|
||||||
|
mouseState->wheelY = gMouseWheelDeltaY;
|
||||||
|
|
||||||
|
gMouseWheelDeltaX = 0;
|
||||||
|
gMouseWheelDeltaY = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void handleTouchEvent(SDL_Event* event)
|
void handleTouchEvent(SDL_Event* event)
|
||||||
{
|
{
|
||||||
int windowWidth = screenGetWidth();
|
int windowWidth = screenGetWidth();
|
||||||
int windowHeight = screenGetHeight();
|
int windowHeight = screenGetHeight();
|
||||||
|
|
||||||
if (event->tfinger.type == SDL_FINGERDOWN) {
|
Uint32 type = event->tfinger.type;
|
||||||
gTouchFingers++;
|
SDL_FingerID id = event->tfinger.fingerId;
|
||||||
|
|
||||||
|
if (id >= 2)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (type == SDL_FINGERDOWN) {
|
||||||
|
if (lastTouchId != -1 && id != lastTouchId) {
|
||||||
|
//displayMonitorAddMessage("em true");
|
||||||
|
em_mode = true;
|
||||||
|
}
|
||||||
|
lastTouchId = id;
|
||||||
|
|
||||||
|
gTouchGestureLastTouchUpTimestamp = event->tfinger.timestamp;
|
||||||
|
|
||||||
gTouchMouseLastX = (int)(event->tfinger.x * windowWidth);
|
gTouchMouseLastX = (int)(event->tfinger.x * windowWidth);
|
||||||
gTouchMouseLastY = (int)(event->tfinger.y * windowHeight);
|
gTouchMouseLastY = (int)(event->tfinger.y * windowHeight);
|
||||||
gTouchMouseDeltaX = 0;
|
gTouchMouseDeltaX = 0;
|
||||||
gTouchMouseDeltaY = 0;
|
gTouchMouseDeltaY = 0;
|
||||||
|
|
||||||
if (event->tfinger.timestamp - gTouchGestureLastTouchDownTimestamp > 250) {
|
lastType = SDL_FINGERDOWN;
|
||||||
gTouchGestureTaps = 0;
|
clicked = false;
|
||||||
gTouchGestureHandled = false;
|
} else if (type == SDL_FINGERMOTION) {
|
||||||
|
if (id == lastTouchId) {
|
||||||
|
int prevX = gTouchMouseLastX;
|
||||||
|
int prevY = gTouchMouseLastY;
|
||||||
|
gTouchMouseLastX = (int)(event->tfinger.x * windowWidth);
|
||||||
|
gTouchMouseLastY = (int)(event->tfinger.y * windowHeight);
|
||||||
|
if(event->tfinger.x < 0.5){
|
||||||
|
gTouchMouseDeltaX += (gTouchMouseLastX - prevX) * 2;
|
||||||
|
gTouchMouseDeltaY += (gTouchMouseLastY - prevY) * 2;
|
||||||
|
} else {
|
||||||
|
gTouchMouseDeltaX += gTouchMouseLastX - prevX;
|
||||||
|
gTouchMouseDeltaY += gTouchMouseLastY - prevY;
|
||||||
|
}
|
||||||
|
gTouchGestureLastTouchUpTimestamp = -1;
|
||||||
|
|
||||||
|
lastType = SDL_FINGERMOTION;
|
||||||
|
clicked = false;
|
||||||
}
|
}
|
||||||
|
} else if (type == SDL_FINGERUP) {
|
||||||
|
if (id != lastTouchId) {
|
||||||
|
em_mode = false;
|
||||||
|
} else {
|
||||||
|
clicked = false;
|
||||||
|
|
||||||
gTouchGestureLastTouchDownTimestamp = event->tfinger.timestamp;
|
if (lastType == SDL_FINGERDOWN && longPressed == false) {
|
||||||
} else if (event->tfinger.type == SDL_FINGERMOTION) {
|
clicked = true;
|
||||||
int prevX = gTouchMouseLastX;
|
}
|
||||||
int prevY = gTouchMouseLastY;
|
longPressed = false;
|
||||||
gTouchMouseLastX = (int)(event->tfinger.x * windowWidth);
|
gTouchGestureLastTouchUpTimestamp = -1;
|
||||||
gTouchMouseLastY = (int)(event->tfinger.y * windowHeight);
|
lastTouchId = -1;
|
||||||
gTouchMouseDeltaX += gTouchMouseLastX - prevX;
|
lastType = SDL_FINGERUP;
|
||||||
gTouchMouseDeltaY += gTouchMouseLastY - prevY;
|
}
|
||||||
} else if (event->tfinger.type == SDL_FINGERUP) {
|
|
||||||
gTouchFingers--;
|
|
||||||
|
|
||||||
int prevX = gTouchMouseLastX;
|
|
||||||
int prevY = gTouchMouseLastY;
|
|
||||||
gTouchMouseLastX = (int)(event->tfinger.x * windowWidth);
|
|
||||||
gTouchMouseLastY = (int)(event->tfinger.y * windowHeight);
|
|
||||||
gTouchMouseDeltaX += gTouchMouseLastX - prevX;
|
|
||||||
gTouchMouseDeltaY += gTouchMouseLastY - prevY;
|
|
||||||
|
|
||||||
gTouchGestureTaps++;
|
|
||||||
gTouchGestureLastTouchUpTimestamp = event->tfinger.timestamp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gLastInputType != INPUT_TYPE_TOUCH) {
|
if (gLastInputType != INPUT_TYPE_TOUCH) {
|
||||||
|
|
Loading…
Reference in New Issue