Skip to content

Commit

Permalink
SDL: Add basic abstraction class for the SDL window.
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Schickel committed Feb 16, 2015
1 parent b000504 commit 627d766
Show file tree
Hide file tree
Showing 37 changed files with 353 additions and 291 deletions.
4 changes: 2 additions & 2 deletions backends/events/sdl/sdl-events.cpp
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion backends/events/symbiansdl/symbiansdl-events.cpp
Expand Up @@ -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);
}
}

Expand Down
6 changes: 3 additions & 3 deletions backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion backends/graphics/dinguxsdl/dinguxsdl-graphics.h
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions backends/graphics/gph/gph-graphics.cpp
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion backends/graphics/gph/gph-graphics.h
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions backends/graphics/maemosdl/maemosdl-graphics.cpp
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion backends/graphics/maemosdl/maemosdl-graphics.h
Expand Up @@ -29,7 +29,7 @@

class MaemoSdlGraphicsManager : public SurfaceSdlGraphicsManager {
public:
MaemoSdlGraphicsManager(SdlEventSource *sdlEventSource);
MaemoSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window);

protected:
virtual bool loadGFXMode();
Expand Down
26 changes: 13 additions & 13 deletions backends/graphics/openglsdl/openglsdl-graphics.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -134,7 +134,7 @@ void OpenGLSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable)

case OSystem::kFeatureIconifyWindow:
if (enable) {
iconifyWindow();
_window->iconifyWindow();
}
break;

Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -362,7 +362,7 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
_glContext = nullptr;
}

destroyWindow();
_window->destroyWindow();

uint32 flags = SDL_WINDOW_OPENGL;
if (_wantsFullScreen) {
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion backends/graphics/openglsdl/openglsdl-graphics.h
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions backends/graphics/openpandora/op-graphics.cpp
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion backends/graphics/openpandora/op-graphics.h
Expand Up @@ -32,7 +32,7 @@ enum {

class OPGraphicsManager : public SurfaceSdlGraphicsManager {
public:
OPGraphicsManager(SdlEventSource *sdlEventSource);
OPGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window);

bool loadGFXMode();
void unloadGFXMode();
Expand Down
4 changes: 2 additions & 2 deletions backends/graphics/samsungtvsdl/samsungtvsdl-graphics.cpp
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion backends/graphics/samsungtvsdl/samsungtvsdl-graphics.h
Expand Up @@ -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);
Expand Down

0 comments on commit 627d766

Please sign in to comment.