PageRenderTime 35ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/lltoolselectrect.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 207 lines | 134 code | 35 blank | 38 comment | 18 complexity | 58aec77059a911bfb751193e6df362a1 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltoolselectrect.cpp
  3. * @brief A tool to select multiple objects with a screen-space rectangle.
  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. // File includes
  28. #include "lltoolselectrect.h"
  29. // Library includes
  30. #include "llgl.h"
  31. #include "llrender.h"
  32. #include "lldarray.h"
  33. // Viewer includes
  34. #include "llviewercontrol.h"
  35. #include "llui.h"
  36. #include "llselectmgr.h"
  37. #include "lltoolmgr.h"
  38. #include "llviewerobject.h"
  39. #include "llviewerobjectlist.h"
  40. #include "llviewerwindow.h"
  41. #include "llviewercamera.h"
  42. #include "llglheaders.h"
  43. // Globals
  44. const S32 SLOP_RADIUS = 5;
  45. //
  46. // Member functions
  47. //
  48. LLToolSelectRect::LLToolSelectRect( LLToolComposite* composite )
  49. :
  50. LLToolSelect( composite ),
  51. mDragStartX(0),
  52. mDragStartY(0),
  53. mDragEndX(0),
  54. mDragEndY(0),
  55. mDragLastWidth(0),
  56. mDragLastHeight(0),
  57. mMouseOutsideSlop(FALSE)
  58. { }
  59. void dialog_refresh_all(void);
  60. BOOL LLToolSelectRect::handleMouseDown(S32 x, S32 y, MASK mask)
  61. {
  62. handlePick(gViewerWindow->pickImmediate(x, y, TRUE));
  63. LLTool::handleMouseDown(x, y, mask);
  64. return mPick.getObject().notNull();
  65. }
  66. void LLToolSelectRect::handlePick(const LLPickInfo& pick)
  67. {
  68. mPick = pick;
  69. // start dragging rectangle
  70. setMouseCapture( TRUE );
  71. mDragStartX = pick.mMousePt.mX;
  72. mDragStartY = pick.mMousePt.mY;
  73. mDragEndX = pick.mMousePt.mX;
  74. mDragEndY = pick.mMousePt.mY;
  75. mMouseOutsideSlop = FALSE;
  76. }
  77. BOOL LLToolSelectRect::handleMouseUp(S32 x, S32 y, MASK mask)
  78. {
  79. setMouseCapture( FALSE );
  80. if( mMouseOutsideSlop )
  81. {
  82. mDragLastWidth = 0;
  83. mDragLastHeight = 0;
  84. mMouseOutsideSlop = FALSE;
  85. if (mask == MASK_CONTROL)
  86. {
  87. LLSelectMgr::getInstance()->deselectHighlightedObjects();
  88. }
  89. else
  90. {
  91. LLSelectMgr::getInstance()->selectHighlightedObjects();
  92. }
  93. return TRUE;
  94. }
  95. else
  96. {
  97. return LLToolSelect::handleMouseUp(x, y, mask);
  98. }
  99. }
  100. BOOL LLToolSelectRect::handleHover(S32 x, S32 y, MASK mask)
  101. {
  102. if( hasMouseCapture() )
  103. {
  104. if (mMouseOutsideSlop || outsideSlop(x, y, mDragStartX, mDragStartY))
  105. {
  106. if (!mMouseOutsideSlop && !(mask & MASK_SHIFT) && !(mask & MASK_CONTROL))
  107. {
  108. // just started rect select, and not adding to current selection
  109. LLSelectMgr::getInstance()->deselectAll();
  110. }
  111. mMouseOutsideSlop = TRUE;
  112. mDragEndX = x;
  113. mDragEndY = y;
  114. handleRectangleSelection(x, y, mask);
  115. }
  116. else
  117. {
  118. return LLToolSelect::handleHover(x, y, mask);
  119. }
  120. lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolSelectRect (active)" << llendl;
  121. }
  122. else
  123. {
  124. lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolSelectRect (inactive)" << llendl;
  125. }
  126. gViewerWindow->setCursor(UI_CURSOR_ARROW);
  127. return TRUE;
  128. }
  129. void LLToolSelectRect::draw()
  130. {
  131. if( hasMouseCapture() && mMouseOutsideSlop)
  132. {
  133. if (gKeyboard->currentMask(TRUE) == MASK_CONTROL)
  134. {
  135. gGL.color4f(1.f, 0.f, 0.f, 1.f);
  136. }
  137. else
  138. {
  139. gGL.color4f(1.f, 1.f, 0.f, 1.f);
  140. }
  141. gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
  142. gl_rect_2d(
  143. llmin(mDragStartX, mDragEndX),
  144. llmax(mDragStartY, mDragEndY),
  145. llmax(mDragStartX, mDragEndX),
  146. llmin(mDragStartY, mDragEndY),
  147. FALSE);
  148. if (gKeyboard->currentMask(TRUE) == MASK_CONTROL)
  149. {
  150. gGL.color4f(1.f, 0.f, 0.f, 0.1f);
  151. }
  152. else
  153. {
  154. gGL.color4f(1.f, 1.f, 0.f, 0.1f);
  155. }
  156. gl_rect_2d(
  157. llmin(mDragStartX, mDragEndX),
  158. llmax(mDragStartY, mDragEndY),
  159. llmax(mDragStartX, mDragEndX),
  160. llmin(mDragStartY, mDragEndY));
  161. }
  162. }
  163. // true if x,y outside small box around start_x,start_y
  164. BOOL LLToolSelectRect::outsideSlop(S32 x, S32 y, S32 start_x, S32 start_y)
  165. {
  166. S32 dx = x - start_x;
  167. S32 dy = y - start_y;
  168. return (dx <= -SLOP_RADIUS || SLOP_RADIUS <= dx || dy <= -SLOP_RADIUS || SLOP_RADIUS <= dy);
  169. }
  170. //
  171. // Static functions
  172. //