summaryrefslogtreecommitdiff
path: root/src/viewport_gui.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-10-17 13:54:05 +0000
committerfrosch <frosch@openttd.org>2010-10-17 13:54:05 +0000
commit12a7e2fde0b53f8d3042f3ee248522e921b80d72 (patch)
tree02c6933987292a4290a1a18e38e70b9a278d6494 /src/viewport_gui.cpp
parentbcd006e4fc5b85b4ab39930cc9eae1d7e6e947a4 (diff)
downloadopenttd-12a7e2fde0b53f8d3042f3ee248522e921b80d72.tar.xz
(svn r20962) -Fix [FS#4166](r20956): Determine tile under cursor before opening the new viewport. It might appear just below the cursor.
Diffstat (limited to 'src/viewport_gui.cpp')
-rw-r--r--src/viewport_gui.cpp24
1 files changed, 18 insertions, 6 deletions
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);
+}