diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-01-28 14:30:10 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-02-09 23:45:11 +0100 |
commit | 8aeb42b16430c85e4bc4052d881b8335d4a2ff36 (patch) | |
tree | b2c3deb9a722bcff49192578995ae7182a711cda /src/graphics.cpp | |
parent | 011f69af465085bd8555737a3297f0e070040128 (diff) | |
download | mana-8aeb42b16430c85e4bc4052d881b8335d4a2ff36.tar.gz mana-8aeb42b16430c85e4bc4052d881b8335d4a2ff36.tar.bz2 mana-8aeb42b16430c85e4bc4052d881b8335d4a2ff36.tar.xz mana-8aeb42b16430c85e4bc4052d881b8335d4a2ff36.zip |
Allow changing fullscreen resolution without restart
Unified Graphics:setFullscreen and Graphics:resize into a single
Graphics:changeVideoMode function that tries to restore the existing mode when
changing to the new mode didn't work, and exists with an error when that also
fails.
Split up handling of SDL_VIDEORESIZE and the adapting to new resolution in the
Client class, so that the second part could also be called when changing
resolution fullscreen mode.
The Video tab in the Setup window now also filters out any modes smaller than
640x480 since the game won't properly adapt to that resolution anyway.
Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src/graphics.cpp')
-rw-r--r-- | src/graphics.cpp | 67 |
1 files changed, 32 insertions, 35 deletions
diff --git a/src/graphics.cpp b/src/graphics.cpp index eb965b50..dfdef349 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -27,6 +27,8 @@ #include "resources/image.h" #include "resources/imageloader.h" +#include "utils/gettext.h" + #include <SDL_gfxBlitFunc.h> Graphics::Graphics(): @@ -53,12 +55,6 @@ bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) int displayFlags = SDL_ANYFORMAT; - mWidth = w; - mHeight = h; - mBpp = bpp; - mFullscreen = fs; - mHWAccel = hwaccel; - if (fs) displayFlags |= SDL_FULLSCREEN; else @@ -74,6 +70,12 @@ bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) if (!mTarget) return false; + mWidth = w; + mHeight = h; + mBpp = bpp; + mFullscreen = fs; + mHWAccel = hwaccel; + char videoDriverName[64]; if (SDL_VideoDriverName(videoDriverName, 64)) @@ -84,54 +86,49 @@ bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) const SDL_VideoInfo *vi = SDL_GetVideoInfo(); logger->log("Possible to create hardware surfaces: %s", - ((vi->hw_available) ? "yes" : "no")); + vi->hw_available ? "yes" : "no"); logger->log("Window manager available: %s", - ((vi->wm_available) ? "yes" : "no")); + vi->wm_available ? "yes" : "no"); logger->log("Accelerated hardware to hardware blits: %s", - ((vi->blit_hw) ? "yes" : "no")); + vi->blit_hw ? "yes" : "no"); logger->log("Accelerated hardware to hardware colorkey blits: %s", - ((vi->blit_hw_CC) ? "yes" : "no")); + vi->blit_hw_CC ? "yes" : "no"); logger->log("Accelerated hardware to hardware alpha blits: %s", - ((vi->blit_hw_A) ? "yes" : "no")); + vi->blit_hw_A ? "yes" : "no"); logger->log("Accelerated software to hardware blits: %s", - ((vi->blit_sw) ? "yes" : "no")); + vi->blit_sw ? "yes" : "no"); logger->log("Accelerated software to hardware colorkey blits: %s", - ((vi->blit_sw_CC) ? "yes" : "no")); + vi->blit_sw_CC ? "yes" : "no"); logger->log("Accelerated software to hardware alpha blits: %s", - ((vi->blit_sw_A) ? "yes" : "no")); + vi->blit_sw_A ? "yes" : "no"); logger->log("Accelerated color fills: %s", - ((vi->blit_fill) ? "yes" : "no")); + vi->blit_fill ? "yes" : "no"); logger->log("Available video memory: %d", vi->video_mem); return true; } -bool Graphics::setFullscreen(bool fs) -{ - if (mFullscreen == fs) - return true; - - return setVideoMode(mWidth, mHeight, mBpp, fs, mHWAccel); -} - -bool Graphics::resize(int width, int height) +bool Graphics::changeVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) { - if (mWidth == width && mHeight == height) + // Just return success if we're already in this mode + if (mWidth == w && + mHeight == h && + mBpp == bpp && + mFullscreen == fs && + mHWAccel == hwaccel) return true; - const int prevWidth = mWidth; - const int prevHeight = mHeight; - _endDraw(); - bool success = setVideoMode(width, height, mBpp, mFullscreen, mHWAccel); + bool success = setVideoMode(w, h, bpp, fs, hwaccel); - // If it didn't work, try to restore the previous size. If that didn't - // work either, bail out (but then we're in deep trouble). - if (!success) - { - if (!setVideoMode(prevWidth, prevHeight, mBpp, mFullscreen, mHWAccel)) - return false; + // If it didn't work, try to restore the previous mode. If that doesn't + // work either, we're in big trouble and bail out. + if (!success) { + if (!setVideoMode(mWidth, mHeight, mBpp, mFullscreen, mHWAccel)) { + logger->error(_("Failed to change video mode and couldn't " + "switch back to the previous mode!")); + } } _beginDraw(); |