aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorJohannes Schickel2015-02-16 00:49:42 +0100
committerJohannes Schickel2015-02-16 01:03:29 +0100
commit627d766325e1d435816648f85dbf9c007269b3f2 (patch)
tree795ea66fd2755e81c7d060ee250fd6f53cf20ade /backends
parentb00050439f0f602cb54500f7fda268a7589b4c8b (diff)
downloadscummvm-rg350-627d766325e1d435816648f85dbf9c007269b3f2.tar.gz
scummvm-rg350-627d766325e1d435816648f85dbf9c007269b3f2.tar.bz2
scummvm-rg350-627d766325e1d435816648f85dbf9c007269b3f2.zip
SDL: Add basic abstraction class for the SDL window.
Diffstat (limited to 'backends')
-rw-r--r--backends/events/sdl/sdl-events.cpp4
-rw-r--r--backends/events/symbiansdl/symbiansdl-events.cpp2
-rw-r--r--backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp6
-rw-r--r--backends/graphics/dinguxsdl/dinguxsdl-graphics.h2
-rw-r--r--backends/graphics/gph/gph-graphics.cpp6
-rw-r--r--backends/graphics/gph/gph-graphics.h2
-rw-r--r--backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp6
-rw-r--r--backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h2
-rw-r--r--backends/graphics/maemosdl/maemosdl-graphics.cpp4
-rw-r--r--backends/graphics/maemosdl/maemosdl-graphics.h2
-rw-r--r--backends/graphics/openglsdl/openglsdl-graphics.cpp26
-rw-r--r--backends/graphics/openglsdl/openglsdl-graphics.h2
-rw-r--r--backends/graphics/openpandora/op-graphics.cpp4
-rw-r--r--backends/graphics/openpandora/op-graphics.h2
-rw-r--r--backends/graphics/samsungtvsdl/samsungtvsdl-graphics.cpp4
-rw-r--r--backends/graphics/samsungtvsdl/samsungtvsdl-graphics.h2
-rw-r--r--backends/graphics/sdl/sdl-graphics.cpp162
-rw-r--r--backends/graphics/sdl/sdl-graphics.h67
-rw-r--r--backends/graphics/surfacesdl/surfacesdl-graphics.cpp18
-rw-r--r--backends/graphics/surfacesdl/surfacesdl-graphics.h2
-rw-r--r--backends/graphics/symbiansdl/symbiansdl-graphics.cpp4
-rw-r--r--backends/graphics/symbiansdl/symbiansdl-graphics.h2
-rw-r--r--backends/graphics/wincesdl/wincesdl-graphics.cpp4
-rw-r--r--backends/graphics/wincesdl/wincesdl-graphics.h2
-rw-r--r--backends/platform/dingux/dingux.cpp2
-rw-r--r--backends/platform/gph/gph-backend.cpp2
-rw-r--r--backends/platform/linuxmoto/linuxmoto-sdl.cpp2
-rw-r--r--backends/platform/maemo/maemo.cpp2
-rw-r--r--backends/platform/openpandora/op-backend.cpp2
-rw-r--r--backends/platform/samsungtv/samsungtv.cpp2
-rw-r--r--backends/platform/sdl/module.mk3
-rw-r--r--backends/platform/sdl/sdl-window.cpp155
-rw-r--r--backends/platform/sdl/sdl-window.h103
-rw-r--r--backends/platform/sdl/sdl.cpp24
-rw-r--r--backends/platform/sdl/sdl.h6
-rw-r--r--backends/platform/symbian/src/SymbianOS.cpp2
-rw-r--r--backends/platform/wince/wince-sdl.cpp2
37 files changed, 353 insertions, 291 deletions
diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp
index 21b0fbad32..18fe5453f8 100644
--- a/backends/events/sdl/sdl-events.cpp
+++ b/backends/events/sdl/sdl-events.cpp
@@ -183,7 +183,7 @@ void SdlEventSource::handleKbdMouse() {
}
if (_graphicsManager) {
- _graphicsManager->warpMouseInWindow((Uint16)_km.x, (Uint16)_km.y);
+ _graphicsManager->getWindow()->warpMouseInWindow((Uint16)_km.x, (Uint16)_km.y);
}
}
}
@@ -471,7 +471,7 @@ bool SdlEventSource::handleKeyDown(SDL_Event &ev, Common::Event &event) {
// Ctrl-m toggles mouse capture
if (event.kbd.hasFlags(Common::KBD_CTRL) && ev.key.keysym.sym == 'm') {
if (_graphicsManager) {
- _graphicsManager->toggleMouseGrab();
+ _graphicsManager->getWindow()->toggleMouseGrab();
}
return false;
}
diff --git a/backends/events/symbiansdl/symbiansdl-events.cpp b/backends/events/symbiansdl/symbiansdl-events.cpp
index 97361e3df0..b0d2c25302 100644
--- a/backends/events/symbiansdl/symbiansdl-events.cpp
+++ b/backends/events/symbiansdl/symbiansdl-events.cpp
@@ -134,7 +134,7 @@ bool SymbianSdlEventSource::remapKey(SDL_Event &ev, Common::Event &event) {
event.type = Common::EVENT_MOUSEMOVE;
processMouseEvent(event, _mouseXZone[_currentZone], _mouseYZone[_currentZone]);
if (_graphicsManager) {
- _graphicsManager->warpMouseInWindow(event.mouse.x, event.mouse.y);
+ _graphicsManager->getWindow()->warpMouseInWindow(event.mouse.x, event.mouse.y);
}
}
diff --git a/backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp b/backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp
index 975e34a314..0b9cc0c7e8 100644
--- a/backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp
+++ b/backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp
@@ -35,8 +35,8 @@ static const OSystem::GraphicsMode s_supportedGraphicsModes[] = {
{0, 0, 0}
};
-DINGUXSdlGraphicsManager::DINGUXSdlGraphicsManager(SdlEventSource *boss)
- : SurfaceSdlGraphicsManager(boss) {
+DINGUXSdlGraphicsManager::DINGUXSdlGraphicsManager(SdlEventSource *boss, SdlWindow *window)
+ : SurfaceSdlGraphicsManager(boss, window) {
}
const OSystem::GraphicsMode *DINGUXSdlGraphicsManager::getSupportedGraphicsModes() const {
@@ -122,7 +122,7 @@ void DINGUXSdlGraphicsManager::initSize(uint w, uint h) {
if (w > 320 || h > 240) {
setGraphicsMode(GFX_HALF);
setGraphicsModeIntern();
- toggleMouseGrab();
+ _window->toggleMouseGrab();
}
_transactionDetails.sizeChanged = true;
diff --git a/backends/graphics/dinguxsdl/dinguxsdl-graphics.h b/backends/graphics/dinguxsdl/dinguxsdl-graphics.h
index fc70e721cf..8a356106ad 100644
--- a/backends/graphics/dinguxsdl/dinguxsdl-graphics.h
+++ b/backends/graphics/dinguxsdl/dinguxsdl-graphics.h
@@ -34,7 +34,7 @@ enum {
class DINGUXSdlGraphicsManager : public SurfaceSdlGraphicsManager {
public:
- DINGUXSdlGraphicsManager(SdlEventSource *boss);
+ DINGUXSdlGraphicsManager(SdlEventSource *boss, SdlWindow *window);
bool hasFeature(OSystem::Feature f);
void setFeatureState(OSystem::Feature f, bool enable);
diff --git a/backends/graphics/gph/gph-graphics.cpp b/backends/graphics/gph/gph-graphics.cpp
index 247e5ed490..65cb3d1d65 100644
--- a/backends/graphics/gph/gph-graphics.cpp
+++ b/backends/graphics/gph/gph-graphics.cpp
@@ -35,8 +35,8 @@ static const OSystem::GraphicsMode s_supportedGraphicsModes[] = {
{0, 0, 0}
};
-GPHGraphicsManager::GPHGraphicsManager(SdlEventSource *sdlEventSource)
- : SurfaceSdlGraphicsManager(sdlEventSource) {
+GPHGraphicsManager::GPHGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window)
+ : SurfaceSdlGraphicsManager(sdlEventSource, window) {
}
const OSystem::GraphicsMode *GPHGraphicsManager::getSupportedGraphicsModes() const {
@@ -141,7 +141,7 @@ void GPHGraphicsManager::initSize(uint w, uint h, const Graphics::PixelFormat *f
if (w > 320 || h > 240) {
setGraphicsMode(GFX_HALF);
setGraphicsModeIntern();
- _eventSource->toggleMouseGrab();
+ _window->toggleMouseGrab();
}
_videoMode.overlayWidth = 320;
diff --git a/backends/graphics/gph/gph-graphics.h b/backends/graphics/gph/gph-graphics.h
index 4a68ea6eed..152d29ddf4 100644
--- a/backends/graphics/gph/gph-graphics.h
+++ b/backends/graphics/gph/gph-graphics.h
@@ -33,7 +33,7 @@ enum {
class GPHGraphicsManager : public SurfaceSdlGraphicsManager {
public:
- GPHGraphicsManager(SdlEventSource *boss);
+ GPHGraphicsManager(SdlEventSource *boss, SdlWindow *window);
bool hasFeature(OSystem::Feature f);
void setFeatureState(OSystem::Feature f, bool enable);
diff --git a/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp b/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp
index f8ab9930d7..52e5b42e8b 100644
--- a/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp
+++ b/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp
@@ -45,8 +45,8 @@ static const OSystem::GraphicsMode s_supportedGraphicsModes[] = {
{0, 0, 0}
};
-LinuxmotoSdlGraphicsManager::LinuxmotoSdlGraphicsManager(SdlEventSource *sdlEventSource)
- : SurfaceSdlGraphicsManager(sdlEventSource) {
+LinuxmotoSdlGraphicsManager::LinuxmotoSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window)
+ : SurfaceSdlGraphicsManager(sdlEventSource, window) {
}
const OSystem::GraphicsMode *LinuxmotoSdlGraphicsManager::getSupportedGraphicsModes() const {
@@ -134,7 +134,7 @@ void LinuxmotoSdlGraphicsManager::initSize(uint w, uint h) {
if (w > 320 || h > 240) {
setGraphicsMode(GFX_HALF);
setGraphicsModeIntern();
- toggleMouseGrab();
+ _window->toggleMouseGrab();
}
_transactionDetails.sizeChanged = true;
diff --git a/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h b/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h
index 8760c5004d..d7a13b1cb4 100644
--- a/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h
+++ b/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h
@@ -27,7 +27,7 @@
class LinuxmotoSdlGraphicsManager : public SurfaceSdlGraphicsManager {
public:
- LinuxmotoSdlGraphicsManager(SdlEventSource *sdlEventSource);
+ LinuxmotoSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window);
virtual void initSize(uint w, uint h);
virtual void setGraphicsModeIntern();
diff --git a/backends/graphics/maemosdl/maemosdl-graphics.cpp b/backends/graphics/maemosdl/maemosdl-graphics.cpp
index 07d6d32d3a..478d022aa0 100644
--- a/backends/graphics/maemosdl/maemosdl-graphics.cpp
+++ b/backends/graphics/maemosdl/maemosdl-graphics.cpp
@@ -29,8 +29,8 @@
#include "backends/events/maemosdl/maemosdl-events.h"
#include "backends/graphics/maemosdl/maemosdl-graphics.h"
-MaemoSdlGraphicsManager::MaemoSdlGraphicsManager(SdlEventSource *sdlEventSource)
- : SurfaceSdlGraphicsManager(sdlEventSource) {
+MaemoSdlGraphicsManager::MaemoSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window)
+ : SurfaceSdlGraphicsManager(sdlEventSource, window) {
}
bool MaemoSdlGraphicsManager::loadGFXMode() {
diff --git a/backends/graphics/maemosdl/maemosdl-graphics.h b/backends/graphics/maemosdl/maemosdl-graphics.h
index c255e94653..4cb84c81ee 100644
--- a/backends/graphics/maemosdl/maemosdl-graphics.h
+++ b/backends/graphics/maemosdl/maemosdl-graphics.h
@@ -29,7 +29,7 @@
class MaemoSdlGraphicsManager : public SurfaceSdlGraphicsManager {
public:
- MaemoSdlGraphicsManager(SdlEventSource *sdlEventSource);
+ MaemoSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window);
protected:
virtual bool loadGFXMode();
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp
index 2710b66ecd..c71b9c9219 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.cpp
+++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp
@@ -28,8 +28,8 @@
#include "common/translation.h"
#endif
-OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint desktopHeight, SdlEventSource *eventSource)
- : SdlGraphicsManager(eventSource), _lastRequestedHeight(0),
+OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint desktopHeight, SdlEventSource *eventSource, SdlWindow *window)
+ : SdlGraphicsManager(eventSource, window), _lastRequestedHeight(0),
#if SDL_VERSION_ATLEAST(2, 0, 0)
_glContext(),
#else
@@ -134,7 +134,7 @@ void OpenGLSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable)
case OSystem::kFeatureIconifyWindow:
if (enable) {
- iconifyWindow();
+ _window->iconifyWindow();
}
break;
@@ -148,7 +148,7 @@ bool OpenGLSdlGraphicsManager::getFeatureState(OSystem::Feature f) {
case OSystem::kFeatureFullscreenMode:
#if SDL_VERSION_ATLEAST(2, 0, 0)
if (_window) {
- return (SDL_GetWindowFlags(_window) & SDL_WINDOW_FULLSCREEN) != 0;
+ return (SDL_GetWindowFlags(_window->getSDLWindow()) & SDL_WINDOW_FULLSCREEN) != 0;
} else {
return _wantsFullScreen;
}
@@ -236,7 +236,7 @@ void OpenGLSdlGraphicsManager::updateScreen() {
// Swap OpenGL buffers
#if SDL_VERSION_ATLEAST(2, 0, 0)
- SDL_GL_SwapWindow(_window);
+ SDL_GL_SwapWindow(_window->getSDLWindow());
#else
SDL_GL_SwapBuffers();
#endif
@@ -271,7 +271,7 @@ void OpenGLSdlGraphicsManager::notifyMousePos(Common::Point mouse) {
}
void OpenGLSdlGraphicsManager::setInternalMousePosition(int x, int y) {
- warpMouseInWindow(x, y);
+ _window->warpMouseInWindow(x, y);
}
bool OpenGLSdlGraphicsManager::loadVideoMode(uint requestedWidth, uint requestedHeight, const Graphics::PixelFormat &format) {
@@ -362,7 +362,7 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
_glContext = nullptr;
}
- destroyWindow();
+ _window->destroyWindow();
uint32 flags = SDL_WINDOW_OPENGL;
if (_wantsFullScreen) {
@@ -371,26 +371,26 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
flags |= SDL_WINDOW_RESIZABLE;
}
- if (!createWindow(width, height, flags)) {
+ if (!_window->createWindow(width, height, flags)) {
// We treat fullscreen requests as a "hint" for now. This means in
// case it is not available we simply ignore it.
if (_wantsFullScreen) {
- createWindow(width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
+ _window->createWindow(width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
}
- if (!_window) {
+ if (!_window->getSDLWindow()) {
return false;
}
}
- _glContext = SDL_GL_CreateContext(_window);
+ _glContext = SDL_GL_CreateContext(_window->getSDLWindow());
if (!_glContext) {
return false;
}
notifyContextCreate(rgba8888, rgba8888);
int actualWidth, actualHeight;
- SDL_GetWindowSize(_window, &actualWidth, &actualHeight);
+ getWindowDimensions(&actualWidth, &actualHeight);
setActualScreenSize(actualWidth, actualHeight);
return true;
#else
@@ -451,7 +451,7 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
void OpenGLSdlGraphicsManager::getWindowDimensions(int *width, int *height) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
- SDL_GetWindowSize(_window, width, height);
+ SDL_GetWindowSize(_window->getSDLWindow(), width, height);
#else
if (width) {
*width = _hwScreen->w;
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.h b/backends/graphics/openglsdl/openglsdl-graphics.h
index 1e927df766..845880eb14 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.h
+++ b/backends/graphics/openglsdl/openglsdl-graphics.h
@@ -32,7 +32,7 @@
class OpenGLSdlGraphicsManager : public OpenGL::OpenGLGraphicsManager, public SdlGraphicsManager, public Common::EventObserver {
public:
- OpenGLSdlGraphicsManager(uint desktopWidth, uint desktopHeight, SdlEventSource *eventSource);
+ OpenGLSdlGraphicsManager(uint desktopWidth, uint desktopHeight, SdlEventSource *eventSource, SdlWindow *window);
virtual ~OpenGLSdlGraphicsManager();
// GraphicsManager API
diff --git a/backends/graphics/openpandora/op-graphics.cpp b/backends/graphics/openpandora/op-graphics.cpp
index 1ded1614de..f4c9dc16cc 100644
--- a/backends/graphics/openpandora/op-graphics.cpp
+++ b/backends/graphics/openpandora/op-graphics.cpp
@@ -32,8 +32,8 @@
static SDL_Cursor *hiddenCursor;
-OPGraphicsManager::OPGraphicsManager(SdlEventSource *sdlEventSource)
- : SurfaceSdlGraphicsManager(sdlEventSource) {
+OPGraphicsManager::OPGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window)
+ : SurfaceSdlGraphicsManager(sdlEventSource, window) {
}
bool OPGraphicsManager::loadGFXMode() {
diff --git a/backends/graphics/openpandora/op-graphics.h b/backends/graphics/openpandora/op-graphics.h
index 8b498d632b..50994072bb 100644
--- a/backends/graphics/openpandora/op-graphics.h
+++ b/backends/graphics/openpandora/op-graphics.h
@@ -32,7 +32,7 @@ enum {
class OPGraphicsManager : public SurfaceSdlGraphicsManager {
public:
- OPGraphicsManager(SdlEventSource *sdlEventSource);
+ OPGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window);
bool loadGFXMode();
void unloadGFXMode();
diff --git a/backends/graphics/samsungtvsdl/samsungtvsdl-graphics.cpp b/backends/graphics/samsungtvsdl/samsungtvsdl-graphics.cpp
index 3603d8a861..0c98462891 100644
--- a/backends/graphics/samsungtvsdl/samsungtvsdl-graphics.cpp
+++ b/backends/graphics/samsungtvsdl/samsungtvsdl-graphics.cpp
@@ -28,8 +28,8 @@
#include "backends/events/samsungtvsdl/samsungtvsdl-events.h"
#include "backends/graphics/samsungtvsdl/samsungtvsdl-graphics.h"
-SamsungTVSdlGraphicsManager::SamsungTVSdlGraphicsManager(SdlEventSource *sdlEventSource)
- : SurfaceSdlGraphicsManager(sdlEventSource) {
+SamsungTVSdlGraphicsManager::SamsungTVSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window)
+ : SurfaceSdlGraphicsManager(sdlEventSource, window) {
}
bool SamsungTVSdlGraphicsManager::hasFeature(OSystem::Feature f) {
diff --git a/backends/graphics/samsungtvsdl/samsungtvsdl-graphics.h b/backends/graphics/samsungtvsdl/samsungtvsdl-graphics.h
index 15ba3dca48..8699d77bc8 100644
--- a/backends/graphics/samsungtvsdl/samsungtvsdl-graphics.h
+++ b/backends/graphics/samsungtvsdl/samsungtvsdl-graphics.h
@@ -29,7 +29,7 @@
class SamsungTVSdlGraphicsManager : public SurfaceSdlGraphicsManager {
public:
- SamsungTVSdlGraphicsManager(SdlEventSource *sdlEventSource);
+ SamsungTVSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window);
bool hasFeature(OSystem::Feature f);
void setFeatureState(OSystem::Feature f, bool enable);
diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp
index f6d56ece01..a13ca45477 100644
--- a/backends/graphics/sdl/sdl-graphics.cpp
+++ b/backends/graphics/sdl/sdl-graphics.cpp
@@ -26,19 +26,11 @@
#include "backends/events/sdl/sdl-events.h"
#include "common/textconsole.h"
-SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source)
- : _eventSource(source)
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- , _window(nullptr), _inputGrabState(false), _windowCaption("ScummVM"), _windowIcon(nullptr)
-#endif
- {
+SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source, SdlWindow *window)
+ : _eventSource(source), _window(window) {
}
SdlGraphicsManager::~SdlGraphicsManager() {
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- SDL_FreeSurface(_windowIcon);
- destroyWindow();
-#endif
}
void SdlGraphicsManager::activateManager() {
@@ -49,113 +41,6 @@ void SdlGraphicsManager::deactivateManager() {
_eventSource->setGraphicsManager(0);
}
-void SdlGraphicsManager::setWindowCaption(const Common::String &caption) {
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- _windowCaption = caption;
- if (_window) {
- SDL_SetWindowTitle(_window, caption.c_str());
- }
-#else
- SDL_WM_SetCaption(caption.c_str(), caption.c_str());
-#endif
-}
-
-void SdlGraphicsManager::setWindowIcon(SDL_Surface *icon) {
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- SDL_FreeSurface(_windowIcon);
- _windowIcon = icon;
- if (_window) {
- SDL_SetWindowIcon(_window, icon);
- }
-#else
- SDL_WM_SetIcon(icon, NULL);
- SDL_FreeSurface(icon);
-#endif
-}
-
-void SdlGraphicsManager::toggleMouseGrab() {
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- if (_window) {
- _inputGrabState = !(SDL_GetWindowGrab(_window) == SDL_TRUE);
- SDL_SetWindowGrab(_window, _inputGrabState ? SDL_TRUE : SDL_FALSE);
- }
-#else
- if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF) {
- SDL_WM_GrabInput(SDL_GRAB_ON);
- } else {
- SDL_WM_GrabInput(SDL_GRAB_OFF);
- }
-#endif
-}
-
-bool SdlGraphicsManager::hasMouseFocus() const {
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- if (_window) {
- return (SDL_GetWindowFlags(_window) & SDL_WINDOW_MOUSE_FOCUS);
- } else {
- return false;
- }
-#else
- return (SDL_GetAppState() & SDL_APPMOUSEFOCUS);
-#endif
-}
-
-void SdlGraphicsManager::warpMouseInWindow(uint x, uint y) {
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- if (_window) {
- SDL_WarpMouseInWindow(_window, x, y);
- }
-#else
- SDL_WarpMouse(x, y);
-#endif
-}
-
-void SdlGraphicsManager::iconifyWindow() {
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- if (_window) {
- SDL_MinimizeWindow(_window);
- }
-#else
- SDL_WM_IconifyWindow();
-#endif
-}
-
-SdlGraphicsManager::State::State()
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- : windowIcon(nullptr)
-#endif
- {
-}
-
-SdlGraphicsManager::State::~State() {
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- SDL_FreeSurface(windowIcon);
-#endif
-}
-
-#if SDL_VERSION_ATLEAST(2, 0, 0)
-SDL_Surface *copySDLSurface(SDL_Surface *src) {
- const bool locked = SDL_MUSTLOCK(src) == SDL_TRUE;
-
- if (locked) {
- if (SDL_LockSurface(src) != 0) {
- return nullptr;
- }
- }
-
- SDL_Surface *res = SDL_CreateRGBSurfaceFrom(src->pixels,
- src->w, src->h, src->format->BitsPerPixel,
- src->pitch, src->format->Rmask, src->format->Gmask,
- src->format->Bmask, src->format->Amask);
-
- if (locked) {
- SDL_UnlockSurface(src);
- }
-
- return res;
-}
-#endif
-
SdlGraphicsManager::State SdlGraphicsManager::getState() {
State state;
@@ -167,30 +52,10 @@ SdlGraphicsManager::State SdlGraphicsManager::getState() {
#ifdef USE_RGB_COLOR
state.pixelFormat = getScreenFormat();
#endif
-
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- state.inputGrabState = _inputGrabState;
- state.windowCaption = _windowCaption;
- state.windowIcon = copySDLSurface(_windowIcon);
-#endif
-
return state;
}
bool SdlGraphicsManager::setState(const State &state) {
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- _inputGrabState = state.inputGrabState;
- if (!_window) {
- _windowCaption = state.windowCaption;
- SDL_FreeSurface(_windowIcon);
- _windowIcon = copySDLSurface(state.windowIcon);
- } else {
- SDL_SetWindowGrab(_window, _inputGrabState ? SDL_TRUE : SDL_FALSE);
- setWindowCaption(state.windowCaption);
- setWindowIcon(copySDLSurface(state.windowIcon));
- }
-#endif
-
beginGFXTransaction();
#ifdef USE_RGB_COLOR
initSize(state.screenWidth, state.screenHeight, &state.pixelFormat);
@@ -208,26 +73,3 @@ bool SdlGraphicsManager::setState(const State &state) {
}
}
-#if SDL_VERSION_ATLEAST(2, 0, 0)
-bool SdlGraphicsManager::createWindow(int width, int height, uint32 flags) {
- destroyWindow();
-
- if (_inputGrabState) {
- flags |= SDL_WINDOW_INPUT_GRABBED;
- }
-
- _window = SDL_CreateWindow(_windowCaption.c_str(), SDL_WINDOWPOS_UNDEFINED,
- SDL_WINDOWPOS_UNDEFINED, width, height, flags);
- if (!_window) {
- return false;
- }
- SDL_SetWindowIcon(_window, _windowIcon);
-
- return true;
-}
-
-void SdlGraphicsManager::destroyWindow() {
- SDL_DestroyWindow(_window);
- _window = nullptr;
-}
-#endif
diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h
index af7242b99e..7f8790a9b4 100644
--- a/backends/graphics/sdl/sdl-graphics.h
+++ b/backends/graphics/sdl/sdl-graphics.h
@@ -24,10 +24,9 @@
#define BACKENDS_GRAPHICS_SDL_SDLGRAPHICS_H
#include "backends/graphics/graphics.h"
+#include "backends/platform/sdl/sdl-window.h"
-#include "backends/platform/sdl/sdl-sys.h"
#include "common/rect.h"
-#include "common/str.h"
class SdlEventSource;
@@ -38,7 +37,7 @@ class SdlEventSource;
*/
class SdlGraphicsManager : virtual public GraphicsManager {
public:
- SdlGraphicsManager(SdlEventSource *source);
+ SdlGraphicsManager(SdlEventSource *source, SdlWindow *window);
virtual ~SdlGraphicsManager();
/**
@@ -94,49 +93,10 @@ 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();
-
- /**
* A (subset) of the graphic manager's state. This is used when switching
* between different SDL graphic managers on runtime.
*/
struct State {
- State();
- ~State();
-
int screenWidth, screenHeight;
bool aspectRatio;
bool fullscreen;
@@ -145,12 +105,6 @@ public:
#ifdef USE_RGB_COLOR
Graphics::PixelFormat pixelFormat;
#endif
-
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- bool inputGrabState;
- Common::String windowCaption;
- SDL_Surface *windowIcon;
-#endif
};
/**
@@ -163,19 +117,14 @@ public:
*/
bool setState(const State &state);
+ /**
+ * Queries the SDL window.
+ */
+ SdlWindow *getWindow() const { return _window; }
+
protected:
SdlEventSource *_eventSource;
-
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- SDL_Window *_window;
-
- bool createWindow(int width, int height, uint32 flags);
- void destroyWindow();
-private:
- bool _inputGrabState;
- Common::String _windowCaption;
- SDL_Surface *_windowIcon;
-#endif
+ SdlWindow *_window;
};
#endif
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index 8e349653d0..d08925349a 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -116,9 +116,9 @@ static AspectRatio getDesiredAspectRatio() {
}
#endif
-SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource)
+SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window)
:
- SdlGraphicsManager(sdlEventSource),
+ SdlGraphicsManager(sdlEventSource, window),
#ifdef USE_OSD
_osdSurface(0), _osdAlpha(SDL_ALPHA_TRANSPARENT), _osdFadeStartTime(0),
#endif
@@ -239,7 +239,7 @@ void SurfaceSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable)
break;
case OSystem::kFeatureIconifyWindow:
if (enable)
- iconifyWindow();
+ _window->iconifyWindow();
break;
default:
break;
@@ -1742,7 +1742,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 (!hasMouseFocus()) {
+ if (!_window->hasMouseFocus()) {
setMousePos(x, y); // but change game cursor position
return;
}
@@ -1752,9 +1752,9 @@ void SurfaceSdlGraphicsManager::warpMouse(int x, int y) {
if (_mouseCurState.x != x || _mouseCurState.y != y) {
if (!_overlayVisible)
- warpMouseInWindow(x * _videoMode.scaleFactor, y1 * _videoMode.scaleFactor);
+ _window->warpMouseInWindow(x * _videoMode.scaleFactor, y1 * _videoMode.scaleFactor);
else
- warpMouseInWindow(x, y1);
+ _window->warpMouseInWindow(x, y1);
// SDL_WarpMouse() generates a mouse movement event, so
// setMousePos() would be called eventually. However, the
@@ -2357,17 +2357,17 @@ void SurfaceSdlGraphicsManager::deinitializeRenderer() {
SDL_DestroyRenderer(_renderer);
_renderer = nullptr;
- destroyWindow();
+ _window->destroyWindow();
}
SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) {
deinitializeRenderer();
- if (!createWindow(width, height, (flags & SDL_FULLSCREEN) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)) {
+ if (!_window->createWindow(width, height, (flags & SDL_FULLSCREEN) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)) {
return nullptr;
}
- _renderer = SDL_CreateRenderer(_window, -1, 0);
+ _renderer = SDL_CreateRenderer(_window->getSDLWindow(), -1, 0);
if (!_renderer) {
deinitializeRenderer();
return nullptr;
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h
index c4227475c0..4ba15a304b 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.h
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h
@@ -77,7 +77,7 @@ public:
*/
class SurfaceSdlGraphicsManager : public SdlGraphicsManager, public Common::EventObserver {
public:
- SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource);
+ SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window);
virtual ~SurfaceSdlGraphicsManager();
virtual void activateManager();
diff --git a/backends/graphics/symbiansdl/symbiansdl-graphics.cpp b/backends/graphics/symbiansdl/symbiansdl-graphics.cpp
index e339fecd1c..c17cfd5efa 100644
--- a/backends/graphics/symbiansdl/symbiansdl-graphics.cpp
+++ b/backends/graphics/symbiansdl/symbiansdl-graphics.cpp
@@ -27,8 +27,8 @@
#include "backends/graphics/symbiansdl/symbiansdl-graphics.h"
#include "backends/platform/symbian/src/SymbianActions.h"
-SymbianSdlGraphicsManager::SymbianSdlGraphicsManager(SdlEventSource *sdlEventSource)
- : SurfaceSdlGraphicsManager(sdlEventSource) {
+SymbianSdlGraphicsManager::SymbianSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window)
+ : SurfaceSdlGraphicsManager(sdlEventSource, window) {
}
int SymbianSdlGraphicsManager::getDefaultGraphicsMode() const {
diff --git a/backends/graphics/symbiansdl/symbiansdl-graphics.h b/backends/graphics/symbiansdl/symbiansdl-graphics.h
index f514db286c..fb9a49a834 100644
--- a/backends/graphics/symbiansdl/symbiansdl-graphics.h
+++ b/backends/graphics/symbiansdl/symbiansdl-graphics.h
@@ -27,7 +27,7 @@
class SymbianSdlGraphicsManager : public SurfaceSdlGraphicsManager {
public:
- SymbianSdlGraphicsManager(SdlEventSource *sdlEventSource);
+ SymbianSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window);
public:
virtual bool hasFeature(OSystem::Feature f);
diff --git a/backends/graphics/wincesdl/wincesdl-graphics.cpp b/backends/graphics/wincesdl/wincesdl-graphics.cpp
index 8e4685dbd8..07f7d47262 100644
--- a/backends/graphics/wincesdl/wincesdl-graphics.cpp
+++ b/backends/graphics/wincesdl/wincesdl-graphics.cpp
@@ -42,8 +42,8 @@
#include "backends/platform/wince/CEScaler.h"
#include "backends/platform/wince/CEgui/ItemAction.h"
-WINCESdlGraphicsManager::WINCESdlGraphicsManager(SdlEventSource *sdlEventSource)
- : SurfaceSdlGraphicsManager(sdlEventSource),
+WINCESdlGraphicsManager::WINCESdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window)
+ : SurfaceSdlGraphicsManager(sdlEventSource, window),
_panelInitialized(false), _noDoubleTapRMB(false), _noDoubleTapPT(false),
_toolbarHighDrawn(false), _newOrientation(0), _orientationLandscape(0),
_panelVisible(true), _saveActiveToolbar(NAME_MAIN_PANEL), _panelStateForced(false),
diff --git a/backends/graphics/wincesdl/wincesdl-graphics.h b/backends/graphics/wincesdl/wincesdl-graphics.h
index 50b422c10d..9316c69e44 100644
--- a/backends/graphics/wincesdl/wincesdl-graphics.h
+++ b/backends/graphics/wincesdl/wincesdl-graphics.h
@@ -41,7 +41,7 @@ extern bool _hasSmartphoneResolution;
class WINCESdlGraphicsManager : public SurfaceSdlGraphicsManager {
public:
- WINCESdlGraphicsManager(SdlEventSource *sdlEventSource);
+ WINCESdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window);
const OSystem::GraphicsMode *getSupportedGraphicsModes() const;
void initSize(uint w, uint h, const Graphics::PixelFormat *format = NULL);
diff --git a/backends/platform/dingux/dingux.cpp b/backends/platform/dingux/dingux.cpp
index 2f11dd31ad..afd80acc1b 100644
--- a/backends/platform/dingux/dingux.cpp
+++ b/backends/platform/dingux/dingux.cpp
@@ -33,7 +33,7 @@ void OSystem_SDL_Dingux::initBackend() {
// Create the graphics manager
if (_graphicsManager == 0) {
- _graphicsManager = new DINGUXSdlGraphicsManager(_eventSource);
+ _graphicsManager = new DINGUXSdlGraphicsManager(_eventSource, _window);
}
// Call parent implementation of this method
diff --git a/backends/platform/gph/gph-backend.cpp b/backends/platform/gph/gph-backend.cpp
index d033191d54..fb1cbe030c 100644
--- a/backends/platform/gph/gph-backend.cpp
+++ b/backends/platform/gph/gph-backend.cpp
@@ -159,7 +159,7 @@ void OSystem_GPH::initBackend() {
// Create the graphics manager
if (_graphicsManager == 0) {
- _graphicsManager = new GPHGraphicsManager(_eventSource);
+ _graphicsManager = new GPHGraphicsManager(_eventSource, _window);
}
/* Pass to POSIX method to do the heavy lifting */
diff --git a/backends/platform/linuxmoto/linuxmoto-sdl.cpp b/backends/platform/linuxmoto/linuxmoto-sdl.cpp
index a0310079de..a2b527e6ce 100644
--- a/backends/platform/linuxmoto/linuxmoto-sdl.cpp
+++ b/backends/platform/linuxmoto/linuxmoto-sdl.cpp
@@ -31,7 +31,7 @@ void OSystem_LINUXMOTO::initBackend() {
_eventSource = new LinuxmotoSdlEventSource();
if (_graphicsManager == 0)
- _graphicsManager = new LinuxmotoSdlGraphicsManager(_eventSource);
+ _graphicsManager = new LinuxmotoSdlGraphicsManager(_eventSource, _window);
// Call parent implementation of this method
OSystem_POSIX::initBackend();
diff --git a/backends/platform/maemo/maemo.cpp b/backends/platform/maemo/maemo.cpp
index e81a208f7b..0ada9da313 100644
--- a/backends/platform/maemo/maemo.cpp
+++ b/backends/platform/maemo/maemo.cpp
@@ -93,7 +93,7 @@ void OSystem_SDL_Maemo::initBackend() {
_eventSource = new MaemoSdlEventSource();
if (_graphicsManager == 0)
- _graphicsManager = new MaemoSdlGraphicsManager(_eventSource);
+ _graphicsManager = new MaemoSdlGraphicsManager(_eventSource, _window);
if (_eventObserver == 0)
_eventObserver = new MaemoSdlEventObserver((MaemoSdlEventSource *)_eventSource);
diff --git a/backends/platform/openpandora/op-backend.cpp b/backends/platform/openpandora/op-backend.cpp
index abe288f5d7..e7975a6aa0 100644
--- a/backends/platform/openpandora/op-backend.cpp
+++ b/backends/platform/openpandora/op-backend.cpp
@@ -147,7 +147,7 @@ void OSystem_OP::initBackend() {
// Create the graphics manager
if (_graphicsManager == 0) {
- _graphicsManager = new OPGraphicsManager(_eventSource);
+ _graphicsManager = new OPGraphicsManager(_eventSource, _window);
}
/* Pass to POSIX method to do the heavy lifting */
diff --git a/backends/platform/samsungtv/samsungtv.cpp b/backends/platform/samsungtv/samsungtv.cpp
index a1d15930f2..a766916fab 100644
--- a/backends/platform/samsungtv/samsungtv.cpp
+++ b/backends/platform/samsungtv/samsungtv.cpp
@@ -40,7 +40,7 @@ void OSystem_SDL_SamsungTV::initBackend() {
_eventSource = new SamsungTVSdlEventSource();
if (_graphicsManager == 0)
- _graphicsManager = new SamsungTVSdlGraphicsManager(_eventSource);
+ _graphicsManager = new SamsungTVSdlGraphicsManager(_eventSource, _window);
// Call parent implementation of this method
OSystem_POSIX::initBackend();
diff --git a/backends/platform/sdl/module.mk b/backends/platform/sdl/module.mk
index a17a326889..6da86706c6 100644
--- a/backends/platform/sdl/module.mk
+++ b/backends/platform/sdl/module.mk
@@ -1,7 +1,8 @@
MODULE := backends/platform/sdl
MODULE_OBJS := \
- sdl.o
+ sdl.o \
+ sdl-window.o
ifdef POSIX
MODULE_OBJS += \
diff --git a/backends/platform/sdl/sdl-window.cpp b/backends/platform/sdl/sdl-window.cpp
new file mode 100644
index 0000000000..b8cf4cfb4d
--- /dev/null
+++ b/backends/platform/sdl/sdl-window.cpp
@@ -0,0 +1,155 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
+#include "backends/platform/sdl/sdl-window.h"
+
+SdlWindow::SdlWindow()
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ : _window(nullptr), _inputGrabState(false), _windowCaption("ScummVM"), _windowIcon(nullptr)
+#endif
+ {
+}
+
+SdlWindow::~SdlWindow() {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ SDL_FreeSurface(_windowIcon);
+ destroyWindow();
+#endif
+}
+
+void SdlWindow::setWindowCaption(const Common::String &caption) {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ _windowCaption = caption;
+ if (_window) {
+ SDL_SetWindowTitle(_window, caption.c_str());
+ }
+#else
+ SDL_WM_SetCaption(caption.c_str(), caption.c_str());
+#endif
+}
+
+void SdlWindow::setWindowIcon(SDL_Surface *icon) {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ SDL_FreeSurface(_windowIcon);
+ _windowIcon = icon;
+ if (_window) {
+ SDL_SetWindowIcon(_window, icon);
+ }
+#else
+ SDL_WM_SetIcon(icon, NULL);
+ SDL_FreeSurface(icon);
+#endif
+}
+
+void SdlWindow::toggleMouseGrab() {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ if (_window) {
+ _inputGrabState = !(SDL_GetWindowGrab(_window) == SDL_TRUE);
+ SDL_SetWindowGrab(_window, _inputGrabState ? SDL_TRUE : SDL_FALSE);
+ }
+#else
+ if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF) {
+ SDL_WM_GrabInput(SDL_GRAB_ON);
+ } else {
+ SDL_WM_GrabInput(SDL_GRAB_OFF);
+ }
+#endif
+}
+
+bool SdlWindow::hasMouseFocus() const {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ if (_window) {
+ return (SDL_GetWindowFlags(_window) & SDL_WINDOW_MOUSE_FOCUS);
+ } else {
+ return false;
+ }
+#else
+ return (SDL_GetAppState() & SDL_APPMOUSEFOCUS);
+#endif
+}
+
+void SdlWindow::warpMouseInWindow(uint x, uint y) {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ if (_window) {
+ SDL_WarpMouseInWindow(_window, x, y);
+ }
+#else
+ SDL_WarpMouse(x, y);
+#endif
+}
+
+void SdlWindow::iconifyWindow() {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ if (_window) {
+ SDL_MinimizeWindow(_window);
+ }
+#else
+ SDL_WM_IconifyWindow();
+#endif
+}
+
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+SDL_Surface *copySDLSurface(SDL_Surface *src) {
+ const bool locked = SDL_MUSTLOCK(src) == SDL_TRUE;
+
+ if (locked) {
+ if (SDL_LockSurface(src) != 0) {
+ return nullptr;
+ }
+ }
+
+ SDL_Surface *res = SDL_CreateRGBSurfaceFrom(src->pixels,
+ src->w, src->h, src->format->BitsPerPixel,
+ src->pitch, src->format->Rmask, src->format->Gmask,
+ src->format->Bmask, src->format->Amask);
+
+ if (locked) {
+ SDL_UnlockSurface(src);
+ }
+
+ return res;
+}
+
+bool SdlWindow::createWindow(int width, int height, uint32 flags) {
+ destroyWindow();
+
+ if (_inputGrabState) {
+ flags |= SDL_WINDOW_INPUT_GRABBED;
+ }
+
+ _window = SDL_CreateWindow(_windowCaption.c_str(), SDL_WINDOWPOS_UNDEFINED,
+ SDL_WINDOWPOS_UNDEFINED, width, height, flags);
+ if (!_window) {
+ return false;
+ }
+ SDL_SetWindowIcon(_window, _windowIcon);
+
+ return true;
+}
+
+void SdlWindow::destroyWindow() {
+ SDL_DestroyWindow(_window);
+ _window = nullptr;
+}
+#endif
diff --git a/backends/platform/sdl/sdl-window.h b/backends/platform/sdl/sdl-window.h
new file mode 100644
index 0000000000..da3dda7f2d
--- /dev/null
+++ b/backends/platform/sdl/sdl-window.h
@@ -0,0 +1,103 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef BACKENDS_PLATFORM_SDL_WINDOW_H
+#define BACKENDS_PLATFORM_SDL_WINDOW_H
+
+#include "backends/platform/sdl/sdl-sys.h"
+
+#include "common/str.h"
+
+class SdlWindow {
+public:
+ SdlWindow();
+ virtual ~SdlWindow();
+
+ /**
+ * 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();
+
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+public:
+ /**
+ * @return The window ScummVM has setup with SDL.
+ */
+ SDL_Window *getSDLWindow() const { return _window; }
+
+ /**
+ * Creates a new SDL window (and destroies the old one).
+ *
+ * @param width Width of the window.
+ * @param height Height of the window.
+ * @param flags SDL flags passed to SDL_CreateWindow
+ * @return true on success, false otherwise
+ */
+ bool createWindow(int width, int height, uint32 flags);
+
+ /**
+ * Destroies the current SDL window.
+ */
+ void destroyWindow();
+
+protected:
+ SDL_Window *_window;
+
+private:
+ bool _inputGrabState;
+ Common::String _windowCaption;
+ SDL_Surface *_windowIcon;
+#endif
+};
+
+#endif
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 434a4ce18a..7978022d6b 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -77,7 +77,8 @@ OSystem_SDL::OSystem_SDL()
_initedSDL(false),
_logger(0),
_mixerManager(0),
- _eventSource(0) {
+ _eventSource(0),
+ _window(0) {
}
@@ -95,6 +96,8 @@ OSystem_SDL::~OSystem_SDL() {
}
delete _graphicsManager;
_graphicsManager = 0;
+ delete _window;
+ _window = 0;
delete _eventManager;
_eventManager = 0;
delete _eventSource;
@@ -149,6 +152,9 @@ void OSystem_SDL::init() {
if (_mutexManager == 0)
_mutexManager = new SdlMutexManager();
+ if (_window == 0)
+ _window = new SdlWindow();
+
#if defined(USE_TASKBAR)
if (_taskbarManager == 0)
_taskbarManager = new Common::TaskbarManager();
@@ -210,7 +216,7 @@ void OSystem_SDL::initBackend() {
Common::String gfxMode(ConfMan.get("gfx_mode"));
for (uint i = _firstGLMode; i < _graphicsModeIds.size(); ++i) {
if (!scumm_stricmp(_graphicsModes[i].name, gfxMode.c_str())) {
- _graphicsManager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource);
+ _graphicsManager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource, _window);
_graphicsMode = i;
break;
}
@@ -219,7 +225,7 @@ void OSystem_SDL::initBackend() {
#endif
if (_graphicsManager == 0) {
- _graphicsManager = new SurfaceSdlGraphicsManager(_eventSource);
+ _graphicsManager = new SurfaceSdlGraphicsManager(_eventSource, _window);
}
}
@@ -328,7 +334,7 @@ void OSystem_SDL::setWindowCaption(const char *caption) {
}
}
- dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->setWindowCaption(cap);
+ _window->setWindowCaption(cap);
}
void OSystem_SDL::quit() {
@@ -491,7 +497,7 @@ void OSystem_SDL::setupIcon() {
if (!sdl_surf) {
warning("SDL_CreateRGBSurfaceFrom(icon) failed");
}
- dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->setWindowIcon(sdl_surf);
+ _window->setWindowIcon(sdl_surf);
free(icon);
}
@@ -596,14 +602,14 @@ bool OSystem_SDL::setGraphicsMode(int mode) {
debug(1, "switching to plain SDL graphics");
sdlGraphicsManager->deactivateManager();
delete _graphicsManager;
- _graphicsManager = sdlGraphicsManager = new SurfaceSdlGraphicsManager(_eventSource);
+ _graphicsManager = sdlGraphicsManager = new SurfaceSdlGraphicsManager(_eventSource, _window);
switchedManager = true;
} else if (_graphicsMode < _firstGLMode && mode >= _firstGLMode) {
debug(1, "switching to OpenGL graphics");
sdlGraphicsManager->deactivateManager();
delete _graphicsManager;
- _graphicsManager = sdlGraphicsManager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource);
+ _graphicsManager = sdlGraphicsManager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource, _window);
switchedManager = true;
}
@@ -653,7 +659,7 @@ void OSystem_SDL::setupGraphicsModes() {
const OSystem::GraphicsMode *srcMode;
int defaultMode;
- GraphicsManager *manager = new SurfaceSdlGraphicsManager(_eventSource);
+ GraphicsManager *manager = new SurfaceSdlGraphicsManager(_eventSource, _window);
srcMode = manager->getSupportedGraphicsModes();
defaultMode = manager->getDefaultGraphicsMode();
while (srcMode->name) {
@@ -667,7 +673,7 @@ void OSystem_SDL::setupGraphicsModes() {
assert(_defaultSDLMode != -1);
_firstGLMode = _graphicsModes.size();
- manager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource);
+ manager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource, _window);
srcMode = manager->getSupportedGraphicsModes();
defaultMode = manager->getDefaultGraphicsMode();
while (srcMode->name) {
diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h
index 5dcc269e55..0f07f6d18d 100644
--- a/backends/platform/sdl/sdl.h
+++ b/backends/platform/sdl/sdl.h
@@ -29,6 +29,7 @@
#include "backends/mixer/sdl/sdl-mixer.h"
#include "backends/events/sdl/sdl-events.h"
#include "backends/log/log.h"
+#include "backends/platform/sdl/sdl-window.h"
#include "common/array.h"
@@ -91,6 +92,11 @@ protected:
*/
SdlEventSource *_eventSource;
+ /**
+ * The SDL output window.
+ */
+ SdlWindow *_window;
+
virtual Common::EventSource *getDefaultEventSource() { return _eventSource; }
/**
diff --git a/backends/platform/symbian/src/SymbianOS.cpp b/backends/platform/symbian/src/SymbianOS.cpp
index 1fca7f5df5..57903d3d26 100644
--- a/backends/platform/symbian/src/SymbianOS.cpp
+++ b/backends/platform/symbian/src/SymbianOS.cpp
@@ -109,7 +109,7 @@ void OSystem_SDL_Symbian::initBackend() {
_mixerManager->init();
}
if (_graphicsManager == 0)
- _graphicsManager = new SymbianSdlGraphicsManager(_eventSource);
+ _graphicsManager = new SymbianSdlGraphicsManager(_eventSource, _window);
// Call parent implementation of this method
OSystem_SDL::initBackend();
diff --git a/backends/platform/wince/wince-sdl.cpp b/backends/platform/wince/wince-sdl.cpp
index 96c9313c5d..c1b0c7f692 100644
--- a/backends/platform/wince/wince-sdl.cpp
+++ b/backends/platform/wince/wince-sdl.cpp
@@ -420,7 +420,7 @@ void OSystem_WINCE3::initBackend() {
}
if (_graphicsManager == 0)
- _graphicsManager = new WINCESdlGraphicsManager(_eventSource);
+ _graphicsManager = new WINCESdlGraphicsManager(_eventSource, _window);
((WINCESdlEventSource *)_eventSource)->init(dynamic_cast<WINCESdlGraphicsManager *>(_graphicsManager));