aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics
diff options
context:
space:
mode:
authorAlejandro Marzini2010-06-07 03:14:42 +0000
committerAlejandro Marzini2010-06-07 03:14:42 +0000
commit280c18f96e3453279c45a00ba5a31733502adc84 (patch)
tree17af3b0f2827223ee696bc35bc33a669cfc30937 /backends/graphics
parenteee8e6960eda0226b8851ae81fa4ead41c61c1b1 (diff)
downloadscummvm-rg350-280c18f96e3453279c45a00ba5a31733502adc84.tar.gz
scummvm-rg350-280c18f96e3453279c45a00ba5a31733502adc84.tar.bz2
scummvm-rg350-280c18f96e3453279c45a00ba5a31733502adc84.zip
Added constructor, destructor. Made some variables and methods public. Removed toggleMouseGrab (now in events). Added feature methods. Fixed missing code for displayMessageOnOSD.
svn-id: r49472
Diffstat (limited to 'backends/graphics')
-rw-r--r--backends/graphics/sdl/sdl-graphics.cpp155
-rw-r--r--backends/graphics/sdl/sdl-graphics.h39
2 files changed, 171 insertions, 23 deletions
diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp
index 3a45255786..295448811d 100644
--- a/backends/graphics/sdl/sdl-graphics.cpp
+++ b/backends/graphics/sdl/sdl-graphics.cpp
@@ -24,6 +24,7 @@
*/
#include "backends/graphics/sdl/sdl-graphics.h"
+#include "common/config-manager.h"
#include "common/mutex.h"
#include "common/util.h"
#ifdef USE_RGB_COLOR
@@ -85,6 +86,150 @@ static const int s_gfxModeSwitchTable[][4] = {
static int cursorStretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY);
#endif
+AspectRatio::AspectRatio(int w, int h) {
+ // TODO : Validation and so on...
+ // Currently, we just ensure the program don't instantiate non-supported aspect ratios
+ _kw = w;
+ _kh = h;
+}
+
+#if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) && defined(USE_SCALERS)
+static const size_t AR_COUNT = 4;
+static const char* desiredAspectRatioAsStrings[AR_COUNT] = { "auto", "4/3", "16/9", "16/10" };
+static const AspectRatio desiredAspectRatios[AR_COUNT] = { AspectRatio(0, 0), AspectRatio(4,3), AspectRatio(16,9), AspectRatio(16,10) };
+
+static AspectRatio getDesiredAspectRatio() {
+ //TODO : We could parse an arbitrary string, if we code enough proper validation
+ Common::String desiredAspectRatio = ConfMan.get("desired_screen_aspect_ratio");
+
+ for (size_t i = 0; i < AR_COUNT; i++) {
+ assert(desiredAspectRatioAsStrings[i] != NULL);
+
+ if (!scumm_stricmp(desiredAspectRatio.c_str(), desiredAspectRatioAsStrings[i])) {
+ return desiredAspectRatios[i];
+ }
+ }
+ // TODO : Report a warning
+ return AspectRatio(0, 0);
+}
+#endif
+
+SdlGraphicsManager::SdlGraphicsManager()
+ :
+#ifdef USE_OSD
+ _osdSurface(0), _osdAlpha(SDL_ALPHA_TRANSPARENT), _osdFadeStartTime(0),
+#endif
+ _hwscreen(0), _screen(0), _tmpscreen(0),
+#ifdef USE_RGB_COLOR
+ _screenFormat(Graphics::PixelFormat::createFormatCLUT8()),
+ _cursorFormat(Graphics::PixelFormat::createFormatCLUT8()),
+#endif
+ _overlayVisible(false),
+ _overlayscreen(0), _tmpscreen2(0),
+ _scalerProc(0), _modeChanged(false), _screenChangeCount(0),
+ _mouseVisible(false), _mouseNeedsRedraw(false), _mouseData(0), _mouseSurface(0),
+ _mouseOrigSurface(0), _cursorTargetScale(1), _cursorPaletteDisabled(true),
+ _currentShakePos(0), _newShakePos(0),
+ _paletteDirtyStart(0), _paletteDirtyEnd(0),
+ _screenIsLocked(false),
+ _graphicsMutex(0), _transactionMode(kTransactionNone) {
+
+ if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) {
+ error("Could not initialize SDL: %s", SDL_GetError());
+ }
+
+ // allocate palette storage
+ _currentPalette = (SDL_Color *)calloc(sizeof(SDL_Color), 256);
+ _cursorPalette = (SDL_Color *)calloc(sizeof(SDL_Color), 256);
+
+ _mouseBackup.x = _mouseBackup.y = _mouseBackup.w = _mouseBackup.h = 0;
+
+ memset(&_mouseCurState, 0, sizeof(_mouseCurState));
+
+ _graphicsMutex = g_system->createMutex();
+
+#ifdef _WIN32_WCE
+ if (ConfMan.hasKey("use_GDI") && ConfMan.getBool("use_GDI")) {
+ SDL_VideoInit("windib", 0);
+ sdlFlags ^= SDL_INIT_VIDEO;
+ }
+#endif
+
+ SDL_ShowCursor(SDL_DISABLE);
+
+ memset(&_oldVideoMode, 0, sizeof(_oldVideoMode));
+ memset(&_videoMode, 0, sizeof(_videoMode));
+ memset(&_transactionDetails, 0, sizeof(_transactionDetails));
+
+#if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) && defined(USE_SCALERS)
+ _videoMode.mode = GFX_DOUBLESIZE;
+ _videoMode.scaleFactor = 2;
+ _videoMode.aspectRatioCorrection = ConfMan.getBool("aspect_ratio");
+ _videoMode.desiredAspectRatio = getDesiredAspectRatio();
+ _scalerProc = Normal2x;
+#else // for small screen platforms
+ _videoMode.mode = GFX_NORMAL;
+ _videoMode.scaleFactor = 1;
+ _videoMode.aspectRatioCorrection = false;
+ _scalerProc = Normal1x;
+#endif
+ _scalerType = 0;
+
+#if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
+ _videoMode.fullscreen = ConfMan.getBool("fullscreen");
+#else
+ _videoMode.fullscreen = true;
+#endif
+}
+
+SdlGraphicsManager::~SdlGraphicsManager() {
+ unloadGFXMode();
+ g_system->deleteMutex(_graphicsMutex);
+
+ free(_currentPalette);
+ free(_cursorPalette);
+ free(_mouseData);
+}
+
+bool SdlGraphicsManager::hasFeature(OSystem::Feature f) {
+ return
+ (f == OSystem::kFeatureFullscreenMode) ||
+ (f == OSystem::kFeatureAspectRatioCorrection) ||
+ (f == OSystem::kFeatureAutoComputeDirtyRects) ||
+ (f == OSystem::kFeatureCursorHasPalette) ||
+ (f == OSystem::kFeatureIconifyWindow);
+}
+
+void SdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable) {
+ switch (f) {
+ case OSystem::kFeatureFullscreenMode:
+ setFullscreenMode(enable);
+ break;
+ case OSystem::kFeatureAspectRatioCorrection:
+ setAspectRatioCorrection(enable);
+ break;
+ case OSystem::kFeatureIconifyWindow:
+ if (enable)
+ SDL_WM_IconifyWindow();
+ break;
+ default:
+ break;
+ }
+}
+
+bool SdlGraphicsManager::getFeatureState(OSystem::Feature f) {
+ assert (_transactionMode == kTransactionNone);
+
+ switch (f) {
+ case OSystem::kFeatureFullscreenMode:
+ return _videoMode.fullscreen;
+ case OSystem::kFeatureAspectRatioCorrection:
+ return _videoMode.aspectRatioCorrection;
+ default:
+ return false;
+ }
+}
+
const OSystem::GraphicsMode *SdlGraphicsManager::getSupportedGraphicsModes() const {
return s_supportedGraphicsModes;
}
@@ -1645,14 +1790,6 @@ static int cursorStretch200To240(uint8 *buf, uint32 pitch, int width, int height
}
#endif
-// Move to events
-/*void SdlGraphicsManager::toggleMouseGrab() {
- if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF)
- SDL_WM_GrabInput(SDL_GRAB_ON);
- else
- SDL_WM_GrabInput(SDL_GRAB_OFF);
-}*/
-
void SdlGraphicsManager::undrawMouse() {
const int x = _mouseBackup.x;
const int y = _mouseBackup.y;
@@ -1883,7 +2020,7 @@ bool SdlGraphicsManager::handleScalerHotkeys(const SDL_KeyboardEvent &key) {
#ifdef USE_OSD
if (_osdSurface) {
const char *newScalerName = 0;
- const GraphicsMode *g = getSupportedGraphicsModes();
+ const OSystem::GraphicsMode *g = getSupportedGraphicsModes();
while (g->name) {
if (g->id == _videoMode.mode) {
newScalerName = g->description;
diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h
index 9310eb3d8c..13ce5af5dc 100644
--- a/backends/graphics/sdl/sdl-graphics.h
+++ b/backends/graphics/sdl/sdl-graphics.h
@@ -36,6 +36,11 @@
#include <SDL.h>
#endif
+#if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
+// Uncomment this to enable the 'on screen display' code.
+#define USE_OSD 1
+#endif
+
enum {
GFX_NORMAL = 0,
GFX_DOUBLESIZE = 1,
@@ -68,14 +73,13 @@ public:
SdlGraphicsManager();
~SdlGraphicsManager();
- bool hasGraphicsFeature(OSystem::Feature f);
- void setGraphicsFeatureState(OSystem::Feature f, bool enable);
- bool getGraphicsFeatureState(OSystem::Feature f);
+ bool hasFeature(OSystem::Feature f);
+ void setFeatureState(OSystem::Feature f, bool enable);
+ bool getFeatureState(OSystem::Feature f);
const OSystem::GraphicsMode *getSupportedGraphicsModes() const;
int getDefaultGraphicsMode() const;
bool setGraphicsMode(int mode);
- bool setGraphicsMode(const char *name);
int getGraphicsMode() const;
#ifdef USE_RGB_COLOR
@@ -116,6 +120,23 @@ public:
}
virtual int getScreenChangeID() const { return _screenChangeCount; }
+#ifdef USE_OSD
+ void displayMessageOnOSD(const char *msg);
+#endif
+
+ // Accessed from OSystem_SDL::pollEvent for EVENT_SCREEN_CHANGED
+ // The way this event works should be changed
+ bool _modeChanged;
+
+ // Accessed from OSystem_SDL::dispatchSDLEvent
+ // A function here for toggling it should be made for this
+ bool _forceFull;
+
+ bool handleScalerHotkeys(const SDL_KeyboardEvent &key); // Move this?
+ bool isScalerHotkey(const Common::Event &event); // Move this?
+
+ void setMousePos(int x, int y);
+
protected:
#ifdef USE_OSD
SDL_Surface *_osdSurface;
@@ -187,7 +208,6 @@ protected:
virtual void setGraphicsModeIntern(); // overloaded by CE backend
/** Force full redraw on next updateScreen */
- bool _forceFull;
ScalerProc *_scalerProc;
int _scalerType;
int _transactionMode;
@@ -195,8 +215,6 @@ protected:
bool _screenIsLocked;
Graphics::Surface _framebuffer;
- /** Current video mode flags (see DF_* constants) */
- bool _modeChanged;
int _screenChangeCount;
enum {
@@ -208,8 +226,6 @@ protected:
SDL_Rect _dirtyRectList[NUM_DIRTY_RECT];
int _numDirtyRects;
- void setMousePos(int x, int y);
-
struct MousePos {
// The mouse position, using either virtual (game) or real
// (overlay) coordinates.
@@ -288,11 +304,6 @@ protected:
virtual bool saveScreenshot(const char *filename); // overloaded by CE backend
int effectiveScreenHeight() const;
-
- void setupIcon();
-
- bool handleScalerHotkeys(const SDL_KeyboardEvent &key); // Move to events?
- bool isScalerHotkey(const Common::Event &event); // Move to events?
};