Add touch input support

Touch input works as a drop-in replacement to the mouse. Touch will be
disabled automatically on overlays to prevent conflicting functions.
This commit is contained in:
RadialApps 2017-08-08 20:42:56 +05:30
parent 5354acca30
commit 051cde9ff8
3 changed files with 43 additions and 1 deletions

View File

@ -396,6 +396,7 @@ void EventThread::process(RGSSThreadData &rtData)
case SDL_FINGERUP : case SDL_FINGERUP :
i = event.tfinger.fingerId; i = event.tfinger.fingerId;
memset(&touchState.fingers[i], 0, sizeof(touchState.fingers[0])); memset(&touchState.fingers[i], 0, sizeof(touchState.fingers[0]));
touchState.ignoreMouse = false;
break; break;
default : default :

View File

@ -68,6 +68,7 @@ public:
struct TouchState struct TouchState
{ {
bool ignoreMouse;
FingerState fingers[MAX_FINGERS]; FingerState fingers[MAX_FINGERS];
}; };

View File

@ -192,6 +192,15 @@ struct MsBinding : public Binding
bool sourceActive() const bool sourceActive() const
{ {
#ifdef __ANDROID__
if (index == 1 && EventThread::touchState.ignoreMouse == false)
{
for (size_t i = 0; i < MAX_FINGERS; ++i)
{
if (EventThread::touchState.fingers[i].down) return true;
}
}
#endif
return EventThread::mouseState.buttons[index]; return EventThread::mouseState.buttons[index];
} }
@ -266,7 +275,10 @@ struct OlBinding : public Binding
{ {
if ((x >= olb.x && x <= olb.x + olb.u.r.width) if ((x >= olb.x && x <= olb.x + olb.u.r.width)
&& y >= olb.y && y <= olb.y + olb.u.r.height) && y >= olb.y && y <= olb.y + olb.u.r.height)
{
EventThread::touchState.ignoreMouse = true;
return true; return true;
}
break; break;
} }
@ -277,7 +289,10 @@ struct OlBinding : public Binding
int d = sqrt(dx*dx + dy*dy); int d = sqrt(dx*dx + dy*dy);
if (d <= olb.u.c.radius) if (d <= olb.u.c.radius)
{
EventThread::touchState.ignoreMouse = true;
return true; return true;
}
break; break;
} }
@ -290,7 +305,10 @@ struct OlBinding : public Binding
s2 = areaSign(x, y, olb.u.t.x2, olb.u.t.y2, olb.x, olb.y) < 0; s2 = areaSign(x, y, olb.u.t.x2, olb.u.t.y2, olb.x, olb.y) < 0;
if ((s0 == s1) && (s1 == s2)) if ((s0 == s1) && (s1 == s2))
{
EventThread::touchState.ignoreMouse = true;
return true; return true;
}
break; break;
} }
@ -549,8 +567,8 @@ struct InputPrivate
bindings.clear(); bindings.clear();
appendBindings(kbStatBindings); appendBindings(kbStatBindings);
appendBindings(msBindings);
appendBindings(olBindings); appendBindings(olBindings);
appendBindings(msBindings);
appendBindings(kbBindings); appendBindings(kbBindings);
appendBindings(jsABindings); appendBindings(jsABindings);
@ -782,6 +800,17 @@ int Input::dir8Value()
int Input::mouseX() int Input::mouseX()
{ {
RGSSThreadData &rtData = shState->rtData(); RGSSThreadData &rtData = shState->rtData();
#ifdef __ANDROID__
for (auto i : p->olBindings) if (i.sourceActive()) return -1;
if (EventThread::touchState.ignoreMouse == false)
for (size_t i = 0; i < MAX_FINGERS; ++i)
{
EventThread::FingerState &f = EventThread::touchState.fingers[i];
if (!f.down) continue;
return (f.x - rtData.screenOffset.x) * rtData.sizeResoRatio.x;
}
#endif
return (EventThread::mouseState.x - rtData.screenOffset.x) * rtData.sizeResoRatio.x; return (EventThread::mouseState.x - rtData.screenOffset.x) * rtData.sizeResoRatio.x;
} }
@ -790,6 +819,17 @@ int Input::mouseY()
{ {
RGSSThreadData &rtData = shState->rtData(); RGSSThreadData &rtData = shState->rtData();
#ifdef __ANDROID__
for (auto i : p->olBindings) if (i.sourceActive()) return -1;
if (EventThread::touchState.ignoreMouse == false)
for (size_t i = 0; i < MAX_FINGERS; ++i)
{
EventThread::FingerState &f = EventThread::touchState.fingers[i];
if (!f.down) continue;
return (f.y - rtData.screenOffset.y) * rtData.sizeResoRatio.y;
}
#endif
return (EventThread::mouseState.y - rtData.screenOffset.y) * rtData.sizeResoRatio.y; return (EventThread::mouseState.y - rtData.screenOffset.y) * rtData.sizeResoRatio.y;
} }