|
|
@ -3,7 +3,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include <OgrePlatform.h>
|
|
|
|
#include <OgrePlatform.h>
|
|
|
|
#include <OgreRoot.h>
|
|
|
|
#include <OgreRoot.h>
|
|
|
|
#include <boost/locale.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
|
|
|
|
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
|
|
|
|
# include <X11/Xlib.h>
|
|
|
|
# include <X11/Xlib.h>
|
|
|
@ -239,6 +238,36 @@ namespace SFO
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MouseMotionEvent InputWrapper::_packageMouseMotion(const SDL_Event &evt)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
MouseMotionEvent pack_evt;
|
|
|
|
|
|
|
|
pack_evt.x = mMouseX;
|
|
|
|
|
|
|
|
pack_evt.xrel = 0;
|
|
|
|
|
|
|
|
pack_evt.y = mMouseY;
|
|
|
|
|
|
|
|
pack_evt.yrel = 0;
|
|
|
|
|
|
|
|
pack_evt.z = mMouseZ;
|
|
|
|
|
|
|
|
pack_evt.zrel = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(evt.type == SDL_MOUSEMOTION)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
pack_evt.x = mMouseX = evt.motion.x;
|
|
|
|
|
|
|
|
pack_evt.y = mMouseY = evt.motion.y;
|
|
|
|
|
|
|
|
pack_evt.xrel = evt.motion.xrel;
|
|
|
|
|
|
|
|
pack_evt.yrel = evt.motion.yrel;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(evt.type == SDL_MOUSEWHEEL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mMouseZ += pack_evt.zrel = (evt.wheel.y * 120);
|
|
|
|
|
|
|
|
pack_evt.z = mMouseZ;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new std::runtime_error("Tried to package non-motion event!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return pack_evt;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InputWrapper::_handleKeyPress(SDL_KeyboardEvent &evt)
|
|
|
|
void InputWrapper::_handleKeyPress(SDL_KeyboardEvent &evt)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//SDL keyboard events are followed by the actual text those keys would generate
|
|
|
|
//SDL keyboard events are followed by the actual text those keys would generate
|
|
|
@ -253,50 +282,58 @@ namespace SFO
|
|
|
|
SDL_Event text_evts[1];
|
|
|
|
SDL_Event text_evts[1];
|
|
|
|
if(SDL_PeepEvents(text_evts, 1, SDL_GETEVENT, SDL_TEXTINPUT, SDL_TEXTINPUT) != 0)
|
|
|
|
if(SDL_PeepEvents(text_evts, 1, SDL_GETEVENT, SDL_TEXTINPUT, SDL_TEXTINPUT) != 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const char* symbol = text_evts[0].text.text;
|
|
|
|
if(strlen(text_evts[0].text.text) != 0)
|
|
|
|
|
|
|
|
|
|
|
|
Uint32 num_bytes = strlen(symbol);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//no valid character is more than 4 bytes
|
|
|
|
|
|
|
|
if(num_bytes > 0 && num_bytes <= 4)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Uint32 u32_symbol = boost::locale::conv::utf_to_utf<Uint32>(symbol)[0];
|
|
|
|
const unsigned char* symbol = reinterpret_cast<unsigned char*>(&(text_evts[0].text.text[0]));
|
|
|
|
|
|
|
|
evt.keysym.unicode = _UTF8ToUTF32(symbol);
|
|
|
|
evt.keysym.unicode = u32_symbol;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mKeyboardListener->keyPressed(evt);
|
|
|
|
mKeyboardListener->keyPressed(evt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MouseMotionEvent InputWrapper::_packageMouseMotion(const SDL_Event &evt)
|
|
|
|
//Lifted from OIS' LinuxKeyboard.cpp
|
|
|
|
|
|
|
|
Uint32 InputWrapper::_UTF8ToUTF32(const unsigned char *buf)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MouseMotionEvent pack_evt;
|
|
|
|
unsigned char FirstChar = buf[0];
|
|
|
|
pack_evt.x = mMouseX;
|
|
|
|
|
|
|
|
pack_evt.xrel = 0;
|
|
|
|
|
|
|
|
pack_evt.y = mMouseY;
|
|
|
|
|
|
|
|
pack_evt.yrel = 0;
|
|
|
|
|
|
|
|
pack_evt.z = mMouseZ;
|
|
|
|
|
|
|
|
pack_evt.zrel = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(evt.type == SDL_MOUSEMOTION)
|
|
|
|
//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
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pack_evt.x = mMouseX = evt.motion.x;
|
|
|
|
len = 2;
|
|
|
|
pack_evt.y = mMouseY = evt.motion.y;
|
|
|
|
val = FirstChar & 0x1F;
|
|
|
|
pack_evt.xrel = evt.motion.xrel;
|
|
|
|
|
|
|
|
pack_evt.yrel = evt.motion.yrel;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(evt.type == SDL_MOUSEWHEEL)
|
|
|
|
else if((FirstChar & 0xF0) == 0xE0) //3 Chars
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mMouseZ += pack_evt.zrel = (evt.wheel.y * 120);
|
|
|
|
len = 3;
|
|
|
|
pack_evt.z = mMouseZ;
|
|
|
|
val = FirstChar & 0x0F;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else if((FirstChar & 0xF8) == 0xF0) //4 Chars
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new std::runtime_error("Tried to package non-motion event!");
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return pack_evt;
|
|
|
|
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)
|
|
|
@ -307,6 +344,8 @@ 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 " << SDLK_SYSREQ << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
return kc;
|
|
|
|
return kc;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -314,6 +353,10 @@ namespace SFO
|
|
|
|
void InputWrapper::_setupOISKeys()
|
|
|
|
void InputWrapper::_setupOISKeys()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//lifted from OIS's SDLKeyboard.cpp
|
|
|
|
//lifted from OIS's SDLKeyboard.cpp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: Consider switching to scancodes so we
|
|
|
|
|
|
|
|
//can properly support international keyboards
|
|
|
|
|
|
|
|
//look at SDL_GetKeyFromScancode and SDL_GetKeyName
|
|
|
|
mKeyMap.insert( KeyMap::value_type(SDLK_UNKNOWN, OIS::KC_UNASSIGNED));
|
|
|
|
mKeyMap.insert( KeyMap::value_type(SDLK_UNKNOWN, OIS::KC_UNASSIGNED));
|
|
|
|
mKeyMap.insert( KeyMap::value_type(SDLK_ESCAPE, OIS::KC_ESCAPE) );
|
|
|
|
mKeyMap.insert( KeyMap::value_type(SDLK_ESCAPE, OIS::KC_ESCAPE) );
|
|
|
|
mKeyMap.insert( KeyMap::value_type(SDLK_1, OIS::KC_1) );
|
|
|
|
mKeyMap.insert( KeyMap::value_type(SDLK_1, OIS::KC_1) );
|
|
|
|