MapEngine center point not exceeding map limits vertically
authorSami Rämö <sami.ramo@ixonos.com>
Mon, 14 Jun 2010 09:22:28 +0000 (12:22 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Mon, 14 Jun 2010 09:22:28 +0000 (12:22 +0300)
src/map/mapcommon.h
src/map/mapengine.cpp
src/map/mapscene.cpp

index bf4c2e2..6f10b0b 100644 (file)
@@ -40,6 +40,9 @@ const int MAP_PIXELS_X = MAX_TILES_PER_SIDE * TILE_SIZE_X;
 const int MAP_MIN_PIXEL_X = 0;
 const int MAP_MAX_PIXEL_X = MAP_PIXELS_X - 1;
 
+const int MAP_MIN_PIXEL_Y = 0;
+const int MAP_MAX_PIXEL_Y = MAX_TILES_PER_SIDE * TILE_SIZE_Y - 1;
+
 const double MAP_SCENE_VERTICAL_OVERSIZE_FACTOR = 0.5;
 const int MAP_SCENE_MIN_PIXEL_X = -MAP_PIXELS_X * MAP_SCENE_VERTICAL_OVERSIZE_FACTOR;
 const int MAP_SCENE_MAX_PIXEL_X = MAP_PIXELS_X * (1 + MAP_SCENE_VERTICAL_OVERSIZE_FACTOR) - 1;
index 635cfe1..6863828 100644 (file)
@@ -389,12 +389,15 @@ void MapEngine::setLocation(QPoint sceneCoordinate)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    // jump to opposite side of the world if world limit is exceeded
+    // jump to opposite side of the world if world horizontal limit is exceeded
     if (sceneCoordinate.x() < MAP_MIN_PIXEL_X)
         sceneCoordinate.setX(sceneCoordinate.x() + MAP_PIXELS_X);
     else if (sceneCoordinate.x() > MAP_MAX_PIXEL_X)
         sceneCoordinate.setX(sceneCoordinate.x() - MAP_PIXELS_X);
 
+    // don't allow vertical scene coordinates go out of the map
+    sceneCoordinate.setY(qBound(MAP_MIN_PIXEL_Y, sceneCoordinate.y(), MAP_MAX_PIXEL_Y));
+
     if (disableAutoCentering(sceneCoordinate))
         emit mapScrolledManually();
 
index c6f3102..33e0278 100644 (file)
@@ -27,9 +27,6 @@
 
 #include "mapscene.h"
 
-const int MAP_MIN_PIXEL_Y = 0;
-const int MAP_MAX_PIXEL_Y = MAX_TILES_PER_SIDE * TILE_SIZE_Y - 1;
-
 MapScene::MapScene(QObject *parent)
     : QGraphicsScene(parent)
     , m_isRemoveStackedTilesRunning(false)