viewport.c
changeset 152 c3964b43943e
parent 137 73f897e1bf4a
child 193 0a7025304867
--- a/viewport.c	Fri Sep 03 18:23:03 2004 +0000
+++ b/viewport.c	Fri Sep 03 19:59:05 2004 +0000
@@ -312,19 +312,23 @@
 	return GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y);
 }
 
-Point GetTileZoomCenter(bool in)
+
+Point GetTileZoomCenterWindow(bool in, Window * w)
 {
 	int x, y;
-	
+	ViewPort * vp;
+
+	vp = w->viewport;
+
 	if (in)	{
-		x = (_cursor.pos.x >> 1) + (_screen.width >> 2);
-		y = (_cursor.pos.y >> 1) + (_screen.height >> 2);
+		x = ( (_cursor.pos.x - vp->left ) >> 1) + (vp->width >> 2);
+		y = ( (_cursor.pos.y - vp->top ) >> 1) + (vp->height >> 2);
 	}
 	else {
-		x = _screen.width - _cursor.pos.x;
-		y = _screen.height - _cursor.pos.y;
+		x = vp->width - (_cursor.pos.x - vp->left);
+		y = vp->height - (_cursor.pos.y - vp->top);
 	}
-	return GetTileFromScreenXY(x, y);
+	return GetTileFromScreenXY(x+vp->left, y+vp->top);
 }
 
 void DrawGroundSpriteAt(uint32 image, int16 x, int16 y, byte z)
@@ -1708,6 +1712,32 @@
 	}
 }
 
+
+/* scrolls the viewport in a window to a given location */
+bool ScrollWindowTo(int x , int y, Window * w)
+{
+	Point pt;
+
+	pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(x, y));
+	WP(w,vp_d).follow_vehicle = -1;
+
+	if (WP(w,vp_d).scrollpos_x == pt.x &&
+			WP(w,vp_d).scrollpos_y == pt.y)
+				return false;
+
+	WP(w,vp_d).scrollpos_x = pt.x;
+	WP(w,vp_d).scrollpos_y = pt.y;
+	return true;
+}
+
+/* scrolls the viewport in a window to a given tile */
+bool ScrollWindowToTile(TileIndex tile, Window * w)
+{
+	return ScrollWindowTo(GET_TILE_X(tile)*16+8, GET_TILE_Y(tile)*16+8, w);
+}
+
+
+
 bool ScrollMainWindowTo(int x, int y)
 {
 	Window *w = FindWindowById(WC_MAIN_WINDOW, 0);