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

/indra/newview/lltoolpipette.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 136 lines | 79 code | 20 blank | 37 comment | 7 complexity | 292ddd728f2915a52879b56517a60d18 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltoolpipette.cpp
  3. * @brief LLToolPipette class implementation
  4. *
  5. * $LicenseInfo:firstyear=2006&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. /**
  27. * A tool to pick texture entry infro from objects in world (color/texture)
  28. */
  29. #include "llviewerprecompiledheaders.h"
  30. // File includes
  31. #include "lltoolpipette.h"
  32. // Library includes
  33. #include "lltooltip.h"
  34. // Viewer includes
  35. #include "llviewerobjectlist.h"
  36. #include "llviewerwindow.h"
  37. #include "llselectmgr.h"
  38. #include "lltoolmgr.h"
  39. //
  40. // Member functions
  41. //
  42. LLToolPipette::LLToolPipette()
  43. : LLTool(std::string("Pipette")),
  44. mSuccess(TRUE)
  45. {
  46. }
  47. LLToolPipette::~LLToolPipette()
  48. { }
  49. BOOL LLToolPipette::handleMouseDown(S32 x, S32 y, MASK mask)
  50. {
  51. mSuccess = TRUE;
  52. mTooltipMsg.clear();
  53. setMouseCapture(TRUE);
  54. gViewerWindow->pickAsync(x, y, mask, pickCallback);
  55. return TRUE;
  56. }
  57. BOOL LLToolPipette::handleMouseUp(S32 x, S32 y, MASK mask)
  58. {
  59. mSuccess = TRUE;
  60. LLSelectMgr::getInstance()->unhighlightAll();
  61. // *NOTE: This assumes the pipette tool is a transient tool.
  62. LLToolMgr::getInstance()->clearTransientTool();
  63. setMouseCapture(FALSE);
  64. return TRUE;
  65. }
  66. BOOL LLToolPipette::handleHover(S32 x, S32 y, MASK mask)
  67. {
  68. gViewerWindow->setCursor(mSuccess ? UI_CURSOR_PIPETTE : UI_CURSOR_NO);
  69. if (hasMouseCapture()) // mouse button is down
  70. {
  71. gViewerWindow->pickAsync(x, y, mask, pickCallback);
  72. return TRUE;
  73. }
  74. return FALSE;
  75. }
  76. BOOL LLToolPipette::handleToolTip(S32 x, S32 y, MASK mask)
  77. {
  78. if (mTooltipMsg.empty())
  79. {
  80. return FALSE;
  81. }
  82. LLRect sticky_rect;
  83. sticky_rect.setCenterAndSize(x, y, 20, 20);
  84. LLToolTipMgr::instance().show(LLToolTip::Params()
  85. .message(mTooltipMsg)
  86. .sticky_rect(sticky_rect));
  87. return TRUE;
  88. }
  89. void LLToolPipette::setTextureEntry(const LLTextureEntry* entry)
  90. {
  91. if (entry)
  92. {
  93. mTextureEntry = *entry;
  94. mSignal(mTextureEntry);
  95. }
  96. }
  97. void LLToolPipette::pickCallback(const LLPickInfo& pick_info)
  98. {
  99. LLViewerObject* hit_obj = pick_info.getObject();
  100. LLSelectMgr::getInstance()->unhighlightAll();
  101. // if we clicked on a face of a valid prim, save off texture entry data
  102. if (hit_obj &&
  103. hit_obj->getPCode() == LL_PCODE_VOLUME &&
  104. pick_info.mObjectFace != -1)
  105. {
  106. //TODO: this should highlight the selected face only
  107. LLSelectMgr::getInstance()->highlightObjectOnly(hit_obj);
  108. const LLTextureEntry* entry = hit_obj->getTE(pick_info.mObjectFace);
  109. LLToolPipette::getInstance()->setTextureEntry(entry);
  110. }
  111. }
  112. void LLToolPipette::setResult(BOOL success, const std::string& msg)
  113. {
  114. mTooltipMsg = msg;
  115. mSuccess = success;
  116. }