--- /dev/null
+#include <msp/graphics/window_private.h>
+#include "mouse.h"
+
+namespace Msp {
+namespace Input {
+
+void Mouse::input_event(const Graphics::Window::Event &event)
+{
+ int type = AInputEvent_getType(event.aevent);
+ if(type!=AINPUT_EVENT_TYPE_MOTION)
+ 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. */
+
+ 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);
+ int pointer_zero = -1;
+ for(int i=0; (i<pointer_count && pointer_zero<0); ++i)
+ if(AMotionEvent_getPointerId(event.aevent, i)==0)
+ pointer_zero = i;
+
+ if(pointer_zero>=0)
+ {
+ float x = AMotionEvent_getX(event.aevent, pointer_zero);
+ float y = AMotionEvent_getY(event.aevent, pointer_zero);
+ set_axis_value(0, x*2/window.get_width()-1, true);
+ set_axis_value(1, 1-y*2/window.get_height(), true);
+ }
+
+ switch(action)
+ {
+ case AMOTION_EVENT_ACTION_DOWN:
+ case AMOTION_EVENT_ACTION_UP:
+ case AMOTION_EVENT_ACTION_POINTER_DOWN:
+ case AMOTION_EVENT_ACTION_POINTER_UP:
+ if(action_pointer==0)
+ set_button_state(1, action==AMOTION_EVENT_ACTION_DOWN, true);
+ break;
+ default:;
+ }
+}
+
+} // namespace Input
+} // namespace Msp