international keyboard support

This commit is contained in:
Chris Danford
2006-06-10 06:50:50 +00:00
parent 566e163401
commit dce168b0c2
13 changed files with 90 additions and 38 deletions
+17
View File
@@ -97,6 +97,23 @@ RString RageInput::GetDeviceSpecificInputString( const DeviceInput &di )
return di.ToString(); return di.ToString();
} }
char RageInput::DeviceButtonToChar( DeviceButton button )
{
FOREACH( InputHandler*, m_pDevices, i )
{
vector<InputDeviceInfo> vDevices;
(*i)->GetDevicesAndDescriptions( vDevices );
FOREACH_CONST( InputDeviceInfo, vDevices, idi )
{
if( idi->id == DEVICE_KEYBOARD )
return (*i)->DeviceButtonToChar(button);
}
}
return '\0';
}
InputDeviceState RageInput::GetInputDeviceState( InputDevice id ) InputDeviceState RageInput::GetInputDeviceState( InputDevice id )
{ {
FOREACH( InputHandler*, m_pDevices, i ) FOREACH( InputHandler*, m_pDevices, i )
+1
View File
@@ -21,6 +21,7 @@ public:
void WindowReset(); void WindowReset();
void AddHandler( InputHandler *pHandler ); void AddHandler( InputHandler *pHandler );
RString GetDeviceSpecificInputString( const DeviceInput &di ); RString GetDeviceSpecificInputString( const DeviceInput &di );
char DeviceButtonToChar( DeviceButton button );
InputDeviceState GetInputDeviceState( InputDevice id ); InputDeviceState GetInputDeviceState( InputDevice id );
RString GetDisplayDevicesString() const; RString GetDisplayDevicesString() const;
-22
View File
@@ -273,28 +273,6 @@ bool DeviceInput::FromString( const RString &s )
return true; return true;
} }
char DeviceInput::ToChar() const
{
if( button < 127 )
return (char) button;
if( button >= KEY_KP_C0 && button <= KEY_KP_C9 )
return (char) (button - KEY_KP_C0) + '0';
switch( button )
{
case KEY_KP_SLASH: return '/';
case KEY_KP_ASTERISK: return '*';
case KEY_KP_HYPHEN: return '-';
case KEY_KP_PLUS: return '+';
case KEY_KP_PERIOD: return '.';
case KEY_KP_EQUAL: return '=';
}
return '\0';
}
/* /*
* Copyright (c) 2001-2002 Chris Danford * Copyright (c) 2001-2002 Chris Danford
* All rights reserved. * All rights reserved.
-2
View File
@@ -337,8 +337,6 @@ public:
bool IsValid() const { return device != DEVICE_NONE; }; bool IsValid() const { return device != DEVICE_NONE; };
void MakeInvalid() { device = DEVICE_NONE; }; void MakeInvalid() { device = DEVICE_NONE; };
char ToChar() const;
bool IsJoystick() const { return ::IsJoystick(device); } bool IsJoystick() const { return ::IsJoystick(device); }
}; };
+2 -1
View File
@@ -23,6 +23,7 @@
#include "ScreenDimensions.h" #include "ScreenDimensions.h"
#include "Command.h" #include "Command.h"
#include "InputEventPlus.h" #include "InputEventPlus.h"
#include "RageInput.h"
// //
// Defines specific to ScreenNameEntryTraditional // Defines specific to ScreenNameEntryTraditional
@@ -515,7 +516,7 @@ void ScreenNameEntryTraditional::Input( const InputEventPlus &input )
if( input.DeviceI == DeviceInput(DEVICE_KEYBOARD, KEY_BACK) ) if( input.DeviceI == DeviceInput(DEVICE_KEYBOARD, KEY_BACK) )
c = CHAR_BACK; c = CHAR_BACK;
else else
c = toupper( input.DeviceI.ToChar() ); c = toupper( INPUTMAN->DeviceButtonToChar( input.DeviceI.button ) );
if( c ) if( c )
{ {
PlayerNumber pn = GAMESTATE->m_MasterPlayerNumber; PlayerNumber pn = GAMESTATE->m_MasterPlayerNumber;
+2 -1
View File
@@ -13,6 +13,7 @@
#include "RageUtil.h" #include "RageUtil.h"
#include "GameState.h" #include "GameState.h"
#include "InputEventPlus.h" #include "InputEventPlus.h"
#include "RageInput.h"
#define CHATINPUT_WIDTH THEME->GetMetricF(m_sName,"ChatInputBoxWidth") #define CHATINPUT_WIDTH THEME->GetMetricF(m_sName,"ChatInputBoxWidth")
#define CHATINPUT_HEIGHT THEME->GetMetricF(m_sName,"ChatInputBoxHeight") #define CHATINPUT_HEIGHT THEME->GetMetricF(m_sName,"ChatInputBoxHeight")
@@ -123,7 +124,7 @@ void ScreenNetSelectBase::Input( const InputEventPlus &input )
break; break;
default: default:
char c; char c;
c = input.DeviceI.ToChar(); c = INPUTMAN->DeviceButtonToChar( input.DeviceI.button );
if( bHoldingShift && !bHoldingCtrl ) if( bHoldingShift && !bHoldingCtrl )
{ {
+2 -1
View File
@@ -22,6 +22,7 @@
#include "RageLog.h" #include "RageLog.h"
#include "song.h" #include "song.h"
#include "InputEventPlus.h" #include "InputEventPlus.h"
#include "RageInput.h"
AutoScreenMessage( SM_NoSongs ) AutoScreenMessage( SM_NoSongs )
AutoScreenMessage( SM_ChangeSong ) AutoScreenMessage( SM_ChangeSong )
@@ -128,7 +129,7 @@ void ScreenNetSelectMusic::Input( const InputEventPlus &input )
INPUTFILTER->IsBeingPressed(DeviceInput(DEVICE_KEYBOARD, KEY_RCTRL)) || INPUTFILTER->IsBeingPressed(DeviceInput(DEVICE_KEYBOARD, KEY_RCTRL)) ||
(!NSMAN->useSMserver); //If we are disconnected, assume no chatting (!NSMAN->useSMserver); //If we are disconnected, assume no chatting
char c = (char) toupper(input.DeviceI.ToChar() ); char c = (char) toupper( INPUTMAN->DeviceButtonToChar(input.DeviceI.button) );
if ( bHoldingCtrl && ( c >= 'A' ) && ( c <= 'Z' ) ) if ( bHoldingCtrl && ( c >= 'A' ) && ( c <= 'Z' ) )
{ {
+4 -4
View File
@@ -10,7 +10,7 @@
#include "ScreenPrompt.h" #include "ScreenPrompt.h"
#include "ActorUtil.h" #include "ActorUtil.h"
#include "InputEventPlus.h" #include "InputEventPlus.h"
#include "RageInput.h"
static const char* g_szKeys[NUM_KEYBOARD_ROWS][KEYS_PER_ROW] = static const char* g_szKeys[NUM_KEYBOARD_ROWS][KEYS_PER_ROW] =
{ {
@@ -183,15 +183,15 @@ void ScreenTextEntry::Input( const InputEventPlus &input )
} }
else if( input.type == IET_FIRST_PRESS ) else if( input.type == IET_FIRST_PRESS )
{ {
if( input.DeviceI.ToChar() >= ' ' ) char c = INPUTMAN->DeviceButtonToChar( input.DeviceI.button );
if( c >= ' ' )
{ {
bool bIsHoldingShift = bool bIsHoldingShift =
INPUTFILTER->IsBeingPressed( DeviceInput(input.DeviceI.device, KEY_RSHIFT)) || INPUTFILTER->IsBeingPressed( DeviceInput(input.DeviceI.device, KEY_RSHIFT)) ||
INPUTFILTER->IsBeingPressed( DeviceInput(input.DeviceI.device, KEY_LSHIFT)); INPUTFILTER->IsBeingPressed( DeviceInput(input.DeviceI.device, KEY_LSHIFT));
char c = input.DeviceI.ToChar();
if( bIsHoldingShift ) if( bIsHoldingShift )
{ {
c = (char)toupper( input.DeviceI.ToChar() ); c = (char)toupper( c );
switch( c ) switch( c )
{ {
case '`': c='~'; break; case '`': c='~'; break;
-4
View File
@@ -654,10 +654,6 @@ SOURCE=.\RageUtil_WorkerThread.cpp
SOURCE=.\RageUtil_WorkerThread.h SOURCE=.\RageUtil_WorkerThread.h
# End Source File # End Source File
# Begin Source File
SOURCE=.\RageUtilLua.cpp
# End Source File
# End Group # End Group
# Begin Group "Data Structures" # Begin Group "Data Structures"
@@ -34,11 +34,32 @@ void InputHandler::ButtonPressed( DeviceInput di, bool Down )
} }
} }
char InputHandler::DeviceButtonToChar( DeviceButton button )
{
if( button < 127 )
return (char) button;
if( button >= KEY_KP_C0 && button <= KEY_KP_C9 )
return (char) (button - KEY_KP_C0) + '0';
switch( button )
{
case KEY_KP_SLASH: return '/';
case KEY_KP_ASTERISK: return '*';
case KEY_KP_HYPHEN: return '-';
case KEY_KP_PLUS: return '+';
case KEY_KP_PERIOD: return '.';
case KEY_KP_EQUAL: return '=';
}
return '\0';
}
RString InputHandler::GetDeviceSpecificInputString( const DeviceInput &di ) RString InputHandler::GetDeviceSpecificInputString( const DeviceInput &di )
{ {
if( di.device == DEVICE_KEYBOARD ) if( di.device == DEVICE_KEYBOARD )
{ {
char c = di.ToChar(); char c = DeviceButtonToChar( di.button );
if( c ) if( c )
{ {
if( c == ' ' ) if( c == ' ' )
@@ -33,6 +33,7 @@ public:
// Override to return a pretty string that's specific to the controller type. // Override to return a pretty string that's specific to the controller type.
virtual RString GetDeviceSpecificInputString( const DeviceInput &di ); virtual RString GetDeviceSpecificInputString( const DeviceInput &di );
virtual char DeviceButtonToChar( DeviceButton button );
// Override to find out whether the controller is currently plugged in. // Override to find out whether the controller is currently plugged in.
// Not all InputHandlers will support this. Not applicable to all InputHandlers. // Not all InputHandlers will support this. Not applicable to all InputHandlers.
@@ -645,6 +645,42 @@ void InputHandler_DInput::GetDevicesAndDescriptions( vector<InputDeviceInfo>& vD
vDevicesOut.push_back( InputDeviceInfo(Devices[i].dev, Devices[i].m_sName) ); vDevicesOut.push_back( InputDeviceInfo(Devices[i].dev, Devices[i].m_sName) );
} }
char InputHandler_DInput::DeviceButtonToChar( DeviceButton button )
{
FOREACH_CONST( DIDevice, Devices, d )
{
if( d->type != DIDevice::KEYBOARD )
continue;
FOREACH_CONST( input_t, d->Inputs, i )
{
if( button != i->num )
continue;
DWORD scancode = i->ofs;
HKL layout = GetKeyboardLayout(0); // 0 == current thread
unsigned char state[256];
// Don't fill key state. We'll do the shift/ctrl/alt
// translations ourself in ScreenTextEntry.
ZERO( state );
UINT vk = MapVirtualKeyEx( scancode, 1, layout );
unsigned short result[2]; // ToAscii writes a max of 2 chars
ZERO( result );
// TODO: Use ToUnicodeEx
int iNum = ToAsciiEx( vk, scancode, state, result, 0, layout );
if( iNum == 1 )
return (char)result[0];
// iNum == 2 will happen only for dead keys. See MSDN for ToAsciiEx.
}
}
return InputHandler::DeviceButtonToChar( button );
}
/* /*
* (c) 2003-2004 Glenn Maynard * (c) 2003-2004 Glenn Maynard
* All rights reserved. * All rights reserved.
@@ -11,6 +11,7 @@ public:
InputHandler_DInput(); InputHandler_DInput();
~InputHandler_DInput(); ~InputHandler_DInput();
void GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevicesOut ); void GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevicesOut );
char DeviceButtonToChar( DeviceButton button );
void Update(); void Update();
bool DevicesChanged(); bool DevicesChanged();
void WindowReset(); void WindowReset();