Skip to content

Commit

Permalink
Bites: rename setupInput to setWindowGrab and disable it by default
Browse files Browse the repository at this point in the history
it works better for the usecases of Bites. Also this API allows
ungrabbing again.
  • Loading branch information
paroj committed Dec 1, 2017
1 parent 5ee0db4 commit da8be54
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
15 changes: 10 additions & 5 deletions Components/Bites/include/OgreApplicationContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
17 changes: 3 additions & 14 deletions Components/Bites/src/OgreApplicationContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -196,7 +195,6 @@ void ApplicationContext::setup()
mRoot->initialise(false);
createWindow(mAppName);

setupInput(mGrabInput);
locateResources();
initialiseRTShaderSystem();
loadResources();
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion Samples/Browser/include/SampleBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1509,6 +1510,7 @@ namespace OgreBites
SampleBrowserGestureView *mGestureView;
#endif
bool mIsShuttingDown;
bool mGrabInput;
};
}

Expand Down
4 changes: 2 additions & 2 deletions Samples/Common/include/SampleContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit da8be54

Please sign in to comment.