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