diff options
author | Alejandro Marzini | 2010-07-19 05:36:10 +0000 |
---|---|---|
committer | Alejandro Marzini | 2010-07-19 05:36:10 +0000 |
commit | 6f70a303bcda770b831e4d22b119f814d2a3a29d (patch) | |
tree | 9d0652a2708a2cc192221967c47d5172e390b8d8 /backends | |
parent | 38b4098f676cd222ba6c5f638d3a6a61974d5f88 (diff) | |
download | scummvm-rg350-6f70a303bcda770b831e4d22b119f814d2a3a29d.tar.gz scummvm-rg350-6f70a303bcda770b831e4d22b119f814d2a3a29d.tar.bz2 scummvm-rg350-6f70a303bcda770b831e4d22b119f814d2a3a29d.zip |
OPENGL: Add basic scaler handle.
svn-id: r51016
Diffstat (limited to 'backends')
-rw-r--r-- | backends/graphics/opengl/opengl-graphics.cpp | 20 | ||||
-rw-r--r-- | backends/graphics/opengl/opengl-graphics.h | 10 | ||||
-rw-r--r-- | backends/graphics/openglsdl/openglsdl-graphics.cpp | 126 | ||||
-rw-r--r-- | backends/graphics/openglsdl/openglsdl-graphics.h | 8 |
4 files changed, 162 insertions, 2 deletions
diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index e2b541bef8..54be9c408c 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -555,7 +555,7 @@ void OpenGLGraphicsManager::internUpdateScreen() { } } -bool OpenGLGraphicsManager::loadGFXMode() { +void OpenGLGraphicsManager::initGL() { // Check available GL Extensions GLTexture::initGLExtensions(); @@ -583,6 +583,10 @@ bool OpenGLGraphicsManager::loadGFXMode() { CHECK_GL_ERROR( glOrtho(0, _videoMode.hardwareWidth, _videoMode.hardwareHeight, 0, -1, 1) ); CHECK_GL_ERROR( glMatrixMode(GL_MODELVIEW) ); CHECK_GL_ERROR( glLoadIdentity() ); +} + +bool OpenGLGraphicsManager::loadGFXMode() { + initGL(); if (!_gameTexture) { byte bpp; @@ -622,6 +626,15 @@ bool OpenGLGraphicsManager::hotswapGFXMode() { return false; } +void OpenGLGraphicsManager::setScale(int newScale) { + if (newScale == _videoMode.scaleFactor) + return; + + _videoMode.scaleFactor = newScale; + + _transactionDetails.sizeChanged = true; +} + void OpenGLGraphicsManager::adjustMouseEvent(const Common::Event &event) { if (!event.synthetic) { Common::Event newEvent(event); @@ -651,6 +664,7 @@ bool OpenGLGraphicsManager::notifyEvent(const Common::Event &event) { case Common::EVENT_MBUTTONUP: adjustMouseEvent(event); return !event.synthetic; + default: break; } @@ -658,4 +672,8 @@ bool OpenGLGraphicsManager::notifyEvent(const Common::Event &event) { return false; } +bool OpenGLGraphicsManager::saveScreenshot(const char *filename) { + return false; +} + #endif diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index 3da501f933..d76e328d07 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -100,6 +100,9 @@ public: bool notifyEvent(const Common::Event &event); protected: + + virtual void initGL(); + // // GFX and video // @@ -146,6 +149,8 @@ protected: virtual void unloadGFXMode(); virtual bool hotswapGFXMode(); + virtual void setScale(int newScale); + // // Game screen // @@ -213,6 +218,11 @@ protected: virtual void refreshCursor(); virtual void adjustMouseEvent(const Common::Event &event); virtual void setMousePos(int x, int y); + + // + // Misc + // + virtual bool saveScreenshot(const char *filename); }; #endif diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp index 99468b1447..938eaaf4c3 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.cpp +++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp @@ -26,6 +26,7 @@ #ifdef USE_OPENGL #include "backends/graphics/openglsdl/openglsdl-graphics.h" +#include "backends/platform/sdl/sdl.h" OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager() : @@ -135,7 +136,7 @@ bool OpenGLSdlGraphicsManager::loadGFXMode() { SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); _hwscreen = SDL_SetVideoMode(_videoMode.hardwareWidth, _videoMode.hardwareHeight, 32, - _videoMode.fullscreen ? (SDL_FULLSCREEN | SDL_OPENGL) : SDL_OPENGL + _videoMode.fullscreen ? (SDL_FULLSCREEN | SDL_OPENGL) : (SDL_OPENGL | SDL_RESIZABLE) ); if (_hwscreen == NULL) { // DON'T use error(), as this tries to bring up the debug @@ -169,4 +170,127 @@ void OpenGLSdlGraphicsManager::internUpdateScreen() { SDL_GL_SwapBuffers(); } +bool OpenGLSdlGraphicsManager::handleScalerHotkeys(Common::KeyCode key) { + + // Ctrl-Alt-a toggles aspect ratio correction + /*if (key == 'a') { + beginGFXTransaction(); + setFeatureState(OSystem::kFeatureAspectRatioCorrection, !_videoMode.aspectRatioCorrection); + endGFXTransaction(); +#ifdef USE_OSD + char buffer[128]; + if (_videoMode.aspectRatioCorrection) + sprintf(buffer, "Enabled aspect ratio correction\n%d x %d -> %d x %d", + _videoMode.screenWidth, _videoMode.screenHeight, + _hwscreen->w, _hwscreen->h + ); + else + sprintf(buffer, "Disabled aspect ratio correction\n%d x %d -> %d x %d", + _videoMode.screenWidth, _videoMode.screenHeight, + _hwscreen->w, _hwscreen->h + ); + displayMessageOnOSD(buffer); +#endif + internUpdateScreen(); + return true; + }*/ + + SDLKey sdlKey = (SDLKey)key; + + // Increase/decrease the scale factor + if (sdlKey == SDLK_EQUALS || sdlKey == SDLK_PLUS || sdlKey == SDLK_MINUS || + sdlKey == SDLK_KP_PLUS || sdlKey == SDLK_KP_MINUS) { + int factor = _videoMode.scaleFactor; + factor += (sdlKey == SDLK_MINUS || sdlKey == SDLK_KP_MINUS) ? -1 : +1; + if (0 < factor && factor < 4) { + beginGFXTransaction(); + setScale(factor); + endGFXTransaction(); + } + } + return false; +} + +void OpenGLSdlGraphicsManager::setFullscreenMode(bool enable) { + +} + +bool OpenGLSdlGraphicsManager::isScalerHotkey(const Common::Event &event) { + if ((event.kbd.flags & (Common::KBD_CTRL|Common::KBD_ALT)) == (Common::KBD_CTRL|Common::KBD_ALT)) { + const bool isScaleKey = (event.kbd.keycode == Common::KEYCODE_EQUALS || event.kbd.keycode == Common::KEYCODE_PLUS || event.kbd.keycode == Common::KEYCODE_MINUS || + event.kbd.keycode == Common::KEYCODE_KP_PLUS || event.kbd.keycode == Common::KEYCODE_KP_MINUS); + + return (isScaleKey || event.kbd.keycode == 'a'); + } + return false; +} + +void OpenGLSdlGraphicsManager::toggleFullScreen() { + beginGFXTransaction(); + setFullscreenMode(!_videoMode.fullscreen); + endGFXTransaction(); +#ifdef USE_OSD + if (_videoMode.fullscreen) + displayMessageOnOSD("Fullscreen mode"); + else + displayMessageOnOSD("Windowed mode"); +#endif +} + +bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) { + switch ((int)event.type) { + case Common::EVENT_KEYDOWN: + // Alt-Return and Alt-Enter toggle full screen mode + if (event.kbd.hasFlags(Common::KBD_ALT) && + (event.kbd.keycode == Common::KEYCODE_RETURN || + event.kbd.keycode == (Common::KeyCode)SDLK_KP_ENTER)) { + toggleFullScreen(); + return true; + } + + // Alt-S: Create a screenshot + if (event.kbd.hasFlags(Common::KBD_ALT) && event.kbd.keycode == 's') { + char filename[20]; + + for (int n = 0;; n++) { + SDL_RWops *file; + + sprintf(filename, "scummvm%05d.bmp", n); + file = SDL_RWFromFile(filename, "r"); + if (!file) + break; + SDL_RWclose(file); + } + if (saveScreenshot(filename)) + printf("Saved '%s'\n", filename); + else + printf("Could not save screenshot!\n"); + return true; + } + + // Ctrl-Alt-<key> will change the GFX mode + if ((event.kbd.flags & (Common::KBD_CTRL|Common::KBD_ALT)) == (Common::KBD_CTRL|Common::KBD_ALT)) { + if (handleScalerHotkeys(event.kbd.keycode)) + return true; + } + case Common::EVENT_KEYUP: + return isScalerHotkey(event); + /*case OSystem_SDL::kSdlEventExpose: + break;*/ + // HACK: Handle special SDL event + case OSystem_SDL::kSdlEventResize: + _videoMode.overlayWidth = event.mouse.x; + _videoMode.overlayHeight = event.mouse.y; + _videoMode.hardwareWidth = event.mouse.x; + _videoMode.hardwareHeight = event.mouse.y; + initGL(); + return true; + + default: + break; + } + + return OpenGLGraphicsManager::notifyEvent(event); +} + #endif diff --git a/backends/graphics/openglsdl/openglsdl-graphics.h b/backends/graphics/openglsdl/openglsdl-graphics.h index f1f0d5ff37..4937e33eef 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.h +++ b/backends/graphics/openglsdl/openglsdl-graphics.h @@ -48,6 +48,8 @@ public: virtual void warpMouse(int x, int y); + virtual bool notifyEvent(const Common::Event &event); + protected: virtual void internUpdateScreen(); @@ -55,6 +57,12 @@ protected: virtual void unloadGFXMode(); virtual bool hotswapGFXMode(); + virtual void setFullscreenMode(bool enable); + + virtual bool handleScalerHotkeys(Common::KeyCode key); + virtual bool isScalerHotkey(const Common::Event &event); + virtual void toggleFullScreen(); + // Hardware screen SDL_Surface *_hwscreen; }; |