lltoolpipette.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * @file lltoolpipette.cpp
  3. * @brief LLToolPipette class implementation
  4. *
  5. * $LicenseInfo:firstyear=2006&license=viewergpl$
  6. *
  7. * Copyright (c) 2006-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. /**
  33. * A tool to pick texture entry info from objects in world (color/texture)
  34. */
  35. #include "llviewerprecompiledheaders.h"
  36. #include "lltoolpipette.h"
  37. #include "llviewerobjectlist.h"
  38. #include "llviewerwindow.h"
  39. #include "llselectmgr.h"
  40. #include "lltoolmgr.h"
  41. LLToolPipette gToolPipette;
  42. LLToolPipette::LLToolPipette()
  43. : LLTool("Pipette"),
  44. mSelectCallback(NULL),
  45. mUserData(NULL),
  46. mSuccess(true)
  47. {
  48. }
  49. bool LLToolPipette::handleMouseDown(S32 x, S32 y, MASK mask)
  50. {
  51. mSuccess = true;
  52. mTooltipMsg.clear();
  53. setMouseCapture(true);
  54. gViewerWindowp->pickAsync(x, y, mask, pickCallback);
  55. return true;
  56. }
  57. bool LLToolPipette::handleMouseUp(S32 x, S32 y, MASK mask)
  58. {
  59. mSuccess = true;
  60. gSelectMgr.unhighlightAll();
  61. // *NOTE: This assumes the pipette tool is a transient tool.
  62. gToolMgr.clearTransientTool();
  63. setMouseCapture(false);
  64. return true;
  65. }
  66. bool LLToolPipette::handleHover(S32 x, S32 y, MASK mask)
  67. {
  68. gViewerWindowp->setCursor(mSuccess ? UI_CURSOR_PIPETTE : UI_CURSOR_NO);
  69. if (hasMouseCapture()) // mouse button is down
  70. {
  71. gViewerWindowp->pickAsync(x, y, mask, pickCallback);
  72. return true;
  73. }
  74. return false;
  75. }
  76. bool LLToolPipette::handleToolTip(S32 x, S32 y, std::string& msg,
  77. LLRect* sticky_rect_screen)
  78. {
  79. if (mTooltipMsg.empty())
  80. {
  81. return false;
  82. }
  83. // Keep tooltip message up when mouse in this part of screen
  84. sticky_rect_screen->setCenterAndSize(x, y, 20, 20);
  85. msg = mTooltipMsg;
  86. return true;
  87. }
  88. void LLToolPipette::pickCallback(const LLPickInfo& pick_info)
  89. {
  90. LLViewerObject* hit_obj = pick_info.getObject();
  91. gSelectMgr.unhighlightAll();
  92. // If we clicked on a face of a valid prim, save off texture entry data
  93. if (hit_obj &&
  94. hit_obj->getPCode() == LL_PCODE_VOLUME &&
  95. pick_info.mObjectFace != -1)
  96. {
  97. // *TODO: this should highlight the selected face only
  98. gSelectMgr.highlightObjectOnly(hit_obj);
  99. gToolPipette.mTextureEntry = *hit_obj->getTE(pick_info.mObjectFace);
  100. if (gToolPipette.mSelectCallback)
  101. {
  102. gToolPipette.mSelectCallback(gToolPipette.mTextureEntry,
  103. gToolPipette.mUserData);
  104. }
  105. }
  106. }
  107. void LLToolPipette::setSelectCallback(select_callback callback, void* user_data)
  108. {
  109. mSelectCallback = callback;
  110. mUserData = user_data;
  111. }
  112. void LLToolPipette::setResult(bool success, const std::string& msg)
  113. {
  114. mTooltipMsg = msg;
  115. mSuccess = success;
  116. }