summaryrefslogtreecommitdiff
path: root/src/smallmap_gui.cpp
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2008-05-05 11:36:43 +0000
committerpeter1138 <peter1138@openttd.org>2008-05-05 11:36:43 +0000
commit4595d2c3b12490c74b4bd6ff245429b7c418d515 (patch)
tree2b03bcb1a0888d81488cf0ab912ed5a356863cee /src/smallmap_gui.cpp
parent57e104f97edb5e3f60d7bab515bb9c97eb21e132 (diff)
downloadopenttd-4595d2c3b12490c74b4bd6ff245429b7c418d515.tar.xz
(svn r12953) -Feature: Open a new viewport when ctrl-clicking on a 'Location' button, a town/station/industry list, or some news items.
Diffstat (limited to 'src/smallmap_gui.cpp')
-rw-r--r--src/smallmap_gui.cpp29
1 files changed, 17 insertions, 12 deletions
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;
}