PageRenderTime 31ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 1ms

/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
Possible License(s): LGPL-2.1
  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. #include "llviewerprecompiledheaders.h"
  27. // self include
  28. #include "llfloatermap.h"
  29. // Library includes
  30. #include "llfloaterreg.h"
  31. #include "llfontgl.h"
  32. #include "llglheaders.h"
  33. // Viewer includes
  34. #include "llagentcamera.h"
  35. #include "llviewercontrol.h"
  36. #include "llnetmap.h"
  37. #include "lltracker.h"
  38. #include "llviewercamera.h"
  39. #include "lldraghandle.h"
  40. #include "lltextbox.h"
  41. #include "llfloaterworldmap.h"
  42. #include "llagent.h"
  43. //
  44. // Constants
  45. //
  46. // The minor cardinal direction labels are hidden if their height is more
  47. // than this proportion of the map.
  48. const F32 MAP_MINOR_DIR_THRESHOLD = 0.07f;
  49. const S32 MAP_PADDING_LEFT = 0;
  50. const S32 MAP_PADDING_TOP = 2;
  51. const S32 MAP_PADDING_RIGHT = 2;
  52. const S32 MAP_PADDING_BOTTOM = 0;
  53. //
  54. // Member functions
  55. //
  56. LLFloaterMap::LLFloaterMap(const LLSD& key)
  57. : LLFloater(key),
  58. mTextBoxEast(NULL),
  59. mTextBoxNorth(NULL),
  60. mTextBoxWest(NULL),
  61. mTextBoxSouth(NULL),
  62. mTextBoxSouthEast(NULL),
  63. mTextBoxNorthEast(NULL),
  64. mTextBoxNorthWest(NULL),
  65. mTextBoxSouthWest(NULL),
  66. mMap(NULL)
  67. {
  68. }
  69. LLFloaterMap::~LLFloaterMap()
  70. {
  71. }
  72. BOOL LLFloaterMap::postBuild()
  73. {
  74. mMap = getChild<LLNetMap>("Net Map");
  75. if (gSavedSettings.getBOOL("DoubleClickTeleport"))
  76. {
  77. mMap->setToolTipMsg(getString("AltToolTipMsg"));
  78. }
  79. else if (gSavedSettings.getBOOL("DoubleClickShowWorldMap"))
  80. {
  81. mMap->setToolTipMsg(getString("ToolTipMsg"));
  82. }
  83. sendChildToBack(mMap);
  84. mTextBoxNorth = getChild<LLTextBox> ("floater_map_north");
  85. mTextBoxEast = getChild<LLTextBox> ("floater_map_east");
  86. mTextBoxWest = getChild<LLTextBox> ("floater_map_west");
  87. mTextBoxSouth = getChild<LLTextBox> ("floater_map_south");
  88. mTextBoxSouthEast = getChild<LLTextBox> ("floater_map_southeast");
  89. mTextBoxNorthEast = getChild<LLTextBox> ("floater_map_northeast");
  90. mTextBoxSouthWest = getChild<LLTextBox> ("floater_map_southwest");
  91. mTextBoxNorthWest = getChild<LLTextBox> ("floater_map_northwest");
  92. updateMinorDirections();
  93. // Get the drag handle all the way in back
  94. sendChildToBack(getDragHandle());
  95. // keep onscreen
  96. gFloaterView->adjustToFitScreen(this, FALSE);
  97. return TRUE;
  98. }
  99. BOOL LLFloaterMap::handleDoubleClick(S32 x, S32 y, MASK mask)
  100. {
  101. // If floater is minimized, minimap should be shown on doubleclick (STORM-299)
  102. if (isMinimized())
  103. {
  104. setMinimized(FALSE);
  105. return TRUE;
  106. }
  107. LLVector3d pos_global = mMap->viewPosToGlobal(x, y);
  108. // If we're not tracking a beacon already, double-click will set one
  109. if (!LLTracker::isTracking(NULL))
  110. {
  111. LLFloaterWorldMap* world_map = LLFloaterWorldMap::getInstance();
  112. if (world_map)
  113. {
  114. world_map->trackLocation(pos_global);
  115. }
  116. }
  117. if (gSavedSettings.getBOOL("DoubleClickTeleport"))
  118. {
  119. // If DoubleClickTeleport is on, double clicking the minimap will teleport there
  120. gAgent.teleportViaLocationLookAt(pos_global);
  121. }
  122. else if (gSavedSettings.getBOOL("DoubleClickShowWorldMap"))
  123. {
  124. LLFloaterReg::showInstance("world_map");
  125. }
  126. return TRUE;
  127. }
  128. void LLFloaterMap::setDirectionPos( LLTextBox* text_box, F32 rotation )
  129. {
  130. // Rotation is in radians.
  131. // Rotation of 0 means x = 1, y = 0 on the unit circle.
  132. F32 map_half_height = (F32)(getRect().getHeight() / 2) - getHeaderHeight()/2;
  133. F32 map_half_width = (F32)(getRect().getWidth() / 2) ;
  134. F32 text_half_height = (F32)(text_box->getRect().getHeight() / 2);
  135. F32 text_half_width = (F32)(text_box->getRect().getWidth() / 2);
  136. F32 radius = llmin( map_half_height - text_half_height, map_half_width - text_half_width );
  137. // Inset by a little to account for position display.
  138. radius -= 8.f;
  139. text_box->setOrigin(
  140. llround(map_half_width - text_half_width + radius * cos( rotation )),
  141. llround(map_half_height - text_half_height + radius * sin( rotation )) );
  142. }
  143. void LLFloaterMap::updateMinorDirections()
  144. {
  145. if (mTextBoxNorthEast == NULL)
  146. {
  147. return;
  148. }
  149. // Hide minor directions if they cover too much of the map
  150. bool show_minors = mTextBoxNorthEast->getRect().getHeight() < MAP_MINOR_DIR_THRESHOLD *
  151. llmin(getRect().getWidth(), getRect().getHeight());
  152. mTextBoxNorthEast->setVisible(show_minors);
  153. mTextBoxNorthWest->setVisible(show_minors);
  154. mTextBoxSouthWest->setVisible(show_minors);
  155. mTextBoxSouthEast->setVisible(show_minors);
  156. }
  157. // virtual
  158. void LLFloaterMap::draw()
  159. {
  160. F32 rotation = 0;
  161. static LLUICachedControl<bool> rotate_map("MiniMapRotate", true);
  162. if( rotate_map )
  163. {
  164. // rotate subsequent draws to agent rotation
  165. rotation = atan2( LLViewerCamera::getInstance()->getAtAxis().mV[VX], LLViewerCamera::getInstance()->getAtAxis().mV[VY] );
  166. }
  167. setDirectionPos( mTextBoxEast, rotation );
  168. setDirectionPos( mTextBoxNorth, rotation + F_PI_BY_TWO );
  169. setDirectionPos( mTextBoxWest, rotation + F_PI );
  170. setDirectionPos( mTextBoxSouth, rotation + F_PI + F_PI_BY_TWO );
  171. setDirectionPos( mTextBoxNorthEast, rotation + F_PI_BY_TWO / 2);
  172. setDirectionPos( mTextBoxNorthWest, rotation + F_PI_BY_TWO + F_PI_BY_TWO / 2);
  173. setDirectionPos( mTextBoxSouthWest, rotation + F_PI + F_PI_BY_TWO / 2);
  174. setDirectionPos( mTextBoxSouthEast, rotation + F_PI + F_PI_BY_TWO + F_PI_BY_TWO / 2);
  175. // Note: we can't just gAgent.check cameraMouselook() because the transition states are wrong.
  176. if(gAgentCamera.cameraMouselook())
  177. {
  178. setMouseOpaque(FALSE);
  179. getDragHandle()->setMouseOpaque(FALSE);
  180. }
  181. else
  182. {
  183. setMouseOpaque(TRUE);
  184. getDragHandle()->setMouseOpaque(TRUE);
  185. }
  186. LLFloater::draw();
  187. }
  188. void LLFloaterMap::reshape(S32 width, S32 height, BOOL called_from_parent)
  189. {
  190. LLFloater::reshape(width, height, called_from_parent);
  191. updateMinorDirections();
  192. }
  193. void LLFloaterMap::handleZoom(const LLSD& userdata)
  194. {
  195. std::string level = userdata.asString();
  196. F32 scale = 0.0f;
  197. if (level == std::string("default"))
  198. {
  199. LLControlVariable *pvar = gSavedSettings.getControl("MiniMapScale");
  200. if(pvar)
  201. {
  202. pvar->resetToDefault();
  203. scale = gSavedSettings.getF32("MiniMapScale");
  204. }
  205. }
  206. else if (level == std::string("close"))
  207. scale = LLNetMap::MAP_SCALE_MAX;
  208. else if (level == std::string("medium"))
  209. scale = LLNetMap::MAP_SCALE_MID;
  210. else if (level == std::string("far"))
  211. scale = LLNetMap::MAP_SCALE_MIN;
  212. if (scale != 0.0f)
  213. {
  214. mMap->setScale(scale);
  215. }
  216. }