Exemplo n.º 1
0
/**
 * \brief	Called every logic cycle. This triggers the events that occur and process them trough various functions
 */
void CInput::pollEvents()
{
	// copy all the input of the last poll to a space for checking pressing or holding a button
	memcpy(last_immediate_keytable, immediate_keytable, KEYTABLE_SIZE*sizeof(char));

	for(int i=0 ; i<MAX_COMMANDS ; i++)
		for(int j=0 ; j<NUM_INPUTS ; j++)
			InputCommand[j][i].lastactive = InputCommand[j][i].active;

	// While there's an event to handle
	while( SDL_PollEvent( &Event ) )
	{
		switch( Event.type )
		{
		case SDL_QUIT:
			g_pLogFile->textOut("SDL: Got quit event!");
			m_exit = true;
			break;
		case SDL_KEYDOWN:
			processKeys(1);
			break;
		case SDL_KEYUP:
			processKeys(0);
			break;
		case SDL_JOYAXISMOTION:
			processJoystickAxis();
			break;
		case SDL_JOYBUTTONDOWN:
			processJoystickButton(1);
			break;
		case SDL_JOYBUTTONUP:
			processJoystickButton(0);
			break;
#ifdef MOUSEWRAPPER
		case SDL_MOUSEBUTTONDOWN:
		case SDL_MOUSEBUTTONUP:
		case SDL_MOUSEMOTION:
			processMouse(Event);
			break;
#endif

		case SDL_VIDEORESIZE:
			CRect newSize(Event.resize.w, Event.resize.h);
			g_pVideoDriver->mp_VideoEngine->resizeDisplayScreen(newSize);
			break;
		}
	}
#ifdef MOUSEWRAPPER
	// Handle mouse emulation layer
	processMouse();
#endif

	for(unsigned int i = 0; i < KEYTABLE_SIZE; ++i)
		firsttime_immediate_keytable[i]
		= !last_immediate_keytable[i] && immediate_keytable[i];

	for(int i=0 ; i<MAX_COMMANDS ; i++)
		for(int j=0 ; j<NUM_INPUTS ; j++)
			InputCommand[j][i].firsttimeactive
			= !InputCommand[j][i].lastactive && InputCommand[j][i].active;

#ifndef MOUSEWRAPPER

	// TODO: I'm not sure, if that should go here...
	// Check, if LALT+ENTER was pressed
	if((getHoldedKey(KALT)) && getPressedKey(KENTER))
	{
		bool value;
		value = g_pVideoDriver->getFullscreen();
		value = !value;
		g_pLogFile->textOut(GREEN,"Fullscreen mode triggered by user!<br>");
		g_pVideoDriver->isFullscreen(value);

		// initialize/activate all drivers
		g_pVideoDriver->stop();
		g_pLogFile->ftextOut("Restarting graphics driver...<br>");
		if ( g_pVideoDriver->applyMode() && g_pVideoDriver->start() )
		{
			g_pLogFile->ftextOut(PURPLE, "Toggled Fullscreen quick shortcut...<br>");
		}
		else
		{
			value = !value;
			g_pLogFile->ftextOut(PURPLE, "Couldn't change the resolution, Rolling back...<br>");
			g_pVideoDriver->applyMode();
			g_pVideoDriver->start();
		}

		if(value) g_pVideoDriver->AddConsoleMsg("Fullscreen enabled");
		else g_pVideoDriver->AddConsoleMsg("Fullscreen disabled");

		g_pInput->flushAll();
	}

	// Check, if LALT+Q or LALT+F4 was pressed
	if(getHoldedKey(KALT) && (getPressedKey(KF4) || getPressedKey(KQ)) )
	{
		g_pLogFile->textOut("User exit request!");
		m_exit = true;
	}
#endif

#if defined(WIZ) || defined(GP2X)
	WIZ_AdjustVolume( volume_direction );
#endif

    // Fix up settings if everything gets messed up
	if (g_pInput->getHoldedKey(KF) &&
		g_pInput->getHoldedKey(KI) &&
		g_pInput->getHoldedKey(KX))
	{
		g_pSettings->loadDefaultGraphicsCfg();
		g_pSettings->saveDrvCfg();
		g_pVideoDriver->stop();
		g_pVideoDriver->start();
	}
}
Exemplo n.º 2
0
/**
 * \brief	Called every logic cycle. This triggers the events that occur and process them through various functions
 */
void CInput::pollEvents()
{
    // Semaphore
    SDL_SemWait( pollSem );

    if(remapper.mappingInput)
    {
        readNewEvent();
        SDL_SemPost( pollSem );
        return;
    }

    Vector2D<float> Pos;
#if SDL_VERSION_ATLEAST(2, 0, 0)

#else
    GsRect<Uint16> Res(SDL_GetVideoSurface()->w, SDL_GetVideoSurface()->h);
#endif

	// copy all the input of the last poll to a space for checking pressing or holding a button
	memcpy(last_immediate_keytable, immediate_keytable, KEYTABLE_SIZE*sizeof(char));

	for(int i=0 ; i<MAX_COMMANDS ; i++)
		for(int j=0 ; j<NUM_INPUTS ; j++)
			InputCommand[j][i].lastactive = InputCommand[j][i].active;


    GsRect<Uint16> activeArea = gVideoDriver.mpVideoEngine->getAspectCorrRect();

    auto &dispRect = gVideoDriver.getVidConfig().m_DisplayRect;


#if SDL_VERSION_ATLEAST(2, 0, 0)
#else
    //if( !gVideoDriver.isOpenGL() )
    {
        activeArea.x = 0;
        activeArea.y = 0;
    }
#endif



	// While there's an event to handle
	while( SDL_PollEvent( &Event ) )
	{
        bool passSDLEventVec = true;

		switch( Event.type )
		{
		case SDL_QUIT:
			gLogging.textOut("SDL: Got quit event!");
			m_exit = true;
            gDreamsForceClose = 1;

			break;
        case SDL_KEYDOWN:
            passSDLEventVec = processKeys(1);
			break;
		case SDL_KEYUP:
            passSDLEventVec = processKeys(0);
            break;
		case SDL_JOYAXISMOTION:
            passSDLEventVec = true;
			processJoystickAxis();
			break;
		case SDL_JOYBUTTONDOWN:
            passSDLEventVec = true;
			processJoystickButton(1);
			break;
		case SDL_JOYBUTTONUP:
            passSDLEventVec = true;
			processJoystickButton(0);
			break;

		case SDL_JOYHATMOTION:
            passSDLEventVec = true;
			processJoystickHat();
			break;

#if SDL_VERSION_ATLEAST(2, 0, 0)
		case SDL_FINGERDOWN:
		case SDL_FINGERUP:
		case SDL_FINGERMOTION:
			processMouse(Event);
			break;

        case SDL_WINDOWEVENT:
            if(Event.window.event == SDL_WINDOWEVENT_RESIZED)
            {
                gVideoDriver.mpVideoEngine->resizeDisplayScreen(
                        GsRect<Uint16>(Event.window.data1,
                                      Event.window.data2) );
                dispRect.w = Event.window.data1;
                dispRect.h = Event.window.data2;
            }
            break;
#else
		case SDL_VIDEORESIZE:
            gVideoDriver.mpVideoEngine->resizeDisplayScreen(
					GsRect<Uint16>(Event.resize.w, Event.resize.h) );
            dispRect.w = Event.resize.w;
            dispRect.h = Event.resize.h;
			break;
#endif

		case SDL_MOUSEBUTTONDOWN:

            // If Virtual gamepad takes control...
            if(mpVirtPad && mpVirtPad->active())
            {                                                
                if(Event.button.button <= 3)
                {
                    transMouseRelCoord(Pos, Event.motion, activeArea);
                    mpVirtPad->mouseDown(Pos);
                }
            }
            else
            {
                if(Event.button.button <= 3)
                {
                    transMouseRelCoord(Pos, Event.motion, activeArea);
                    m_EventList.add( new PointingDevEvent( Pos, PDE_BUTTONDOWN ) );
                    gPointDevice.mPointingState.mActionButton = 1;
                    gPointDevice.mPointingState.mPos = Pos;
                }
                else if(Event.button.button == 4) // scroll up
                {
                    gEventManager.add( new MouseWheelEvent( Vector2D<float>(0.0, -1.0) ) );
                }
                else if(Event.button.button == 5) // scroll down
                {
                    gEventManager.add( new MouseWheelEvent( Vector2D<float>(0.0, 1.0) ) );
                }
            }

			break;

		case SDL_MOUSEBUTTONUP:
            if(mpVirtPad && mpVirtPad->active())
            {
                transMouseRelCoord(Pos, Event.motion, activeArea);
                mpVirtPad->mouseUp(Pos);
            }
            else
            {
                passSDLEventVec = true;
                transMouseRelCoord(Pos, Event.motion, activeArea);
                m_EventList.add( new PointingDevEvent( Pos, PDE_BUTTONUP ) );
                gPointDevice.mPointingState.mActionButton = 0;
                gPointDevice.mPointingState.mPos = Pos;
            }

			break;

		case SDL_MOUSEMOTION:
            transMouseRelCoord(Pos, Event.motion, activeArea);
            m_EventList.add( new PointingDevEvent( Pos, PDE_MOVED ) );
            gPointDevice.mPointingState.mPos = Pos;
			break;
		}

        if(passSDLEventVec)
        {
            mSDLEventVec.push_back(Event);
        }
        else
        {
            mBackEventBuffer.push_back(Event);
        }
	}
#ifdef MOUSEWRAPPER
	// Handle mouse emulation layer
	processMouse();
#endif

	for(unsigned int i = 0; i < KEYTABLE_SIZE; ++i)
		firsttime_immediate_keytable[i]
		= !last_immediate_keytable[i] && immediate_keytable[i];

	for(int i=0 ; i<MAX_COMMANDS ; i++)
		for(int j=0 ; j<NUM_INPUTS ; j++)
			InputCommand[j][i].firsttimeactive
			= !InputCommand[j][i].lastactive && InputCommand[j][i].active;

#ifndef MOUSEWRAPPER

	// TODO: I'm not sure, if that should go here...
	// Check, if LALT+ENTER was pressed
	if((getHoldedKey(KALT)) && getPressedKey(KENTER))
	{
		bool value;
        value = gVideoDriver.getFullscreen();
		value = !value;
		gLogging.textOut(GREEN,"Fullscreen mode triggered by user!<br>");
        gVideoDriver.isFullscreen(value);

		// initialize/activate all drivers
		gLogging.ftextOut("Restarting graphics driver...<br>");
        if ( gVideoDriver.applyMode() && gVideoDriver.start() )
		{
			gLogging.ftextOut(PURPLE, "Toggled Fullscreen quick shortcut...<br>");
		}
		else
		{
			value = !value;
			gLogging.ftextOut(PURPLE, "Couldn't change the resolution, Rolling back...<br>");
            gVideoDriver.applyMode();
            gVideoDriver.start();
		}

		gInput.flushAll();
	}

	// Check, if LALT+Q or LALT+F4 was pressed
	if(getHoldedKey(KALT) && (getPressedKey(KF4) || getPressedKey(KQ)) )
	{
		gLogging.textOut("User exit request!");
		m_exit = true;
        gDreamsForceClose = 1;
	}
#endif

#if defined(WIZ) || defined(GP2X)
	WIZ_AdjustVolume( volume_direction );
#endif

    SDL_SemPost( pollSem );
}