2003-02-16 04:01:45 +00:00
|
|
|
#include "global.h"
|
2001-11-03 10:52:42 +00:00
|
|
|
#include "RageInput.h"
|
2002-05-01 19:14:55 +00:00
|
|
|
#include "RageLog.h"
|
2003-02-16 02:25:22 +00:00
|
|
|
#include "arch/InputHandler/InputHandler.h"
|
2005-03-15 00:30:26 +00:00
|
|
|
#include "arch/arch.h"
|
2005-08-17 05:56:59 +00:00
|
|
|
#include "Foreach.h"
|
2005-12-31 02:20:03 +00:00
|
|
|
#include "Preference.h"
|
2006-09-21 04:27:45 +00:00
|
|
|
#include "LuaManager.h"
|
2005-03-15 00:30:26 +00:00
|
|
|
|
2002-05-19 01:59:48 +00:00
|
|
|
RageInput* INPUTMAN = NULL; // globally accessable input device
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2006-01-22 01:00:06 +00:00
|
|
|
static Preference<RString> g_sInputDrivers( "InputDrivers", "" ); // "" == DEFAULT_INPUT_DRIVER_LIST
|
2005-12-31 02:20:03 +00:00
|
|
|
|
|
|
|
|
RageInput::RageInput()
|
2001-11-03 10:52:42 +00:00
|
|
|
{
|
2002-07-31 19:40:40 +00:00
|
|
|
LOG->Trace( "RageInput::RageInput()" );
|
2002-05-19 01:59:48 +00:00
|
|
|
|
2006-09-21 04:27:45 +00:00
|
|
|
// Register with Lua.
|
|
|
|
|
{
|
|
|
|
|
Lua *L = LUA->Get();
|
|
|
|
|
lua_pushstring( L, "INPUTMAN" );
|
2006-09-21 04:49:55 +00:00
|
|
|
this->PushSelf( L );
|
2006-09-21 04:27:45 +00:00
|
|
|
lua_settable( L, LUA_GLOBALSINDEX );
|
|
|
|
|
LUA->Release( L );
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-18 21:24:33 +00:00
|
|
|
LoadDrivers();
|
2001-11-03 10:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
2002-11-29 20:37:12 +00:00
|
|
|
RageInput::~RageInput()
|
2001-11-03 10:52:42 +00:00
|
|
|
{
|
2003-02-16 02:25:22 +00:00
|
|
|
/* Delete optional devices. */
|
2005-05-14 09:26:05 +00:00
|
|
|
for( unsigned i = 0; i < m_pDevices.size(); ++i )
|
|
|
|
|
delete m_pDevices[i];
|
2006-09-21 04:27:45 +00:00
|
|
|
|
|
|
|
|
// Unregister with Lua.
|
|
|
|
|
LUA->UnsetGlobal( "INPUTMAN" );
|
2002-11-29 20:37:12 +00:00
|
|
|
}
|
2002-08-20 23:12:52 +00:00
|
|
|
|
2005-12-18 21:24:33 +00:00
|
|
|
void RageInput::LoadDrivers()
|
|
|
|
|
{
|
|
|
|
|
for( unsigned i = 0; i < m_pDevices.size(); ++i )
|
|
|
|
|
delete m_pDevices[i];
|
|
|
|
|
m_pDevices.clear();
|
|
|
|
|
|
|
|
|
|
/* Init optional devices. */
|
2006-11-17 18:25:20 +00:00
|
|
|
MakeInputHandlers( g_sInputDrivers, m_pDevices );
|
2005-12-18 21:24:33 +00:00
|
|
|
|
|
|
|
|
/* If no input devices are loaded, the user won't be able to input anything. */
|
|
|
|
|
if( m_pDevices.size() == 0 )
|
|
|
|
|
LOG->Warn( "No input devices were loaded." );
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-18 22:53:47 +00:00
|
|
|
void RageInput::Update()
|
2002-11-29 20:37:12 +00:00
|
|
|
{
|
2003-02-16 02:25:22 +00:00
|
|
|
/* Update optional devices. */
|
2005-05-14 09:26:05 +00:00
|
|
|
for( unsigned i = 0; i < m_pDevices.size(); ++i )
|
2005-12-18 22:51:12 +00:00
|
|
|
m_pDevices[i]->Update();
|
2003-02-16 01:35:48 +00:00
|
|
|
}
|
2002-08-20 23:12:52 +00:00
|
|
|
|
2005-12-18 03:08:12 +00:00
|
|
|
bool RageInput::DevicesChanged()
|
|
|
|
|
{
|
|
|
|
|
/* Update optional devices. */
|
|
|
|
|
for( unsigned i = 0; i < m_pDevices.size(); ++i )
|
|
|
|
|
{
|
|
|
|
|
if( m_pDevices[i]->DevicesChanged() )
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2006-02-27 17:51:27 +00:00
|
|
|
void RageInput::GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevicesOut ) const
|
2003-05-28 02:35:05 +00:00
|
|
|
{
|
2005-05-14 09:26:05 +00:00
|
|
|
for( unsigned i = 0; i < m_pDevices.size(); ++i )
|
2006-02-27 17:51:27 +00:00
|
|
|
m_pDevices[i]->GetDevicesAndDescriptions( vDevicesOut );
|
2003-05-28 02:35:05 +00:00
|
|
|
}
|
2003-06-18 05:43:12 +00:00
|
|
|
|
|
|
|
|
void RageInput::WindowReset()
|
|
|
|
|
{
|
2005-05-14 09:26:05 +00:00
|
|
|
for( unsigned i = 0; i < m_pDevices.size(); ++i )
|
|
|
|
|
m_pDevices[i]->WindowReset();
|
2003-06-18 05:43:12 +00:00
|
|
|
}
|
2004-05-06 00:42:06 +00:00
|
|
|
|
2005-05-14 09:23:30 +00:00
|
|
|
void RageInput::AddHandler( InputHandler *pHandler )
|
|
|
|
|
{
|
|
|
|
|
ASSERT( pHandler != NULL );
|
2005-05-14 09:26:05 +00:00
|
|
|
m_pDevices.push_back( pHandler );
|
2005-05-14 09:23:30 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-22 01:00:06 +00:00
|
|
|
RString RageInput::GetDeviceSpecificInputString( const DeviceInput &di )
|
2005-08-17 05:56:59 +00:00
|
|
|
{
|
|
|
|
|
FOREACH( InputHandler*, m_pDevices, i )
|
|
|
|
|
{
|
2006-02-27 17:51:27 +00:00
|
|
|
vector<InputDeviceInfo> vDevices;
|
|
|
|
|
(*i)->GetDevicesAndDescriptions( vDevices );
|
2005-08-17 05:56:59 +00:00
|
|
|
|
2006-02-27 17:51:27 +00:00
|
|
|
FOREACH_CONST( InputDeviceInfo, vDevices, idi )
|
|
|
|
|
{
|
|
|
|
|
if( idi->id == di.device )
|
|
|
|
|
return (*i)->GetDeviceSpecificInputString(di);
|
|
|
|
|
}
|
2005-08-17 05:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
2005-12-09 01:48:20 +00:00
|
|
|
return di.ToString();
|
2005-08-17 05:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
2006-06-15 06:07:45 +00:00
|
|
|
RString RageInput::GetLocalizedInputString( const DeviceInput &di )
|
|
|
|
|
{
|
|
|
|
|
FOREACH( InputHandler*, m_pDevices, i )
|
|
|
|
|
{
|
|
|
|
|
vector<InputDeviceInfo> vDevices;
|
|
|
|
|
(*i)->GetDevicesAndDescriptions( vDevices );
|
|
|
|
|
|
|
|
|
|
FOREACH_CONST( InputDeviceInfo, vDevices, idi )
|
|
|
|
|
{
|
|
|
|
|
if( idi->id == di.device )
|
|
|
|
|
return (*i)->GetLocalizedInputString(di);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Capitalize( DeviceButtonToString(di.button) );
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-15 03:33:29 +00:00
|
|
|
wchar_t RageInput::DeviceInputToChar( DeviceInput di, bool bUseCurrentKeyModifiers )
|
|
|
|
|
{
|
|
|
|
|
FOREACH( InputHandler*, m_pDevices, i )
|
|
|
|
|
{
|
|
|
|
|
vector<InputDeviceInfo> vDevices;
|
|
|
|
|
(*i)->GetDevicesAndDescriptions( vDevices );
|
|
|
|
|
|
|
|
|
|
FOREACH_CONST( InputDeviceInfo, vDevices, idi )
|
|
|
|
|
{
|
|
|
|
|
if( idi->id == di.device )
|
|
|
|
|
return (*i)->DeviceButtonToChar(di.button, bUseCurrentKeyModifiers);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return '\0';
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-20 22:49:25 +00:00
|
|
|
InputDeviceState RageInput::GetInputDeviceState( InputDevice id )
|
|
|
|
|
{
|
|
|
|
|
FOREACH( InputHandler*, m_pDevices, i )
|
|
|
|
|
{
|
2006-02-27 17:51:27 +00:00
|
|
|
vector<InputDeviceInfo> vDevices;
|
|
|
|
|
(*i)->GetDevicesAndDescriptions( vDevices );
|
2005-08-20 22:49:25 +00:00
|
|
|
|
2006-02-27 17:51:27 +00:00
|
|
|
FOREACH_CONST( InputDeviceInfo, vDevices, idi )
|
|
|
|
|
{
|
|
|
|
|
if( idi->id == id )
|
|
|
|
|
return (*i)->GetInputDeviceState(id);
|
|
|
|
|
}
|
2005-08-20 22:49:25 +00:00
|
|
|
}
|
|
|
|
|
|
2006-10-07 04:13:43 +00:00
|
|
|
return InputDeviceState_Invalid;
|
2005-08-20 22:49:25 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-26 06:17:57 +00:00
|
|
|
RString RageInput::GetDisplayDevicesString() const
|
|
|
|
|
{
|
2006-02-27 17:51:27 +00:00
|
|
|
vector<InputDeviceInfo> vDevices;
|
|
|
|
|
GetDevicesAndDescriptions( vDevices );
|
|
|
|
|
|
2006-01-26 06:17:57 +00:00
|
|
|
vector<RString> vs;
|
|
|
|
|
for( unsigned i=0; i<vDevices.size(); ++i )
|
|
|
|
|
{
|
2006-02-27 17:51:27 +00:00
|
|
|
const RString &sDescription = vDevices[i].sDesc;
|
|
|
|
|
InputDevice id = vDevices[i].id;
|
2006-01-26 06:17:57 +00:00
|
|
|
if( sDescription == "MonkeyKeyboard" )
|
|
|
|
|
continue; // hide this
|
2006-02-27 17:51:27 +00:00
|
|
|
vs.push_back( ssprintf("%s (%s)", sDescription.c_str(), InputDeviceToString(id).c_str()) );
|
2006-01-26 06:17:57 +00:00
|
|
|
}
|
|
|
|
|
return join("\n",vs);
|
|
|
|
|
}
|
2005-06-04 01:56:03 +00:00
|
|
|
|
|
|
|
|
// lua start
|
|
|
|
|
#include "LuaBinding.h"
|
|
|
|
|
|
2005-06-20 05:02:03 +00:00
|
|
|
class LunaRageInput: public Luna<RageInput>
|
2005-06-04 01:56:03 +00:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static int GetDescriptions( T* p, lua_State *L )
|
|
|
|
|
{
|
2006-02-27 17:51:27 +00:00
|
|
|
vector<InputDeviceInfo> vDevices;
|
|
|
|
|
p->GetDevicesAndDescriptions( vDevices );
|
2006-01-22 01:00:06 +00:00
|
|
|
vector<RString> vsDescriptions;
|
2006-02-27 17:51:27 +00:00
|
|
|
FOREACH_CONST( InputDeviceInfo, vDevices, idi )
|
|
|
|
|
vsDescriptions.push_back( idi->sDesc );
|
2005-06-04 01:56:03 +00:00
|
|
|
LuaHelpers::CreateTableFromArray( vsDescriptions, L );
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-27 20:30:29 +00:00
|
|
|
LunaRageInput()
|
2005-06-04 01:56:03 +00:00
|
|
|
{
|
2006-09-27 20:30:29 +00:00
|
|
|
ADD_METHOD( GetDescriptions );
|
2005-06-04 01:56:03 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LUA_REGISTER_CLASS( RageInput )
|
|
|
|
|
// lua end
|
|
|
|
|
|
|
|
|
|
|
2004-05-06 00:42:06 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2001-2004 Chris Danford, Glenn Maynard
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, and/or sell copies of the Software, and to permit persons to
|
|
|
|
|
* whom the Software is furnished to do so, provided that the above
|
|
|
|
|
* copyright notice(s) and this permission notice appear in all copies of
|
|
|
|
|
* the Software and that both the above copyright notice(s) and this
|
|
|
|
|
* permission notice appear in supporting documentation.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
|
|
|
|
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
|
|
|
|
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
|
|
|
|
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
|
|
|
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
|
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|