Browse Source

Use unicode for key events despite the fact that our current Plasma20 fonts only support latin-1

Adam Johnson 14 years ago committed by Branan Purvine-Riley
parent
commit
a29a7deda0
  1. 7
      Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp
  2. 2
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp
  3. 2
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.h
  4. 2
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIDialogMod.cpp
  5. 2
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIDialogMod.h
  6. 4
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.cpp
  7. 2
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.h
  8. 2
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp
  9. 2
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.h
  10. 4
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.cpp
  11. 2
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.h
  12. 5
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.cpp
  13. 2
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.h
  14. 2
      Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp
  15. 137
      Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp
  16. 2
      Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.h

7
Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp

@ -519,7 +519,8 @@ hsBool pfConsole::MsgReceive( plMessage *msg )
void pfConsole::IHandleKey( plKeyEventMsg *msg ) void pfConsole::IHandleKey( plKeyEventMsg *msg )
{ {
char *c, key; char *c;
wchar_t key;
int i,eol; int i,eol;
static hsBool findAgain = false; static hsBool findAgain = false;
static UInt32 findCounter = 0; static UInt32 findCounter = 0;
@ -831,13 +832,13 @@ void pfConsole::IHandleKey( plKeyEventMsg *msg )
{ {
key = plKeyboardDevice::KeyEventToChar( msg ); key = plKeyboardDevice::KeyEventToChar( msg );
// do they want to go into help mode? // do they want to go into help mode?
if( !fPythonMode && key == '?' && fWorkingCursor == 0 ) if( !fPythonMode && key == L'?' && fWorkingCursor == 0 )
{ {
/// Go into help mode /// Go into help mode
fHelpMode = true; fHelpMode = true;
} }
// do they want to go into Python mode? // do they want to go into Python mode?
else if( !fHelpMode && key == '\\' && fWorkingCursor == 0 ) else if( !fHelpMode && key == L'\\' && fWorkingCursor == 0 )
{ {
// toggle Python mode // toggle Python mode
fPythonMode = fPythonMode ? false:true; fPythonMode = fPythonMode ? false:true;

2
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp

@ -879,7 +879,7 @@ void pfGUIControlMod::Write( hsStream *s, hsResMgr *mgr )
//// HandleKeyPress/Event //////////////////////////////////////////////////// //// HandleKeyPress/Event ////////////////////////////////////////////////////
hsBool pfGUIControlMod::HandleKeyPress( char key, UInt8 modifiers ) hsBool pfGUIControlMod::HandleKeyPress( wchar_t key, UInt8 modifiers )
{ {
return false; return false;
} }

2
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.h

@ -193,7 +193,7 @@ class pfGUIControlMod : public plSingleModifier
virtual void HandleMouseHover( hsPoint3 &mousePt, UInt8 modifiers ) {;} virtual void HandleMouseHover( hsPoint3 &mousePt, UInt8 modifiers ) {;}
virtual void HandleMouseDblClick( hsPoint3 &mousePt, UInt8 modifiers ) {;} virtual void HandleMouseDblClick( hsPoint3 &mousePt, UInt8 modifiers ) {;}
virtual hsBool HandleKeyPress( char key, UInt8 modifiers ); virtual hsBool HandleKeyPress( wchar_t key, UInt8 modifiers );
virtual hsBool HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef key, UInt8 modifiers ); virtual hsBool HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef key, UInt8 modifiers );
void SetHandler( pfGUICtrlProcObject *h ) { ISetHandler( h, true ); } void SetHandler( pfGUICtrlProcObject *h ) { ISetHandler( h, true ); }

2
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIDialogMod.cpp

@ -551,7 +551,7 @@ hsBool pfGUIDialogMod::HandleKeyEvent( pfGameGUIMgr::EventType event, plKey
//// HandleKeyPress ////////////////////////////////////////////////////////// //// HandleKeyPress //////////////////////////////////////////////////////////
hsBool pfGUIDialogMod::HandleKeyPress( char key, UInt8 modifiers ) hsBool pfGUIDialogMod::HandleKeyPress( wchar_t key, UInt8 modifiers )
{ {
// Same deal as HandleKeyPress. Only problem is, we needed the msg to translate // Same deal as HandleKeyPress. Only problem is, we needed the msg to translate
// to a char, so it had to be done up at the mgr level (sadly) // to a char, so it had to be done up at the mgr level (sadly)

2
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIDialogMod.h

@ -119,7 +119,7 @@ class pfGUIDialogMod : public plSingleModifier
virtual hsBool HandleMouseEvent( pfGameGUIMgr::EventType event, hsScalar mouseX, hsScalar mouseY, UInt8 modifiers ); virtual hsBool HandleMouseEvent( pfGameGUIMgr::EventType event, hsScalar mouseX, hsScalar mouseY, UInt8 modifiers );
hsBool HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef key, UInt8 modifiers ); hsBool HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef key, UInt8 modifiers );
hsBool HandleKeyPress( char key, UInt8 modifiers ); hsBool HandleKeyPress( wchar_t key, UInt8 modifiers );
void UpdateInterestingThings( hsScalar mouseX, hsScalar mouseY, UInt8 modifiers, hsBool modalPreset ); void UpdateInterestingThings( hsScalar mouseX, hsScalar mouseY, UInt8 modifiers, hsBool modalPreset );
void SetControlOfInterest( pfGUIControlMod *c ); void SetControlOfInterest( pfGUIControlMod *c );

4
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.cpp

@ -277,10 +277,8 @@ void pfGUIEditBoxMod::HandleMouseDrag( hsPoint3 &mousePt, UInt8 modifiers )
{ {
} }
hsBool pfGUIEditBoxMod::HandleKeyPress( char inKey, UInt8 modifiers ) hsBool pfGUIEditBoxMod::HandleKeyPress( wchar_t key, UInt8 modifiers )
{ {
wchar_t key = (wchar_t)inKey;
if( fBuffer == nil ) if( fBuffer == nil )
return false; return false;

2
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.h

@ -90,7 +90,7 @@ class pfGUIEditBoxMod : public pfGUIControlMod
virtual void HandleMouseUp( hsPoint3 &mousePt, UInt8 modifiers ); virtual void HandleMouseUp( hsPoint3 &mousePt, UInt8 modifiers );
virtual void HandleMouseDrag( hsPoint3 &mousePt, UInt8 modifiers ); virtual void HandleMouseDrag( hsPoint3 &mousePt, UInt8 modifiers );
virtual hsBool HandleKeyPress( char key, UInt8 modifiers ); virtual hsBool HandleKeyPress( wchar_t key, UInt8 modifiers );
virtual hsBool HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef key, UInt8 modifiers ); virtual hsBool HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef key, UInt8 modifiers );
virtual void PurgeDynaTextMapImage(); virtual void PurgeDynaTextMapImage();

2
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp

@ -905,7 +905,7 @@ void pfGUIListBoxMod::AddSelection( Int32 item )
//// HandleKeyPress ////////////////////////////////////////////////////////// //// HandleKeyPress //////////////////////////////////////////////////////////
hsBool pfGUIListBoxMod::HandleKeyPress( char key, UInt8 modifiers ) hsBool pfGUIListBoxMod::HandleKeyPress( wchar_t key, UInt8 modifiers )
{ {
return false; return false;
} }

2
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.h

@ -133,7 +133,7 @@ class pfGUIListBoxMod : public pfGUIControlMod
virtual void HandleMouseHover( hsPoint3 &mousePt, UInt8 modifiers ); virtual void HandleMouseHover( hsPoint3 &mousePt, UInt8 modifiers );
virtual void HandleMouseDblClick( hsPoint3 &mousePt, UInt8 modifiers ); virtual void HandleMouseDblClick( hsPoint3 &mousePt, UInt8 modifiers );
virtual hsBool HandleKeyPress( char key, UInt8 modifiers ); virtual hsBool HandleKeyPress( wchar_t key, UInt8 modifiers );
virtual hsBool HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef key, UInt8 modifiers ); virtual hsBool HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef key, UInt8 modifiers );
virtual hsBool FilterMousePosition( hsPoint3 &mousePt ); virtual hsBool FilterMousePosition( hsPoint3 &mousePt );

4
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.cpp

@ -1072,10 +1072,8 @@ void pfGUIMultiLineEditCtrl::HandleMouseDrag( hsPoint3 &mousePt, UInt8 modifi
IMoveCursorTo( IPointToPosition( (Int16)(mousePt.fX), (Int16)(mousePt.fY) ) ); IMoveCursorTo( IPointToPosition( (Int16)(mousePt.fX), (Int16)(mousePt.fY) ) );
} }
hsBool pfGUIMultiLineEditCtrl::HandleKeyPress( char keyIn, UInt8 modifiers ) hsBool pfGUIMultiLineEditCtrl::HandleKeyPress( wchar_t key, UInt8 modifiers )
{ {
wchar_t key = (wchar_t)keyIn;
if ((fPrevCtrl || fNextCtrl) && (fLineStarts.GetCount() <= GetFirstVisibleLine())) if ((fPrevCtrl || fNextCtrl) && (fLineStarts.GetCount() <= GetFirstVisibleLine()))
return true; // we're ignoring if we can't actually edit our visible frame (and we're linked) return true; // we're ignoring if we can't actually edit our visible frame (and we're linked)

2
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.h

@ -195,7 +195,7 @@ class pfGUIMultiLineEditCtrl : public pfGUIControlMod
virtual void HandleMouseUp( hsPoint3 &mousePt, UInt8 modifiers ); virtual void HandleMouseUp( hsPoint3 &mousePt, UInt8 modifiers );
virtual void HandleMouseDrag( hsPoint3 &mousePt, UInt8 modifiers ); virtual void HandleMouseDrag( hsPoint3 &mousePt, UInt8 modifiers );
virtual hsBool HandleKeyPress( char key, UInt8 modifiers ); virtual hsBool HandleKeyPress( wchar_t key, UInt8 modifiers );
virtual hsBool HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef key, UInt8 modifiers ); virtual hsBool HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef key, UInt8 modifiers );
virtual void PurgeDynaTextMapImage(); virtual void PurgeDynaTextMapImage();

5
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.cpp

@ -594,10 +594,13 @@ hsBool pfGameGUIMgr::IHandleKeyEvt( EventType event, plKeyDef key, UInt8 modifi
// Like IHandleKeyPress, but takes in a char for distributing actual // Like IHandleKeyPress, but takes in a char for distributing actual
// characters typed. // characters typed.
hsBool pfGameGUIMgr::IHandleKeyPress( char key, UInt8 modifiers ) hsBool pfGameGUIMgr::IHandleKeyPress( wchar_t key, UInt8 modifiers )
{ {
pfGUIDialogMod *dlg; pfGUIDialogMod *dlg;
// Really... Don't handle any nil keypresses
if (key == nil)
return false;
for( dlg = fActiveDialogs; dlg != nil; dlg = dlg->GetNext() ) for( dlg = fActiveDialogs; dlg != nil; dlg = dlg->GetNext() )
{ {

2
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.h

@ -153,7 +153,7 @@ class pfGameGUIMgr : public hsKeyedObject
hsBool IHandleMouse( EventType event, hsScalar mouseX, hsScalar mouseY, UInt8 modifiers, UInt32 *desiredCursor ); hsBool IHandleMouse( EventType event, hsScalar mouseX, hsScalar mouseY, UInt8 modifiers, UInt32 *desiredCursor );
hsBool IHandleKeyEvt( EventType event, plKeyDef key, UInt8 modifiers ); hsBool IHandleKeyEvt( EventType event, plKeyDef key, UInt8 modifiers );
hsBool IHandleKeyPress( char key, UInt8 modifiers ); hsBool IHandleKeyPress( wchar_t key, UInt8 modifiers );
hsBool IModalBlocking( void ); hsBool IModalBlocking( void );

2
Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp

@ -890,7 +890,7 @@ void plPythonFileMod::RemoveTarget(plSceneObject* so)
void plPythonFileMod::HandleDiscardedKey( plKeyEventMsg *msg ) void plPythonFileMod::HandleDiscardedKey( plKeyEventMsg *msg )
{ {
// So OnDefaultKeyCaught takes two parameters: the key character pressed and a boolean saying up or down // So OnDefaultKeyCaught takes two parameters: the key character pressed and a boolean saying up or down
char keyChar = plKeyboardDevice::KeyEventToChar( msg ); wchar_t keyChar = plKeyboardDevice::KeyEventToChar( msg );
// if the caps lock is down then reverse upper and lowercase // if the caps lock is down then reverse upper and lowercase
if ( msg->GetCapsLockKeyDown() ) if ( msg->GetCapsLockKeyDown() )

137
Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp

@ -204,120 +204,43 @@ void plKeyboardDevice::HandleWindowActivate(bool bActive, HWND hWnd)
//// KeyEventToChar ////////////////////////////////////////////////////////// //// KeyEventToChar //////////////////////////////////////////////////////////
// Translate a Plasma key event to an actual char // Translate a Plasma key event to an actual char
char plKeyboardDevice::KeyEventToChar( plKeyEventMsg *msg ) wchar_t plKeyboardDevice::KeyEventToChar( plKeyEventMsg *msg )
{ {
short code = msg->GetKeyCode(); unsigned int code = msg->GetKeyCode();
char c = 0; wchar_t c = 0;
unsigned char kbState[256]; unsigned char kbState[256];
unsigned char buffer[256]; wchar_t buffer[256];
UINT scanCode; unsigned int scanCode;
int retVal; int retVal;
buffer[0] = 0; buffer[0] = 0;
switch( code ) // let windows translate everything for us!
scanCode = MapVirtualKeyW(code, 0);
GetKeyboardState(kbState);
if (fIgnoreCapsLock)
kbState[KEY_CAPSLOCK] = 0; // clear the caps lock key
retVal = ToUnicode(code, scanCode, kbState, (wchar_t*)buffer, 256, 0);
if (retVal == -1)
{ {
case KEY_A: // It's a stored dead key.
case KEY_B: c = 0;
case KEY_C: fKeyIsDeadKey = true;
case KEY_D: }
case KEY_E: else if (retVal == 0)
case KEY_F: // Invalid crap
case KEY_G: c = 0;
case KEY_H: else if (retVal == 1)
case KEY_I: {
case KEY_J: // Exactly one good character
case KEY_K: fKeyIsDeadKey = false;
case KEY_L: c = buffer[0];
case KEY_M: }
case KEY_N: else if (retVal >= 2)
case KEY_O: {
case KEY_P: fKeyIsDeadKey = !fKeyIsDeadKey;
case KEY_Q: if (!fKeyIsDeadKey)
case KEY_R: c = buffer[0];
case KEY_S:
case KEY_T:
case KEY_U:
case KEY_V:
case KEY_W:
case KEY_X:
case KEY_Y:
case KEY_Z:
case KEY_1:
case KEY_2:
case KEY_3:
case KEY_4:
case KEY_5:
case KEY_6:
case KEY_7:
case KEY_8:
case KEY_9:
case KEY_0:
case KEY_TILDE:
case KEY_COMMA:
case KEY_PERIOD:
case KEY_LBRACKET:
case KEY_RBRACKET:
case KEY_BACKSLASH:
case KEY_SLASH:
case KEY_DASH:
case KEY_EQUAL:
case KEY_SEMICOLON:
case KEY_QUOTE:
// let windows translate everything for us!
scanCode = MapVirtualKeyEx(code,0,GetKeyboardLayout(0));
GetKeyboardState(kbState);
if (fIgnoreCapsLock)
kbState[KEY_CAPSLOCK] = 0; // clear the caps lock key
retVal = ToAsciiEx(code,scanCode,kbState,(unsigned short*)buffer,0,GetKeyboardLayout(0));
if (retVal == 2)
{
if ((buffer[0] == buffer[1]) && (!fKeyIsDeadKey))
{
// it's actually a dead key, since the previous key wasn't a dead key
c = (char)buffer[0];
fKeyIsDeadKey = true;
}
else
{
c = (char)buffer[1]; // it was an untranslated dead key, so copy the unconverted key
fKeyIsDeadKey = false;
}
}
else if (retVal == 0)
c = 0; // it's invalid
else
{
c = (char)buffer[0];
if (retVal < 0) // the key was a dead key
fKeyIsDeadKey = true;
else
fKeyIsDeadKey = false;
}
break;
case KEY_ESCAPE: c = 27; break;
case KEY_TAB: c = '\t'; break;
case KEY_BACKSPACE: c = 8; break;
case KEY_ENTER: c = '\n'; break;
case KEY_SPACE: c = ' '; break;
// numlock on numbers
case KEY_NUMPAD0: c = '0'; break;
case KEY_NUMPAD1: c = '1'; break;
case KEY_NUMPAD2: c = '2'; break;
case KEY_NUMPAD3: c = '3'; break;
case KEY_NUMPAD4: c = '4'; break;
case KEY_NUMPAD5: c = '5'; break;
case KEY_NUMPAD6: c = '6'; break;
case KEY_NUMPAD7: c = '7'; break;
case KEY_NUMPAD8: c = '8'; break;
case KEY_NUMPAD9: c = '9'; break;
// everything else
default:
c = 0;
break;
} }
return c; return c;

2
Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.h

@ -113,7 +113,7 @@ public:
static plKeyboardDevice* GetInstance() { return fInstance; } static plKeyboardDevice* GetInstance() { return fInstance; }
static char KeyEventToChar( plKeyEventMsg *msg ); static wchar_t KeyEventToChar( plKeyEventMsg *msg );
}; };
class plPlate; class plPlate;

Loading…
Cancel
Save