added basic gesture system on Android

This commit is contained in:
2017-04-18 01:10:06 +02:00
parent 45cf8c9168
commit ea1bff1f10
5 changed files with 141 additions and 3 deletions

View File

@@ -373,20 +373,78 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
// case AINPUT_SOURCE_TOUCHSCREEN:
{
int action = AKeyEvent_getAction(event) & AMOTION_EVENT_ACTION_MASK;
float x = AMotionEvent_getX(event, 0);
float y = AMotionEvent_getY(event, 0);
int32_t index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)
>> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
int pointer_id = AMotionEvent_getPointerId(event, index);
int32_t count = AMotionEvent_getPointerCount(event);
struct Pointer
{
int id = -1;
int idx;
glm::vec2 pos;
};
static Pointer p0, p1;
static int tracked = 0;
float x = AMotionEvent_getX(event, index);
float y = AMotionEvent_getY(event, index);
//LOG("event source: %d", AInputEvent_getSource(event));
MouseEvent e;
switch (action) {
case AMOTION_EVENT_ACTION_DOWN:
p0.id = AMotionEvent_getPointerId(event, 0);
p0.pos = {x, y};
App::I.mouse_down(0, x, y);
tracked = 1;
LOG("first down");
return 1;
case AMOTION_EVENT_ACTION_POINTER_DOWN:
if (count == 2)
{
p1.id = AMotionEvent_getPointerId(event, index);
p1.idx = index;
p1.pos = {x, y};
tracked = 2;
LOG("second down");
App::I.mouse_cancel(0);
App::I.gesture_start(p0.pos, p1.pos);
}
return 1;
case AMOTION_EVENT_ACTION_UP:
tracked = 0;
p0.id = -1;
p1.id = -1;
App::I.mouse_up(0, x, y);
LOG("first up");
return 1;
case AMOTION_EVENT_ACTION_POINTER_UP:
if (p1.id == AMotionEvent_getPointerId(event, index))
{
p1.id = -1;
LOG("second up");
App::I.gesture_end();
}
return 1;
case AMOTION_EVENT_ACTION_HOVER_MOVE: // pen move before touching
case AMOTION_EVENT_ACTION_MOVE:
App::I.mouse_move(x, y);
if (tracked == 1)
{
App::I.mouse_move(x, y);
LOG("single move");
}
else
{
if (p0.id == pointer_id)
{
LOG("first move");
p0.pos = {x, y};
}
if (p1.id == pointer_id)
{
LOG("second move");
p1.pos = {x, y};
}
App::I.gesture_move(p0.pos, p1.pos);
}
return 1;
default:
//LOG("motion action: %d", action);