PageRenderTime 29ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/lltoolselectland.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 234 lines | 147 code | 48 blank | 39 comment | 14 complexity | 321976769abbc730c34e60afcd1fc55d MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltoolselectland.cpp
  3. * @brief LLToolSelectLand class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&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. #include "lltoolselectland.h"
  28. // indra includes
  29. #include "llparcel.h"
  30. // Viewer includes
  31. #include "llviewercontrol.h"
  32. #include "llfloatertools.h"
  33. #include "llselectmgr.h"
  34. #include "llstatusbar.h"
  35. #include "llviewerparcelmgr.h"
  36. #include "llviewerwindow.h"
  37. //
  38. // Member functions
  39. //
  40. LLToolSelectLand::LLToolSelectLand( )
  41. : LLTool( std::string("Parcel") ),
  42. mDragStartGlobal(),
  43. mDragEndGlobal(),
  44. mDragEndValid(FALSE),
  45. mDragStartX(0),
  46. mDragStartY(0),
  47. mDragEndX(0),
  48. mDragEndY(0),
  49. mMouseOutsideSlop(FALSE),
  50. mWestSouthBottom(),
  51. mEastNorthTop()
  52. { }
  53. LLToolSelectLand::~LLToolSelectLand()
  54. {
  55. }
  56. BOOL LLToolSelectLand::handleMouseDown(S32 x, S32 y, MASK mask)
  57. {
  58. BOOL hit_land = gViewerWindow->mousePointOnLandGlobal(x, y, &mDragStartGlobal);
  59. if (hit_land)
  60. {
  61. setMouseCapture( TRUE );
  62. mDragStartX = x;
  63. mDragStartY = y;
  64. mDragEndX = x;
  65. mDragEndY = y;
  66. mDragEndValid = TRUE;
  67. mDragEndGlobal = mDragStartGlobal;
  68. sanitize_corners(mDragStartGlobal, mDragEndGlobal, mWestSouthBottom, mEastNorthTop);
  69. mWestSouthBottom -= LLVector3d( PARCEL_GRID_STEP_METERS/2, PARCEL_GRID_STEP_METERS/2, 0 );
  70. mEastNorthTop += LLVector3d( PARCEL_GRID_STEP_METERS/2, PARCEL_GRID_STEP_METERS/2, 0 );
  71. roundXY(mWestSouthBottom);
  72. roundXY(mEastNorthTop);
  73. mMouseOutsideSlop = TRUE; //FALSE;
  74. LLViewerParcelMgr::getInstance()->deselectLand();
  75. }
  76. return hit_land;
  77. }
  78. BOOL LLToolSelectLand::handleDoubleClick(S32 x, S32 y, MASK mask)
  79. {
  80. LLVector3d pos_global;
  81. BOOL hit_land = gViewerWindow->mousePointOnLandGlobal(x, y, &pos_global);
  82. if (hit_land)
  83. {
  84. // Auto-select this parcel
  85. LLViewerParcelMgr::getInstance()->selectParcelAt( pos_global );
  86. return TRUE;
  87. }
  88. return FALSE;
  89. }
  90. BOOL LLToolSelectLand::handleMouseUp(S32 x, S32 y, MASK mask)
  91. {
  92. if( hasMouseCapture() )
  93. {
  94. setMouseCapture( FALSE );
  95. if (mMouseOutsideSlop && mDragEndValid)
  96. {
  97. // Take the drag start and end locations, then map the southwest
  98. // point down to the next grid location, and the northeast point up
  99. // to the next grid location.
  100. sanitize_corners(mDragStartGlobal, mDragEndGlobal, mWestSouthBottom, mEastNorthTop);
  101. mWestSouthBottom -= LLVector3d( PARCEL_GRID_STEP_METERS/2, PARCEL_GRID_STEP_METERS/2, 0 );
  102. mEastNorthTop += LLVector3d( PARCEL_GRID_STEP_METERS/2, PARCEL_GRID_STEP_METERS/2, 0 );
  103. roundXY(mWestSouthBottom);
  104. roundXY(mEastNorthTop);
  105. // Don't auto-select entire parcel.
  106. mSelection = LLViewerParcelMgr::getInstance()->selectLand( mWestSouthBottom, mEastNorthTop, FALSE );
  107. }
  108. mMouseOutsideSlop = FALSE;
  109. mDragEndValid = FALSE;
  110. return TRUE;
  111. }
  112. return FALSE;
  113. }
  114. BOOL LLToolSelectLand::handleHover(S32 x, S32 y, MASK mask)
  115. {
  116. if( hasMouseCapture() )
  117. {
  118. if (mMouseOutsideSlop || outsideSlop(x, y, mDragStartX, mDragStartY))
  119. {
  120. mMouseOutsideSlop = TRUE;
  121. // Must do this every frame, in case the camera moved or the land moved
  122. // since last frame.
  123. // If doesn't hit land, doesn't change old value
  124. LLVector3d land_global;
  125. BOOL hit_land = gViewerWindow->mousePointOnLandGlobal(x, y, &land_global);
  126. if (hit_land)
  127. {
  128. mDragEndValid = TRUE;
  129. mDragEndGlobal = land_global;
  130. sanitize_corners(mDragStartGlobal, mDragEndGlobal, mWestSouthBottom, mEastNorthTop);
  131. mWestSouthBottom -= LLVector3d( PARCEL_GRID_STEP_METERS/2, PARCEL_GRID_STEP_METERS/2, 0 );
  132. mEastNorthTop += LLVector3d( PARCEL_GRID_STEP_METERS/2, PARCEL_GRID_STEP_METERS/2, 0 );
  133. roundXY(mWestSouthBottom);
  134. roundXY(mEastNorthTop);
  135. lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolSelectLand (active, land)" << llendl;
  136. gViewerWindow->setCursor(UI_CURSOR_ARROW);
  137. }
  138. else
  139. {
  140. mDragEndValid = FALSE;
  141. lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolSelectLand (active, no land)" << llendl;
  142. gViewerWindow->setCursor(UI_CURSOR_NO);
  143. }
  144. mDragEndX = x;
  145. mDragEndY = y;
  146. }
  147. else
  148. {
  149. lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolSelectLand (active, in slop)" << llendl;
  150. gViewerWindow->setCursor(UI_CURSOR_ARROW);
  151. }
  152. }
  153. else
  154. {
  155. lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolSelectLand (inactive)" << llendl;
  156. gViewerWindow->setCursor(UI_CURSOR_ARROW);
  157. }
  158. return TRUE;
  159. }
  160. void LLToolSelectLand::render()
  161. {
  162. if( hasMouseCapture() && /*mMouseOutsideSlop &&*/ mDragEndValid)
  163. {
  164. LLViewerParcelMgr::getInstance()->renderRect( mWestSouthBottom, mEastNorthTop );
  165. }
  166. }
  167. void LLToolSelectLand::handleSelect()
  168. {
  169. gFloaterTools->setStatusText("selectland");
  170. }
  171. void LLToolSelectLand::handleDeselect()
  172. {
  173. mSelection = NULL;
  174. }
  175. void LLToolSelectLand::roundXY(LLVector3d &vec)
  176. {
  177. vec.mdV[VX] = llround( vec.mdV[VX], (F64)PARCEL_GRID_STEP_METERS );
  178. vec.mdV[VY] = llround( vec.mdV[VY], (F64)PARCEL_GRID_STEP_METERS );
  179. }
  180. // true if x,y outside small box around start_x,start_y
  181. BOOL LLToolSelectLand::outsideSlop(S32 x, S32 y, S32 start_x, S32 start_y)
  182. {
  183. S32 dx = x - start_x;
  184. S32 dy = y - start_y;
  185. return (dx <= -2 || 2 <= dx || dy <= -2 || 2 <= dy);
  186. }