Fix for [#950]
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6395 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: a78c3403d861fb0be0fb4d80bd46be335334ed75 Former-commit-id: 6a977646425d8b62dcfa53b2ff7430b3cb36c1a3
This commit is contained in:
parent
92f3c5a1d4
commit
46b1b818cc
2 changed files with 38 additions and 28 deletions
|
@ -58,10 +58,8 @@ private: // Private data members.
|
|||
//! Initialization flag for the underlying software layers.
|
||||
static bool _bInitialized;
|
||||
|
||||
#if SDL_MAJOR_VERSION < 2
|
||||
//! Unicode for each typed SDL key sym + modifier
|
||||
std::map<Uint32, Uint16> _mapUnicodes;
|
||||
#endif
|
||||
};
|
||||
|
||||
GfEventLoop::Private::Private()
|
||||
|
@ -118,11 +116,40 @@ int GfEventLoop::Private::translateKeySym(int code, int modifier, int unicode)
|
|||
// Done.
|
||||
return keyUnicode;
|
||||
#else
|
||||
int keyUnicode = code; //default to returning code
|
||||
|
||||
// Make the Numpad <Enter> key behave like the regular <Enter> key
|
||||
if(SDLK_KP_ENTER == code)
|
||||
code = SDLK_RETURN;
|
||||
keyUnicode = SDLK_RETURN;
|
||||
|
||||
return code;
|
||||
else
|
||||
{
|
||||
const Uint32 keyId = ((Uint32)code & GF_MAX_KEYCODE) | (((Uint32)modifier) << 9);
|
||||
|
||||
// If unicode - add to the map...
|
||||
if(unicode)
|
||||
{
|
||||
// Truncate unicodes above GF_MAX_KEYCODE (no need for more).
|
||||
keyUnicode = (unsigned short)(unicode & GF_MAX_KEYCODE);
|
||||
_mapUnicodes[keyId] = (unsigned short)keyUnicode;
|
||||
GfLogDebug("translateKeySym(c=%X, m=%X, u=%X) : '%c', id=%X, ucode=%X (nk=%d)\n",
|
||||
code, modifier, unicode, // Truncate high bits for MSVC 2010 bugs.
|
||||
(keyUnicode > 0 && keyUnicode < 128 && isprint(keyUnicode & 0x7F))
|
||||
? (char)(keyUnicode & 0x7F) : ' ',
|
||||
keyId, keyUnicode, _mapUnicodes.size());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Search it in our unicode map.
|
||||
const std::map<Uint32, Uint16>::const_iterator itUnicode = _mapUnicodes.find(keyId);
|
||||
if (itUnicode != _mapUnicodes.end())
|
||||
{
|
||||
keyUnicode = (*itUnicode).second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return keyUnicode;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -136,6 +136,7 @@ void GfuiEventLoop::operator()()
|
|||
#if SDL_MAJOR_VERSION >= 2
|
||||
static int unicode = 0;
|
||||
static SDL_Keymod modifier = KMOD_NONE;
|
||||
static SDL_Keycode keysym = SDLK_UNKNOWN;
|
||||
#endif
|
||||
|
||||
// Check for events.
|
||||
|
@ -165,12 +166,11 @@ void GfuiEventLoop::operator()()
|
|||
{
|
||||
injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 0,0);
|
||||
}
|
||||
#if 0
|
||||
else
|
||||
{
|
||||
printf("SDL_KEYDOWN: %c\r\n",(char)event.key.keysym.sym);
|
||||
//GfLogDebug("SDL_KEYDOWN: %c\r\n",(char)event.key.keysym.sym);
|
||||
keysym = event.key.keysym.sym;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
|
||||
|
@ -178,8 +178,8 @@ void GfuiEventLoop::operator()()
|
|||
case SDL_TEXTINPUT:
|
||||
unicode = (int)(event.text.text[0]);
|
||||
modifier = SDL_GetModState();
|
||||
injectKeyboardEvent(unicode,modifier, 0,0);
|
||||
//printf("SDL_TEXTINPUT: %c %X\r\n",(char)unicode,modifier);
|
||||
injectKeyboardEvent(keysym, modifier, 0, unicode);
|
||||
//GfLogDebug("SDL_TEXTINPUT: %c %X\r\n",(char)unicode,modifier);
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
@ -187,25 +187,8 @@ void GfuiEventLoop::operator()()
|
|||
#if SDL_MAJOR_VERSION < 2
|
||||
injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 1,event.key.keysym.unicode);
|
||||
#else
|
||||
if((event.key.keysym.sym & SDLK_SCANCODE_MASK) == SDLK_SCANCODE_MASK)
|
||||
{
|
||||
injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 1,0);
|
||||
}
|
||||
else if(false == isprint(event.key.keysym.sym))
|
||||
{
|
||||
injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 1,0);
|
||||
}
|
||||
else if((event.key.keysym.mod & KMOD_CTRL)
|
||||
||(event.key.keysym.mod & KMOD_ALT)
|
||||
||(event.key.keysym.mod & KMOD_GUI))
|
||||
{
|
||||
injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 1,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
injectKeyboardEvent(unicode, event.key.keysym.mod, 1,0);
|
||||
//printf("SDL_KEYUP: %c unicode = %c\r\n",(char)event.key.keysym.sym,unicode);
|
||||
}
|
||||
injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 1,0);
|
||||
//GfLogDebug("SDL_KEYUP: %c\r\n",(char)event.key.keysym.sym);
|
||||
#endif
|
||||
break;
|
||||
|
||||
|
|
Loading…
Reference in a new issue