Merge pull request #506 from bgK/lock_mouse

MYST3: Lock the mouse in the game window
This commit is contained in:
Bastien Bouclet 2012-01-27 01:34:54 -08:00
commit 545ed542fd
7 changed files with 35 additions and 0 deletions

View File

@ -61,6 +61,9 @@ public:
virtual void warpMouse(int x, int y) = 0;
virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale = 1, const Graphics::PixelFormat *format = NULL) = 0;
// ResidualVM specific method
virtual bool lockMouse(bool lock) = 0;
virtual void displayMessageOnOSD(const char *msg) {}
};

View File

@ -537,6 +537,15 @@ bool SurfaceSdlGraphicsManager::showMouse(bool visible) {
return true;
}
// ResidualVM specific method
bool SurfaceSdlGraphicsManager::lockMouse(bool lock) {
if (lock)
SDL_WM_GrabInput(SDL_GRAB_ON);
else
SDL_WM_GrabInput(SDL_GRAB_OFF);
return true;
}
void SurfaceSdlGraphicsManager::warpMouse(int x, int y) {
SDL_WarpMouse(x, y);
}

View File

@ -81,6 +81,9 @@ public:
virtual void warpMouse(int x, int y);
void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale = 1, const Graphics::PixelFormat *format = NULL) {}
// ResidualVM specific method
virtual bool lockMouse(bool lock);
#ifdef USE_OSD
virtual void displayMessageOnOSD(const char *msg);
#endif

View File

@ -125,6 +125,11 @@ bool ModularBackend::showMouse(bool visible) {
return _graphicsManager->showMouse(visible);
}
// ResidualVM specific method
bool ModularBackend::lockMouse(bool visible) {
return _graphicsManager->lockMouse(visible);
}
void ModularBackend::warpMouse(int x, int y) {
_graphicsManager->warpMouse(x, y);
}

View File

@ -83,6 +83,9 @@ public:
virtual void warpMouse(int x, int y);
virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale = 1, const Graphics::PixelFormat *format = NULL);
// ResidualVM specific method
virtual bool lockMouse(bool lock);
//@}
/** @name Events and Time */

View File

@ -443,6 +443,13 @@ public:
*/
virtual bool showMouse(bool visible) = 0;
/**
* Lock or unlock the mouse cursor within the window.
*
* ResidualVM specific method
*/
virtual bool lockMouse(bool lock) = 0;
/**
* Move ("warp") the mouse cursor to the specified position in virtual
* screen coordinates.

View File

@ -134,6 +134,7 @@ Common::Error Myst3Engine::run() {
_system->setupScreen(w, h, false, true);
_system->showMouse(false);
_system->lockMouse(true);
addArchive("OVER101.m3o", false);
addArchive("ENGLISH.m3t", true);
@ -183,6 +184,8 @@ Common::Error Myst3Engine::run() {
_archiveNode->close();
_system->lockMouse(false);
return Common::kNoError;
}
@ -308,8 +311,10 @@ void Myst3Engine::processInput(bool lookOnly) {
break;
case Common::KEYCODE_d:
if (event.kbd.flags & Common::KBD_CTRL) {
_system->lockMouse(false);
_console->attach();
_console->onFrame();
_system->lockMouse(true);
}
break;
default: