changeset 5014:89edbdeebf4f draft

(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)
author Darkvater <Darkvater@openttd.org>
date Fri, 03 Nov 2006 00:48:03 +0000
parents f5c6b127fad9
children 98ba9439e240
files viewport.c
diffstat 1 files changed, 15 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/viewport.c
+++ b/viewport.c
@@ -297,6 +297,7 @@
 {
 	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 @@
 	b = x-y;
 #endif
 
-	if ((uint)a < MapMaxX() * TILE_SIZE && (uint)b < MapMaxY() * TILE_SIZE) {
-		uint z;
-
-		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;
-	}
+	/* 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;
+
+	pt.x = a + z;
+	pt.y = b + z;
 
 	return pt;
 }