|
|
@ -67,12 +67,15 @@ namespace SFO
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
if (!evt.key.repeat)
|
|
|
|
if (!evt.key.repeat)
|
|
|
|
_handleKeyPress(evt.key);
|
|
|
|
mKeyboardListener->keyPressed(evt.key);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case SDL_KEYUP:
|
|
|
|
case SDL_KEYUP:
|
|
|
|
if (!evt.key.repeat)
|
|
|
|
if (!evt.key.repeat)
|
|
|
|
mKeyboardListener->keyReleased(evt.key);
|
|
|
|
mKeyboardListener->keyReleased(evt.key);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_TEXTINPUT:
|
|
|
|
|
|
|
|
mKeyboardListener->textInput(evt.text);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case SDL_WINDOWEVENT:
|
|
|
|
case SDL_WINDOWEVENT:
|
|
|
|
handleWindowEvent(evt);
|
|
|
|
handleWindowEvent(evt);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -220,74 +223,6 @@ namespace SFO
|
|
|
|
return pack_evt;
|
|
|
|
return pack_evt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InputWrapper::_handleKeyPress(SDL_KeyboardEvent &evt)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//SDL keyboard events are followed by the actual text those keys would generate
|
|
|
|
|
|
|
|
//to account for languages that require multiple keystrokes to produce a key.
|
|
|
|
|
|
|
|
//Look for an event immediately following ours, assuming each key produces exactly
|
|
|
|
|
|
|
|
//one character or none at all.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: Check if this works properly for multibyte symbols
|
|
|
|
|
|
|
|
//do we have to worry about endian-ness?
|
|
|
|
|
|
|
|
//for that matter, check if we even need to do any of this.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SDL_Event text_evts[1];
|
|
|
|
|
|
|
|
if(SDL_PeepEvents(text_evts, 1, SDL_GETEVENT, SDL_TEXTINPUT, SDL_TEXTINPUT) != 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(strlen(text_evts[0].text.text) != 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
const unsigned char* symbol = reinterpret_cast<unsigned char*>(&(text_evts[0].text.text[0]));
|
|
|
|
|
|
|
|
evt.keysym.unicode = _UTF8ToUTF32(symbol);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mKeyboardListener->keyPressed(evt);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Lifted from OIS' LinuxKeyboard.cpp
|
|
|
|
|
|
|
|
Uint32 InputWrapper::_UTF8ToUTF32(const unsigned char *buf)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
unsigned char FirstChar = buf[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//it's an ascii char, bail out early.
|
|
|
|
|
|
|
|
if(FirstChar < 128)
|
|
|
|
|
|
|
|
return FirstChar;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Uint32 val = 0;
|
|
|
|
|
|
|
|
Sint32 len = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if((FirstChar & 0xE0) == 0xC0) //2 Chars
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
len = 2;
|
|
|
|
|
|
|
|
val = FirstChar & 0x1F;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if((FirstChar & 0xF0) == 0xE0) //3 Chars
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
len = 3;
|
|
|
|
|
|
|
|
val = FirstChar & 0x0F;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if((FirstChar & 0xF8) == 0xF0) //4 Chars
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
len = 4;
|
|
|
|
|
|
|
|
val = FirstChar & 0x07;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if((FirstChar & 0xFC) == 0xF8) //5 Chars
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
len = 5;
|
|
|
|
|
|
|
|
val = FirstChar & 0x03;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else // if((FirstChar & 0xFE) == 0xFC) //6 Chars
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
len = 6;
|
|
|
|
|
|
|
|
val = FirstChar & 0x01;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(int i = 1; i < len; i++)
|
|
|
|
|
|
|
|
val = (val << 6) | (buf[i] & 0x3F);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return val;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OIS::KeyCode InputWrapper::sdl2OISKeyCode(SDL_Keycode code)
|
|
|
|
OIS::KeyCode InputWrapper::sdl2OISKeyCode(SDL_Keycode code)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OIS::KeyCode kc = OIS::KC_UNASSIGNED;
|
|
|
|
OIS::KeyCode kc = OIS::KC_UNASSIGNED;
|
|
|
@ -296,8 +231,6 @@ namespace SFO
|
|
|
|
|
|
|
|
|
|
|
|
if(ois_equiv != mKeyMap.end())
|
|
|
|
if(ois_equiv != mKeyMap.end())
|
|
|
|
kc = ois_equiv->second;
|
|
|
|
kc = ois_equiv->second;
|
|
|
|
else
|
|
|
|
|
|
|
|
std::cerr << "Couldn't find OIS key for " << code << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return kc;
|
|
|
|
return kc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|