]> git.tdb.fi Git - libs/gui.git/blob - source/input/android/touchscreen.cpp
6472f4476b973d2b813f6404af8e787f3d7e14e1
[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 bool Touchscreen::is_available()
8 {
9         return true;
10 }
11
12 void Touchscreen::input_event(const Graphics::Window::Event &event)
13 {
14         int action = AMotionEvent_getAction(event.aevent);
15         int action_pointer = (action&AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)>>AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
16         action &= AMOTION_EVENT_ACTION_MASK;
17
18         int pointer_count = AMotionEvent_getPointerCount(event.aevent);
19         for(int i=0; i<pointer_count; ++i)
20         {
21                 int pointer = AMotionEvent_getPointerId(event.aevent, i);
22                 float x = AMotionEvent_getX(event.aevent, i);
23                 float y = AMotionEvent_getY(event.aevent, i);
24                 touch_move(pointer, x*2/window.get_width()-1, 1-y*2/window.get_height());
25         }
26
27         switch(action)
28         {
29         case AMOTION_EVENT_ACTION_DOWN:
30         case AMOTION_EVENT_ACTION_POINTER_DOWN:
31                 touch_down(AMotionEvent_getPointerId(event.aevent, action_pointer));
32                 break;
33         case AMOTION_EVENT_ACTION_UP:
34         case AMOTION_EVENT_ACTION_POINTER_UP:
35                 touch_up(AMotionEvent_getPointerId(event.aevent, action_pointer));
36                 break;
37         default:;
38         }
39 }
40
41 } // namespace Input
42 } // namespace Msp