Skip to content

Commit

Permalink
SDL: Let SDL based graphics managers inherit from SdlGraphicsManager.
Browse files Browse the repository at this point in the history
This also adapts port I can not test (not even the compilation). So if this
breaks anything I am sorry about it.
  • Loading branch information
Johannes Schickel committed Aug 8, 2011
1 parent dedc74a commit 0630a88
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 45 deletions.
23 changes: 14 additions & 9 deletions backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp
Expand Up @@ -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);
}
}

Expand Down
1 change: 1 addition & 0 deletions backends/graphics/dinguxsdl/dinguxsdl-graphics.h
Expand Up @@ -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 */
23 changes: 14 additions & 9 deletions backends/graphics/gph/gph-graphics.cpp
Expand Up @@ -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);
}
}

Expand Down
1 change: 1 addition & 0 deletions backends/graphics/gph/gph-graphics.h
Expand Up @@ -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 */
23 changes: 14 additions & 9 deletions backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp
Expand Up @@ -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);
}
}

Expand Down
1 change: 1 addition & 0 deletions backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h
Expand Up @@ -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);
};
Expand Down
49 changes: 48 additions & 1 deletion backends/graphics/openglsdl/openglsdl-graphics.cpp
Expand Up @@ -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),
Expand Down Expand Up @@ -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
13 changes: 10 additions & 3 deletions backends/graphics/openglsdl/openglsdl-graphics.h
Expand Up @@ -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);
Expand All @@ -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();

Expand Down
20 changes: 19 additions & 1 deletion backends/graphics/surfacesdl/surfacesdl-graphics.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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
8 changes: 7 additions & 1 deletion backends/graphics/surfacesdl/surfacesdl-graphics.h
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down
24 changes: 14 additions & 10 deletions backends/graphics/wincesdl/wincesdl-graphics.cpp
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions backends/graphics/wincesdl/wincesdl-graphics.h
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions backends/platform/sdl/sdl.cpp
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 0630a88

Please sign in to comment.