summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjurkan <jurkan@gmx.de>2012-03-09 23:31:51 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-03-18 20:44:26 +0100
commit054246ebffcdd20da72a8e464b40eaf64d484743 (patch)
tree88ce8873a9228dd2e16516304d2c23ca56d201f0
parent3ce3e5876c69495bfa5a7f7d326a3ff849f2f1f5 (diff)
downloadmana-054246ebffcdd20da72a8e464b40eaf64d484743.tar.gz
mana-054246ebffcdd20da72a8e464b40eaf64d484743.tar.bz2
mana-054246ebffcdd20da72a8e464b40eaf64d484743.tar.xz
mana-054246ebffcdd20da72a8e464b40eaf64d484743.zip
Fixed issues with rendering very small maps
Added a black background for maps that are smaller than the screen resolution and centered them on screen. Reviewed-by: Thorbjørn Lindeijer Mantis-issue: 193
-rw-r--r--src/gui/viewport.cpp62
1 files changed, 38 insertions, 24 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index fd6bc6a3..1b5b00c3 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -97,8 +97,12 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
{
static int lastTick = tick_time;
+ // Check whether map was successfully loaded since
+ // the rest of this function relies on it
if (!mMap || !local_player)
{
+ // Render unicolor background to avoid
+ // rendering issues
gcnGraphics->setColor(gcn::Color(64, 64, 64));
gcnGraphics->fillRectangle(
gcn::Rectangle(0, 0, getWidth(), getHeight()));
@@ -178,37 +182,47 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
};
// Don't move camera so that the end of the map is on screen
- const int viewXmax =
- mMap->getWidth() * mMap->getTileWidth() - graphics->getWidth();
- const int viewYmax =
- mMap->getHeight() * mMap->getTileHeight() - graphics->getHeight();
- if (mMap)
+ const int mapWidthPixels = mMap->getWidth() * mMap->getTileWidth();
+ const int mapHeightPixels = mMap->getHeight() * mMap->getTileHeight();
+ const int viewXmax = mapWidthPixels - graphics->getWidth();
+ const int viewYmax = mapHeightPixels - graphics->getHeight();
+ if (mPixelViewX < 0)
+ mPixelViewX = 0;
+ if (mPixelViewY < 0)
+ mPixelViewY = 0;
+ if (mPixelViewX > viewXmax)
+ mPixelViewX = viewXmax;
+ if (mPixelViewY > viewYmax)
+ mPixelViewY = viewYmax;
+
+ // Center camera on map if the map is smaller than the screen
+ if (mapWidthPixels < graphics->getWidth())
+ mPixelViewX = (mapWidthPixels - graphics->getWidth()) / 2;
+ if (mapHeightPixels < graphics->getHeight())
+ mPixelViewY = (mapHeightPixels - graphics->getHeight()) / 2;
+
+ // Draw black background if map is smaller than the screen
+ if ( mapWidthPixels < graphics->getWidth()
+ || mapHeightPixels < graphics->getHeight())
{
- if (mPixelViewX < 0)
- mPixelViewX = 0;
- if (mPixelViewY < 0)
- mPixelViewY = 0;
- if (mPixelViewX > viewXmax)
- mPixelViewX = viewXmax;
- if (mPixelViewY > viewYmax)
- mPixelViewY = viewYmax;
+ gcnGraphics->setColor(gcn::Color(0, 0, 0));
+ gcnGraphics->fillRectangle(
+ gcn::Rectangle(0, 0, getWidth(), getHeight()));
+
}
// Draw tiles and sprites
- if (mMap)
- {
- mMap->draw(graphics, (int) mPixelViewX, (int) mPixelViewY);
+ mMap->draw(graphics, (int) mPixelViewX, (int) mPixelViewY);
- if (mDebugFlags)
+ if (mDebugFlags)
+ {
+ if (mDebugFlags & (Map::DEBUG_GRID | Map::DEBUG_COLLISION_TILES))
{
- if (mDebugFlags & (Map::DEBUG_GRID | Map::DEBUG_COLLISION_TILES))
- {
- mMap->drawCollision(graphics, (int) mPixelViewX,
- (int) mPixelViewY, mDebugFlags);
- }
-
- _drawDebugPath(graphics);
+ mMap->drawCollision(graphics, (int) mPixelViewX,
+ (int) mPixelViewY, mDebugFlags);
}
+
+ _drawDebugPath(graphics);
}
if (local_player->getCheckNameSetting())