]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/android/touchscreen.cpp
Add touchscreen support on Android
[libs/gui.git] / source / input / android / touchscreen.cpp
index bfbf7aaa8181c78aa73373fddf56de71b989f374..f4703c340b8d5cca4fc9164a16a57d0474b01726 100644 (file)
@@ -1,10 +1,36 @@
+#include <msp/graphics/window_private.h>
 #include "touchscreen.h"
 
 namespace Msp {
 namespace Input {
 
-void Touchscreen::input_event(const Graphics::Window::Event &)
+void Touchscreen::input_event(const Graphics::Window::Event &event)
 {
+       int action = AMotionEvent_getAction(event.aevent);
+       int action_pointer = (action&AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)>>AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
+       action &= AMOTION_EVENT_ACTION_MASK;
+
+       int pointer_count = AMotionEvent_getPointerCount(event.aevent);
+       for(int i=0; i<pointer_count; ++i)
+       {
+               int pointer = AMotionEvent_getPointerId(event.aevent, i);
+               float x = AMotionEvent_getX(event.aevent, i);
+               float y = AMotionEvent_getY(event.aevent, i);
+               touch_move(pointer, x*2/window.get_width()-1, 1-y*2/window.get_height());
+       }
+
+       switch(action)
+       {
+       case AMOTION_EVENT_ACTION_DOWN:
+       case AMOTION_EVENT_ACTION_POINTER_DOWN:
+               touch_down(AMotionEvent_getPointerId(event.aevent, action_pointer));
+               break;
+       case AMOTION_EVENT_ACTION_UP:
+       case AMOTION_EVENT_ACTION_POINTER_UP:
+               touch_up(AMotionEvent_getPointerId(event.aevent, action_pointer));
+               break;
+       default:;
+       }
 }
 
 } // namespace Input