1 #include <msp/graphics/window_private.h>
2 #include "touchscreen.h"
7 bool Touchscreen::is_available()
12 void Touchscreen::input_event(const Graphics::Window::Event &event)
14 int type = AInputEvent_getType(event.aevent);
15 if(type!=AINPUT_EVENT_TYPE_MOTION)
18 int source = AInputEvent_getSource(event.aevent);
19 if(source!=AINPUT_SOURCE_TOUCHSCREEN && source!=AINPUT_SOURCE_STYLUS)
22 int action = AMotionEvent_getAction(event.aevent);
23 int action_pointer = (action&AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)>>AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
24 action &= AMOTION_EVENT_ACTION_MASK;
26 int pointer_count = AMotionEvent_getPointerCount(event.aevent);
27 for(int i=0; i<pointer_count; ++i)
29 int pointer = AMotionEvent_getPointerId(event.aevent, i);
30 float x = AMotionEvent_getX(event.aevent, i);
31 float y = AMotionEvent_getY(event.aevent, i);
32 touch_move(pointer, x*2/window.get_width()-1, 1-y*2/window.get_height());
37 case AMOTION_EVENT_ACTION_DOWN:
38 case AMOTION_EVENT_ACTION_POINTER_DOWN:
39 touch_down(AMotionEvent_getPointerId(event.aevent, action_pointer));
41 case AMOTION_EVENT_ACTION_UP:
42 case AMOTION_EVENT_ACTION_POINTER_UP:
43 touch_up(AMotionEvent_getPointerId(event.aevent, action_pointer));