PageRenderTime 31ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/lltool.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 202 lines | 125 code | 26 blank | 51 comment | 11 complexity | a9d9782bc63659202cbf164d5f31d23f MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltool.cpp
  3. * @brief LLTool 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. #include "llviewerprecompiledheaders.h"
  27. #include "lltool.h"
  28. #include "indra_constants.h"
  29. #include "llerror.h"
  30. #include "llview.h"
  31. #include "llviewerwindow.h"
  32. #include "llviewercontrol.h"
  33. #include "lltoolcomp.h"
  34. #include "lltoolfocus.h"
  35. #include "llfocusmgr.h"
  36. #include "llagent.h"
  37. #include "llviewerjoystick.h"
  38. extern BOOL gDebugClicks;
  39. //static
  40. const std::string LLTool::sNameNull("null");
  41. LLTool::LLTool( const std::string& name, LLToolComposite* composite ) :
  42. mComposite( composite ),
  43. mName(name)
  44. {
  45. }
  46. LLTool::~LLTool()
  47. {
  48. if( hasMouseCapture() )
  49. {
  50. llwarns << "Tool deleted holding mouse capture. Mouse capture removed." << llendl;
  51. gFocusMgr.removeMouseCaptureWithoutCallback( this );
  52. }
  53. }
  54. BOOL LLTool::handleAnyMouseClick(S32 x, S32 y, MASK mask, LLMouseHandler::EClickType clicktype, BOOL down)
  55. {
  56. BOOL result = LLMouseHandler::handleAnyMouseClick(x, y, mask, clicktype, down);
  57. // This behavior was moved here from LLViewerWindow::handleAnyMouseClick, so it can be selectively overridden by LLTool subclasses.
  58. if(down && result)
  59. {
  60. // This is necessary to force clicks in the world to cause edit
  61. // boxes that might have keyboard focus to relinquish it, and hence
  62. // cause a commit to update their value. JC
  63. gFocusMgr.setKeyboardFocus(NULL);
  64. }
  65. return result;
  66. }
  67. BOOL LLTool::handleMouseDown(S32 x, S32 y, MASK mask)
  68. {
  69. if (gDebugClicks)
  70. {
  71. llinfos << "LLTool left mouse down" << llendl;
  72. }
  73. // by default, didn't handle it
  74. // llinfos << "LLTool::handleMouseDown" << llendl;
  75. gAgent.setControlFlags(AGENT_CONTROL_LBUTTON_DOWN);
  76. return TRUE;
  77. }
  78. BOOL LLTool::handleMouseUp(S32 x, S32 y, MASK mask)
  79. {
  80. if (gDebugClicks)
  81. {
  82. llinfos << "LLTool left mouse up" << llendl;
  83. }
  84. // by default, didn't handle it
  85. // llinfos << "LLTool::handleMouseUp" << llendl;
  86. gAgent.setControlFlags(AGENT_CONTROL_LBUTTON_UP);
  87. return TRUE;
  88. }
  89. BOOL LLTool::handleHover(S32 x, S32 y, MASK mask)
  90. {
  91. gViewerWindow->setCursor(UI_CURSOR_ARROW);
  92. lldebugst(LLERR_USER_INPUT) << "hover handled by a tool" << llendl;
  93. // by default, do nothing, say we handled it
  94. return TRUE;
  95. }
  96. BOOL LLTool::handleScrollWheel(S32 x, S32 y, S32 clicks)
  97. {
  98. // by default, didn't handle it
  99. // llinfos << "LLTool::handleScrollWheel" << llendl;
  100. return FALSE;
  101. }
  102. BOOL LLTool::handleDoubleClick(S32 x,S32 y,MASK mask)
  103. {
  104. // llinfos << "LLTool::handleDoubleClick" << llendl;
  105. // by default, pretend it's a left click
  106. return FALSE;
  107. }
  108. BOOL LLTool::handleRightMouseDown(S32 x,S32 y,MASK mask)
  109. {
  110. // by default, didn't handle it
  111. // llinfos << "LLTool::handleRightMouseDown" << llendl;
  112. return FALSE;
  113. }
  114. BOOL LLTool::handleRightMouseUp(S32 x, S32 y, MASK mask)
  115. {
  116. // by default, didn't handle it
  117. // llinfos << "LLTool::handleRightMouseDown" << llendl;
  118. return FALSE;
  119. }
  120. BOOL LLTool::handleMiddleMouseDown(S32 x,S32 y,MASK mask)
  121. {
  122. // by default, didn't handle it
  123. // llinfos << "LLTool::handleMiddleMouseDown" << llendl;
  124. return FALSE;
  125. }
  126. BOOL LLTool::handleMiddleMouseUp(S32 x, S32 y, MASK mask)
  127. {
  128. // by default, didn't handle it
  129. // llinfos << "LLTool::handleMiddleMouseUp" << llendl;
  130. return FALSE;
  131. }
  132. BOOL LLTool::handleToolTip(S32 x, S32 y, MASK mask)
  133. {
  134. // by default, didn't handle it
  135. // llinfos << "LLTool::handleToolTip" << llendl;
  136. return FALSE;
  137. }
  138. void LLTool::setMouseCapture( BOOL b )
  139. {
  140. if( b )
  141. {
  142. gFocusMgr.setMouseCapture(mComposite ? mComposite : this );
  143. }
  144. else
  145. if( hasMouseCapture() )
  146. {
  147. gFocusMgr.setMouseCapture( NULL );
  148. }
  149. }
  150. // virtual
  151. void LLTool::draw()
  152. { }
  153. BOOL LLTool::hasMouseCapture()
  154. {
  155. return gFocusMgr.getMouseCapture() == (mComposite ? mComposite : this);
  156. }
  157. BOOL LLTool::handleKey(KEY key, MASK mask)
  158. {
  159. return FALSE;
  160. }
  161. LLTool* LLTool::getOverrideTool(MASK mask)
  162. {
  163. // NOTE: if in flycam mode, ALT-ZOOM camera should be disabled
  164. if (LLViewerJoystick::getInstance()->getOverrideCamera())
  165. {
  166. return NULL;
  167. }
  168. if (gSavedSettings.getBOOL("EnableAltZoom"))
  169. {
  170. if (mask & MASK_ALT)
  171. {
  172. return LLToolCamera::getInstance();
  173. }
  174. }
  175. return NULL;
  176. }