]> git.tdb.fi Git - libs/gui.git/blob - source/input/android/touchscreen.cpp
Add touchscreen support on Android
[libs/gui.git] / source / input / android / touchscreen.cpp
1 #include <msp/graphics/window_private.h>
2 #include "touchscreen.h"
3
4 namespace Msp {
5 namespace Input {
6
7 void Touchscreen::input_event(const Graphics::Window::Event &event)
8 {
9         int action = AMotionEvent_getAction(event.aevent);
10         int action_pointer = (action&AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)>>AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
11         action &= AMOTION_EVENT_ACTION_MASK;
12
13         int pointer_count = AMotionEvent_getPointerCount(event.aevent);
14         for(int i=0; i<pointer_count; ++i)
15         {
16                 int pointer = AMotionEvent_getPointerId(event.aevent, i);
17                 float x = AMotionEvent_getX(event.aevent, i);
18                 float y = AMotionEvent_getY(event.aevent, i);
19                 touch_move(pointer, x*2/window.get_width()-1, 1-y*2/window.get_height());
20         }
21
22         switch(action)
23         {
24         case AMOTION_EVENT_ACTION_DOWN:
25         case AMOTION_EVENT_ACTION_POINTER_DOWN:
26                 touch_down(AMotionEvent_getPointerId(event.aevent, action_pointer));
27                 break;
28         case AMOTION_EVENT_ACTION_UP:
29         case AMOTION_EVENT_ACTION_POINTER_UP:
30                 touch_up(AMotionEvent_getPointerId(event.aevent, action_pointer));
31                 break;
32         default:;
33         }
34 }
35
36 } // namespace Input
37 } // namespace Msp