Beispiel #1
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;
	}
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;
}
Beispiel #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)
	{
		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;
}
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);
}
Beispiel #5
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;
}
    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;
    }
//----------------------------------------------------------------------------//
int32_t AndroidAppHelper::handleInput (struct android_app* app, AInputEvent* event)
{
    static int prev_x = -1;
    static int prev_y = -1;
    if (true)
    {
        if (AInputEvent_getType (event) == AINPUT_EVENT_TYPE_MOTION)
        {
            int action = (int) (AMOTION_EVENT_ACTION_MASK & AMotionEvent_getAction (event));
            float x = AMotionEvent_getRawX (event, 0);
            float y = AMotionEvent_getRawY (event, 0);
            if (action == AMOTION_EVENT_ACTION_MOVE)
            {
                if (prev_x > 0 || prev_y > 0)
                {
                    float delta_x = x - prev_x;
                    float delta_y = y - prev_x;
                    CEGuiEGLBaseApplication::getSingleton().getSampleApp()->injectMousePosition (
                        static_cast<float> (x), static_cast<float> (y));
                }
            }
            else if (action == AMOTION_EVENT_ACTION_DOWN)
            {
                CEGuiEGLBaseApplication::getSingleton().getSampleApp()->injectMousePosition (x, y);
                CEGuiEGLBaseApplication::getSingleton().getSampleApp()->injectMouseButtonDown (CEGUI::LeftButton);
            }
            else if (action == AMOTION_EVENT_ACTION_UP)
            {
                CEGuiEGLBaseApplication::getSingleton().getSampleApp()->injectMouseButtonUp (CEGUI::LeftButton);
            }
            prev_x = x;
            prev_y = y;
        }
        else if (AInputEvent_getType (event) == AINPUT_EVENT_TYPE_KEY)
        {
            //keyboard injection
        }

        return 1;
    }
    return 0;

}
static void _log_event(AInputEvent *event) {
    if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY) {
        LOGD("DEBUG: Key event: action=%d, keycode=%d, meta=0x%x, source=%d",
            AKeyEvent_getAction(event),
            AKeyEvent_getKeyCode(event),
            AKeyEvent_getMetaState(event),
            (int)(AInputEvent_getSource(event)));
    } else if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) {
        LOGD("DEBUG: Motion event: deviceid=%d, pointerid=%d, sourceid=%d, action=%d, keycode=%d"
         "x,y=%f,%f, raw x,y=%f,%f, source=%d",
        (int)AInputEvent_getDeviceId(event),
        (int)AMotionEvent_getPointerId(event, 0),
        (int)AInputEvent_getSource(event),
        (int)AKeyEvent_getAction(event),
        (int)AKeyEvent_getKeyCode(event),
        (float)AMotionEvent_getX(event,0),
        (float)AMotionEvent_getY(event,0),
        (float)AMotionEvent_getRawX(event,0),
        (float)AMotionEvent_getRawY(event,0),
        (int)(AInputEvent_getSource(event)));
    } else {
        LOGD("DEBUG: other type of event, %d", AInputEvent_getType(event));
    }
}
    bool InputService::onTrackballEvent(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 ORTHOGONAL_MOVE = 1.0f;
        const float DIAGONAL_MOVE   = 0.707f;
        const float THRESHOLD       = (1/100.0f);

         if (AMotionEvent_getAction(pEvent) == AMOTION_EVENT_ACTION_MOVE) {
            float lDirectionX = AMotionEvent_getX(pEvent, 0);
            float lDirectionY = AMotionEvent_getY(pEvent, 0);
            float lHorizontal, lVertical;

            if (lDirectionX < -THRESHOLD) {
                if (lDirectionY < -THRESHOLD) {
                    lHorizontal = -DIAGONAL_MOVE;
                    lVertical   = DIAGONAL_MOVE;
                } else if (lDirectionY > THRESHOLD) {
                    lHorizontal = -DIAGONAL_MOVE;
                    lVertical   = -DIAGONAL_MOVE;
                } else {
                    lHorizontal = -ORTHOGONAL_MOVE;
                    lVertical   = 0.0f;
                }
            } else if (lDirectionX > THRESHOLD) {
                if (lDirectionY < -THRESHOLD) {
                    lHorizontal = DIAGONAL_MOVE;
                    lVertical   = DIAGONAL_MOVE;
                } else if (lDirectionY > THRESHOLD) {
                    lHorizontal = DIAGONAL_MOVE;
                    lVertical   = -DIAGONAL_MOVE;
                } else {
                    lHorizontal = ORTHOGONAL_MOVE;
                    lVertical   = 0.0f;
                }
            } else if (lDirectionY < -THRESHOLD) {
                lHorizontal = 0.0f;
                lVertical   = ORTHOGONAL_MOVE;
            } else if (lDirectionY > THRESHOLD) {
                lHorizontal = 0.0f;
                lVertical   = -ORTHOGONAL_MOVE;
            }

            // Ends movement if there is a counter movement.
            if ((lHorizontal < 0.0f) && (mHorizontal > 0.0f)) {
                mHorizontal = 0.0f;
            } else if ((lHorizontal > 0.0f) && (mHorizontal < 0.0f)) {
                mHorizontal = 0.0f;
            } else {
                mHorizontal = lHorizontal;
            }

            if ((lVertical < 0.0f) && (mVertical > 0.0f)) {
                mVertical = 0.0f;
            } else if ((lVertical > 0.0f) && (mVertical < 0.0f)) {
                mVertical = 0.0f;
            } else {
                mVertical = lVertical;
            }
        } else {
            mHorizontal = 0.0f; mVertical = 0.0f;
        }
        return true;
    }