int32_t Engine::onMotionEvent(android_app* app, AInputEvent* event) {
        if (!this->loaded) return 0;
        if (!this->focused) return 0;

        size_t pointerCount =  AMotionEvent_getPointerCount(event);

        this->updateUptime();

        for (size_t i = 0; i < pointerCount; i++) {
            size_t pointerId = AMotionEvent_getPointerId(event, i);
            size_t action = AMotionEvent_getAction(event) & AMOTION_EVENT_ACTION_MASK;
            size_t pointerIndex = i;
        
            if (action == AMOTION_EVENT_ACTION_POINTER_DOWN || action == AMOTION_EVENT_ACTION_POINTER_UP) {
                pointerIndex = (AMotionEvent_getAction(event) & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
                pointerId = AMotionEvent_getPointerId(event, pointerIndex);
            }

            this->touchEventParamCache[0] = pointerId;
            this->touchEventParamCache[1] = action;
            this->touchEventParamCache[2] = AMotionEvent_getX(event, pointerIndex);
            this->touchEventParamCache[3] = AMotionEvent_getY(event, pointerIndex);
            this->touchEventParamCache[4] = this->uptime.time;
            this->touchEventParamCache[5] = this->uptime.millitm;
            this->touchEventParamCache[6] = AInputEvent_getDeviceId(event);
            this->touchEventParamCache[7] = AInputEvent_getSource(event);
            
            if (callSqFunction_Bool_Floats(this->sqvm, EMO_NAMESPACE, EMO_FUNC_MOTIONEVENT, this->touchEventParamCache, MOTION_EVENT_PARAMS_SIZE, false)) {
                return 1;
            }
        }
Ejemplo n.º 2
0
/**
  * Process the next input event.
  */
static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) 
{
  struct engine* engine = (struct engine*)app->userData;
  if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) 
  {
    int x = AMotionEvent_getX(event, 0);
    int y = AMotionEvent_getY(event, 0);
    if ((AMOTION_EVENT_ACTION_MASK & AMotionEvent_getAction( event )) == AMOTION_EVENT_ACTION_DOWN)
    {
      nuiAndroidBridge::androidMouse(0, 0, x, y);
    }
    else if ((AMOTION_EVENT_ACTION_MASK & AMotionEvent_getAction( event )) == AMOTION_EVENT_ACTION_UP)
    {
      nuiAndroidBridge::androidMouse(0, 1, x, y);      
    }
    else if ((AMOTION_EVENT_ACTION_MASK & AMotionEvent_getAction( event )) == AMOTION_EVENT_ACTION_MOVE)
    {
      nuiAndroidBridge::androidMotion(x, y);
    }

    
    engine->animating = 1;
    engine->state.x = AMotionEvent_getX(event, 0);
    engine->state.y = AMotionEvent_getY(event, 0);
    return 1;
  }
  return 0;
}
Ejemplo n.º 3
0
/**
 * Process the next input event.
 */
static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) {
    struct engine* engine = (struct engine*)app->userData;
    if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) {
        if (AMotionEvent_getAction(event) == AMOTION_EVENT_ACTION_DOWN
            || AMotionEvent_getAction(event) == AMOTION_EVENT_ACTION_MOVE) {
            input_manager_touch_down(AMotionEvent_getRawX(event, 0),
                                     AMotionEvent_getRawY(event, 0));
            return 1;
        }
    }

    input_manager_touch_up();
    return 0;
}
Ejemplo n.º 4
0
    bool InputService::onTouchEvent(AInputEvent* pEvent) {
#ifdef INPUTSERVICE_LOG_EVENTS
         packt_Log_debug("AMotionEvent_getAction=%d", AMotionEvent_getAction(pEvent));
         packt_Log_debug("AMotionEvent_getFlags=%d", AMotionEvent_getFlags(pEvent));
         packt_Log_debug("AMotionEvent_getMetaState=%d", AMotionEvent_getMetaState(pEvent));
         packt_Log_debug("AMotionEvent_getEdgeFlags=%d", AMotionEvent_getEdgeFlags(pEvent));
         packt_Log_debug("AMotionEvent_getDownTime=%lld", AMotionEvent_getDownTime(pEvent));
         packt_Log_debug("AMotionEvent_getEventTime=%lld", AMotionEvent_getEventTime(pEvent));
         packt_Log_debug("AMotionEvent_getXOffset=%f", AMotionEvent_getXOffset(pEvent));
         packt_Log_debug("AMotionEvent_getYOffset=%f", AMotionEvent_getYOffset(pEvent));
         packt_Log_debug("AMotionEvent_getXPrecision=%f", AMotionEvent_getXPrecision(pEvent));
         packt_Log_debug("AMotionEvent_getYPrecision=%f", AMotionEvent_getYPrecision(pEvent));
         packt_Log_debug("AMotionEvent_getPointerCount=%d", AMotionEvent_getPointerCount(pEvent));
         packt_Log_debug("AMotionEvent_getRawX=%f", AMotionEvent_getRawX(pEvent, 0));
         packt_Log_debug("AMotionEvent_getRawY=%f", AMotionEvent_getRawY(pEvent, 0));
         packt_Log_debug("AMotionEvent_getX=%f", AMotionEvent_getX(pEvent, 0));
         packt_Log_debug("AMotionEvent_getY=%f", AMotionEvent_getY(pEvent, 0));
         packt_Log_debug("AMotionEvent_getPressure=%f", AMotionEvent_getPressure(pEvent, 0));
         packt_Log_debug("AMotionEvent_getSize=%f", AMotionEvent_getSize(pEvent, 0));
         packt_Log_debug("AMotionEvent_getOrientation=%f", AMotionEvent_getOrientation(pEvent, 0));
         packt_Log_debug("AMotionEvent_getTouchMajor=%f", AMotionEvent_getTouchMajor(pEvent, 0));
         packt_Log_debug("AMotionEvent_getTouchMinor=%f", AMotionEvent_getTouchMinor(pEvent, 0));
#endif
        const float TOUCH_MAX_RANGE = 65.0f; // In pixels.

        if (mRefPoint != NULL) {
            if (AMotionEvent_getAction(pEvent)
                            == AMOTION_EVENT_ACTION_MOVE) {
                // Needs a conversion to proper coordinates
                // (origin at bottom/left). Only lMoveY needs it.
                float lMoveX = AMotionEvent_getX(pEvent, 0)
                             - mRefPoint->mPosX;
                float lMoveY = mHeight - AMotionEvent_getY(pEvent, 0)
                             - mRefPoint->mPosY;
                float lMoveRange = sqrt((lMoveX * lMoveX)
                                      + (lMoveY * lMoveY));

                if (lMoveRange > TOUCH_MAX_RANGE) {
                    float lCropFactor = TOUCH_MAX_RANGE / lMoveRange;
                    lMoveX *= lCropFactor; lMoveY *= lCropFactor;
                }

                mHorizontal = lMoveX / TOUCH_MAX_RANGE;
                mVertical   = lMoveY / TOUCH_MAX_RANGE;
            } else {
                mHorizontal = 0.0f; mVertical = 0.0f;
            }
        }
        return true;
    }
Ejemplo n.º 5
0
int32_t handle_input_events(struct android_app* app, AInputEvent* event) {
	int etype = AInputEvent_getType(event);
	switch (etype) {
	case AINPUT_EVENT_TYPE_KEY:
		int32_t eaction, eflags, ekeycode, escancode;
		eaction = AKeyEvent_getAction(event);
		eflags = AKeyEvent_getFlags(event);
		ekeycode = AKeyEvent_getKeyCode(event);
//		LOGI(2, "%s", get_key_event_str(eaction, eflags, ekeycode));
		break;
	case AINPUT_EVENT_TYPE_MOTION:
		int32_t action, posX, pointer_index;
		action = AMotionEvent_getAction(event);
		pointer_index = (action&AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
		posX = AMotionEvent_getX(event, pointer_index);
		//write a command to the activity lifecycle event queue (pipe)
		if (action == AMOTION_EVENT_ACTION_MOVE) {
			int xMove = posX - mPreviousX;
			USERDATA* userData = (USERDATA*)app->userData;
			userData->xMove = xMove;
			app->redrawNeeded = 1;
		}
		mPreviousX = posX;
//		LOGI(2, "action: %d, posX: %d, mPreviousX: %d, posX: %d", action, posX, mPreviousX, posX);
		break;
	default:
		LOGI(2, "other input event");
		break;
	}
}
int32_t AndroidAppHelper::handleInput (struct android_app* app, AInputEvent* event)
{
    if (mInputInjector)
    {
        if (AInputEvent_getType (event) == AINPUT_EVENT_TYPE_MOTION)
        {
            int action = (int) (AMOTION_EVENT_ACTION_MASK & AMotionEvent_getAction (event));

            if (action == 0)
            {
                mInputInjector->injectTouchEvent (2, AMotionEvent_getRawX (event, 0),
                                                  AMotionEvent_getRawY (event, 0));
            }
            mInputInjector->injectTouchEvent (action, AMotionEvent_getRawX (event, 0),
                                              AMotionEvent_getRawY (event, 0));
        }
        else
        {
            mInputInjector->injectKeyEvent (AKeyEvent_getAction (event), AKeyEvent_getKeyCode (event));
        }

        return 1;
    }
    return 0;
}
Ejemplo n.º 7
0
/**
 * Process the next input event.
 */
static int32_t engine_handle_input(struct android_app* app,
                                   AInputEvent* event) {
  struct engine* engine = (struct engine*)app->userData;
  if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) {
    unsigned int flags =
        AMotionEvent_getAction(event) & AMOTION_EVENT_ACTION_MASK;

    // gpg-cpp: Sign in or out on tap
    if (flags == AMOTION_EVENT_ACTION_UP ||
        flags == AMOTION_EVENT_ACTION_POINTER_UP) {

      LOGI("Motion");
      if (!StateManager::GetGameServices()->IsAuthorized()) {
        LOGI("Signing in");
        StateManager::BeginUserInitiatedSignIn();
      } else {
        LOGI("Signing out");
        StateManager::SignOut();
      }
    }

    // Make things pretty
    engine->animating = 1;
    engine->state.x = AMotionEvent_getX(event, 0);
    engine->state.y = AMotionEvent_getY(event, 0);
    return 1;
  }

  return 0;
}
Ejemplo n.º 8
0
bool CAndroidMouse::onMouseEvent(AInputEvent* event)
{
  if (event == NULL)
    return false;

  int32_t eventAction = AMotionEvent_getAction(event);
  int8_t mouseAction = eventAction & AMOTION_EVENT_ACTION_MASK;
  size_t mousePointer = eventAction >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;

  CXBMCApp::android_printf("%s pointer:%i", __PRETTY_FUNCTION__, mousePointer);
  float x = AMotionEvent_getX(event, mousePointer);
  float y = AMotionEvent_getY(event, mousePointer);

  switch (mouseAction)
  {
    case AMOTION_EVENT_ACTION_UP:
    case AMOTION_EVENT_ACTION_DOWN:
      MouseButton(x,y,mouseAction);
      return true;
    default:
      MouseMove(x,y);
      return true;
  }
  return false;
}
Ejemplo n.º 9
0
	static int32_t handleInput(struct android_app* app, AInputEvent* event) 
	{
		if (okit.getInput())
		{
	        if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) 
            {
                int action = (int)(AMOTION_EVENT_ACTION_MASK & AMotionEvent_getAction(event));
                    
				
                if (action == 0)
					okit.injectTouch(2, AMotionEvent_getRawX(event, 0), AMotionEvent_getRawY(event, 0));
                    
                okit.injectTouch(action, AMotionEvent_getRawX(event, 0), AMotionEvent_getRawY(event, 0));
            }
            else 
            {
				int action = AKeyEvent_getAction(event);
				int unicodeChar = 0;
				okit.injectKey(action, unicodeChar, AKeyEvent_getKeyCode(event));
                //mInputInjector->injectKeyEvent(AKeyEvent_getAction(event), AKeyEvent_getKeyCode(event));
            }

            return 1;
        }
        return 0;
	}
Ejemplo n.º 10
0
/**
 * Process the next input event.
 */
static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
{
	struct engine* engine = (struct engine*)app->userData;
	if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION)
	{
		int32_t ret = 0;

		int32_t action = AMotionEvent_getAction(event);
		if (action == AMOTION_EVENT_ACTION_DOWN)
		{
			engine->touchIsDown = true;
			ret = 1;
		}
		else if (action == AMOTION_EVENT_ACTION_UP)
		{
			engine->touchIsDown = false;
			ret = 1;
		}

		if (ret)
		{
			engine->touchX = static_cast<float>(AMotionEvent_getRawX(event, 0)) / engine->width;
			engine->touchY = static_cast<float>(AMotionEvent_getRawY(event, 0)) / engine->height;
		}
		return ret;
	}
	return 0;
}
Ejemplo n.º 11
0
bool CAndroidMouse::onMouseEvent(AInputEvent* event)
{
  if (event == NULL)
    return false;

  int32_t eventAction = AMotionEvent_getAction(event);
  int8_t mouseAction = eventAction & AMOTION_EVENT_ACTION_MASK;
  size_t mousePointerIdx = eventAction >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
  int32_t mousePointerId = AMotionEvent_getPointerId(event, mousePointerIdx);

#ifdef DEBUG_VERBOSE
  CXBMCApp::android_printf("%s idx:%i, id:%i", __PRETTY_FUNCTION__, mousePointerIdx, mousePointerId);
#endif
  CPoint in(AMotionEvent_getX(event, mousePointerIdx), AMotionEvent_getY(event, mousePointerIdx));
  CPoint out = in * m_droid2guiRatio;

  switch (mouseAction)
  {
    case AMOTION_EVENT_ACTION_UP:
    case AMOTION_EVENT_ACTION_DOWN:
      MouseButton(out.x, out.y, mouseAction, AMotionEvent_getButtonState(event));
      return true;
    case AMOTION_EVENT_ACTION_SCROLL:
      MouseWheel(out.x, out.y, AMotionEvent_getAxisValue(event, AMOTION_EVENT_AXIS_VSCROLL, mousePointerIdx));
      return true;
    default:
      MouseMove(out.x, out.y);
      return true;
  }
  return false;
}
int32_t GLESApplication::handleInput(android_app *app, AInputEvent *event)
{
    int32_t eventType = AInputEvent_getType(event);

    if (eventType == AINPUT_EVENT_TYPE_MOTION) {   
        int32_t action = AMotionEvent_getAction(event);    
        switch(action) {
        case AMOTION_EVENT_ACTION_DOWN:
            onTouchDown(AMotionEvent_getX(event, 0), AMotionEvent_getY(event, 0));
            break;
        case AMOTION_EVENT_ACTION_MOVE:
            onTouchMove(AMotionEvent_getX(event, 0), AMotionEvent_getY(event, 0));
            break;
            
        case AMOTION_EVENT_ACTION_UP:
            onTouchUp(AMotionEvent_getX(event, 0), AMotionEvent_getY(event, 0));
            break;
            
        default:
            break;
        }
    }
    
    return 0;
}
Ejemplo n.º 13
0
//--------------------------------------------------------------------------------
// DoubletapDetector
//--------------------------------------------------------------------------------
GESTURE_STATE DoubletapDetector::Detect(const AInputEvent* motion_event) {
  if (AMotionEvent_getPointerCount(motion_event) > 1) {
    // Only support single double tap
    return false;
  }

  bool tap_detected = tap_detector_.Detect(motion_event);

  int32_t action = AMotionEvent_getAction(motion_event);
  unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
  switch (flags) {
    case AMOTION_EVENT_ACTION_DOWN: {
      int64_t eventTime = AMotionEvent_getEventTime(motion_event);
      if (eventTime - last_tap_time_ <= DOUBLE_TAP_TIMEOUT) {
        float x = AMotionEvent_getX(motion_event, 0) - last_tap_x_;
        float y = AMotionEvent_getY(motion_event, 0) - last_tap_y_;
        if (x * x + y * y < DOUBLE_TAP_SLOP * DOUBLE_TAP_SLOP * dp_factor_) {
          LOGI("DoubletapDetector: Doubletap detected");
          return GESTURE_STATE_ACTION;
        }
      }
      break;
    }
    case AMOTION_EVENT_ACTION_UP:
      if (tap_detected) {
        last_tap_time_ = AMotionEvent_getEventTime(motion_event);
        last_tap_x_ = AMotionEvent_getX(motion_event, 0);
        last_tap_y_ = AMotionEvent_getY(motion_event, 0);
      }
      break;
  }
  return GESTURE_STATE_NONE;
}
Ejemplo n.º 14
0
//--------------------------------------------------------------------------------
// TapDetector
//--------------------------------------------------------------------------------
GESTURE_STATE TapDetector::Detect(const AInputEvent* motion_event) {
  if (AMotionEvent_getPointerCount(motion_event) > 1) {
    // Only support single touch
    return false;
  }

  int32_t action = AMotionEvent_getAction(motion_event);
  unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
  switch (flags) {
    case AMOTION_EVENT_ACTION_DOWN:
      down_pointer_id_ = AMotionEvent_getPointerId(motion_event, 0);
      down_x_ = AMotionEvent_getX(motion_event, 0);
      down_y_ = AMotionEvent_getY(motion_event, 0);
      break;
    case AMOTION_EVENT_ACTION_UP: {
      int64_t eventTime = AMotionEvent_getEventTime(motion_event);
      int64_t downTime = AMotionEvent_getDownTime(motion_event);
      if (eventTime - downTime <= TAP_TIMEOUT) {
        if (down_pointer_id_ == AMotionEvent_getPointerId(motion_event, 0)) {
          float x = AMotionEvent_getX(motion_event, 0) - down_x_;
          float y = AMotionEvent_getY(motion_event, 0) - down_y_;
          if (x * x + y * y < TOUCH_SLOP * TOUCH_SLOP * dp_factor_) {
            LOGI("TapDetector: Tap detected");
            return GESTURE_STATE_ACTION;
          }
        }
      }
      break;
    }
  }
  return GESTURE_STATE_NONE;
}
Ejemplo n.º 15
0
void WindowImplAndroid::processPointerEvent(bool isDown, AInputEvent* _event, ActivityStates* states)
{
    int32_t device = AInputEvent_getSource(_event);
    int32_t action = AMotionEvent_getAction(_event);

    int index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
    int id = AMotionEvent_getPointerId(_event, index);

    float x = AMotionEvent_getX(_event, index);
    float y = AMotionEvent_getY(_event, index);

    Event event;

    if (isDown)
    {
        if (device == AINPUT_SOURCE_MOUSE)
        {
            event.type = Event::MouseButtonPressed;
            event.mouseButton.button = static_cast<Mouse::Button>(id);
            event.mouseButton.x = x;
            event.mouseButton.y = y;

            if (id >= 0 && id < Mouse::ButtonCount)
                states->isButtonPressed[id] = true;
        }
        else if (device == AINPUT_SOURCE_TOUCHSCREEN)
        {
            event.type = Event::TouchBegan;
            event.touch.finger = id;
            event.touch.x = x;
            event.touch.y = y;

            states->touchEvents[id] = Vector2i(event.touch.x, event.touch.y);
        }
    }
    else
    {
        if (device == AINPUT_SOURCE_MOUSE)
        {
            event.type = Event::MouseButtonReleased;
            event.mouseButton.button = static_cast<Mouse::Button>(id);
            event.mouseButton.x = x;
            event.mouseButton.y = y;

            if (id >= 0 && id < Mouse::ButtonCount)
                states->isButtonPressed[id] = false;
        }
        else if (device == AINPUT_SOURCE_TOUCHSCREEN)
        {
            event.type = Event::TouchEnded;
            event.touch.finger = id;
            event.touch.x = x;
            event.touch.y = y;

            states->touchEvents.erase(id);
        }
    }

    forwardEvent(event);
}
Ejemplo n.º 16
0
/**
 * Process the next input event.
 */
static int32_t handle_motion_event(struct android_app* app, AInputEvent* event)
{
	struct engine* engine = (struct engine*)app->userData;
	int i, c = AMotionEvent_getPointerCount(event);
	for( i = 0; i<c; i++) {
		int32_t action = AMotionEvent_getAction(event);
		uint32_t id = action >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
		uint32_t index = AMotionEvent_getPointerId(event, i);
		float x = AMotionEvent_getX(event, i);
		float y = AMotionEvent_getY(event, i);
		action = action & AMOTION_EVENT_ACTION_MASK;
		if (action == AMOTION_EVENT_ACTION_DOWN) {
			/* Workaround, these are needed in order to 
			dispatch GK_ON_MOUSE_DOWN. The problem is that
			the library assumes that the 'mouse' is moved over
			a panel, before it's pressed. 
			In case of thouchscreen the 'press' event happens before 
			the 'move' which results in wrong/invalid gkMouseTarget.
			The mouse down event is dispatched ON the gkMouseTarget.
			*/
			onWindowMouseMove(x,y);	
			gkUpdateMouseTarget(gkMainPanel);
			gkCheckFocusedPanel();

			onWindowMouseDown(x,y,index);
		}else if (action == AMOTION_EVENT_ACTION_MOVE) {
			onWindowMouseMove(x,y);
		}else if (action == AMOTION_EVENT_ACTION_UP) {
			onWindowMouseUp(x,y,index);
		}
		__android_log_print(ANDROID_LOG_INFO, "GK", "action: %d index: %d  id: %d i: %d", action, index, id, i);
	}
        return 1;
}
Ejemplo n.º 17
0
		static int HandleInput(struct android_app* app, AInputEvent* event)
		{
			Android_App* myapp = (Android_App*) app->userData;

			if(myapp)
			{
				switch(AInputEvent_getType(event))
				{
                    case AINPUT_EVENT_TYPE_KEY:
                    {
                        switch(AKeyEvent_getKeyCode(event))
                        {
                            case 4:
                                // Back
                                if(AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_UP)
                                    myapp->OnKeyPress(enumKEY_Back);
                                break;
                            case 24:
                                // Volume up
                                break;
                            case 25:
                                // Volume down
                                break;
                        }
                        break;
                    }
					case AINPUT_EVENT_TYPE_MOTION: // Handle touch events
					{
						switch(AMotionEvent_getAction(event))
						{
							case AMOTION_EVENT_ACTION_DOWN:
							{
								Touch t = { AMotionEvent_getX(event, 0), AMotionEvent_getY(event, 0) };
								myapp->OnTouchDown(&t, 1);

								break;
							}
							case AMOTION_EVENT_ACTION_MOVE:
							{
								Touch t = { AMotionEvent_getX(event, 0), AMotionEvent_getY(event, 0) };
								myapp->OnTouchMoved(&t, 1);

								break;
							}
							case AMOTION_EVENT_ACTION_UP:
							{
								Touch t = { AMotionEvent_getX(event, 0), AMotionEvent_getY(event, 0) };
								myapp->OnTouchUp(&t, 1);

								break;
							}
						}
						return 1;
					}
				}
			}

			return 1;
		}
Ejemplo n.º 18
0
// Process the next input event.
static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
{
    if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION)
    {
        int32_t action = AMotionEvent_getAction(event);
        size_t pointerIndex;
        size_t pointerId;
        size_t pointerCount;
        switch (action & AMOTION_EVENT_ACTION_MASK)
        {
            case AMOTION_EVENT_ACTION_DOWN:
                // Primary pointer down
                pointerId = AMotionEvent_getPointerId(event, 0);
                gameplay::Platform::touchEventInternal(Touch::TOUCH_PRESS, AMotionEvent_getX(event, 0), AMotionEvent_getY(event, 0), pointerId);
                __primaryTouchId = pointerId;
                break;
            case AMOTION_EVENT_ACTION_UP:
                pointerId = AMotionEvent_getPointerId(event, 0);
                if (__multiTouch || __primaryTouchId == pointerId)
                {
                    gameplay::Platform::touchEventInternal(Touch::TOUCH_RELEASE, AMotionEvent_getX(event, 0), AMotionEvent_getY(event, 0), pointerId);
                }
                __primaryTouchId = -1;
                break;
            case AMOTION_EVENT_ACTION_POINTER_DOWN:
                // Non-primary pointer down
                if (__multiTouch)
                {
                    pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
                    pointerId = AMotionEvent_getPointerId(event, pointerIndex);
                    gameplay::Platform::touchEventInternal(Touch::TOUCH_PRESS, AMotionEvent_getX(event, pointerIndex), AMotionEvent_getY(event, pointerIndex), pointerId);
                }
                break;
            case AMOTION_EVENT_ACTION_POINTER_UP:
                pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
                pointerId = AMotionEvent_getPointerId(event, pointerIndex);
                if (__multiTouch || __primaryTouchId == pointerId)
                {
                    gameplay::Platform::touchEventInternal(Touch::TOUCH_RELEASE, AMotionEvent_getX(event, pointerIndex), AMotionEvent_getY(event, pointerIndex), pointerId);
                }
                if (__primaryTouchId == pointerId)
                    __primaryTouchId = -1;
                break;
            case AMOTION_EVENT_ACTION_MOVE:
                // ACTION_MOVE events are batched, unlike the other events.
                pointerCount = AMotionEvent_getPointerCount(event);
                for (size_t i = 0; i < pointerCount; ++i)
                {
                    pointerId = AMotionEvent_getPointerId(event, i);
                    if (__multiTouch || __primaryTouchId == pointerId)
                    {
                        gameplay::Platform::touchEventInternal(Touch::TOUCH_MOVE, AMotionEvent_getX(event, i), AMotionEvent_getY(event, i), pointerId);
                    }
                }
                break;
        }
        return 1;
    } 
Ejemplo n.º 19
0
GESTURE_STATE DragDetector::Detect(const AInputEvent* event) {
  GESTURE_STATE ret = GESTURE_STATE_NONE;
  int32_t action = AMotionEvent_getAction(event);
  int32_t index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >>
                  AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
  uint32_t flags = action & AMOTION_EVENT_ACTION_MASK;
  event_ = event;

  int32_t count = AMotionEvent_getPointerCount(event);
  switch (flags) {
    case AMOTION_EVENT_ACTION_DOWN:
      vec_pointers_.push_back(AMotionEvent_getPointerId(event, 0));
      ret = GESTURE_STATE_START;
      break;
    case AMOTION_EVENT_ACTION_POINTER_DOWN:
      vec_pointers_.push_back(AMotionEvent_getPointerId(event, index));
      break;
    case AMOTION_EVENT_ACTION_UP:
      vec_pointers_.pop_back();
      ret = GESTURE_STATE_END;
      break;
    case AMOTION_EVENT_ACTION_POINTER_UP: {
      int32_t released_pointer_id = AMotionEvent_getPointerId(event, index);

      std::vector<int32_t>::iterator it = vec_pointers_.begin();
      std::vector<int32_t>::iterator it_end = vec_pointers_.end();
      int32_t i = 0;
      for (; it != it_end; ++it, ++i) {
        if (*it == released_pointer_id) {
          vec_pointers_.erase(it);
          break;
        }
      }

      if (i <= 1) {
        // Reset pinch or drag
        if (count == 2) {
          ret = GESTURE_STATE_START;
        }
      }
      break;
    }
    case AMOTION_EVENT_ACTION_MOVE:
      switch (count) {
        case 1:
          // Drag
          ret = GESTURE_STATE_MOVE;
          break;
        default:
          break;
      }
      break;
    case AMOTION_EVENT_ACTION_CANCEL:
      break;
  }

  return ret;
}
int32 CorePlatformAndroid::HandleInput(AppHandle handle, AInputEvent* event)
{
    CorePlatformAndroid *core = (CorePlatformAndroid *)handle->userData;
    
    int32 eventType = AInputEvent_getType(event);
    if (eventType == AINPUT_EVENT_TYPE_MOTION)
    {
//        Logger::Info("***[ TOUCH START ]***");

        
        int32 actionUnmasked = AMotionEvent_getAction(event);
		int32 action = (actionUnmasked & AMOTION_EVENT_ACTION_MASK);

//        Logger::Info("Action unmasked = %d", actionUnmasked);
//        Logger::Info("Action = %d", action);

        int32 numEvents = AMotionEvent_getPointerCount(event);
//        Logger::Info("Pointers count = %d", numEvents);

        switch (action)
        {
            case AMOTION_EVENT_ACTION_DOWN:
            case AMOTION_EVENT_ACTION_POINTER_DOWN:
                UpdateTouchPositions(UIEvent::PHASE_BEGAN, event);
                break;

            case AMOTION_EVENT_ACTION_CANCEL:
                UpdateTouchPositions(UIEvent::PHASE_CANCELLED, event);
                break;

            case AMOTION_EVENT_ACTION_UP:
                UpdateTouchPositions(UIEvent::PHASE_ENDED, event);
                break;

            case AMOTION_EVENT_ACTION_POINTER_UP:
            {
                int32 actindex = (actionUnmasked & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK);
                actindex >>= AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
                
//                Logger::Debug("[CorePlatformAndroid::HandleInput] pointer up (%d)", actindex);
                UpdateSingleTouchPosition(UIEvent::PHASE_ENDED, event, actindex);
                break;
            }

            case AMOTION_EVENT_ACTION_MOVE:
                UpdateTouchPositions(DAVA::UIEvent::PHASE_DRAG, event);
                break;
                
            default:
                Logger::Warning("[CorePlatformAndroid::HandleInput] Unhandled motion event!");
                break;
        }
        
//        Logger::Info("***[ TOUCH END ]***");

        return 1;
    }
Ejemplo n.º 21
0
/**
 * Process the next input event.
 */
static
int32_t
engine_handle_input( struct android_app* app, AInputEvent* event )
{
	struct ENGINE* engine = (struct ENGINE*)app->userData;
	if( AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION )
	{
		engine->render		= 1;
		int nPointerCount	= AMotionEvent_getPointerCount( event );
		int nSourceId		= AInputEvent_getSource( event );
		int n;

		for( n = 0 ; n < nPointerCount ; ++n )
		{
			int nPointerId	= AMotionEvent_getPointerId( event, n );
			int nAction		= AMOTION_EVENT_ACTION_MASK & AMotionEvent_getAction( event );
			struct TOUCHSTATE *touchstate = 0;

			if( nSourceId == AINPUT_SOURCE_TOUCHPAD )
				touchstate = engine->touchstate_pad;
			else
				touchstate = engine->touchstate_screen;

			if( nAction == AMOTION_EVENT_ACTION_POINTER_DOWN || nAction == AMOTION_EVENT_ACTION_POINTER_UP )
			{
				int nPointerIndex = (AMotionEvent_getAction( event ) & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
				nPointerId = AMotionEvent_getPointerId( event, nPointerIndex );
			}

			if( nAction == AMOTION_EVENT_ACTION_DOWN || nAction == AMOTION_EVENT_ACTION_POINTER_DOWN )
			{
				touchstate[nPointerId].down = 1;
			}
			else if( nAction == AMOTION_EVENT_ACTION_UP || nAction == AMOTION_EVENT_ACTION_POINTER_UP || nAction == AMOTION_EVENT_ACTION_CANCEL )
			{
				touchstate[nPointerId].down = 0;
			}

			if (touchstate[nPointerId].down == 1)
			{
				touchstate[nPointerId].x = AMotionEvent_getX( event, n );
				touchstate[nPointerId].y = AMotionEvent_getY( event, n );
			}
		}
Ejemplo n.º 22
0
static int32_t custom_handle_input(struct android_app* _application, AInputEvent* _event)
{
    if( AInputEvent_getType(_event) == AINPUT_EVENT_TYPE_MOTION )
    {
    	i32 pointerCount = AMotionEvent_getPointerCount(_event);
    	i32 sourceId = AInputEvent_getSource(_event);

    	for(ui32 i = 0 ; i < pointerCount ; ++i)
    	{
    		i32 pointerId = AMotionEvent_getPointerId(_event, i);
    		i32 action = AMOTION_EVENT_ACTION_MASK & AMotionEvent_getAction(_event);
    		i32 rawAction	= AMotionEvent_getAction(_event);

    		if(sourceId == AINPUT_SOURCE_TOUCHPAD)
    		{

    		}
    		else
    		{

    		}

    		f32 pointX = AMotionEvent_getX(_event, 0);
    		f32 pointY = AMotionEvent_getY(_event, 0);

    		if(action == AMOTION_EVENT_ACTION_POINTER_DOWN || action == AMOTION_EVENT_ACTION_POINTER_UP)
    		{
    			i32 pointerIndex = (AMotionEvent_getAction(_event) & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
    			pointerId = AMotionEvent_getPointerId(_event, pointerIndex);
    		}

    		if(action == AMOTION_EVENT_ACTION_DOWN || action == AMOTION_EVENT_ACTION_POINTER_DOWN)
    		{
    			IInputContext::NativeCallTapRecognizerPressed(glm::ivec2(pointX, pointY));
    		}
    		else if( action == AMOTION_EVENT_ACTION_UP || action == AMOTION_EVENT_ACTION_POINTER_UP || action == AMOTION_EVENT_ACTION_CANCEL )
    		{
    			IInputContext::NativeCallTapRecognizerReleased(glm::ivec2(pointX, pointY));
    		}
    		else if(action == AMOTION_EVENT_ACTION_MOVE)
    		{
    			IInputContext::NativeCallTapRecognizerMoved(glm::ivec2(pointX, pointY));
    		}
    	}
Ejemplo n.º 23
0
bool NativeEngine::HandleInput(AInputEvent *event) {

    if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION)
    {
        int32_t action = AMotionEvent_getAction(event);
        size_t pointerIndex;
        size_t pointerId;
        size_t pointerCount;
        int x;
        int y;

        switch (action & AMOTION_EVENT_ACTION_MASK)
        {
            case AMOTION_EVENT_ACTION_DOWN:
                pointerId = AMotionEvent_getPointerId(event, 0);
                x = AMotionEvent_getX(event, 0);
                y = AMotionEvent_getY(event, 0);

                touchBegan(pointerId, Origami::maths::vec2(x, y));

                break;
            case AMOTION_EVENT_ACTION_UP:
                pointerId = AMotionEvent_getPointerId(event, 0);
                x = AMotionEvent_getX(event, 0);
                y = AMotionEvent_getY(event, 0);

                touchended(pointerId, Origami::maths::vec2(x, y));
                break;
            case AMOTION_EVENT_ACTION_POINTER_DOWN:
                pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
                pointerId = AMotionEvent_getPointerId(event, pointerIndex);
                x = AMotionEvent_getX(event, pointerIndex);
                y = AMotionEvent_getY(event, pointerIndex);

                touchBegan(pointerId, Origami::maths::vec2(x, y));
                break;
            case AMOTION_EVENT_ACTION_POINTER_UP:
                pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
                pointerId = AMotionEvent_getPointerId(event, pointerIndex);
                x = AMotionEvent_getX(event, pointerIndex);
                y = AMotionEvent_getY(event, pointerIndex);

                touchended(pointerId, Origami::maths::vec2(x, y));
                break;
            case AMOTION_EVENT_ACTION_MOVE:
                pointerCount = AMotionEvent_getPointerCount(event);
                for (size_t i = 0; i < pointerCount; ++i) {
                    pointerId = AMotionEvent_getPointerId(event, i);
                    x = AMotionEvent_getX(event, i);
                    y = AMotionEvent_getY(event, i);

                    touchMoved(pointerId, Origami::maths::vec2(x, y));
                }
                break;
        }
    }
Ejemplo n.º 24
0
bool CAndroidTouch::onTouchEvent(AInputEvent* event)
{
  CXBMCApp::android_printf("%s", __PRETTY_FUNCTION__);
  if (event == NULL)
    return false;

  size_t numPointers = AMotionEvent_getPointerCount(event);
  if (numPointers <= 0)
  {
    CXBMCApp::android_printf(" => aborting touch event because there are no active pointers");
    return false;
  }

  if (numPointers > TOUCH_MAX_POINTERS)
    numPointers = TOUCH_MAX_POINTERS;

  int32_t eventAction = AMotionEvent_getAction(event);
  int8_t touchAction = eventAction & AMOTION_EVENT_ACTION_MASK;
  size_t touchPointer = eventAction >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
  
  CTouchInput::TouchEvent touchEvent = CTouchInput::TouchEventAbort;
  switch (touchAction)
  {
    case AMOTION_EVENT_ACTION_DOWN:
    case AMOTION_EVENT_ACTION_POINTER_DOWN:
      touchEvent = CTouchInput::TouchEventDown;
      break;

    case AMOTION_EVENT_ACTION_UP:
    case AMOTION_EVENT_ACTION_POINTER_UP:
      touchEvent = CTouchInput::TouchEventUp;
      break;

    case AMOTION_EVENT_ACTION_MOVE:
      touchEvent = CTouchInput::TouchEventMove;
      break;

    case AMOTION_EVENT_ACTION_OUTSIDE:
    case AMOTION_EVENT_ACTION_CANCEL:
    default:
      break;
  }

  float x = AMotionEvent_getX(event, touchPointer);
  float y = AMotionEvent_getY(event, touchPointer);
  float size = m_dpi / 16.0f;
  int64_t time = AMotionEvent_getEventTime(event);

  // first update all touch pointers
  for (unsigned int pointer = 0; pointer < numPointers; pointer++)
    CTouchInput::Get().Update(pointer, AMotionEvent_getX(event, pointer), AMotionEvent_getY(event, pointer),
    AMotionEvent_getEventTime(event), m_dpi / 16.0f);

  // now send the event
  return CTouchInput::Get().Handle(touchEvent, x, y, time, touchPointer, size);
}
Ejemplo n.º 25
0
static bool CookEvent_Motion(AInputEvent *event, CookedEventCallback callback) {
    int src = AInputEvent_getSource(event);
    int action = AMotionEvent_getAction(event);
    int actionMasked = action & AMOTION_EVENT_ACTION_MASK;
    int ptrIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >>
            AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;

    struct CookedEvent ev;
    memset(&ev, 0, sizeof(ev));

    if (actionMasked == AMOTION_EVENT_ACTION_DOWN || actionMasked ==
            AMOTION_EVENT_ACTION_POINTER_DOWN) {
        ev.type = COOKED_EVENT_TYPE_POINTER_DOWN;
    } else if (actionMasked == AMOTION_EVENT_ACTION_UP || actionMasked ==
            AMOTION_EVENT_ACTION_POINTER_UP) {
        ev.type = COOKED_EVENT_TYPE_POINTER_UP;
    } else {
        ev.type = COOKED_EVENT_TYPE_POINTER_MOVE;
    }

    ev.motionPointerId = AMotionEvent_getPointerId(event, ptrIndex);
    ev.motionIsOnScreen = (src == AINPUT_SOURCE_TOUCHSCREEN);
    ev.motionX = AMotionEvent_getX(event, ptrIndex);
    ev.motionY = AMotionEvent_getY(event, ptrIndex);

    if (ev.motionIsOnScreen) {
        // use screen size as the motion range
        ev.motionMinX = 0.0f;
        ev.motionMaxX = SceneManager::GetInstance()->GetScreenWidth();
        ev.motionMinY = 0.0f;
        ev.motionMaxY = SceneManager::GetInstance()->GetScreenHeight();
    } else {
        // look up motion range for this device
        _look_up_motion_range((int) AInputEvent_getDeviceId(event),
            (int)AInputEvent_getSource(event), &ev.motionMinX, &ev.motionMaxX,
            &ev.motionMinY, &ev.motionMaxY);
    }

    // deliver event
    callback(&ev);

    // deliver motion info about other pointers (for multi-touch)
    int ptrCount = AMotionEvent_getPointerCount(event);
    for (int i = 0; i < ptrCount; i++) {
        ev.type = COOKED_EVENT_TYPE_POINTER_MOVE;
        ev.motionX = AMotionEvent_getX(event, i);
        ev.motionY = AMotionEvent_getY(event, i);
        ev.motionPointerId = AMotionEvent_getPointerId(event, i);
        callback(&ev);        
    }

    // If this is a touch-nav event, return false to indicate that we haven't handled it.
    // This will trigger translation of swipes to DPAD keys, which is what we want.
    // Otherwise, we say that we've handled it.
    return (src != SOURCE_TOUCH_NAVIGATION);
}
void ApplicationContextAndroid::_fireInputEventAndroid(AInputEvent* event, int wheel) {
    Event evt = {0};

    static TouchFingerEvent lastTouch = {0};

    if(wheel) {
        evt.type = MOUSEWHEEL;
        evt.wheel.y = wheel;
        _fireInputEvent(evt, 0);
        lastTouch.fingerId = -1; // prevent move-jump after pinch is over
        return;
    }

    if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) {
        int32_t action = AMOTION_EVENT_ACTION_MASK & AMotionEvent_getAction(event);

        switch (action) {
        case AMOTION_EVENT_ACTION_DOWN:
            evt.type = FINGERDOWN;
            break;
        case AMOTION_EVENT_ACTION_UP:
            evt.type = FINGERUP;
            break;
        case AMOTION_EVENT_ACTION_MOVE:
            evt.type = FINGERMOTION;
            break;
        default:
            return;
        }

        Ogre::RenderWindow* win = getRenderWindow();

        evt.tfinger.fingerId = AMotionEvent_getPointerId(event, 0);
        evt.tfinger.x = AMotionEvent_getRawX(event, 0) / win->getWidth();
        evt.tfinger.y = AMotionEvent_getRawY(event, 0) / win->getHeight();

        if(evt.type == FINGERMOTION) {
            if(evt.tfinger.fingerId != lastTouch.fingerId)
                return; // wrong finger

            evt.tfinger.dx = evt.tfinger.x - lastTouch.x;
            evt.tfinger.dy = evt.tfinger.y - lastTouch.y;
        }

        lastTouch = evt.tfinger;
    } else {
        if(AKeyEvent_getKeyCode(event) != AKEYCODE_BACK)
            return;

        evt.type = AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN ? KEYDOWN : KEYUP;
        evt.key.keysym.sym = SDLK_ESCAPE;
    }

    _fireInputEvent(evt, 0);
}
Ejemplo n.º 27
0
int32_t cxAndroid::HandleMotionInput(AInputEvent* event)
{
    cxInt action = AMotionEvent_getAction(event);
    cxInt atype =  action & AMOTION_EVENT_ACTION_MASK;
    switch (atype) {
        case AMOTION_EVENT_ACTION_POINTER_DOWN:{
            cxInt idx = action >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
            cxTouchId id = AMotionEvent_getPointerId(event, idx);
            cxFloat x = AMotionEvent_getX(event, idx);
            cxFloat y = AMotionEvent_getY(event, idx);
            cxEngine::Instance()->Dispatch(id, cxTouchPoint::Began, x, y);
            break;
        }
        case AMOTION_EVENT_ACTION_POINTER_UP:{
            cxInt idx = action >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
            cxTouchId id = AMotionEvent_getPointerId(event, idx);
            cxFloat x = AMotionEvent_getX(event, idx);
            cxFloat y = AMotionEvent_getY(event, idx);
            cxEngine::Instance()->Dispatch(id, cxTouchPoint::Ended, x, y);
            break;
        }
        case AMOTION_EVENT_ACTION_MOVE:{
            cxInt count = (cxInt)AMotionEvent_getPointerCount(event);
            for(cxInt i=0; i < count; i++){
                cxTouchId id = AMotionEvent_getPointerId(event, i);
                cxFloat x = AMotionEvent_getX(event, i);
                cxFloat y =AMotionEvent_getY(event, i);
                cxEngine::Instance()->Dispatch(id, cxTouchPoint::Moved, x, y);
            }
            break;
        }
        case AMOTION_EVENT_ACTION_DOWN:{
            cxInt count = (cxInt)AMotionEvent_getPointerCount(event);
            for(cxInt i=0; i < count; i++){
                cxTouchId id = AMotionEvent_getPointerId(event, i);
                cxFloat x = AMotionEvent_getX(event, i);
                cxFloat y =AMotionEvent_getY(event, i);
                cxEngine::Instance()->Dispatch(id, cxTouchPoint::Began, x, y);
            }
            break;
        }
        case AMOTION_EVENT_ACTION_UP:{
            cxInt count = (cxInt)AMotionEvent_getPointerCount(event);
            for(cxInt i=0; i < count; i++){
                cxTouchId id = AMotionEvent_getPointerId(event, i);
                cxFloat x = AMotionEvent_getX(event, i);
                cxFloat y =AMotionEvent_getY(event, i);
                cxEngine::Instance()->Dispatch(id, cxTouchPoint::Ended, x, y);
            }
            break;
        }
    }
    return 0;
}
Ejemplo n.º 28
0
void WindowImplAndroid::processScrollEvent(AInputEvent* _event, ActivityStates* states)
{
    // Prepare the java virtual machine
    jint lResult;
    jint lFlags = 0;

    JavaVM* lJavaVM = states->activity->vm;
    JNIEnv* lJNIEnv = states->activity->env;

    JavaVMAttachArgs lJavaVMAttachArgs;
    lJavaVMAttachArgs.version = JNI_VERSION_1_6;
    lJavaVMAttachArgs.name = "NativeThread";
    lJavaVMAttachArgs.group = NULL;

    lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs);

    if (lResult == JNI_ERR)
        err() << "Failed to initialize JNI, couldn't get the unicode value" << std::endl;

    // Retrieve everything we need to create this MotionEvent in java
    jlong downTime = AMotionEvent_getDownTime(_event);
    jlong eventTime = AMotionEvent_getEventTime(_event);
    jint action = AMotionEvent_getAction(_event);
    jfloat x = AMotionEvent_getX(_event, 0);
    jfloat y = AMotionEvent_getY(_event, 0);
    jfloat pressure = AMotionEvent_getPressure(_event, 0);
    jfloat size = AMotionEvent_getSize(_event, 0);
    jint metaState = AMotionEvent_getMetaState(_event);
    jfloat xPrecision = AMotionEvent_getXPrecision(_event);
    jfloat yPrecision = AMotionEvent_getYPrecision(_event);
    jint deviceId = AInputEvent_getDeviceId(_event);
    jint edgeFlags = AMotionEvent_getEdgeFlags(_event);

    // Create the MotionEvent object in java trough its static constructor obtain()
    jclass ClassMotionEvent = lJNIEnv->FindClass("android/view/MotionEvent");
    jmethodID StaticMethodObtain = lJNIEnv->GetStaticMethodID(ClassMotionEvent, "obtain", "(JJIFFFFIFFII)Landroid/view/MotionEvent;");
    jobject ObjectMotionEvent = lJNIEnv->CallStaticObjectMethod(ClassMotionEvent, StaticMethodObtain, downTime, eventTime, action, x, y, pressure, size, metaState, xPrecision, yPrecision, deviceId, edgeFlags);

    // Call its getAxisValue() method to get the delta value of our wheel move event
    jmethodID MethodGetAxisValue = lJNIEnv->GetMethodID(ClassMotionEvent, "getAxisValue", "(I)F");
    jfloat delta = lJNIEnv->CallFloatMethod(ObjectMotionEvent, MethodGetAxisValue, 0x00000001);

    // Create and send our mouse wheel event
    Event event;
    event.type = Event::MouseWheelMoved;
    event.mouseWheel.delta = static_cast<double>(delta);
    event.mouseWheel.x = AMotionEvent_getX(_event, 0);
    event.mouseWheel.y = AMotionEvent_getY(_event, 0);

    forwardEvent(event);

    // Dettach this thread from the JVM
    lJavaVM->DetachCurrentThread();
}
Ejemplo n.º 29
0
int32_t android_handle_motion(struct android_app* app, AInputEvent* event)
{
    Director* director = static_cast<AInstance*>(app->userData)->director.get();
    switch (AMotionEvent_getAction(event) & AMOTION_EVENT_ACTION_MASK)
    {
        case AMOTION_EVENT_ACTION_DOWN:
        case AMOTION_EVENT_ACTION_POINTER_DOWN: {
            const int32_t index = (AMotionEvent_getAction(event) &
                                   AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >>
                                  AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
            Pointer p = get_pointer_event(event, index);
            director->input().on_pointer_began(ArrayView<Pointer>(p));
            break;
        }
        case AMOTION_EVENT_ACTION_UP:
        case AMOTION_EVENT_ACTION_POINTER_UP: {
            const int32_t index = (AMotionEvent_getAction(event) &
                                   AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >>
                                  AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
            Pointer p = get_pointer_event(event, index);
            director->input().on_pointer_ended(ArrayView<Pointer>(p));
            break;
        }
        case AMOTION_EVENT_ACTION_MOVE: {
            const size_t count = AMotionEvent_getPointerCount(event);
            auto pointers = std::make_unique<Pointer[]>(count);
            for (size_t i = 0; i < count; ++i)
                pointers[i] = get_pointer_event(event, i);
            director->input().on_pointer_moved(
                ArrayView<Pointer>(pointers.get(), count));
            break;
        }
        case AMOTION_EVENT_ACTION_CANCEL:
        case AMOTION_EVENT_ACTION_OUTSIDE:
            director->input().on_pointer_canceled();
            break;
        default:
            break;
    }
    return 1;
}
Ejemplo n.º 30
0
	int32_t Window::handle_input( AInputEvent* event )
	{
		switch( AInputEvent_getType( event ) )
		{
		case AINPUT_EVENT_TYPE_MOTION:
		{
			int action = AMotionEvent_getAction( event );
			int index = action >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
			action &= AMOTION_EVENT_ACTION_MASK;
			switch( action )
			{
			case AMOTION_EVENT_ACTION_DOWN:
			case AMOTION_EVENT_ACTION_POINTER_DOWN:
				pointevent(
					"pointdown",
					index + 1,
					AMotionEvent_getX( event, 0 ),
					AMotionEvent_getY( event, 0 ) );
				break;
			case AMOTION_EVENT_ACTION_UP:
			case AMOTION_EVENT_ACTION_CANCEL:
				pointevent(
					"pointup",
					AMotionEvent_getPointerId( event, 0 ) + 1,
					-1,
					-1 );
				break;
			case AMOTION_EVENT_ACTION_POINTER_UP:
				pointevent(
					"pointup",
					index + 1,
					-1,
					-1 );
				break;
			case AMOTION_EVENT_ACTION_MOVE:
				for(
					int i = 0;
					i < int( AMotionEvent_getPointerCount( event ) );
					++i )
				{
				pointevent(
					"pointmove",
					AMotionEvent_getPointerId( event, i ) + 1,
					AMotionEvent_getX( event, i ),
					AMotionEvent_getY( event, i ) );
				}
				break;
			}
			return 0;
		} break;
		}
		return 0;
	}