PageRenderTime 60ms CodeModel.GetById 22ms app.highlight 34ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llfloatermap.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 251 lines | 168 code | 35 blank | 48 comment | 27 complexity | 04c5f4631f607e9e391e966b0b92ebc4 MD5 | raw file
  1/** 
  2 * @file llfloatermap.cpp
  3 * @brief The "mini-map" or radar in the upper right part of the screen.
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29// self include
 30#include "llfloatermap.h"
 31
 32// Library includes
 33#include "llfloaterreg.h"
 34#include "llfontgl.h"
 35#include "llglheaders.h"
 36
 37// Viewer includes
 38#include "llagentcamera.h"
 39#include "llviewercontrol.h"
 40#include "llnetmap.h"
 41#include "lltracker.h"
 42#include "llviewercamera.h"
 43#include "lldraghandle.h"
 44#include "lltextbox.h"
 45#include "llfloaterworldmap.h"
 46#include "llagent.h"
 47
 48//
 49// Constants
 50//
 51
 52// The minor cardinal direction labels are hidden if their height is more
 53// than this proportion of the map.
 54const F32 MAP_MINOR_DIR_THRESHOLD = 0.07f;
 55const S32 MAP_PADDING_LEFT = 0;
 56const S32 MAP_PADDING_TOP = 2;
 57const S32 MAP_PADDING_RIGHT = 2;
 58const S32 MAP_PADDING_BOTTOM = 0;
 59//
 60// Member functions
 61//
 62
 63LLFloaterMap::LLFloaterMap(const LLSD& key) 
 64	: LLFloater(key),
 65	  mTextBoxEast(NULL),
 66	  mTextBoxNorth(NULL),
 67	  mTextBoxWest(NULL),
 68	  mTextBoxSouth(NULL),
 69	  mTextBoxSouthEast(NULL),
 70	  mTextBoxNorthEast(NULL),
 71	  mTextBoxNorthWest(NULL),
 72	  mTextBoxSouthWest(NULL),
 73	  mMap(NULL)
 74{
 75}
 76
 77LLFloaterMap::~LLFloaterMap()
 78{
 79}
 80
 81BOOL LLFloaterMap::postBuild()
 82{
 83	mMap = getChild<LLNetMap>("Net Map");
 84	if (gSavedSettings.getBOOL("DoubleClickTeleport"))
 85	{
 86		mMap->setToolTipMsg(getString("AltToolTipMsg"));
 87	}
 88	else if (gSavedSettings.getBOOL("DoubleClickShowWorldMap"))
 89	{
 90		mMap->setToolTipMsg(getString("ToolTipMsg"));
 91	}
 92	sendChildToBack(mMap);
 93	
 94	mTextBoxNorth = getChild<LLTextBox> ("floater_map_north");
 95	mTextBoxEast = getChild<LLTextBox> ("floater_map_east");
 96	mTextBoxWest = getChild<LLTextBox> ("floater_map_west");
 97	mTextBoxSouth = getChild<LLTextBox> ("floater_map_south");
 98	mTextBoxSouthEast = getChild<LLTextBox> ("floater_map_southeast");
 99	mTextBoxNorthEast = getChild<LLTextBox> ("floater_map_northeast");
100	mTextBoxSouthWest = getChild<LLTextBox> ("floater_map_southwest");
101	mTextBoxNorthWest = getChild<LLTextBox> ("floater_map_northwest");
102
103	updateMinorDirections();
104
105	// Get the drag handle all the way in back
106	sendChildToBack(getDragHandle());
107
108	// keep onscreen
109	gFloaterView->adjustToFitScreen(this, FALSE);
110
111	return TRUE;
112}
113
114BOOL LLFloaterMap::handleDoubleClick(S32 x, S32 y, MASK mask)
115{
116	// If floater is minimized, minimap should be shown on doubleclick (STORM-299)
117	if (isMinimized())
118	{
119		setMinimized(FALSE);
120		return TRUE;
121	}
122
123	LLVector3d pos_global = mMap->viewPosToGlobal(x, y);
124	
125	// If we're not tracking a beacon already, double-click will set one 
126	if (!LLTracker::isTracking(NULL))
127	{
128		LLFloaterWorldMap* world_map = LLFloaterWorldMap::getInstance();
129		if (world_map)
130		{
131			world_map->trackLocation(pos_global);
132		}
133	}
134	
135	if (gSavedSettings.getBOOL("DoubleClickTeleport"))
136	{
137		// If DoubleClickTeleport is on, double clicking the minimap will teleport there
138		gAgent.teleportViaLocationLookAt(pos_global);
139	}
140	else if (gSavedSettings.getBOOL("DoubleClickShowWorldMap"))
141	{
142		LLFloaterReg::showInstance("world_map");
143	}
144	return TRUE;
145}
146
147void LLFloaterMap::setDirectionPos( LLTextBox* text_box, F32 rotation )
148{
149	// Rotation is in radians.
150	// Rotation of 0 means x = 1, y = 0 on the unit circle.
151
152	F32 map_half_height = (F32)(getRect().getHeight() / 2) - getHeaderHeight()/2;
153	F32 map_half_width = (F32)(getRect().getWidth() / 2) ;
154	F32 text_half_height = (F32)(text_box->getRect().getHeight() / 2);
155	F32 text_half_width = (F32)(text_box->getRect().getWidth() / 2);
156	F32 radius = llmin( map_half_height - text_half_height, map_half_width - text_half_width );
157
158	// Inset by a little to account for position display.
159	radius -= 8.f;
160
161	text_box->setOrigin( 
162		llround(map_half_width - text_half_width + radius * cos( rotation )),
163		llround(map_half_height - text_half_height + radius * sin( rotation )) );
164}
165
166void LLFloaterMap::updateMinorDirections()
167{
168	if (mTextBoxNorthEast == NULL)
169	{
170		return;
171	}
172
173	// Hide minor directions if they cover too much of the map
174	bool show_minors = mTextBoxNorthEast->getRect().getHeight() < MAP_MINOR_DIR_THRESHOLD *
175		llmin(getRect().getWidth(), getRect().getHeight());
176
177	mTextBoxNorthEast->setVisible(show_minors);
178	mTextBoxNorthWest->setVisible(show_minors);
179	mTextBoxSouthWest->setVisible(show_minors);
180	mTextBoxSouthEast->setVisible(show_minors);
181}
182
183// virtual
184void LLFloaterMap::draw()
185{
186	F32 rotation = 0;
187
188	static LLUICachedControl<bool> rotate_map("MiniMapRotate", true);
189	if( rotate_map )
190	{
191		// rotate subsequent draws to agent rotation
192		rotation = atan2( LLViewerCamera::getInstance()->getAtAxis().mV[VX], LLViewerCamera::getInstance()->getAtAxis().mV[VY] );
193	}
194
195	setDirectionPos( mTextBoxEast,  rotation );
196	setDirectionPos( mTextBoxNorth, rotation + F_PI_BY_TWO );
197	setDirectionPos( mTextBoxWest,  rotation + F_PI );
198	setDirectionPos( mTextBoxSouth, rotation + F_PI + F_PI_BY_TWO );
199
200	setDirectionPos( mTextBoxNorthEast, rotation +						F_PI_BY_TWO / 2);
201	setDirectionPos( mTextBoxNorthWest, rotation + F_PI_BY_TWO +		F_PI_BY_TWO / 2);
202	setDirectionPos( mTextBoxSouthWest, rotation + F_PI +				F_PI_BY_TWO / 2);
203	setDirectionPos( mTextBoxSouthEast, rotation + F_PI + F_PI_BY_TWO + F_PI_BY_TWO / 2);
204
205	// Note: we can't just gAgent.check cameraMouselook() because the transition states are wrong.
206	if(gAgentCamera.cameraMouselook())
207	{
208		setMouseOpaque(FALSE);
209		getDragHandle()->setMouseOpaque(FALSE);
210	}
211	else
212	{
213		setMouseOpaque(TRUE);
214		getDragHandle()->setMouseOpaque(TRUE);
215	}
216	
217	LLFloater::draw();
218}
219
220void LLFloaterMap::reshape(S32 width, S32 height, BOOL called_from_parent)
221{
222	LLFloater::reshape(width, height, called_from_parent);
223	
224	updateMinorDirections();
225}
226
227void LLFloaterMap::handleZoom(const LLSD& userdata)
228{
229	std::string level = userdata.asString();
230	
231	F32 scale = 0.0f;
232	if (level == std::string("default"))
233	{
234		LLControlVariable *pvar = gSavedSettings.getControl("MiniMapScale");
235		if(pvar)
236		{
237			pvar->resetToDefault();
238			scale = gSavedSettings.getF32("MiniMapScale");
239		}
240	}
241	else if (level == std::string("close"))
242		scale = LLNetMap::MAP_SCALE_MAX;
243	else if (level == std::string("medium"))
244		scale = LLNetMap::MAP_SCALE_MID;
245	else if (level == std::string("far"))
246		scale = LLNetMap::MAP_SCALE_MIN;
247	if (scale != 0.0f)
248	{
249		mMap->setScale(scale);
250	}
251}