Changeset - r16245:5fda73d1d097
[Not reviewed]
master
0 1 0
frosch - 14 years ago 2010-10-16 23:13:05
frosch@openttd.org
(svn r20956) -Feature: Center new extra viewports on the tile below the mouse. Only center on center of main viewport if mouse is not in any viewport.
1 file changed with 7 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/viewport_gui.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file viewport_gui.cpp Extra viewport window. */
 

	
 
#include "stdafx.h"
 
#include "landscape.h"
 
#include "window_gui.h"
 
#include "viewport_func.h"
 
#include "gfx_func.h"
 
#include "strings_func.h"
 
#include "zoom_func.h"
 
#include "window_func.h"
 
#include "tilehighlight_func.h"
 

	
 
#include "table/strings.h"
 
#include "table/sprites.h"
 

	
 
/** Widget numbers of the extra viewport window. */
 
enum ExtraViewportWindowWidgets {
 
	EVW_CAPTION,
 
	EVW_VIEWPORT,
 
	EVW_ZOOMIN,
 
	EVW_ZOOMOUT,
 
	EVW_MAIN_TO_VIEW,
 
	EVW_VIEW_TO_MAIN,
 
};
 

	
 
/* Extra ViewPort Window Stuff */
 
static const NWidgetPart _nested_extra_view_port_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY, EVW_CAPTION), SetDataTip(STR_EXTRA_VIEW_PORT_TITLE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_SHADEBOX, COLOUR_GREY),
 
		NWidget(WWT_STICKYBOX, COLOUR_GREY),
 
	EndContainer(),
 
	NWidget(WWT_PANEL, COLOUR_GREY),
 
		NWidget(NWID_VIEWPORT, INVALID_COLOUR, EVW_VIEWPORT), SetPadding(2, 2, 2, 2), SetResize(1, 1), SetFill(1, 1),
 
@@ -49,49 +50,54 @@ static const NWidgetPart _nested_extra_v
 
			NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, EVW_MAIN_TO_VIEW), SetFill(1, 1), SetResize(1, 0),
 
										SetDataTip(STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW, STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT),
 
			NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, EVW_VIEW_TO_MAIN), SetFill(1, 1), SetResize(1, 0),
 
										SetDataTip(STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN, STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN_TT),
 
		EndContainer(),
 
	EndContainer(),
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), SetResize(1, 0), EndContainer(),
 
		NWidget(WWT_RESIZEBOX, COLOUR_GREY),
 
	EndContainer(),
 
};
 

	
 
class ExtraViewportWindow : public Window {
 
public:
 
	ExtraViewportWindow(const WindowDesc *desc, int window_number, TileIndex tile) : Window()
 
	{
 
		this->InitNested(desc, window_number);
 

	
 
		NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(EVW_VIEWPORT);
 
		nvp->InitializeViewport(this, 0, ZOOM_LVL_NORMAL);
 
		this->DisableWidget(EVW_ZOOMIN);
 

	
 
		Point pt;
 
		if (tile == INVALID_TILE) {
 
			/* the main window with the main view */
 
			/* 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. */
 
			const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
 

	
 
			/* center on same place as main window (zoom is maximum, no adjustment needed) */
 
			pt.x = w->viewport->scrollpos_x + w->viewport->virtual_width / 2;
 
			pt.y = w->viewport->scrollpos_y + w->viewport->virtual_height / 2;
 
		} else {
 
			pt = RemapCoords(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, TileHeight(tile));
 
		}
 

	
 
		this->viewport->scrollpos_x = pt.x - this->viewport->virtual_width / 2;
 
		this->viewport->scrollpos_y = pt.y - this->viewport->virtual_height / 2;
 
		this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x;
 
		this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y;
 
	}
 

	
 
	virtual void SetStringParameters(int widget) const
 
	{
 
		switch (widget) {
 
			case EVW_CAPTION:
 
				/* set the number in the title bar */
 
				SetDParam(0, this->window_number + 1);
 
				break;
 
		}
 
	}
0 comments (0 inline, 0 general)