From da8be54d8f992820718b40837e4d67fa4ad1b2ec Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Fri, 1 Dec 2017 17:19:00 +0100 Subject: [PATCH] Bites: rename setupInput to setWindowGrab and disable it by default it works better for the usecases of Bites. Also this API allows ungrabbing again. --- .../Bites/include/OgreApplicationContext.h | 15 ++++++++++----- Components/Bites/src/OgreApplicationContext.cpp | 17 +++-------------- Samples/Browser/include/SampleBrowser.h | 4 +++- Samples/Common/include/SampleContext.h | 4 ++-- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/Components/Bites/include/OgreApplicationContext.h b/Components/Bites/include/OgreApplicationContext.h index 3b4dea49196..b8ee4a8c985 100644 --- a/Components/Bites/include/OgreApplicationContext.h +++ b/Components/Bites/include/OgreApplicationContext.h @@ -99,7 +99,7 @@ namespace OgreBites public Ogre::WindowEventListener { public: - explicit ApplicationContext(const Ogre::String& appName = OGRE_VERSION_NAME, bool grabInput = true); + explicit ApplicationContext(const Ogre::String& appName = OGRE_VERSION_NAME, bool unused = true); virtual ~ApplicationContext(); @@ -194,9 +194,15 @@ namespace OgreBites virtual bool oneTimeConfig(); /** - Sets up SDL input. + When input is grabbed the mouse is confined to the window. */ - virtual void setupInput(bool grab); + void setWindowGrab(NativeWindowType* win, bool grab = true); + + /// @overload + void setWindowGrab(bool grab = true) { + OgreAssert(!mWindows.empty(), "create a window first"); + setWindowGrab(mWindows[0].native, grab); + } /** Finds context-wide resource groups. I load paths from a config file here, @@ -265,7 +271,7 @@ namespace OgreBites /// @overload void removeInputListener(InputListener* lis) { - OgreAssert(!mWindows.empty(), "called after all windows we deleted"); + OgreAssert(!mWindows.empty(), "called after all windows were deleted"); removeInputListener(mWindows[0].native, lis); } @@ -303,7 +309,6 @@ namespace OgreBites Ogre::FileSystemLayer* mFSLayer; // File system abstraction layer Ogre::Root* mRoot; // OGRE root StaticPluginLoader mStaticPluginLoader; - bool mGrabInput; bool mFirstRun; Ogre::String mNextRenderer; // name of renderer used for next run Ogre::String mAppName; diff --git a/Components/Bites/src/OgreApplicationContext.cpp b/Components/Bites/src/OgreApplicationContext.cpp index 3d9eb53469e..ea0bae1012c 100644 --- a/Components/Bites/src/OgreApplicationContext.cpp +++ b/Components/Bites/src/OgreApplicationContext.cpp @@ -33,13 +33,12 @@ namespace OgreBites { static const char* SHADER_CACHE_FILENAME = "cache.bin"; -ApplicationContext::ApplicationContext(const Ogre::String& appName, bool grabInput) +ApplicationContext::ApplicationContext(const Ogre::String& appName, bool) #if (OGRE_THREAD_PROVIDER == 3) && (OGRE_NO_TBB_SCHEDULER == 1) : mTaskScheduler(tbb::task_scheduler_init::deferred) #endif { mAppName = appName; - mGrabInput = grabInput; mFSLayer = new Ogre::FileSystemLayer(mAppName); mRoot = NULL; mOverlaySystem = NULL; @@ -196,7 +195,6 @@ void ApplicationContext::setup() mRoot->initialise(false); createWindow(mAppName); - setupInput(mGrabInput); locateResources(); initialiseRTShaderSystem(); loadResources(); @@ -530,21 +528,12 @@ void ApplicationContext::_fireInputEvent(const Event& event, uint32_t windowID) } } -void ApplicationContext::setupInput(bool _grab) +void ApplicationContext::setWindowGrab(NativeWindowType* win, bool _grab) { #if OGRE_BITES_HAVE_SDL - if (!mWindows[0].native) - { - OGRE_EXCEPT(Ogre::Exception::ERR_INVALID_STATE, - "you must create a SDL window first", - "SampleContext::setupInput"); - } - - SDL_ShowCursor(SDL_FALSE); - SDL_bool grab = SDL_bool(_grab); - SDL_SetWindowGrab(mWindows[0].native, grab); + SDL_SetWindowGrab(win, grab); SDL_SetRelativeMouseMode(grab); #endif } diff --git a/Samples/Browser/include/SampleBrowser.h b/Samples/Browser/include/SampleBrowser.h index 90116edbe61..e77233d2ec3 100644 --- a/Samples/Browser/include/SampleBrowser.h +++ b/Samples/Browser/include/SampleBrowser.h @@ -149,7 +149,7 @@ namespace OgreBites public: SampleBrowser(bool nograb = false, int startSampleIndex = -1) - : SampleContext("OGRE Sample Browser", !nograb) + : SampleContext("OGRE Sample Browser"), mGrabInput(!nograb) { mIsShuttingDown = false; mTrayMgr = 0; @@ -919,6 +919,7 @@ namespace OgreBites ApplicationContext::setup(); mWindow = getRenderWindow(); addInputListener(this); + if(mGrabInput) setWindowGrab(); #ifdef OGRE_STATIC_LIB // Check if the render system supports any shader profiles. // Don't load samples that require shaders if we don't have any shader support, GL ES 1.x for example. @@ -1509,6 +1510,7 @@ namespace OgreBites SampleBrowserGestureView *mGestureView; #endif bool mIsShuttingDown; + bool mGrabInput; }; } diff --git a/Samples/Common/include/SampleContext.h b/Samples/Common/include/SampleContext.h index 1146105a87e..cccc847c04a 100644 --- a/Samples/Common/include/SampleContext.h +++ b/Samples/Common/include/SampleContext.h @@ -44,8 +44,8 @@ namespace OgreBites public: Ogre::RenderWindow* mWindow; - SampleContext(const Ogre::String& appName = OGRE_VERSION_NAME, bool grabInput = true) - : ApplicationContext(appName, grabInput), mWindow(NULL) + SampleContext(const Ogre::String& appName = OGRE_VERSION_NAME) + : ApplicationContext(appName), mWindow(NULL) { mCurrentSample = 0; mSamplePaused = false;