summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui.h1
-rw-r--r--src/toolbar_gui.cpp4
-rw-r--r--src/viewport_gui.cpp24
3 files changed, 21 insertions, 8 deletions
diff --git a/src/gui.h b/src/gui.h
index f896a290c..4385af452 100644
--- a/src/gui.h
+++ b/src/gui.h
@@ -66,6 +66,7 @@ enum WarningLevel {
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x = 0, int y = 0);
void ShowExtraViewPortWindow(TileIndex tile = INVALID_TILE);
+void ShowExtraViewPortWindowForTileUnderCursor();
/* bridge_gui.cpp */
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, byte bridge_type);
diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp
index 98a27dcbf..6b2d0876f 100644
--- a/src/toolbar_gui.cpp
+++ b/src/toolbar_gui.cpp
@@ -1343,7 +1343,7 @@ struct MainToolbarWindow : Window {
case MTHK_GIANT_SCREENSHOT: MenuClickWorldScreenshot(); break;
case MTHK_CHEATS: if (!_networking) ShowCheatWindow(); break;
case MTHK_TERRAFORM: ShowTerraformToolbar(); break;
- case MTHK_EXTRA_VIEWPORT: ShowExtraViewPortWindow(); break;
+ case MTHK_EXTRA_VIEWPORT: ShowExtraViewPortWindowForTileUnderCursor(); break;
#ifdef ENABLE_NETWORK
case MTHK_CLIENT_LIST: if (_networking) ShowClientList(); break;
#endif
@@ -1645,7 +1645,7 @@ public:
case MTEHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
case MTEHK_TERRAFORM: ShowEditorTerraformToolbar(); break;
case MTEHK_SMALLMAP: ShowSmallMap(); break;
- case MTEHK_EXTRA_VIEWPORT: ShowExtraViewPortWindow(); break;
+ case MTEHK_EXTRA_VIEWPORT: ShowExtraViewPortWindowForTileUnderCursor(); break;
default: return ES_NOT_HANDLED;
}
return ES_HANDLED;
diff --git a/src/viewport_gui.cpp b/src/viewport_gui.cpp
index 1a919fe10..9d74a3369 100644
--- a/src/viewport_gui.cpp
+++ b/src/viewport_gui.cpp
@@ -71,12 +71,7 @@ public:
Point pt;
if (tile == INVALID_TILE) {
- /* Use tile under mouse as center for new viewport */
- Point pt = GetTileBelowCursor();
- if (pt.x != -1) tile = TileVirtXY(pt.x, pt.y);
- }
- if (tile == INVALID_TILE) {
- /* Still no tile? Use center of main viewport. */
+ /* No tile? Use center of main viewport. */
const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
/* center on same place as main window (zoom is maximum, no adjustment needed) */
@@ -175,6 +170,10 @@ static const WindowDesc _extra_view_port_desc(
_nested_extra_view_port_widgets, lengthof(_nested_extra_view_port_widgets)
);
+/**
+ * Show a new Extra Viewport window.
+ * @param tile Tile to center the view on. INVALID_TILE means to use the center of main viewport.
+ */
void ShowExtraViewPortWindow(TileIndex tile)
{
int i = 0;
@@ -184,3 +183,16 @@ void ShowExtraViewPortWindow(TileIndex tile)
new ExtraViewportWindow(&_extra_view_port_desc, i, tile);
}
+
+/**
+ * Show a new Extra Viewport window.
+ * Center it on the tile under the cursor, if the cursor is inside a viewport.
+ * If that fails, center it on main viewport center.
+ */
+void ShowExtraViewPortWindowForTileUnderCursor()
+{
+ /* Use tile under mouse as center for new viewport.
+ * Do this before creating the window, it might appear just below the mouse. */
+ Point pt = GetTileBelowCursor();
+ ShowExtraViewPortWindow(pt.x != -1 ? TileVirtXY(pt.x, pt.y) : INVALID_TILE);
+}