From 8292b80eac900ec5dd75d184063b7b35934e800a Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sat, 21 Jan 2012 12:30:36 +0100 Subject: Allow resizing of the game in windowed mode Window positions are semi-smartly corrected as a result of the resize. Not supported when using OpenGL on Windows for now. Reviewed-by: Yohann Ferreira Conflicts: src/client.cpp src/client.h src/game.cpp src/gui/gui.cpp src/gui/widgets/window.cpp --- src/graphics.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/graphics.cpp') diff --git a/src/graphics.cpp b/src/graphics.cpp index bbd398aa5..46433639e 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -76,6 +76,8 @@ bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) if (fs) displayFlags |= SDL_FULLSCREEN; + else + displayFlags |= SDL_RESIZABLE; if (hwaccel) displayFlags |= SDL_HWSURFACE | SDL_DOUBLEBUF; @@ -141,6 +143,31 @@ bool Graphics::setFullscreen(bool fs) return setVideoMode(mWidth, mHeight, mBpp, fs, mHWAccel); } +bool Graphics::resize(int width, int height) +{ + if (mWidth == width && mHeight == height) + return true; + + const int prevWidth = mWidth; + const int prevHeight = mHeight; + + _endDraw(); + + bool success = setVideoMode(width, height, mBpp, mFullscreen, mHWAccel); + + // 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; + } + + _beginDraw(); + + return success; +} + int Graphics::getWidth() const { return mWidth; -- cgit v1.2.3-60-g2f50