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

/indra/newview/lltoolobjpicker.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 174 lines | 110 code | 30 blank | 34 comment | 7 complexity | 2af47e90862d204f33203b364f62f875 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltoolobjpicker.cpp
  3. * @brief LLToolObjPicker class implementation
  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. // LLToolObjPicker is a transient tool, useful for a single object pick.
  27. #include "llviewerprecompiledheaders.h"
  28. #include "lltoolobjpicker.h"
  29. #include "llagent.h"
  30. #include "llselectmgr.h"
  31. #include "llworld.h"
  32. #include "llviewercontrol.h"
  33. #include "llmenugl.h"
  34. #include "lltoolmgr.h"
  35. #include "llviewerobject.h"
  36. #include "llviewerobjectlist.h"
  37. #include "llviewermenu.h"
  38. #include "llviewercamera.h"
  39. #include "llviewerwindow.h"
  40. #include "lldrawable.h"
  41. #include "llrootview.h"
  42. LLToolObjPicker::LLToolObjPicker()
  43. : LLTool( std::string("ObjPicker"), NULL ),
  44. mPicked( FALSE ),
  45. mHitObjectID( LLUUID::null ),
  46. mExitCallback( NULL ),
  47. mExitCallbackData( NULL )
  48. { }
  49. // returns TRUE if an object was selected
  50. BOOL LLToolObjPicker::handleMouseDown(S32 x, S32 y, MASK mask)
  51. {
  52. LLRootView* viewp = gViewerWindow->getRootView();
  53. BOOL handled = viewp->handleMouseDown(x, y, mask);
  54. mHitObjectID.setNull();
  55. if (! handled)
  56. {
  57. // didn't click in any UI object, so must have clicked in the world
  58. gViewerWindow->pickAsync(x, y, mask, pickCallback);
  59. handled = TRUE;
  60. }
  61. else
  62. {
  63. if (hasMouseCapture())
  64. {
  65. setMouseCapture(FALSE);
  66. }
  67. else
  68. {
  69. llwarns << "PickerTool doesn't have mouse capture on mouseDown" << llendl;
  70. }
  71. }
  72. // Pass mousedown to base class
  73. LLTool::handleMouseDown(x, y, mask);
  74. return handled;
  75. }
  76. void LLToolObjPicker::pickCallback(const LLPickInfo& pick_info)
  77. {
  78. LLToolObjPicker::getInstance()->mHitObjectID = pick_info.mObjectID;
  79. LLToolObjPicker::getInstance()->mPicked = pick_info.mObjectID.notNull();
  80. }
  81. BOOL LLToolObjPicker::handleMouseUp(S32 x, S32 y, MASK mask)
  82. {
  83. LLView* viewp = gViewerWindow->getRootView();
  84. BOOL handled = viewp->handleHover(x, y, mask);
  85. if (handled)
  86. {
  87. // let UI handle this
  88. }
  89. LLTool::handleMouseUp(x, y, mask);
  90. if (hasMouseCapture())
  91. {
  92. setMouseCapture(FALSE);
  93. }
  94. else
  95. {
  96. llwarns << "PickerTool doesn't have mouse capture on mouseUp" << llendl;
  97. }
  98. return handled;
  99. }
  100. BOOL LLToolObjPicker::handleHover(S32 x, S32 y, MASK mask)
  101. {
  102. LLView *viewp = gViewerWindow->getRootView();
  103. BOOL handled = viewp->handleHover(x, y, mask);
  104. if (!handled)
  105. {
  106. // Used to do pick on hover. Now we just always display the cursor.
  107. ECursorType cursor = UI_CURSOR_ARROWLOCKED;
  108. cursor = UI_CURSOR_TOOLPICKOBJECT3;
  109. gViewerWindow->setCursor(cursor);
  110. }
  111. return handled;
  112. }
  113. void LLToolObjPicker::onMouseCaptureLost()
  114. {
  115. if (mExitCallback)
  116. {
  117. mExitCallback(mExitCallbackData);
  118. mExitCallback = NULL;
  119. mExitCallbackData = NULL;
  120. }
  121. mPicked = FALSE;
  122. mHitObjectID.setNull();
  123. }
  124. // virtual
  125. void LLToolObjPicker::setExitCallback(void (*callback)(void *), void *callback_data)
  126. {
  127. mExitCallback = callback;
  128. mExitCallbackData = callback_data;
  129. }
  130. // virtual
  131. void LLToolObjPicker::handleSelect()
  132. {
  133. LLTool::handleSelect();
  134. setMouseCapture(TRUE);
  135. }
  136. // virtual
  137. void LLToolObjPicker::handleDeselect()
  138. {
  139. if (hasMouseCapture())
  140. {
  141. LLTool::handleDeselect();
  142. setMouseCapture(FALSE);
  143. }
  144. }