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. */
+#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