lltoolselectland.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /**
  2. * @file lltoolselectland.cpp
  3. * @brief LLToolSelectLand class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "lltoolselectland.h"
  34. // indra includes
  35. #include "llparcel.h"
  36. // Viewer includes
  37. #include "llagent.h"
  38. #include "llviewercontrol.h"
  39. #include "llfloatertools.h"
  40. #include "llselectmgr.h"
  41. #include "llstatusbar.h"
  42. #include "lltoolview.h"
  43. #include "llviewerparcelmgr.h"
  44. #include "llviewerwindow.h"
  45. LLToolSelectLand gToolSelectLand;
  46. LLToolSelectLand::LLToolSelectLand()
  47. : LLTool("Parcel"),
  48. mDragEndValid(false),
  49. mMouseOutsideSlop(false),
  50. mDragStartX(0),
  51. mDragStartY(0),
  52. mDragEndX(0),
  53. mDragEndY(0)
  54. {
  55. }
  56. bool LLToolSelectLand::handleMouseDown(S32 x, S32 y, MASK mask)
  57. {
  58. bool hit_land = gViewerWindowp->mousePointOnLandGlobal(x, y,
  59. &mDragStartGlobal);
  60. if (hit_land)
  61. {
  62. setMouseCapture(true);
  63. mDragStartX = x;
  64. mDragStartY = y;
  65. mDragEndX = x;
  66. mDragEndY = y;
  67. mDragEndValid = true;
  68. mDragEndGlobal = mDragStartGlobal;
  69. sanitize_corners(mDragStartGlobal, mDragEndGlobal, mWestSouthBottom,
  70. mEastNorthTop);
  71. mWestSouthBottom -= LLVector3d(PARCEL_GRID_STEP_METERS / 2,
  72. PARCEL_GRID_STEP_METERS / 2, 0);
  73. mEastNorthTop += LLVector3d(PARCEL_GRID_STEP_METERS / 2,
  74. PARCEL_GRID_STEP_METERS / 2, 0);
  75. roundXY(mWestSouthBottom);
  76. roundXY(mEastNorthTop);
  77. mMouseOutsideSlop = true; //false;
  78. gViewerParcelMgr.deselectLand();
  79. }
  80. return hit_land;
  81. }
  82. bool LLToolSelectLand::handleDoubleClick(S32 x, S32 y, MASK mask)
  83. {
  84. LLVector3d pos_global;
  85. bool hit_land = gViewerWindowp->mousePointOnLandGlobal(x, y, &pos_global);
  86. if (hit_land)
  87. {
  88. // Auto-select this parcel
  89. gViewerParcelMgr.selectParcelAt(pos_global);
  90. return true;
  91. }
  92. return false;
  93. }
  94. bool LLToolSelectLand::handleMouseUp(S32 x, S32 y, MASK mask)
  95. {
  96. if (hasMouseCapture())
  97. {
  98. setMouseCapture(false);
  99. if (mMouseOutsideSlop && mDragEndValid)
  100. {
  101. // Take the drag start and end locations, then map the southwest
  102. // point down to the next grid location, and the northeast point up
  103. // to the next grid location.
  104. sanitize_corners(mDragStartGlobal, mDragEndGlobal,
  105. mWestSouthBottom, mEastNorthTop);
  106. mWestSouthBottom -= LLVector3d(PARCEL_GRID_STEP_METERS / 2,
  107. PARCEL_GRID_STEP_METERS / 2, 0);
  108. mEastNorthTop += LLVector3d(PARCEL_GRID_STEP_METERS / 2,
  109. PARCEL_GRID_STEP_METERS / 2, 0);
  110. roundXY(mWestSouthBottom);
  111. roundXY(mEastNorthTop);
  112. // Don't auto-select entire parcel.
  113. mSelection = gViewerParcelMgr.selectLand(mWestSouthBottom,
  114. mEastNorthTop, false);
  115. }
  116. mMouseOutsideSlop = false;
  117. mDragEndValid = false;
  118. return true;
  119. }
  120. return false;
  121. }
  122. bool LLToolSelectLand::handleHover(S32 x, S32 y, MASK mask)
  123. {
  124. if (hasMouseCapture())
  125. {
  126. if (mMouseOutsideSlop || outsideSlop(x, y, mDragStartX, mDragStartY))
  127. {
  128. mMouseOutsideSlop = true;
  129. // Must do this every frame, in case the camera moved or the land
  130. // moved since last frame.
  131. // If doesn't hit land, doesn't change old value
  132. LLVector3d land_global;
  133. bool hit_land = gViewerWindowp->mousePointOnLandGlobal(x, y,
  134. &land_global);
  135. if (hit_land)
  136. {
  137. mDragEndValid = true;
  138. mDragEndGlobal = land_global;
  139. sanitize_corners(mDragStartGlobal, mDragEndGlobal,
  140. mWestSouthBottom, mEastNorthTop);
  141. mWestSouthBottom -= LLVector3d(PARCEL_GRID_STEP_METERS / 2,
  142. PARCEL_GRID_STEP_METERS / 2, 0);
  143. mEastNorthTop += LLVector3d(PARCEL_GRID_STEP_METERS / 2,
  144. PARCEL_GRID_STEP_METERS / 2, 0);
  145. roundXY(mWestSouthBottom);
  146. roundXY(mEastNorthTop);
  147. LL_DEBUGS("UserInput") << "hover handled by LLToolSelectLand (active, land)"
  148. << LL_ENDL;
  149. gWindowp->setCursor(UI_CURSOR_ARROW);
  150. }
  151. else
  152. {
  153. mDragEndValid = false;
  154. LL_DEBUGS("UserInput") << "hover handled by LLToolSelectLand (active, no land)"
  155. << LL_ENDL;
  156. gWindowp->setCursor(UI_CURSOR_NO);
  157. }
  158. mDragEndX = x;
  159. mDragEndY = y;
  160. }
  161. else
  162. {
  163. LL_DEBUGS("UserInput") << "hover handled by LLToolSelectLand (active, in slop)"
  164. << LL_ENDL;
  165. gWindowp->setCursor(UI_CURSOR_ARROW);
  166. }
  167. }
  168. else
  169. {
  170. LL_DEBUGS("UserInput") << "hover handled by LLToolSelectLand (inactive)"
  171. << LL_ENDL;
  172. gWindowp->setCursor(UI_CURSOR_ARROW);
  173. }
  174. return true;
  175. }
  176. void LLToolSelectLand::render()
  177. {
  178. if (hasMouseCapture() && /*mMouseOutsideSlop &&*/ mDragEndValid)
  179. {
  180. gViewerParcelMgr.renderRect(mWestSouthBottom, mEastNorthTop);
  181. }
  182. }
  183. void LLToolSelectLand::handleSelect()
  184. {
  185. if (gFloaterToolsp)
  186. {
  187. gFloaterToolsp->setStatusText("selectland");
  188. }
  189. }
  190. void LLToolSelectLand::handleDeselect()
  191. {
  192. mSelection = NULL;
  193. }
  194. void LLToolSelectLand::roundXY(LLVector3d &vec)
  195. {
  196. vec.mdV[VX] = ll_round(vec.mdV[VX], (F64)PARCEL_GRID_STEP_METERS);
  197. vec.mdV[VY] = ll_round(vec.mdV[VY], (F64)PARCEL_GRID_STEP_METERS);
  198. }
  199. // true if x,y outside small box around start_x,start_y
  200. bool LLToolSelectLand::outsideSlop(S32 x, S32 y, S32 start_x, S32 start_y)
  201. {
  202. S32 dx = x - start_x;
  203. S32 dy = y - start_y;
  204. return dx <= -2 || 2 <= dx || dy <= -2 || 2 <= dy;
  205. }