Esempio n. 1
0
/**
 * \brief	normally called, when a save game or high score entry is being made. It will return a charakter that was typed.
 * \return	character as std::string, which was entered
 */
std::string CInput::getPressedTypingKey(void)
{
	int i;
	std::string buf;

	for(i=KA ; i<=KZ ; i++)
	{
		if (getHoldedKey(KSHIFT) && getPressedKey(i))
		{
			buf = 'A' + i - KA;
			return buf;
		}
		else if(getPressedKey(i))
		{
			buf = 'a' + i - KA;
			return buf;
		}
	}
	for(i=KSPACE ; i<=KAT ; i++)
	{
		if(getPressedKey(i))
		{
			buf = 32 + i - KSPACE;
			return buf;
		}
	}
		for(i=KLEFTBRACKET ; i<=KBACKQUOTE ; i++)
	{
		if(getPressedKey(i))
		{
			buf = '[' + i - KLEFTBRACKET;
			return buf;
		}
	}
		for(i=KLEFTBRACE ; i<=KTILDE ; i++)
	{
		if(getPressedKey(i))
		{
			buf = '{' + i - KLEFTBRACE;
			return buf;
		}
	}
	return buf;
}
Esempio n. 2
0
/**
 * \brief	returns if a numerical key was pressed
 * \return	number as std::string, which was entered
 */
std::string CInput::getPressedNumKey(void)
{
	int i;
	std::string buf;

	for(i=KNUM0 ; i<=KNUM9 ; i++)
	{
		if(getPressedKey(i))
		{
			buf = '0' + i - KNUM0;
			return buf;
		}
	}
	return buf;
}
Esempio n. 3
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();
	}
}
Esempio n. 4
0
/**
 * \brief	This will tell if any key was pressed and it fits the to command array, so we can tell, the command
 * 			was triggered.
 * \param	keydown	this parameter tells if the keys is down or has already been released.
 */
void CInput::processKeys(int keydown)
{
	// Input for player commands
	for(int i=0 ; i<MAX_COMMANDS ; i++)
	{
		for(int j=0 ; j<NUM_INPUTS ; j++)
		{
			if(InputCommand[j][i].keysym == Event.key.keysym.sym &&
					InputCommand[j][i].joyeventtype == ETYPE_KEYBOARD)
				InputCommand[j][i].active = (keydown) ? true : false;
		}
	}

	// ... and for general keys
    switch(Event.key.keysym.sym)
	{
			// These are only used for ingame stuff or menu, but not for controlling the player anymore
		case SDLK_LEFT: 	immediate_keytable[KLEFT]	= keydown;  break;
		case SDLK_UP:	immediate_keytable[KUP]		= keydown;  break;
		case SDLK_RIGHT:	immediate_keytable[KRIGHT]	= keydown;  break;
		case SDLK_DOWN:	immediate_keytable[KDOWN]	= keydown;  break;

			// Page Keys
		case SDLK_PAGEUP:	immediate_keytable[KPGUP]	= keydown;  break;
		case SDLK_PAGEDOWN:	immediate_keytable[KPGDN]		= keydown;  break;

		case SDLK_RETURN:immediate_keytable[KENTER]	= keydown;  break;
		case SDLK_RCTRL:immediate_keytable[KCTRL]	= keydown;  break;
		case SDLK_LCTRL:immediate_keytable[KCTRL]	= keydown;  break;
		case SDLK_SPACE:immediate_keytable[KSPACE]	= keydown;  break;
		case SDLK_RALT:immediate_keytable[KALT]		= keydown;  break;
		case SDLK_LALT:immediate_keytable[KALT]		= keydown;  break;
		case SDLK_TAB:immediate_keytable[KTAB]		= keydown;  break;
		case SDLK_LSHIFT:immediate_keytable[KSHIFT]	= keydown;  break;
		case SDLK_RSHIFT:immediate_keytable[KSHIFT]	= keydown;  break;
		case SDLK_ESCAPE:immediate_keytable[KQUIT]	= keydown;  break;

		case SDLK_BACKSPACE:immediate_keytable[KBCKSPCE] = keydown; break;

		case SDLK_QUOTE:immediate_keytable[KQUOTE]	= keydown;  break;
		case SDLK_COMMA:immediate_keytable[KCOMMA]	= keydown;  break;
		case SDLK_PERIOD:immediate_keytable[KPERIOD]	= keydown;  break;
		case SDLK_SLASH:immediate_keytable[KSLASH]	= keydown;  break;
		case SDLK_SEMICOLON:immediate_keytable[KSEMICOLON]	= keydown;  break;
		case SDLK_EQUALS:immediate_keytable[KEQUAL]	= keydown;  break;
		case SDLK_LEFTBRACKET:immediate_keytable[KLEFTBRACKET]	= keydown;  break;
		case SDLK_BACKSLASH:immediate_keytable[KBACKSLASH]	= keydown;  break;
		case SDLK_RIGHTBRACKET:immediate_keytable[KRIGHTBRACKET]	= keydown;  break;
		case SDLK_BACKQUOTE:immediate_keytable[KBACKQUOTE]	= keydown;  break;

		case SDLK_a:immediate_keytable[KA]	= keydown;  break;
		case SDLK_b:immediate_keytable[KB]	= keydown;  break;
		case SDLK_c:immediate_keytable[KC]	= keydown;  break;
		case SDLK_d:immediate_keytable[KD]	= keydown;  break;
		case SDLK_e:immediate_keytable[KE]	= keydown;  break;
		case SDLK_f:immediate_keytable[KF]	= keydown;  break;
		case SDLK_g:immediate_keytable[KG]	= keydown;  break;
		case SDLK_h:immediate_keytable[KH]	= keydown;  break;
		case SDLK_i:immediate_keytable[KI]	= keydown;  break;
		case SDLK_j:immediate_keytable[KJ]	= keydown;  break;
		case SDLK_k:immediate_keytable[KK]	= keydown;  break;
		case SDLK_l:immediate_keytable[KL]	= keydown;  break;
		case SDLK_m:immediate_keytable[KM]	= keydown;  break;
		case SDLK_n:immediate_keytable[KN]	= keydown;  break;
		case SDLK_o:immediate_keytable[KO]	= keydown;  break;
		case SDLK_p:immediate_keytable[KP]	= keydown;  break;
		case SDLK_q:immediate_keytable[KQ]	= keydown;  break;
		case SDLK_r:immediate_keytable[KR]	= keydown;  break;
		case SDLK_s:immediate_keytable[KS]	= keydown;  break;
		case SDLK_t:immediate_keytable[KT]	= keydown;  break;
		case SDLK_u:immediate_keytable[KU]	= keydown;  break;
		case SDLK_v:immediate_keytable[KV]	= keydown;  break;
		case SDLK_w:immediate_keytable[KW]	= keydown;  break;
		case SDLK_x:immediate_keytable[KX]	= keydown;  break;
		case SDLK_y:immediate_keytable[KY]	= keydown;  break;
		case SDLK_z:immediate_keytable[KZ]	= keydown;  break;

		case SDLK_F1:immediate_keytable[KF1]	= keydown;  break;
		case SDLK_F2:immediate_keytable[KF2]	= keydown;  break;
		case SDLK_F3:immediate_keytable[KF3]	= keydown;  break;
		case SDLK_F4:immediate_keytable[KF4]	= keydown;  break;
		case SDLK_F5:immediate_keytable[KF5]	= keydown;  break;
		case SDLK_F6:immediate_keytable[KF6]	= keydown;  break;
		case SDLK_F7:immediate_keytable[KF7]	= keydown;  break;
		case SDLK_F8:immediate_keytable[KF8]	= keydown;  break;
		case SDLK_F9:immediate_keytable[KF9]	= keydown;  break;
		case SDLK_F10:immediate_keytable[KF10]	= keydown;  break;

		case SDLK_0:immediate_keytable[KNUM0] = keydown;  break;
		case SDLK_1:immediate_keytable[KNUM1] = keydown;  break;
		case SDLK_2:immediate_keytable[KNUM2] = keydown;  break;
		case SDLK_3:immediate_keytable[KNUM3] = keydown;  break;
		case SDLK_4:immediate_keytable[KNUM4] = keydown;  break;
		case SDLK_5:immediate_keytable[KNUM5] = keydown;  break;
		case SDLK_6:immediate_keytable[KNUM6] = keydown;  break;
		case SDLK_7:immediate_keytable[KNUM7] = keydown;  break;
		case SDLK_8:immediate_keytable[KNUM8] = keydown;  break;
		case SDLK_9:immediate_keytable[KNUM9] = keydown;  break;

		case SDLK_EXCLAIM:immediate_keytable[KEXCLAIM]	= keydown;  break;
		case SDLK_QUOTEDBL:immediate_keytable[KDBLQUOTE]	= keydown;  break;
		case SDLK_HASH:immediate_keytable[KHASH]	= keydown;  break;
		case SDLK_DOLLAR:immediate_keytable[KDOLLAR]	= keydown;  break;
		case SDLK_AMPERSAND:immediate_keytable[KAMPERSAND]	= keydown;  break;
		case SDLK_ASTERISK:immediate_keytable[KAST]	= keydown;  break;
		case SDLK_LEFTPAREN:immediate_keytable[KLEFTPAREN]	= keydown;  break;
		case SDLK_RIGHTPAREN:immediate_keytable[KRIGHTPAREN]	= keydown;  break;
		case SDLK_COLON:immediate_keytable[KCOLON]	= keydown;  break;
		case SDLK_LESS:immediate_keytable[KLESS]	= keydown;  break;
		case SDLK_GREATER:immediate_keytable[KGREATER]	= keydown;  break;
		case SDLK_QUESTION:immediate_keytable[KQUESTION]	= keydown;  break;
		case SDLK_AT:immediate_keytable[KAT]	= keydown;  break;
		case SDLK_CARET:immediate_keytable[KCARET]	= keydown;  break;
		case SDLK_UNDERSCORE:immediate_keytable[KUNDERSCORE]	= keydown;  break;
		case SDLK_MINUS:immediate_keytable[KMINUS]	= keydown;  break;
		case SDLK_PLUS:immediate_keytable[KPLUS]	= keydown;  break;

		default: break;
	}

	if(getHoldedKey(KSHIFT))
	{
		if(getPressedKey(KBACKQUOTE)) immediate_keytable[KTILDE] = keydown;
		if(getPressedKey(KNUM1)) immediate_keytable[KEXCLAIM] = keydown;
		if(getPressedKey(KNUM2)) immediate_keytable[KAT] = keydown;
		if(getPressedKey(KNUM3)) immediate_keytable[KHASH] = keydown;
		if(getPressedKey(KNUM4)) immediate_keytable[KDOLLAR] = keydown;
		if(getPressedKey(KNUM5)) immediate_keytable[KPERCENT] = keydown;
		if(getPressedKey(KNUM6)) immediate_keytable[KCARET] = keydown;
		if(getPressedKey(KNUM7)) immediate_keytable[KAMPERSAND] = keydown;
		if(getPressedKey(KNUM8)) immediate_keytable[KAST] = keydown;
		if(getPressedKey(KNUM9)) immediate_keytable[KLEFTPAREN] = keydown;
		if(getPressedKey(KNUM0)) immediate_keytable[KRIGHTPAREN] = keydown;
		if(getPressedKey(KMINUS)) immediate_keytable[KUNDERSCORE] = keydown;
		if(getPressedKey(KEQUAL)) immediate_keytable[KPLUS] = keydown;
		if(getPressedKey(KBACKSLASH)) immediate_keytable[KLINE] = keydown;
		if(getPressedKey(KLEFTBRACKET)) immediate_keytable[KLEFTBRACE] = keydown;
		if(getPressedKey(KRIGHTBRACKET)) immediate_keytable[KRIGHTBRACE] = keydown;
		if(getPressedKey(KSEMICOLON)) immediate_keytable[KCOLON] = keydown;
		if(getPressedKey(KQUOTE)) immediate_keytable[KDBLQUOTE] = keydown;
		if(getPressedKey(KCOMMA)) immediate_keytable[KLESS] = keydown;
		if(getPressedKey(KPERIOD)) immediate_keytable[KGREATER] = keydown;
		if(getPressedKey(KSLASH)) immediate_keytable[KQUESTION] = keydown;
	}
}
Esempio n. 5
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 );
}