lltoolobjpicker.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /**
  2. * @file lltoolobjpicker.cpp
  3. * @brief LLToolObjPicker class implementation
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-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. // LLToolObjPicker is a transient tool, useful for a single object pick.
  33. #include "llviewerprecompiledheaders.h"
  34. #include "lltoolobjpicker.h"
  35. #include "llagent.h"
  36. #include "lltoolmgr.h"
  37. #include "llviewerobjectlist.h"
  38. #include "llviewerwindow.h"
  39. LLToolObjPicker gToolObjPicker;
  40. LLToolObjPicker::LLToolObjPicker()
  41. : LLTool("ObjPicker", NULL),
  42. mExitCallback(NULL),
  43. mExitCallbackData(NULL),
  44. mPicked(false)
  45. {
  46. }
  47. // Returns true if an object was selected
  48. //virtual
  49. bool LLToolObjPicker::handleMouseDown(S32 x, S32 y, MASK mask)
  50. {
  51. LLView* viewp = gViewerWindowp->getRootView();
  52. bool handled = viewp->handleMouseDown(x, y, mask);
  53. mHitObjectID.setNull();
  54. if (!handled)
  55. {
  56. // didn't click in any UI object, so must have clicked in the world
  57. gViewerWindowp->pickAsync(x, y, mask, pickCallback);
  58. handled = true;
  59. }
  60. else
  61. {
  62. if (hasMouseCapture())
  63. {
  64. setMouseCapture(false);
  65. }
  66. else
  67. {
  68. llwarns << "PickerTool doesn't have mouse capture on mouseDown"
  69. << llendl;
  70. }
  71. }
  72. // Pass mousedown to base class
  73. LLTool::handleMouseDown(x, y, mask);
  74. return handled;
  75. }
  76. //static
  77. void LLToolObjPicker::pickCallback(const LLPickInfo& pick_info)
  78. {
  79. gToolObjPicker.mHitObjectID = pick_info.mObjectID;
  80. gToolObjPicker.mPicked = pick_info.mObjectID.notNull();
  81. }
  82. //virtual
  83. bool LLToolObjPicker::handleMouseUp(S32 x, S32 y, MASK mask)
  84. {
  85. LLView* viewp = gViewerWindowp->getRootView();
  86. // Let the UI handle this
  87. bool handled = viewp->handleHover(x, y, mask);
  88. LLTool::handleMouseUp(x, y, mask);
  89. if (hasMouseCapture())
  90. {
  91. setMouseCapture(false);
  92. }
  93. else
  94. {
  95. llwarns_sparse << "No capture on mouse up" << llendl;
  96. }
  97. return handled;
  98. }
  99. //virtual
  100. bool LLToolObjPicker::handleHover(S32 x, S32 y, MASK mask)
  101. {
  102. LLView* viewp = gViewerWindowp->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. gWindowp->setCursor(cursor);
  110. }
  111. return handled;
  112. }
  113. //virtual
  114. void LLToolObjPicker::onMouseCaptureLost()
  115. {
  116. if (mExitCallback)
  117. {
  118. mExitCallback(mExitCallbackData);
  119. mExitCallback = NULL;
  120. mExitCallbackData = NULL;
  121. }
  122. mPicked = false;
  123. mHitObjectID.setNull();
  124. }
  125. //virtual
  126. void LLToolObjPicker::handleSelect()
  127. {
  128. LLTool::handleSelect();
  129. setMouseCapture(true);
  130. }
  131. //virtual
  132. void LLToolObjPicker::handleDeselect()
  133. {
  134. if (hasMouseCapture())
  135. {
  136. LLTool::handleDeselect();
  137. setMouseCapture(false);
  138. }
  139. }