1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-04-09 21:44:54 +00:00

Bring back the option to not grab mouse. Useful if running in a mouse-controlled GUI debugger.

This commit is contained in:
scrawl 2013-11-29 20:06:54 +01:00
parent ce2d521b8f
commit bcf61331ab
7 changed files with 19 additions and 8 deletions

View File

@ -147,6 +147,7 @@ OMW::Engine::Engine(Files::ConfigurationManager& configurationManager)
, mEncoding(ToUTF8::WINDOWS_1252) , mEncoding(ToUTF8::WINDOWS_1252)
, mEncoder(NULL) , mEncoder(NULL)
, mActivationDistanceOverride(-1) , mActivationDistanceOverride(-1)
, mGrab(true)
{ {
std::srand ( std::time(NULL) ); std::srand ( std::time(NULL) );
@ -370,7 +371,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
std::string keybinderUser = (mCfgMgr.getUserPath() / "input.xml").string(); std::string keybinderUser = (mCfgMgr.getUserPath() / "input.xml").string();
bool keybinderUserExists = boost::filesystem::exists(keybinderUser); bool keybinderUserExists = boost::filesystem::exists(keybinderUser);
MWInput::InputManager* input = new MWInput::InputManager (*mOgre, *this, keybinderUser, keybinderUserExists); MWInput::InputManager* input = new MWInput::InputManager (*mOgre, *this, keybinderUser, keybinderUserExists, mGrab);
mEnvironment.setInputManager (input); mEnvironment.setInputManager (input);
MWGui::WindowManager* window = new MWGui::WindowManager( MWGui::WindowManager* window = new MWGui::WindowManager(

View File

@ -79,6 +79,8 @@ namespace OMW
bool mScriptConsoleMode; bool mScriptConsoleMode;
std::string mStartupScript; std::string mStartupScript;
int mActivationDistanceOverride; int mActivationDistanceOverride;
// Grab mouse?
bool mGrab;
Compiler::Extensions mExtensions; Compiler::Extensions mExtensions;
Compiler::Context *mScriptContext; Compiler::Context *mScriptContext;
@ -152,6 +154,8 @@ namespace OMW
/// Start as a new game. /// Start as a new game.
void setNewGame(bool newGame); void setNewGame(bool newGame);
void setGrabMouse(bool grab) { mGrab = grab; }
/// Initialise and enter main loop. /// Initialise and enter main loop.
void go(); void go();

View File

@ -154,6 +154,8 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
("fallback", bpo::value<FallbackMap>()->default_value(FallbackMap(), "") ("fallback", bpo::value<FallbackMap>()->default_value(FallbackMap(), "")
->multitoken()->composing(), "fallback values") ->multitoken()->composing(), "fallback values")
("no-grab", "Don't grab mouse cursor")
("activate-dist", bpo::value <int> ()->default_value (-1), "activation distance override"); ("activate-dist", bpo::value <int> ()->default_value (-1), "activation distance override");
bpo::parsed_options valid_opts = bpo::command_line_parser(argc, argv) bpo::parsed_options valid_opts = bpo::command_line_parser(argc, argv)
@ -184,6 +186,8 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
if (!run) if (!run)
return false; return false;
engine.setGrabMouse(!variables.count("no-grab"));
// Font encoding settings // Font encoding settings
std::string encoding(variables["encoding"].as<std::string>()); std::string encoding(variables["encoding"].as<std::string>());
std::cout << ToUTF8::encodingUsingMessage(encoding) << std::endl; std::cout << ToUTF8::encodingUsingMessage(encoding) << std::endl;

View File

@ -87,7 +87,7 @@ namespace MWInput
{ {
InputManager::InputManager(OEngine::Render::OgreRenderer &ogre, InputManager::InputManager(OEngine::Render::OgreRenderer &ogre,
OMW::Engine& engine, OMW::Engine& engine,
const std::string& userFile, bool userFileExists) const std::string& userFile, bool userFileExists, bool grab)
: mOgre(ogre) : mOgre(ogre)
, mPlayer(NULL) , mPlayer(NULL)
, mEngine(engine) , mEngine(engine)
@ -111,7 +111,7 @@ namespace MWInput
Ogre::RenderWindow* window = ogre.getWindow (); Ogre::RenderWindow* window = ogre.getWindow ();
mInputManager = new SFO::InputWrapper(mOgre.getSDLWindow(), mOgre.getWindow()); mInputManager = new SFO::InputWrapper(mOgre.getSDLWindow(), mOgre.getWindow(), grab);
mInputManager->setMouseEventCallback (this); mInputManager->setMouseEventCallback (this);
mInputManager->setKeyboardEventCallback (this); mInputManager->setKeyboardEventCallback (this);
mInputManager->setWindowEventCallback(this); mInputManager->setWindowEventCallback(this);

View File

@ -61,7 +61,7 @@ namespace MWInput
public: public:
InputManager(OEngine::Render::OgreRenderer &_ogre, InputManager(OEngine::Render::OgreRenderer &_ogre,
OMW::Engine& engine, OMW::Engine& engine,
const std::string& userFile, bool userFileExists); const std::string& userFile, bool userFileExists, bool grab);
virtual ~InputManager(); virtual ~InputManager();

View File

@ -9,7 +9,7 @@ namespace SFO
{ {
/// \brief General purpose wrapper for OGRE applications around SDL's event /// \brief General purpose wrapper for OGRE applications around SDL's event
/// queue, mostly used for handling input-related events. /// queue, mostly used for handling input-related events.
InputWrapper::InputWrapper(SDL_Window* window, Ogre::RenderWindow* ogreWindow) : InputWrapper::InputWrapper(SDL_Window* window, Ogre::RenderWindow* ogreWindow, bool grab) :
mSDLWindow(window), mSDLWindow(window),
mOgreWindow(ogreWindow), mOgreWindow(ogreWindow),
mWarpCompensate(false), mWarpCompensate(false),
@ -27,7 +27,8 @@ namespace SFO
mWindowHasFocus(true), mWindowHasFocus(true),
mWantGrab(false), mWantGrab(false),
mWantRelative(false), mWantRelative(false),
mWantMouseVisible(false) mWantMouseVisible(false),
mAllowGrab(grab)
{ {
_setupOISKeys(); _setupOISKeys();
} }
@ -226,7 +227,7 @@ namespace SFO
void InputWrapper::updateMouseSettings() void InputWrapper::updateMouseSettings()
{ {
mGrabPointer = mWantGrab && mMouseInWindow && mWindowHasFocus; mGrabPointer = mWantGrab && mMouseInWindow && mWindowHasFocus;
SDL_SetWindowGrab(mSDLWindow, mGrabPointer ? SDL_TRUE : SDL_FALSE); SDL_SetWindowGrab(mSDLWindow, mGrabPointer && mAllowGrab ? SDL_TRUE : SDL_FALSE);
SDL_ShowCursor(mWantMouseVisible || !mWindowHasFocus); SDL_ShowCursor(mWantMouseVisible || !mWindowHasFocus);

View File

@ -16,7 +16,7 @@ namespace SFO
class InputWrapper class InputWrapper
{ {
public: public:
InputWrapper(SDL_Window *window, Ogre::RenderWindow* ogreWindow); InputWrapper(SDL_Window *window, Ogre::RenderWindow* ogreWindow, bool grab);
~InputWrapper(); ~InputWrapper();
void setMouseEventCallback(MouseListener* listen) { mMouseListener = listen; } void setMouseEventCallback(MouseListener* listen) { mMouseListener = listen; }
@ -62,6 +62,7 @@ namespace SFO
bool mWarpCompensate; bool mWarpCompensate;
bool mWrapPointer; bool mWrapPointer;
bool mAllowGrab;
bool mWantMouseVisible; bool mWantMouseVisible;
bool mWantGrab; bool mWantGrab;
bool mWantRelative; bool mWantRelative;