summaryrefslogtreecommitdiff
path: root/viewport.c
diff options
context:
space:
mode:
authordarkvater <darkvater@openttd.org>2004-09-03 19:59:05 +0000
committerdarkvater <darkvater@openttd.org>2004-09-03 19:59:05 +0000
commit4fec362b32801648da47340a127908643ef9cb5d (patch)
tree3520ffc76fe6adcce29cac5bbd06de35ff5f53a5 /viewport.c
parent4bf6ad14061c9ee57518aa0b5f56163e2624a648 (diff)
downloadopenttd-4fec362b32801648da47340a127908643ef9cb5d.tar.xz
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
Diffstat (limited to 'viewport.c')
-rw-r--r--viewport.c44
1 files changed, 37 insertions, 7 deletions
diff --git a/viewport.c b/viewport.c
index a1d6614ed..60a637671 100644
--- a/viewport.c
+++ b/viewport.c
@@ -312,19 +312,23 @@ Point GetTileBelowCursor()
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 @@ void PlaceObject()
}
}
+
+/* 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);