summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-11-03 00:48:03 +0000
committerDarkvater <darkvater@openttd.org>2006-11-03 00:48:03 +0000
commita9fa6fd5060db97614240788e8f7658bd06f3ae4 (patch)
tree24c3bf3df4bbaa94898aec3171c70d50ea842b5b
parent7977bd51a490c5cb5bca26041c696c7b3ab68e6c (diff)
downloadopenttd-a9fa6fd5060db97614240788e8f7658bd06f3ae4.tar.xz
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
would be outside the map. Change behaviour so that a reasonable approximation is returned so that zooming (out) still works (GrimRC)
-rw-r--r--viewport.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/viewport.c b/viewport.c
index 5738e0fef..88d6ea9e5 100644
--- a/viewport.c
+++ b/viewport.c
@@ -297,6 +297,7 @@ static Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y)
{
Point pt;
int a,b;
+ uint z;
if ( (uint)(x -= vp->left) >= (uint)vp->width ||
(uint)(y -= vp->top) >= (uint)vp->height) {
@@ -315,20 +316,20 @@ static Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y)
b = x-y;
#endif
- if ((uint)a < MapMaxX() * TILE_SIZE && (uint)b < MapMaxY() * TILE_SIZE) {
- uint z;
+ /* we need to move variables in to the valid range, as the
+ * GetTileZoomCenterWindow() function can call here with invalid x and/or y,
+ * when the user tries to zoom out along the sides of the map */
+ a = clamp(a, 0, (int)(MapMaxX() * TILE_SIZE) - 1);
+ b = clamp(b, 0, (int)(MapMaxY() * TILE_SIZE) - 1);
- z = GetSlopeZ(a, b ) / 2;
- z = GetSlopeZ(a + z, b + z) / 2;
- z = GetSlopeZ(a + z, b + z) / 2;
- z = GetSlopeZ(a + z, b + z) / 2;
- z = GetSlopeZ(a + z, b + z) / 2;
+ z = GetSlopeZ(a, b ) / 2;
+ z = GetSlopeZ(a + z, b + z) / 2;
+ z = GetSlopeZ(a + z, b + z) / 2;
+ z = GetSlopeZ(a + z, b + z) / 2;
+ z = GetSlopeZ(a + z, b + z) / 2;
- pt.x = a + z;
- pt.y = b + z;
- } else {
- pt.x = pt.y = -1;
- }
+ pt.x = a + z;
+ pt.y = b + z;
return pt;
}