Re #377 Fixed keyboard management regression of r3501 (back to usability)

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@3506 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 1e2cf3752d4d30e5698e891f36e7e4b266a52e50
Former-commit-id: 3657550457063ae63c641c31aa3e6100a096945b
This commit is contained in:
pouillot 2011-04-19 17:07:45 +00:00
parent c8034bc9f6
commit bbd4ceb711
6 changed files with 23 additions and 22 deletions

View file

@ -58,8 +58,8 @@ GfApplication::GfApplication(const char* pszName, const char* pszDesc, int argc,
_pSelf = this;
// Initialize the gaming framework.
GfInit();
GfInit();
// Store the command line options.
if (argv)
for (int i = 0; i < argc; i++)

View file

@ -62,17 +62,14 @@ private: // Private data members.
std::map<Uint32, Uint16> _mapUnicodes;
};
//! Initialization flag for the underlying software layers.
bool GfEventLoop::Private::_bInitialized = 0;
GfEventLoop::Private::Private()
: cbKeyboardDown(0), cbKeyboardUp(0), cbIdle(0), cbTimer(0), bQuit(false)
{
if (!_bInitialized)
static bool bInitialized = false;
if (!bInitialized)
{
SDL_EnableUNICODE(/*enable=*/1); // For keyboard "key press" event key code translation
_bInitialized = true;
bInitialized = true;
}
}
@ -85,23 +82,28 @@ GfEventLoop::Private::Private()
// Known issues (TODO): No support for Caps and NumLock keys ... don't use them !
int GfEventLoop::Private::translateKeySym(int code, int modifier, int unicode)
{
int keyUnicode;
// Generate the key Id from its code and modifier.
const Uint32 keyId = ((Uint32)code & 0x1FF) | (((Uint32)modifier) << 9);
// Search it in our unicode map.
const std::map<Uint32, Uint16>::const_iterator itUnicode = _mapUnicodes.find(keyId);
// If not found, update the map for next times.
int keyUnicode;
if (itUnicode == _mapUnicodes.end())
{
// Truncate unicodes above GF_MAX_KEYCODE (no need for more).
keyUnicode = unicode ? (unicode & GF_MAX_KEYCODE) : code;
_mapUnicodes[keyId] = keyUnicode;
//GfLogDebug("translateKeySym: New key id=0x%08X, unicode=%d (%d)\n",
// keyId, keyUnicode, _mapUnicodes.size());
//GfLogDebug("translateKeySym(c=%d, m=%d, u=%d) : New key id=0x%08X, unicode=%d (%d)\n",
// code, modifier, unicode, keyId, keyUnicode, _mapUnicodes.size());
}
// If found, get the unicode from the map.
else
keyUnicode = (*itUnicode).second;
// Done.
return keyUnicode;
}

View file

@ -20,7 +20,7 @@
GfuiApplication::GfuiApplication(const char* pszName, const char* pszDesc, int argc, char **argv)
: GfApplication(pszName ? pszName : "GfuiApplication", pszDesc, argc, argv)
: GfApplication((pszName ? pszName : "GfuiApplication"), pszDesc, argc, argv)
{
// Help about the options.
_optionsHelp.lstSyntaxLines.push_back("[-m|--hardmouse]");

View file

@ -52,6 +52,7 @@ GfuiEventLoop::Private::Private()
// GfuiEventLoop class ============================================================
GfuiEventLoop::GfuiEventLoop()
: GfEventLoop()
{
_pPrivate = new Private;
}

View file

@ -344,7 +344,11 @@ bool GfScrInit(void)
GfLogError("Couldn't initialize SDL video sub-system (%s)\n", SDL_GetError());
return false;
}
// Enable unicode translation for SDL key press events, even if already done before
// (SDL_InitSubSystem(SDL_INIT_VIDEO) seems to break it).
SDL_EnableUNICODE(/*enable=*/1);
// Query system video capabilities.
// Note: Does not work very well as long as you don't force SDL to use
// a special hardware driver ... which we don't want at all (the default is the one).

View file

@ -785,12 +785,6 @@ Uint32 network_callbackfunc(Uint32 interval, void *param)
bool NetworkInit()
{
// Initialize SDL : not needed, as already done in GfInit.
// if ( SDL_InitSubSystem(SDL_INIT_TIMER) < 0 ) {
// GfLogTrace("NetworkInit : Couldn't initialize SDL: %s\n", SDL_GetError());
// return false;
// }
g_bInit = true;
return true;