From 0630a88a04e9688d664751b6a68edf622d76b348 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 8 Aug 2011 23:46:05 +0200 Subject: [PATCH] SDL: Let SDL based graphics managers inherit from SdlGraphicsManager. This also adapts port I can not test (not even the compilation). So if this breaks anything I am sorry about it. --- .../graphics/dinguxsdl/dinguxsdl-graphics.cpp | 23 +++++---- .../graphics/dinguxsdl/dinguxsdl-graphics.h | 1 + backends/graphics/gph/gph-graphics.cpp | 23 +++++---- backends/graphics/gph/gph-graphics.h | 1 + .../linuxmotosdl/linuxmotosdl-graphics.cpp | 23 +++++---- .../linuxmotosdl/linuxmotosdl-graphics.h | 1 + .../graphics/openglsdl/openglsdl-graphics.cpp | 49 ++++++++++++++++++- .../graphics/openglsdl/openglsdl-graphics.h | 13 +++-- .../surfacesdl/surfacesdl-graphics.cpp | 20 +++++++- .../graphics/surfacesdl/surfacesdl-graphics.h | 8 ++- .../graphics/wincesdl/wincesdl-graphics.cpp | 24 +++++---- .../graphics/wincesdl/wincesdl-graphics.h | 2 + backends/platform/sdl/sdl.cpp | 4 +- 13 files changed, 147 insertions(+), 45 deletions(-) diff --git a/backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp b/backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp index 8075d0d45bc9..5aa39aa9a53c 100644 --- a/backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp +++ b/backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp @@ -514,17 +514,22 @@ void DINGUXSdlGraphicsManager::adjustMouseEvent(const Common::Event &event) { if (!event.synthetic) { Common::Event newEvent(event); newEvent.synthetic = true; - if (!_overlayVisible) { - if (_videoMode.mode == GFX_HALF) { - newEvent.mouse.x *= 2; - newEvent.mouse.y *= 2; - } - newEvent.mouse.x /= _videoMode.scaleFactor; - newEvent.mouse.y /= _videoMode.scaleFactor; - if (_videoMode.aspectRatioCorrection) - newEvent.mouse.y = aspect2Real(newEvent.mouse.y); + transformMouseCoordinates(newEvent.mouse); + g_system->getEventManager()->pushEvent(newEvent); + } +} + +void DINGUXSdlGraphicsManager::transformMouseCoordinates(Common::Point &point) { + if (!_overlayVisible) { + if (_videoMode.mode == GFX_HALF) { + point.x *= 2; + point.y *= 2; } g_system->getEventManager()->pushEvent(newEvent); + point.x /= _videoMode.scaleFactor; + point.y /= _videoMode.scaleFactor; + if (_videoMode.aspectRatioCorrection) + point.y = aspect2Real(point.y); } } diff --git a/backends/graphics/dinguxsdl/dinguxsdl-graphics.h b/backends/graphics/dinguxsdl/dinguxsdl-graphics.h index 84a784b77129..468a19a3eec8 100644 --- a/backends/graphics/dinguxsdl/dinguxsdl-graphics.h +++ b/backends/graphics/dinguxsdl/dinguxsdl-graphics.h @@ -58,6 +58,7 @@ class DINGUXSdlGraphicsManager : public SurfaceSdlGraphicsManager { SurfaceSdlGraphicsManager::VideoState *getVideoMode(); virtual void adjustMouseEvent(const Common::Event &event); + virtual void transformMouseCoordinates(Common::Point &point); }; #endif /* BACKENDS_GRAPHICS_SDL_DINGUX_H */ diff --git a/backends/graphics/gph/gph-graphics.cpp b/backends/graphics/gph/gph-graphics.cpp index 82a32203fbdc..12643fbff86a 100644 --- a/backends/graphics/gph/gph-graphics.cpp +++ b/backends/graphics/gph/gph-graphics.cpp @@ -583,17 +583,22 @@ void GPHGraphicsManager::adjustMouseEvent(const Common::Event &event) { if (!event.synthetic) { Common::Event newEvent(event); newEvent.synthetic = true; - if (!_overlayVisible) { - if (_videoMode.mode == GFX_HALF) { - newEvent.mouse.x *= 2; - newEvent.mouse.y *= 2; - } - newEvent.mouse.x /= _videoMode.scaleFactor; - newEvent.mouse.y /= _videoMode.scaleFactor; - if (_videoMode.aspectRatioCorrection) - newEvent.mouse.y = aspect2Real(newEvent.mouse.y); + transformMouseCoordinates(newEvent.mouse); + g_system->getEventManager()->pushEvent(newEvent); + } +} + +void GPHGraphicsManager::transformMouseCoordinates(Common::Point &point) { + if (!_overlayVisible) { + if (_videoMode.mode == GFX_HALF) { + point.x *= 2; + point.y *= 2; } g_system->getEventManager()->pushEvent(newEvent); + point.x /= _videoMode.scaleFactor; + point.y /= _videoMode.scaleFactor; + if (_videoMode.aspectRatioCorrection) + point.y = aspect2Real(point.y); } } diff --git a/backends/graphics/gph/gph-graphics.h b/backends/graphics/gph/gph-graphics.h index 45b861856999..f7d0ce43fd9c 100644 --- a/backends/graphics/gph/gph-graphics.h +++ b/backends/graphics/gph/gph-graphics.h @@ -57,6 +57,7 @@ class GPHGraphicsManager : public SurfaceSdlGraphicsManager { SurfaceSdlGraphicsManager::VideoState *getVideoMode(); virtual void adjustMouseEvent(const Common::Event &event); + virtual void transformMouseCoordinates(Common::Point &point); }; #endif /* BACKENDS_GRAPHICS_GPH_H */ diff --git a/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp b/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp index 732074b7e26a..bf21bec3fb6f 100644 --- a/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp +++ b/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp @@ -482,17 +482,22 @@ void LinuxmotoSdlGraphicsManager::adjustMouseEvent(const Common::Event &event) { if (!event.synthetic) { Common::Event newEvent(event); newEvent.synthetic = true; - if (!_overlayVisible) { - if (_videoMode.mode == GFX_HALF) { - newEvent.mouse.x *= 2; - newEvent.mouse.y *= 2; - } - newEvent.mouse.x /= _videoMode.scaleFactor; - newEvent.mouse.y /= _videoMode.scaleFactor; - if (_videoMode.aspectRatioCorrection) - newEvent.mouse.y = aspect2Real(newEvent.mouse.y); + transformMouseCoordinates(newEvent.mouse); + g_system->getEventManager()->pushEvent(newEvent); + } +} + +void LinuxmotoSdlGraphicsManager::transformMouseCoordinates(Common::Point &point) { + if (!_overlayVisible) { + if (_videoMode.mode == GFX_HALF) { + point.x *= 2; + point.y *= 2; } g_system->getEventManager()->pushEvent(newEvent); + point.x /= _videoMode.scaleFactor; + point.y /= _videoMode.scaleFactor; + if (_videoMode.aspectRatioCorrection) + point.y = aspect2Real(point.y); } } diff --git a/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h b/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h index 938512f32395..f615018733fd 100644 --- a/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h +++ b/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h @@ -42,6 +42,7 @@ class LinuxmotoSdlGraphicsManager : public SurfaceSdlGraphicsManager { virtual void hideOverlay(); virtual void warpMouse(int x, int y); + virtual void transformMouseCoordinates(Common::Point &point); protected: virtual void adjustMouseEvent(const Common::Event &event); }; diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp index bd7dd32e3b79..8828cb5f4922 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.cpp +++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp @@ -30,8 +30,9 @@ #include "common/textconsole.h" #include "common/translation.h" -OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager() +OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(SdlEventSource *eventSource) : + SdlGraphicsManager(eventSource), _hwscreen(0), _screenResized(false), _activeFullscreenMode(-2), @@ -655,4 +656,50 @@ bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) { return OpenGLGraphicsManager::notifyEvent(event); } +void OpenGLSdlGraphicsManager::notifyVideoExpose() { +} + +void OpenGLSdlGraphicsManager::notifyResize(const uint width, const uint height) { + // Do not resize if ignoring resize events. + if (!_ignoreResizeFrames && !getFullscreenMode()) { + bool scaleChanged = false; + beginGFXTransaction(); + _videoMode.hardwareWidth = width; + _videoMode.hardwareHeight = height; + + if (_videoMode.mode != OpenGL::GFX_ORIGINAL) { + _screenResized = true; + calculateDisplaySize(_videoMode.hardwareWidth, _videoMode.hardwareHeight); + } + + int scale = MIN(_videoMode.hardwareWidth / _videoMode.screenWidth, + _videoMode.hardwareHeight / _videoMode.screenHeight); + + if (getScale() != scale) { + scaleChanged = true; + setScale(MAX(MIN(scale, 3), 1)); + } + + if (_videoMode.mode == OpenGL::GFX_ORIGINAL) { + calculateDisplaySize(_videoMode.hardwareWidth, _videoMode.hardwareHeight); + } + + _transactionDetails.sizeChanged = true; + endGFXTransaction(); +#ifdef USE_OSD + if (scaleChanged) + displayScaleChangedMsg(); +#endif + } +} + +void OpenGLSdlGraphicsManager::transformMouseCoordinates(Common::Point &point) { + adjustMousePosition(point.x, point.y); +} + +void OpenGLSdlGraphicsManager::notifyMousePos(Common::Point mouse) { + _cursorState.x = mouse.x; + _cursorState.y = mouse.y; +} + #endif diff --git a/backends/graphics/openglsdl/openglsdl-graphics.h b/backends/graphics/openglsdl/openglsdl-graphics.h index ba9f94db2d37..6cd255bbb84d 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.h +++ b/backends/graphics/openglsdl/openglsdl-graphics.h @@ -23,19 +23,20 @@ #ifndef BACKENDS_GRAPHICS_OPENGLSDL_H #define BACKENDS_GRAPHICS_OPENGLSDL_H -#include "backends/platform/sdl/sdl-sys.h" #if defined(ARRAYSIZE) && !defined(_WINDOWS_) #undef ARRAYSIZE #endif +#include "backends/platform/sdl/sdl-sys.h" +#include "backends/graphics/sdl/sdl-graphics.h" #include "backends/graphics/opengl/opengl-graphics.h" /** * SDL OpenGL graphics manager */ -class OpenGLSdlGraphicsManager : public OpenGLGraphicsManager { +class OpenGLSdlGraphicsManager : public OpenGLGraphicsManager, public SdlGraphicsManager { public: - OpenGLSdlGraphicsManager(); + OpenGLSdlGraphicsManager(SdlEventSource *eventSource); virtual ~OpenGLSdlGraphicsManager(); virtual bool hasFeature(OSystem::Feature f); @@ -49,6 +50,12 @@ class OpenGLSdlGraphicsManager : public OpenGLGraphicsManager { virtual void updateScreen(); + // SdlGraphicsManager interface + virtual void notifyVideoExpose(); + virtual void notifyResize(const uint width, const uint height); + virtual void transformMouseCoordinates(Common::Point &point); + virtual void notifyMousePos(Common::Point mouse); + protected: virtual void internUpdateScreen(); diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp index 2d41ecead42a..293fd9b188c6 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp @@ -122,7 +122,7 @@ static AspectRatio getDesiredAspectRatio() { SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource) : - _sdlEventSource(sdlEventSource), + SdlGraphicsManager(sdlEventSource), _sdlEventSource(sdlEventSource), #ifdef USE_OSD _osdSurface(0), _osdAlpha(SDL_ALPHA_TRANSPARENT), _osdFadeStartTime(0), #endif @@ -2324,4 +2324,22 @@ bool SurfaceSdlGraphicsManager::notifyEvent(const Common::Event &event) { return false; } +void SurfaceSdlGraphicsManager::notifyVideoExpose() { + _forceFull = true; +} + +void SurfaceSdlGraphicsManager::transformMouseCoordinates(Common::Point &point) { + if (!_overlayVisible) { + point.x /= _videoMode.scaleFactor; + point.y /= _videoMode.scaleFactor; + if (_videoMode.aspectRatioCorrection) + point.y = aspect2Real(point.y); + } +} + +void SurfaceSdlGraphicsManager::notifyMousePos(Common::Point mouse) { + transformMouseCoordinates(mouse); + setMousePos(mouse.x, mouse.y); +} + #endif diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h index cd8710d443c9..3de59c79be6f 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.h +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h @@ -24,6 +24,7 @@ #define BACKENDS_GRAPHICS_SURFACESDL_GRAPHICS_H #include "backends/graphics/graphics.h" +#include "backends/graphics/sdl/sdl-graphics.h" #include "graphics/pixelformat.h" #include "graphics/scaler.h" #include "common/events.h" @@ -74,7 +75,7 @@ class AspectRatio { /** * SDL graphics manager */ -class SurfaceSdlGraphicsManager : public GraphicsManager, public Common::EventObserver { +class SurfaceSdlGraphicsManager : public GraphicsManager, public SdlGraphicsManager, public Common::EventObserver { public: SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource); virtual ~SurfaceSdlGraphicsManager(); @@ -140,6 +141,11 @@ class SurfaceSdlGraphicsManager : public GraphicsManager, public Common::EventOb // Override from Common::EventObserver bool notifyEvent(const Common::Event &event); + // SdlGraphicsManager interface + virtual void notifyVideoExpose(); + virtual void transformMouseCoordinates(Common::Point &point); + virtual void notifyMousePos(Common::Point mouse); + protected: SdlEventSource *_sdlEventSource; diff --git a/backends/graphics/wincesdl/wincesdl-graphics.cpp b/backends/graphics/wincesdl/wincesdl-graphics.cpp index b1b4d4cbe722..023000d6c1e4 100644 --- a/backends/graphics/wincesdl/wincesdl-graphics.cpp +++ b/backends/graphics/wincesdl/wincesdl-graphics.cpp @@ -1162,20 +1162,24 @@ void WINCESdlGraphicsManager::adjustMouseEvent(const Common::Event &event) { if (!event.synthetic) { Common::Event newEvent(event); newEvent.synthetic = true; - /* - if (!_overlayVisible) { - newEvent.mouse.x = newEvent.mouse.x * _scaleFactorXd / _scaleFactorXm; - newEvent.mouse.y = newEvent.mouse.y * _scaleFactorYd / _scaleFactorYm; - newEvent.mouse.x /= _videoMode.scaleFactor; - newEvent.mouse.y /= _videoMode.scaleFactor; - if (_videoMode.aspectRatioCorrection) - newEvent.mouse.y = aspect2Real(newEvent.mouse.y); - } - */ + transformMouseCoordinates(newEvent.mouse); g_system->getEventManager()->pushEvent(newEvent); } } +void WINCESdlGraphicsManager::transformMouseCoordinates(Common::Point &point) { + /* + if (!_overlayVisible) { + point.x = point.x * _scaleFactorXd / _scaleFactorXm; + point.y = point.y * _scaleFactorYd / _scaleFactorYm; + point.x /= _videoMode.scaleFactor; + point.y /= _videoMode.scaleFactor; + if (_videoMode.aspectRatioCorrection) + point.y = aspect2Real(point.y); + } + */ +} + void WINCESdlGraphicsManager::setMousePos(int x, int y) { if (x != _mouseCurState.x || y != _mouseCurState.y) { undrawMouse(); diff --git a/backends/graphics/wincesdl/wincesdl-graphics.h b/backends/graphics/wincesdl/wincesdl-graphics.h index c9fc145194cd..f80a72b553d0 100644 --- a/backends/graphics/wincesdl/wincesdl-graphics.h +++ b/backends/graphics/wincesdl/wincesdl-graphics.h @@ -158,6 +158,8 @@ class WINCESdlGraphicsManager : public SurfaceSdlGraphicsManager { static zoneDesc _zones[TOTAL_ZONES]; + virtual void transformMouseCoordinates(Common::Point &point); + protected: virtual void adjustMouseEvent(const Common::Event &event); diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index e72b95bdc1d5..63871f503413 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -174,7 +174,7 @@ void OSystem_SDL::initBackend() { // If the gfx_mode is from OpenGL, create the OpenGL graphics manager if (use_opengl) { - _graphicsManager = new OpenGLSdlGraphicsManager(); + _graphicsManager = new OpenGLSdlGraphicsManager(_eventSource); graphicsManagerType = 1; } } @@ -538,7 +538,7 @@ bool OSystem_SDL::setGraphicsMode(int mode) { } else if (_graphicsMode < _sdlModesCount && mode >= _sdlModesCount) { debug(1, "switching to OpenGL graphics"); delete _graphicsManager; - _graphicsManager = new OpenGLSdlGraphicsManager(); + _graphicsManager = new OpenGLSdlGraphicsManager(_eventSource); ((OpenGLSdlGraphicsManager *)_graphicsManager)->initEventObserver(); _graphicsManager->beginGFXTransaction(); }