Esempio n. 1
0
    void SDLWrapper::OnInput( )
    {
        SDL_Event event;

        if( SDL_PollEvent( &event ))
        {
            // Clean exit if window is closed
            //
            if( event.type == SDL_QUIT )
            {
                OnExit( );
            }

            switch( event.type )
            {
                case SDL_KEYDOWN:
                    OnKeyDown( event.key );
                    break;

                case SDL_KEYUP:
                    OnKeyUp( event.key );
                    break;

                case SDL_MOUSEMOTION:
                    OnMouseMove( event.motion.x,
                                 event.motion.y,
                                 event.motion.xrel,
                                 event.motion.yrel,
                                 ( event.motion.state & SDL_BUTTON( SDL_BUTTON_LEFT   )) != 0,   // Left button clicked
                                 ( event.motion.state & SDL_BUTTON( SDL_BUTTON_RIGHT  )) != 0,   // Right button clicked
                                 ( event.motion.state & SDL_BUTTON( SDL_BUTTON_MIDDLE )) != 0 ); // Middle button clicked
                    break;

                case SDL_MOUSEBUTTONDOWN:
                    HandleMouseButtonDownEvents( &event );
                    break;

                case SDL_MOUSEBUTTONUP:
                    HandleMouseButtonUpEvents( &event );
                    break;

                #if EMSCRIPTEN
                case SDL_FINGERMOTION:
                    OnFingerMotion( &event );
                    break;

                case SDL_FINGERDOWN:
                    OnFingerDown( &event );
                    break;

                case SDL_FINGERUP:
                    OnFingerUp( &event );
                    break;
                #endif
            }
        }
    }
Esempio n. 2
0
InReaction CTouchInput::HandleEvent(const SDL_Event_* ev)
{
	UNUSED2(ev); // may be unused depending on #ifs

	if (!IsEnabled())
		return IN_PASS;

#if EMULATE_FINGERS_WITH_MOUSE
	switch(ev->ev.type)
	{
	case SDL_MOUSEBUTTONDOWN:
	{
		int button;
		if (ev->ev.button.button == SDL_BUTTON_LEFT)
			button = 0;
		else if (ev->ev.button.button == SDL_BUTTON_RIGHT)
			button = 1;
		else
			return IN_PASS;

		m_MouseEmulateDownPos[button] = CVector2D(ev->ev.button.x, ev->ev.button.y);
		if (m_MouseEmulateState[button] == MOUSE_INACTIVE)
		{
			m_MouseEmulateState[button] = MOUSE_ACTIVATING;
			OnFingerDown(button, ev->ev.button.x, ev->ev.button.y);
		}
		else if (m_MouseEmulateState[button] == MOUSE_ACTIVE_UP)
		{
			m_MouseEmulateState[button] = MOUSE_ACTIVE_DOWN;
		}
		return IN_HANDLED;
	}

	case SDL_MOUSEBUTTONUP:
	{
		int button;
		if (ev->ev.button.button == SDL_BUTTON_LEFT)
			button = 0;
		else if (ev->ev.button.button == SDL_BUTTON_RIGHT)
			button = 1;
		else
			return IN_PASS;

		if (m_MouseEmulateState[button] == MOUSE_ACTIVATING)
		{
			m_MouseEmulateState[button] = MOUSE_ACTIVE_UP;
		}
		else if (m_MouseEmulateState[button] == MOUSE_ACTIVE_DOWN)
		{
			float dist = (m_MouseEmulateDownPos[button] - CVector2D(ev->ev.button.x, ev->ev.button.y)).Length();
			if (dist <= 2)
			{
				m_MouseEmulateState[button] = MOUSE_INACTIVE;
				OnFingerUp(button, ev->ev.button.x, ev->ev.button.y);
			}
			else
			{
				m_MouseEmulateState[button] = MOUSE_ACTIVE_UP;
			}
		}
		return IN_HANDLED;
	}

	case SDL_MOUSEMOTION:
	{
		for (size_t i = 0; i < MAX_MOUSE; ++i)
		{
			if (m_MouseEmulateState[i] == MOUSE_ACTIVE_DOWN)
			{
				OnFingerMotion(i, ev->ev.motion.x, ev->ev.motion.y);
			}
		}
		return IN_HANDLED;
	}
	}
#endif

#if SDL_VERSION_ATLEAST(2, 0, 0)
	switch(ev->ev.type)
	{
	case SDL_FINGERDOWN:
	case SDL_FINGERUP:
	case SDL_FINGERMOTION:
	{
		// Map finger events onto the mouse, for basic testing
		debug_printf(L"finger %s tid=%lld fid=%lld s=%d x=%d y=%d dx=%d dy=%d p=%d\n",
			ev->ev.type == SDL_FINGERDOWN ? "down" :
			ev->ev.type == SDL_FINGERUP ? "up" :
			ev->ev.type == SDL_FINGERMOTION ? "motion" : "?",
			ev->ev.tfinger.touchId, ev->ev.tfinger.fingerId, ev->ev.tfinger.state,
			ev->ev.tfinger.x, ev->ev.tfinger.y, ev->ev.tfinger.dx, ev->ev.tfinger.dy, ev->ev.tfinger.pressure);

		if (ev->ev.type == SDL_FINGERDOWN)
			OnFingerDown(ev->ev.tfinger.fingerId, g_xres * (ev->ev.tfinger.x/32767.0f), g_yres * (ev->ev.tfinger.y/32767.0f));
		else if (ev->ev.type == SDL_FINGERUP)
			OnFingerUp(ev->ev.tfinger.fingerId, g_xres * (ev->ev.tfinger.x/32767.0f), g_yres * (ev->ev.tfinger.y/32767.0f));
		else if (ev->ev.type == SDL_FINGERMOTION)
			OnFingerMotion(ev->ev.tfinger.fingerId, g_xres * (ev->ev.tfinger.x/32767.0f), g_yres * (ev->ev.tfinger.y/32767.0f));
		return IN_HANDLED;
	}
	}
#endif

	return IN_PASS;
}
Esempio n. 3
0
void Events::Poll()
{
    GamePad::Clear();
    Joystick::Clear();
    Keyboard::Clear();
    Mouse::Clear();

    while (SDL_PollEvent(&mEvent))
    {
        switch (mEvent.type)
        {
        case SDL_QUIT:
            OnQuit();
            break;
        case SDL_APP_TERMINATING:
            OnAppTerminating();
            break;
        case SDL_APP_LOWMEMORY:
            OnAppLowMemory();
            break;
        case SDL_APP_WILLENTERBACKGROUND:
            OnAppWillEnterBackground();
            break;
        case SDL_APP_DIDENTERBACKGROUND:
            OnAppDidEnterBackground();
            break;
        case SDL_APP_WILLENTERFOREGROUND:
            OnAppWillEnterForeground();
            break;
        case SDL_APP_DIDENTERFOREGROUND:
            OnAppDidEnterForeground();
            break;
        case SDL_WINDOWEVENT:
            OnWindowEvent();
            break;
        case SDL_SYSWMEVENT:
            OnSysWMEvent();
            break;
        case SDL_KEYDOWN:
            OnKeyDown(mEvent.key.keysym.sym, mEvent.key.keysym.mod, mEvent.key.repeat);
            Keyboard::SetKey(mEvent.key.keysym.sym, true);
            break;
        case SDL_KEYUP:
            OnKeyUp(mEvent.key.keysym.sym, mEvent.key.keysym.mod, mEvent.key.repeat);
            Keyboard::SetKey(mEvent.key.keysym.sym, false);
            break;
        case SDL_TEXTEDITING:
            OnTextEditing();
            break;
        case SDL_TEXTINPUT:
            OnTextInput();
            break;
        case SDL_MOUSEMOTION:
            OnMouseMotion(mEvent.motion.x, mEvent.motion.y, mEvent.motion.xrel, mEvent.motion.yrel);
            Mouse::SetPosition(mEvent.motion.x, mEvent.motion.y);
            break;
        case SDL_MOUSEBUTTONDOWN:
            switch(mEvent.button.button)
            {
            case SDL_BUTTON_LEFT:
                OnMouseLeftButtonDown(mEvent.button.x, mEvent.button.y);
                break;
            case SDL_BUTTON_RIGHT:
                OnMouseRightButtonDown(mEvent.button.x, mEvent.button.y);
                break;
            case SDL_BUTTON_MIDDLE:
                OnMouseMiddleButtonDown(mEvent.button.x, mEvent.button.y);
                break;
            case SDL_BUTTON_X1:
                OnMouseLeftButtonDown(mEvent.button.x, mEvent.button.y);
                break;
            case SDL_BUTTON_X2:
                OnMouseLeftButtonDown(mEvent.button.x, mEvent.button.y);
                break;
            }
            break;
        case SDL_MOUSEBUTTONUP:
            switch(mEvent.button.button)
            {
            case SDL_BUTTON_LEFT:
                OnMouseLeftButtonUp(mEvent.button.x, mEvent.button.y);
                break;
            case SDL_BUTTON_RIGHT:
                OnMouseRightButtonUp(mEvent.button.x, mEvent.button.y);
                break;
            case SDL_BUTTON_MIDDLE:
                OnMouseMiddleButtonUp(mEvent.button.x, mEvent.button.y);
                break;
            case SDL_BUTTON_X1:
                OnMouseLeftButtonUp(mEvent.button.x, mEvent.button.y);
                break;
            case SDL_BUTTON_X2:
                OnMouseLeftButtonUp(mEvent.button.x, mEvent.button.y);
                break;
            }
            break;
        case SDL_MOUSEWHEEL:
            OnMouseWheel(mEvent.wheel.x, mEvent.wheel.y);
            Mouse::SetScroll(mEvent.wheel.x, mEvent.wheel.y);
            break;
        case SDL_JOYAXISMOTION:
            OnJoyAxisMotion();
            break;
        case SDL_JOYBALLMOTION:
            OnJoyBallMotion();
            break;
        case SDL_JOYHATMOTION:
            OnJoyHatMotion();
            break;
        case SDL_JOYBUTTONDOWN:
            OnJoyBallButtonDown();
            break;
        case SDL_JOYBUTTONUP:
            OnJoyBallButtonUp();
            break;
        case SDL_JOYDEVICEADDED:
            OnJoyDeviceAdded();
            break;
        case SDL_JOYDEVICEREMOVED:
            OnJoyDeviceRemoved();
            break;
        case SDL_CONTROLLERAXISMOTION:
            OnControllerAxisMotion(mEvent.caxis.axis, mEvent.caxis.value, mEvent.caxis.which);
            GamePad::SetAxis(mEvent.caxis.axis, mEvent.caxis.value, mEvent.caxis.which);
            break;
        case SDL_CONTROLLERBUTTONDOWN:
            OnControllerButtonDown(mEvent.cbutton.button, mEvent.cbutton.which);
            GamePad::SetButton(mEvent.cbutton.button, true, mEvent.cbutton.which);
            break;
        case SDL_CONTROLLERBUTTONUP:
            OnControllerButtonUp(mEvent.cbutton.button, mEvent.cbutton.which);
            GamePad::SetButton(mEvent.cbutton.button, false, mEvent.cbutton.which);
            break;
        case SDL_CONTROLLERDEVICEADDED:
            OnControllerDeviceAdded(mEvent.cdevice.which);
            GamePad::Add(mEvent.cdevice.which);
            break;
        case SDL_CONTROLLERDEVICEREMOVED:
            OnControllerDeviceRemoved(mEvent.cdevice.which);
            GamePad::Remove(mEvent.cdevice.which);
            break;
        case SDL_CONTROLLERDEVICEREMAPPED:
            OnControllerDeviceRemapped(mEvent.cdevice.which);
            break;
        case SDL_FINGERDOWN:
            OnFingerDown();
            break;
        case SDL_FINGERUP:
            OnFingerUp();
            break;
        case SDL_FINGERMOTION:
            OnFingerMotion();
            break;
        case SDL_DOLLARGESTURE:
            OnDollarGesture();
            break;
        case SDL_DOLLARRECORD:
            OnDollarRecord();
            break;
        case SDL_MULTIGESTURE:
            OnMultiGesture();
            break;
        case SDL_CLIPBOARDUPDATE:
            OnClipboardUpdate();
            break;
        case SDL_DROPFILE:
            OnDropFile();
            break;
        case SDL_USEREVENT:
            OnUserEvent();
            break;
        default:
            OnUndefined();
            break;
        }
    }
}