/indra/newview/lltoolgun.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 141 lines · 91 code · 20 blank · 30 comment · 9 complexity · 3e1b917096e0c1394d9b26db28ddb1d6 MD5 · raw file

  1. /**
  2. * @file lltoolgun.cpp
  3. * @brief LLToolGun 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 "lltoolgun.h"
  28. #include "llviewerwindow.h"
  29. #include "llagent.h"
  30. #include "llagentcamera.h"
  31. #include "llviewercontrol.h"
  32. #include "llsky.h"
  33. #include "llappviewer.h"
  34. #include "llresmgr.h"
  35. #include "llfontgl.h"
  36. #include "llui.h"
  37. #include "llviewertexturelist.h"
  38. #include "llviewercamera.h"
  39. #include "llhudmanager.h"
  40. #include "lltoolmgr.h"
  41. #include "lltoolgrab.h"
  42. // Linden library includes
  43. #include "llwindow.h" // setMouseClipping()
  44. LLToolGun::LLToolGun( LLToolComposite* composite )
  45. : LLTool( std::string("gun"), composite ),
  46. mIsSelected(FALSE)
  47. {
  48. }
  49. void LLToolGun::handleSelect()
  50. {
  51. gViewerWindow->hideCursor();
  52. gViewerWindow->moveCursorToCenter();
  53. gViewerWindow->getWindow()->setMouseClipping(TRUE);
  54. mIsSelected = TRUE;
  55. }
  56. void LLToolGun::handleDeselect()
  57. {
  58. gViewerWindow->moveCursorToCenter();
  59. gViewerWindow->showCursor();
  60. gViewerWindow->getWindow()->setMouseClipping(FALSE);
  61. mIsSelected = FALSE;
  62. }
  63. BOOL LLToolGun::handleMouseDown(S32 x, S32 y, MASK mask)
  64. {
  65. gGrabTransientTool = this;
  66. LLToolMgr::getInstance()->getCurrentToolset()->selectTool( LLToolGrab::getInstance() );
  67. return LLToolGrab::getInstance()->handleMouseDown(x, y, mask);
  68. }
  69. BOOL LLToolGun::handleHover(S32 x, S32 y, MASK mask)
  70. {
  71. if( gAgentCamera.cameraMouselook() && mIsSelected )
  72. {
  73. const F32 NOMINAL_MOUSE_SENSITIVITY = 0.0025f;
  74. F32 mouse_sensitivity = gSavedSettings.getF32("MouseSensitivity");
  75. mouse_sensitivity = clamp_rescale(mouse_sensitivity, 0.f, 15.f, 0.5f, 2.75f) * NOMINAL_MOUSE_SENSITIVITY;
  76. // ...move the view with the mouse
  77. // get mouse movement delta
  78. S32 dx = -gViewerWindow->getCurrentMouseDX();
  79. S32 dy = -gViewerWindow->getCurrentMouseDY();
  80. if (dx != 0 || dy != 0)
  81. {
  82. // ...actually moved off center
  83. if (gSavedSettings.getBOOL("InvertMouse"))
  84. {
  85. gAgent.pitch(mouse_sensitivity * -dy);
  86. }
  87. else
  88. {
  89. gAgent.pitch(mouse_sensitivity * dy);
  90. }
  91. LLVector3 skyward = gAgent.getReferenceUpVector();
  92. gAgent.rotate(mouse_sensitivity * dx, skyward.mV[VX], skyward.mV[VY], skyward.mV[VZ]);
  93. if (gSavedSettings.getBOOL("MouseSun"))
  94. {
  95. gSky.setSunDirection(LLViewerCamera::getInstance()->getAtAxis(), LLVector3(0.f, 0.f, 0.f));
  96. gSky.setOverrideSun(TRUE);
  97. gSavedSettings.setVector3("SkySunDefaultPosition", LLViewerCamera::getInstance()->getAtAxis());
  98. }
  99. gViewerWindow->moveCursorToCenter();
  100. gViewerWindow->hideCursor();
  101. }
  102. lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolGun (mouselook)" << llendl;
  103. }
  104. else
  105. {
  106. lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolGun (not mouselook)" << llendl;
  107. }
  108. // HACK to avoid assert: error checking system makes sure that the cursor is set during every handleHover. This is actually a no-op since the cursor is hidden.
  109. gViewerWindow->setCursor(UI_CURSOR_ARROW);
  110. return TRUE;
  111. }
  112. void LLToolGun::draw()
  113. {
  114. if( gSavedSettings.getBOOL("ShowCrosshairs") )
  115. {
  116. LLUIImagePtr crosshair = LLUI::getUIImage("crosshairs.tga");
  117. crosshair->draw(
  118. ( gViewerWindow->getWorldViewRectScaled().getWidth() - crosshair->getWidth() ) / 2,
  119. ( gViewerWindow->getWorldViewRectScaled().getHeight() - crosshair->getHeight() ) / 2);
  120. }
  121. }