]> git.tdb.fi Git - libs/gui.git/commitdiff
Add touchscreen support on Android
authorMikko Rasa <tdb@tdb.fi>
Fri, 19 Dec 2014 01:30:41 +0000 (03:30 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 19 Dec 2014 01:54:41 +0000 (03:54 +0200)
source/input/android/mouse.cpp
source/input/android/touchscreen.cpp

index b16b6be2331077f48e57ddc2ee4deadde932ea01..3fbc5bebab3affc54b8d478fcdc412f7680dd4ca 100644 (file)
@@ -10,6 +10,10 @@ void Mouse::input_event(const Graphics::Window::Event &event)
        if(type!=AINPUT_EVENT_TYPE_MOTION)
                return;
 
+       int source = AInputEvent_getSource(event.aevent);
+       if(window.get_touch_input() && source!=AINPUT_SOURCE_MOUSE && source!=AINPUT_SOURCE_TOUCHPAD)
+               return;
+
        /* Emulate a mouse with the touch events of a single finger.  If more
        fingers appear while the first one is held down, they are ignored, even if
        the first finger is released. */
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