From 78c0929b18e508f3f18728dc55e760470308d796 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Mon, 5 May 2008 11:36:43 +0000 Subject: (svn r12953) -Feature: Open a new viewport when ctrl-clicking on a 'Location' button, a town/station/industry list, or some news items. --- src/smallmap_gui.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src/smallmap_gui.cpp') diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index 1cba5798b..b4e70ac4c 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -1191,25 +1191,30 @@ static const WindowDesc _extra_view_port_desc = { ExtraViewPortWndProc }; -void ShowExtraViewPortWindow() +void ShowExtraViewPortWindow(TileIndex tile) { - Window *w, *v; int i = 0; /* find next free window number for extra viewport */ while (FindWindowById(WC_EXTRA_VIEW_PORT, i) != NULL) i++; - w = AllocateWindowDescFront(&_extra_view_port_desc, i); + Window *w = AllocateWindowDescFront(&_extra_view_port_desc, i); if (w != NULL) { - int x, y; - /* the main window with the main view */ - v = FindWindowById(WC_MAIN_WINDOW, 0); - - /* center on same place as main window (zoom is maximum, no adjustment needed) */ - x = WP(v, vp_d).scrollpos_x; - y = WP(v, vp_d).scrollpos_y; - WP(w, vp_d).scrollpos_x = x + (v->viewport->virtual_width - (w->widget[4].right - w->widget[4].left) - 1) / 2; - WP(w, vp_d).scrollpos_y = y + (v->viewport->virtual_height - (w->widget[4].bottom - w->widget[4].top) - 1) / 2; + Point pt; + + if (tile == INVALID_TILE) { + /* the main window with the main view */ + const Window *v = FindWindowById(WC_MAIN_WINDOW, 0); + + /* center on same place as main window (zoom is maximum, no adjustment needed) */ + pt.x = WP(v, vp_d).scrollpos_x + v->viewport->virtual_height / 2; + pt.y = WP(v, vp_d).scrollpos_y + v->viewport->virtual_height / 2; + } else { + pt = RemapCoords(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, TileHeight(tile)); + } + + WP(w, vp_d).scrollpos_x = pt.x - ((w->widget[4].right - w->widget[4].left) - 1) / 2; + WP(w, vp_d).scrollpos_y = pt.y - ((w->widget[4].bottom - w->widget[4].top) - 1) / 2; WP(w, vp_d).dest_scrollpos_x = WP(w, vp_d).scrollpos_x; WP(w, vp_d).dest_scrollpos_y = WP(w, vp_d).scrollpos_y; } -- cgit v1.2.3-54-g00ecf