aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics/sdl
diff options
context:
space:
mode:
Diffstat (limited to 'backends/graphics/sdl')
-rw-r--r--backends/graphics/sdl/sdl-graphics.cpp162
-rw-r--r--backends/graphics/sdl/sdl-graphics.h67
2 files changed, 10 insertions, 219 deletions
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