summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-03-24 22:30:09 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-03-24 22:30:09 +0100
commitbbb4c1c61863b9032af2291bff20814733995391 (patch)
tree3ea88d5d789e2046c88680bf6decc088f29719fd /src/gui
parent096b2cd614c521db3dd5b26508ce983e50acc531 (diff)
parenta5690fa2a4cce2698225f1f558183f6fe306d860 (diff)
downloadmana-bbb4c1c61863b9032af2291bff20814733995391.tar.gz
mana-bbb4c1c61863b9032af2291bff20814733995391.tar.bz2
mana-bbb4c1c61863b9032af2291bff20814733995391.tar.xz
mana-bbb4c1c61863b9032af2291bff20814733995391.zip
Merge branch '0.6'
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/serverdialog.cpp4
-rw-r--r--src/gui/serverdialog.h2
-rw-r--r--src/gui/viewport.cpp62
3 files changed, 41 insertions, 27 deletions
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp
index 0a2b96f4..9802224b 100644
--- a/src/gui/serverdialog.cpp
+++ b/src/gui/serverdialog.cpp
@@ -78,13 +78,13 @@ ServersListModel::ServersListModel(ServerInfos *servers, ServerDialog *parent):
int ServersListModel::getNumberOfElements()
{
- MutexLocker lock = mParent->lock();
+ MutexLocker lock(mParent->getMutex());
return mServers->size();
}
std::string ServersListModel::getElementAt(int elementIndex)
{
- MutexLocker lock = mParent->lock();
+ MutexLocker lock(mParent->getMutex());
const ServerInfo &server = mServers->at(elementIndex);
std::string myServer;
myServer += server.hostname;
diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h
index eedf5134..cf9e62e7 100644
--- a/src/gui/serverdialog.h
+++ b/src/gui/serverdialog.h
@@ -113,7 +113,7 @@ class ServerDialog : public Window,
protected:
friend class ServersListModel;
- MutexLocker lock() { return MutexLocker(&mMutex); }
+ Mutex *getMutex() { return &mMutex; }
friend class CustomServerDialog;
/**
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())