(svn r20962) -Fix [FS#4166](r20956): Determine tile under cursor before opening the new viewport. It might appear just below the cursor.

This commit is contained in:
frosch
2010-10-17 13:54:05 +00:00
parent 587e63f841
commit 0571d871d4
3 changed files with 21 additions and 8 deletions

View File

@@ -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);
}