diff options
author | Johannes Schickel | 2015-01-24 23:42:12 +0100 |
---|---|---|
committer | Johannes Schickel | 2015-01-25 18:57:38 +0100 |
commit | 3a2db0135d93b5f12fd42f04db3b6ad9d40834d3 (patch) | |
tree | 5b021b6b70148fb60bcaa08be7f68b427b730d09 /backends/graphics | |
parent | 4e1ffc9434f771d3f43e66104adeea9e0166123c (diff) | |
download | scummvm-rg350-3a2db0135d93b5f12fd42f04db3b6ad9d40834d3.tar.gz scummvm-rg350-3a2db0135d93b5f12fd42f04db3b6ad9d40834d3.tar.bz2 scummvm-rg350-3a2db0135d93b5f12fd42f04db3b6ad9d40834d3.zip |
SDL: Refactor WM specific functionality into SdlGraphicsManager.
Diffstat (limited to 'backends/graphics')
-rw-r--r-- | backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp | 2 | ||||
-rw-r--r-- | backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp | 2 | ||||
-rw-r--r-- | backends/graphics/openglsdl/openglsdl-graphics.cpp | 4 | ||||
-rw-r--r-- | backends/graphics/sdl/sdl-graphics.cpp | 31 | ||||
-rw-r--r-- | backends/graphics/sdl/sdl-graphics.h | 38 | ||||
-rw-r--r-- | backends/graphics/surfacesdl/surfacesdl-graphics.cpp | 8 |
6 files changed, 77 insertions, 8 deletions
diff --git a/backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp b/backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp index 343efa4da6..975e34a314 100644 --- a/backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp +++ b/backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp @@ -122,7 +122,7 @@ void DINGUXSdlGraphicsManager::initSize(uint w, uint h) { if (w > 320 || h > 240) { setGraphicsMode(GFX_HALF); setGraphicsModeIntern(); - _eventSource->toggleMouseGrab(); + toggleMouseGrab(); } _transactionDetails.sizeChanged = true; diff --git a/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp b/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp index 22b271ae1a..f8ab9930d7 100644 --- a/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp +++ b/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp @@ -134,7 +134,7 @@ void LinuxmotoSdlGraphicsManager::initSize(uint w, uint h) { if (w > 320 || h > 240) { setGraphicsMode(GFX_HALF); setGraphicsModeIntern(); - _eventSource->toggleMouseGrab(); + toggleMouseGrab(); } _transactionDetails.sizeChanged = true; diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp index b028cd5b1a..fc2956755d 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.cpp +++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp @@ -108,7 +108,7 @@ void OpenGLSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable) case OSystem::kFeatureIconifyWindow: if (enable) { - SDL_WM_IconifyWindow(); + iconifyWindow(); } break; @@ -229,7 +229,7 @@ void OpenGLSdlGraphicsManager::notifyMousePos(Common::Point mouse) { } void OpenGLSdlGraphicsManager::setInternalMousePosition(int x, int y) { - SDL_WarpMouse(x, y); + warpMouseInWindow(x, y); } bool OpenGLSdlGraphicsManager::loadVideoMode(uint requestedWidth, uint requestedHeight, const Graphics::PixelFormat &format) { diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp index b5e49fa397..d42c88f5d6 100644 --- a/backends/graphics/sdl/sdl-graphics.cpp +++ b/backends/graphics/sdl/sdl-graphics.cpp @@ -22,7 +22,9 @@ #include "backends/graphics/sdl/sdl-graphics.h" +#include "backends/platform/sdl/sdl-sys.h" #include "backends/events/sdl/sdl-events.h" +#include "common/textconsole.h" SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source) : _eventSource(source) { @@ -38,3 +40,32 @@ void SdlGraphicsManager::activateManager() { void SdlGraphicsManager::deactivateManager() { _eventSource->setGraphicsManager(0); } + +void SdlGraphicsManager::setWindowCaption(const Common::String &caption) { + SDL_WM_SetCaption(caption.c_str(), caption.c_str()); +} + +void SdlGraphicsManager::setWindowIcon(SDL_Surface *icon) { + SDL_WM_SetIcon(icon, NULL); + SDL_FreeSurface(icon); +} + +void SdlGraphicsManager::toggleMouseGrab() { + if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF) { + SDL_WM_GrabInput(SDL_GRAB_ON); + } else { + SDL_WM_GrabInput(SDL_GRAB_OFF); + } +} + +bool SdlGraphicsManager::hasMouseFocus() const { + return (SDL_GetAppState() & SDL_APPMOUSEFOCUS); +} + +void SdlGraphicsManager::warpMouseInWindow(uint x, uint y) { + SDL_WarpMouse(x, y); +} + +void SdlGraphicsManager::iconifyWindow() { + SDL_WM_IconifyWindow(); +} diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h index 3ef540708a..216fc2d200 100644 --- a/backends/graphics/sdl/sdl-graphics.h +++ b/backends/graphics/sdl/sdl-graphics.h @@ -25,7 +25,9 @@ #include "backends/graphics/graphics.h" +#include "backends/platform/sdl/sdl-sys.h" #include "common/rect.h" +#include "common/str.h" class SdlEventSource; @@ -91,6 +93,42 @@ public: */ virtual void notifyMousePos(Common::Point mouse) = 0; + /** + * Change the caption of the window. + * + * @param caption New window caption in UTF-8 encoding. + */ + void setWindowCaption(const Common::String &caption); + + /** + * Attach an icon to the window. + * + * @param icon The surface to use as icon. SdlGraphicsManager takes + * ownership over it. + */ + void setWindowIcon(SDL_Surface *icon); + + /** + * Toggle mouse grab state. This decides whether the cursor can leave the + * window or not. + */ + void toggleMouseGrab(); + + /** + * Check whether the application has mouse focus. + */ + bool hasMouseFocus() const; + + /** + * Warp the mouse to the specified position in window coordinates. + */ + void warpMouseInWindow(uint x, uint y); + + /** + * Iconifies the window. + */ + void iconifyWindow(); + protected: SdlEventSource *_eventSource; }; diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp index 7f3c99fcea..583c85e446 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp @@ -235,7 +235,7 @@ void SurfaceSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable) break; case OSystem::kFeatureIconifyWindow: if (enable) - SDL_WM_IconifyWindow(); + iconifyWindow(); break; default: break; @@ -1710,7 +1710,7 @@ void SurfaceSdlGraphicsManager::warpMouse(int x, int y) { int y1 = y; // Don't change actual mouse position, when mouse is outside of our window (in case of windowed mode) - if (!(SDL_GetAppState( ) & SDL_APPMOUSEFOCUS)) { + if (!hasMouseFocus()) { setMousePos(x, y); // but change game cursor position return; } @@ -1720,9 +1720,9 @@ void SurfaceSdlGraphicsManager::warpMouse(int x, int y) { if (_mouseCurState.x != x || _mouseCurState.y != y) { if (!_overlayVisible) - SDL_WarpMouse(x * _videoMode.scaleFactor, y1 * _videoMode.scaleFactor); + warpMouseInWindow(x * _videoMode.scaleFactor, y1 * _videoMode.scaleFactor); else - SDL_WarpMouse(x, y1); + warpMouseInWindow(x, y1); // SDL_WarpMouse() generates a mouse movement event, so // setMousePos() would be called eventually. However, the |