summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjurkan <jurkan@gmx.de>2012-07-10 21:33:59 +0200
committerjurkan <jurkan@gmx.de>2012-07-15 22:46:24 +0200
commit3fcc5566baf8ee329f24b7e884f604ce470dcfdd (patch)
treeb0ec5d4e1eaa552bb8dc097afb4090c5f4d34596
parent353a4bb01c7050273007527b33afc76d25d6cc71 (diff)
downloadmana-client-3fcc5566baf8ee329f24b7e884f604ce470dcfdd.tar.gz
mana-client-3fcc5566baf8ee329f24b7e884f604ce470dcfdd.tar.bz2
mana-client-3fcc5566baf8ee329f24b7e884f604ce470dcfdd.tar.xz
mana-client-3fcc5566baf8ee329f24b7e884f604ce470dcfdd.zip
Implemented client scaling in SDL mode
-rw-r--r--src/client.cpp3
-rw-r--r--src/graphics.cpp56
-rw-r--r--src/graphics.h5
3 files changed, 48 insertions, 16 deletions
diff --git a/src/client.cpp b/src/client.cpp
index ce29f1b1..fec41f5e 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -1399,9 +1399,6 @@ void Client::handleVideoResize(int width, int height)
width = std::max(640, width);
height = std::max(360, height);
- if (graphics->getWidth() == width && graphics->getHeight() == height)
- return;
-
if (graphics->changeVideoMode(width,
height,
graphics->getBpp(),
diff --git a/src/graphics.cpp b/src/graphics.cpp
index d4b6778c..553f33ab 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -30,6 +30,7 @@
#include "utils/gettext.h"
#include <SDL_gfxBlitFunc.h>
+#include <SDL/SDL_rotozoom.h>
Graphics::Graphics():
mWidth(0),
@@ -38,8 +39,10 @@ Graphics::Graphics():
mBpp(0),
mFullscreen(false),
mHWAccel(false),
- mBlitMode(BLIT_NORMAL)
+ mBlitMode(BLIT_NORMAL),
+ mScreenSurface(0)
{
+ mTarget = 0;
}
Graphics::~Graphics()
@@ -66,13 +69,22 @@ bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel)
else
displayFlags |= SDL_SWSURFACE;
- setTarget(SDL_SetVideoMode(w, h, bpp, displayFlags));
+ SDL_FreeSurface(mTarget);
+ mTarget = 0;
+
+ mScreenSurface = SDL_SetVideoMode(w, h, bpp, displayFlags);
+ const SDL_PixelFormat& fmt = *(mScreenSurface->format);
+ setTarget(SDL_CreateRGBSurface(SDL_SWSURFACE, 640, 360, fmt.BitsPerPixel, fmt.Rmask, fmt.Gmask, fmt.Bmask, 0));
if (!mTarget)
return false;
- mWidth = w;
- mHeight = h;
+ mWidth = 640;
+ mHeight = 360;
+
+ // Calculate scaling factor
+ mScale = std::min(w / 640, h / 360);
+
mBpp = bpp;
mFullscreen = fs;
mHWAccel = hwaccel;
@@ -112,8 +124,8 @@ bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel)
bool Graphics::changeVideoMode(int w, int h, int bpp, bool fs, bool hwaccel)
{
// Just return success if we're already in this mode
- if (mWidth == w &&
- mHeight == h &&
+ if (mScreenSurface && mScreenSurface->w == w &&
+ mScreenSurface->h == h &&
mBpp == bpp &&
mFullscreen == fs &&
mHWAccel == hwaccel)
@@ -123,12 +135,14 @@ bool Graphics::changeVideoMode(int w, int h, int bpp, bool fs, bool hwaccel)
bool success = setVideoMode(w, h, bpp, fs, hwaccel);
- // If it didn't work, try to restore the previous mode. If that doesn't
+ // If it didn't work, try to restore fallback resolution. If that doesn't
// work either, we're in big trouble and bail out.
- if (!success) {
- if (!setVideoMode(mWidth, mHeight, mBpp, mFullscreen, mHWAccel)) {
+ if (!success)
+ {
+ if (!setVideoMode(640, 360, mBpp, mFullscreen, mHWAccel))
+ {
logger->error(_("Failed to change video mode and couldn't "
- "switch back to the previous mode!"));
+ "switch back to the fallback mode!"));
}
}
@@ -362,7 +376,27 @@ void Graphics::drawImageRect(int x, int y, int w, int h,
void Graphics::updateScreen()
{
- SDL_Flip(mTarget);
+ // Center viewport
+ SDL_Rect dstRect;
+ dstRect.x = (mScreenSurface->w-getWidth() * mScale) / 2;
+ dstRect.y = (mScreenSurface->h-getHeight() * mScale) / 2;
+
+ // Zoom in if necessary
+ if (mScale > 1)
+ {
+ SDL_Surface *tmp = zoomSurface(mTarget, mScale, mScale, 0);
+
+ // Copy temporary surface to screen
+ SDL_BlitSurface(tmp, NULL, mScreenSurface, &dstRect);
+ SDL_FreeSurface(tmp);
+ }
+ else
+ {
+ // Copy mTarget directly to screen
+ SDL_BlitSurface(mTarget, NULL, mScreenSurface, &dstRect);
+ }
+
+ SDL_Flip(mScreenSurface);
}
SDL_Surface *Graphics::getScreenshot()
diff --git a/src/graphics.h b/src/graphics.h
index 2e23b382..cffdb143 100644
--- a/src/graphics.h
+++ b/src/graphics.h
@@ -195,12 +195,12 @@ class Graphics : public gcn::SDLGraphics
virtual void updateScreen();
/**
- * Returns the width of the screen.
+ * Returns the width of the drawable surface.
*/
int getWidth() const { return mWidth; }
/**
- * Returns the height of the screen.
+ * Returns the height of the drawable surface.
*/
int getHeight() const { return mHeight; }
@@ -241,6 +241,7 @@ class Graphics : public gcn::SDLGraphics
bool mFullscreen;
bool mHWAccel;
BlitMode mBlitMode;
+ SDL_Surface *mScreenSurface;
};
extern Graphics *graphics;