mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 16:09:39 +00:00
remove dependency on boost::locale, use system mouse position in in-game menus
This commit is contained in:
parent
eff26159d9
commit
403b6756f5
3 changed files with 86 additions and 47 deletions
|
@ -221,9 +221,10 @@ namespace MWInput
|
||||||
bool main_menu = mWindows.containsMode(MWGui::GM_MainMenu);
|
bool main_menu = mWindows.containsMode(MWGui::GM_MainMenu);
|
||||||
|
|
||||||
bool was_relative = mInputManager->getMouseRelative();
|
bool was_relative = mInputManager->getMouseRelative();
|
||||||
bool is_relative = !main_menu;
|
bool is_relative = !mWindows.isGuiMode();
|
||||||
|
|
||||||
//don't keep the pointer away from the window edge in the main menu
|
// don't keep the pointer away from the window edge in gui mode
|
||||||
|
// stop using raw mouse motions and switch to system cursor movements
|
||||||
mInputManager->setMouseRelative(is_relative);
|
mInputManager->setMouseRelative(is_relative);
|
||||||
|
|
||||||
//we switched to non-relative mode, move our cursor to where the in-game
|
//we switched to non-relative mode, move our cursor to where the in-game
|
||||||
|
@ -472,17 +473,11 @@ namespace MWInput
|
||||||
// We keep track of our own mouse position, so that moving the mouse while in
|
// We keep track of our own mouse position, so that moving the mouse while in
|
||||||
// game mode does not move the position of the GUI cursor
|
// game mode does not move the position of the GUI cursor
|
||||||
|
|
||||||
//FIXME: Except in the main menu, since we let the pointer escape
|
// Don't support the UI sensitivity slider to reduce headache
|
||||||
if(!mWindows.containsMode(MWGui::GM_MainMenu))
|
// related to when the mouse can leave the window, and what to
|
||||||
{
|
// do when it re-enters
|
||||||
mMouseX += float(arg.xrel) * mUISensitivity;
|
mMouseX = arg.x;
|
||||||
mMouseY += float(arg.yrel) * mUISensitivity * mUIYMultiplier;
|
mMouseY = arg.y;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mMouseX = arg.x;
|
|
||||||
mMouseY = arg.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
mMouseX = std::max(0.f, std::min(mMouseX, float(viewSize.width)));
|
mMouseX = std::max(0.f, std::min(mMouseX, float(viewSize.width)));
|
||||||
mMouseY = std::max(0.f, std::min(mMouseY, float(viewSize.height)));
|
mMouseY = std::max(0.f, std::min(mMouseY, float(viewSize.height)));
|
||||||
|
|
105
extern/sdl4ogre/sdlinputwrapper.cpp
vendored
105
extern/sdl4ogre/sdlinputwrapper.cpp
vendored
|
@ -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,36 +238,6 @@ namespace SFO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
const char* symbol = text_evts[0].text.text;
|
|
||||||
|
|
||||||
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];
|
|
||||||
|
|
||||||
evt.keysym.unicode = u32_symbol;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mKeyboardListener->keyPressed(evt);
|
|
||||||
}
|
|
||||||
|
|
||||||
MouseMotionEvent InputWrapper::_packageMouseMotion(const SDL_Event &evt)
|
MouseMotionEvent InputWrapper::_packageMouseMotion(const SDL_Event &evt)
|
||||||
{
|
{
|
||||||
MouseMotionEvent pack_evt;
|
MouseMotionEvent pack_evt;
|
||||||
|
@ -299,6 +268,74 @@ 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;
|
||||||
|
@ -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) );
|
||||||
|
|
7
extern/sdl4ogre/sdlinputwrapper.hpp
vendored
7
extern/sdl4ogre/sdlinputwrapper.hpp
vendored
|
@ -32,13 +32,14 @@ namespace SFO
|
||||||
|
|
||||||
void warpMouse(int x, int y);
|
void warpMouse(int x, int y);
|
||||||
private:
|
private:
|
||||||
|
bool _start();
|
||||||
|
|
||||||
bool _handleWarpMotion(const SDL_MouseMotionEvent& evt);
|
bool _handleWarpMotion(const SDL_MouseMotionEvent& evt);
|
||||||
void _wrapMousePointer(const SDL_MouseMotionEvent &evt);
|
void _wrapMousePointer(const SDL_MouseMotionEvent &evt);
|
||||||
|
|
||||||
MouseMotionEvent _packageMouseMotion(const SDL_Event& evt);
|
MouseMotionEvent _packageMouseMotion(const SDL_Event& evt);
|
||||||
void _handleKeyPress(SDL_KeyboardEvent& evt);
|
|
||||||
|
|
||||||
bool _start();
|
void _handleKeyPress(SDL_KeyboardEvent& evt);
|
||||||
|
Uint32 _UTF8ToUTF32(const unsigned char *buf);
|
||||||
void _setupOISKeys();
|
void _setupOISKeys();
|
||||||
|
|
||||||
SFO::MouseListener* mMouseListener;
|
SFO::MouseListener* mMouseListener;
|
||||||
|
|
Loading…
Reference in a new issue