PageRenderTime 38ms CodeModel.GetById 24ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

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