Merge: More keep going
[nit.git] / lib / android / input_events.nit
index 48c2d72..351040e 100644 (file)
@@ -54,29 +54,31 @@ in "C" `{
 private extern class NativeAndroidMotionEvent `{AInputEvent *`}
 
        fun pointers_count: Int `{
-               return AMotionEvent_getPointerCount(recv);
+               return AMotionEvent_getPointerCount(self);
        `}
 
+       # Did this motion event just started?
        fun just_went_down: Bool `{
-               return (AMotionEvent_getAction(recv) & AMOTION_EVENT_ACTION_MASK) == AMOTION_EVENT_ACTION_DOWN;
+               return (AMotionEvent_getAction(self) & AMOTION_EVENT_ACTION_MASK) == AMOTION_EVENT_ACTION_DOWN;
        `}
 
        fun edge: Int `{
-               return AMotionEvent_getEdgeFlags(recv);
+               return AMotionEvent_getEdgeFlags(self);
        `}
 
+       # Get the non-primary pointer id that just went down (returns -1 or > 0)
        fun index_down_pointer: Int `{
-               int a = AMotionEvent_getAction(recv);
+               int a = AMotionEvent_getAction(self);
                if ((a & AMOTION_EVENT_ACTION_MASK) == AMOTION_EVENT_ACTION_POINTER_DOWN)
                        return (a & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
                else return -1;
        `}
 
-       fun action: AMotionEventAction `{ return AMotionEvent_getAction(recv); `}
+       fun action: AMotionEventAction `{ return AMotionEvent_getAction(self); `}
 end
 
 private extern class AMotionEventAction `{ int32_t `}
-       fun action: Int `{ return recv & AMOTION_EVENT_ACTION_MASK; `}
+       fun action: Int `{ return self & AMOTION_EVENT_ACTION_MASK; `}
 
        fun is_down: Bool do return action == 0
        fun is_up: Bool do return action == 1
@@ -134,8 +136,14 @@ class AndroidMotionEvent
 
        redef fun down_pointer: nullable AndroidPointerEvent
        do
+               if just_went_down then
+                       # The primary pointer went down
+                       return pointers[0]
+               end
+
                var i = native.index_down_pointer
                if i > 0 then
+                       # A secondary pointer went down
                        return pointers[i]
                else
                        return null
@@ -178,6 +186,12 @@ class AndroidPointerEvent
        end
 
        redef fun depressed do return not pressed
+
+       # Does this pointer just began touching the screen?
+       fun just_went_down: Bool
+       do
+               return motion_event.down_pointer == self
+       end
 end
 
 # An hardware key event
@@ -185,16 +199,16 @@ extern class AndroidKeyEvent `{AInputEvent *`}
        super KeyEvent
        super AndroidInputEvent
 
-       private fun action: Int `{ return AKeyEvent_getAction(recv); `}
+       private fun action: Int `{ return AKeyEvent_getAction(self); `}
 
        redef fun is_down: Bool do return action == 0
        redef fun is_up: Bool do return action == 1
 
        # Hardware code of the key raising this event
-       fun key_code: Int `{ return AKeyEvent_getKeyCode(recv); `}
+       fun key_code: Int `{ return AKeyEvent_getKeyCode(self); `}
 
        redef fun to_c `{
-               int code = AKeyEvent_getKeyCode(recv);
+               int code = AKeyEvent_getKeyCode(self);
                if (code >= AKEYCODE_0 && code <= AKEYCODE_9)
                        return '0'+code-AKEYCODE_0;
                if (code >= AKEYCODE_A && code <= AKEYCODE_Z)
@@ -202,6 +216,8 @@ extern class AndroidKeyEvent `{AInputEvent *`}
                return 0;
        `}
 
+       redef fun name do return key_code.to_s
+
        # Was this event raised by the back key?
        fun is_back_key: Bool do return key_code == 4