begin to support text input

actorid
Jordan Milne 12 years ago
parent 5fa77da9d4
commit cb01df49c0

@ -413,6 +413,7 @@ namespace MWInput
} }
#endif #endif
*/ */
MyGUI::InputManager::getInstance().injectKeyPress(MyGUI::KeyCode::Enum(arg.keysym.sym), text); MyGUI::InputManager::getInstance().injectKeyPress(MyGUI::KeyCode::Enum(arg.keysym.sym), text);
return true; return true;

@ -27,8 +27,10 @@ namespace MWInput
MWSDLInputWrapper::~MWSDLInputWrapper() MWSDLInputWrapper::~MWSDLInputWrapper()
{ {
SDL_DestroyWindow(mSDLWindow); if(mSDLWindow != NULL)
SDL_DestroyWindow(mSDLWindow);
mSDLWindow = NULL; mSDLWindow = NULL;
SDL_StopTextInput();
SDL_Quit(); SDL_Quit();
} }
@ -52,6 +54,8 @@ namespace MWInput
if(mSDLWindow == NULL) if(mSDLWindow == NULL)
return false; return false;
SDL_StartTextInput();
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
//linux-specific event-handling fixups //linux-specific event-handling fixups
SDL_SysWMinfo wm_info; SDL_SysWMinfo wm_info;
@ -119,7 +123,7 @@ namespace MWInput
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
mKeyboardListener->keyPressed(evt.key); _handleKeyPress(evt.key);
break; break;
case SDL_KEYUP: case SDL_KEYUP:
mKeyboardListener->keyReleased(evt.key); mKeyboardListener->keyReleased(evt.key);
@ -228,4 +232,23 @@ namespace MWInput
warpMouse(width / 2, height / 2); warpMouse(width / 2, height / 2);
} }
} }
void MWSDLInputWrapper::_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.
//TODO: This won't work for multibyte characters, but MyGUI is the only consumer
//of these, does it even support multibyte characters?
SDL_Event text_evts[1];
if(SDL_PeepEvents(text_evts, 1, SDL_GETEVENT, SDL_TEXTINPUT, SDL_TEXTINPUT) != 0)
{
evt.keysym.unicode = text_evts[0].text.text[0];
}
mKeyboardListener->keyPressed(evt);
}
} }

@ -30,6 +30,8 @@ namespace MWInput
bool _handleWarpMotion(const SDL_MouseMotionEvent& evt); bool _handleWarpMotion(const SDL_MouseMotionEvent& evt);
void _wrapMousePointer(const SDL_MouseMotionEvent &evt); void _wrapMousePointer(const SDL_MouseMotionEvent &evt);
void _handleKeyPress(SDL_KeyboardEvent& evt);
bool _start(); bool _start();
ICS::MWSDLMouseListener* mMouseListener; ICS::MWSDLMouseListener* mMouseListener;

Loading…
Cancel
Save