Android touch double tap detection (Refs #173) [skip ci]
This commit is contained in:
parent
9edc993bf9
commit
bf82026295
2 changed files with 21 additions and 5 deletions
|
|
@ -1181,6 +1181,9 @@ int32_t VulkanExampleBase::handleAppInput(struct android_app* app, AInputEvent*
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case AMOTION_EVENT_ACTION_UP: {
|
case AMOTION_EVENT_ACTION_UP: {
|
||||||
|
vulkanExample->lastTapTime = AMotionEvent_getEventTime(event);
|
||||||
|
vulkanExample->touchPos.x = AMotionEvent_getX(event, 0);
|
||||||
|
vulkanExample->touchPos.y = AMotionEvent_getY(event, 0);
|
||||||
vulkanExample->touchTimer = 0.0;
|
vulkanExample->touchTimer = 0.0;
|
||||||
vulkanExample->touchDown = false;
|
vulkanExample->touchDown = false;
|
||||||
vulkanExample->camera.keys.up = false;
|
vulkanExample->camera.keys.up = false;
|
||||||
|
|
@ -1188,9 +1191,22 @@ int32_t VulkanExampleBase::handleAppInput(struct android_app* app, AInputEvent*
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AMOTION_EVENT_ACTION_DOWN: {
|
case AMOTION_EVENT_ACTION_DOWN: {
|
||||||
|
// Detect double tap
|
||||||
|
int64_t eventTime = AMotionEvent_getEventTime(event);
|
||||||
|
if (eventTime - vulkanExample->lastTapTime <= vks::android::DOUBLE_TAP_TIMEOUT) {
|
||||||
|
float deadZone = (160.f / vks::android::screenDensity) * vks::android::DOUBLE_TAP_SLOP * vks::android::DOUBLE_TAP_SLOP;
|
||||||
|
float x = AMotionEvent_getX(event, 0) - vulkanExample->touchPos.x;
|
||||||
|
float y = AMotionEvent_getY(event, 0) - vulkanExample->touchPos.y;
|
||||||
|
if ((x * x + y * y) < deadZone) {
|
||||||
|
vulkanExample->keyPressed(TOUCH_DOUBLE_TAP);
|
||||||
|
vulkanExample->touchDown = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
vulkanExample->touchDown = true;
|
||||||
|
}
|
||||||
vulkanExample->touchPos.x = AMotionEvent_getX(event, 0);
|
vulkanExample->touchPos.x = AMotionEvent_getX(event, 0);
|
||||||
vulkanExample->touchPos.y = AMotionEvent_getY(event, 0);
|
vulkanExample->touchPos.y = AMotionEvent_getY(event, 0);
|
||||||
vulkanExample->touchDown = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AMOTION_EVENT_ACTION_MOVE: {
|
case AMOTION_EVENT_ACTION_MOVE: {
|
||||||
|
|
@ -1210,7 +1226,6 @@ int32_t VulkanExampleBase::handleAppInput(struct android_app* app, AInputEvent*
|
||||||
|
|
||||||
vulkanExample->touchPos.x = eventX;
|
vulkanExample->touchPos.x = eventX;
|
||||||
vulkanExample->touchPos.y = eventY;
|
vulkanExample->touchPos.y = eventY;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Base", "Base", "{09B9A54B-F
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
base\camera.hpp = base\camera.hpp
|
base\camera.hpp = base\camera.hpp
|
||||||
base\frustum.hpp = base\frustum.hpp
|
base\frustum.hpp = base\frustum.hpp
|
||||||
|
base\keycodes.hpp = base\keycodes.hpp
|
||||||
base\threadpool.hpp = base\threadpool.hpp
|
base\threadpool.hpp = base\threadpool.hpp
|
||||||
base\vulkanandroid.cpp = base\vulkanandroid.cpp
|
base\vulkanandroid.cpp = base\vulkanandroid.cpp
|
||||||
base\vulkanandroid.h = base\vulkanandroid.h
|
base\vulkanandroid.h = base\vulkanandroid.h
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue