PageRenderTime 60ms CodeModel.GetById 20ms app.highlight 12ms RepoModel.GetById 18ms app.codeStats 0ms

/indra/newview/lltoolobjpicker.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 174 lines | 110 code | 30 blank | 34 comment | 7 complexity | 2af47e90862d204f33203b364f62f875 MD5 | raw file
  1/** 
  2 * @file lltoolobjpicker.cpp
  3 * @brief LLToolObjPicker 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// LLToolObjPicker is a transient tool, useful for a single object pick.
 28
 29#include "llviewerprecompiledheaders.h"
 30
 31#include "lltoolobjpicker.h"
 32
 33#include "llagent.h"
 34#include "llselectmgr.h"
 35#include "llworld.h"
 36#include "llviewercontrol.h"
 37#include "llmenugl.h"
 38#include "lltoolmgr.h"
 39#include "llviewerobject.h"
 40#include "llviewerobjectlist.h"
 41#include "llviewermenu.h"
 42#include "llviewercamera.h"
 43#include "llviewerwindow.h"
 44#include "lldrawable.h"
 45#include "llrootview.h"
 46
 47
 48LLToolObjPicker::LLToolObjPicker()
 49:	LLTool( std::string("ObjPicker"), NULL ),
 50	mPicked( FALSE ),
 51	mHitObjectID( LLUUID::null ),
 52	mExitCallback( NULL ),
 53	mExitCallbackData( NULL )
 54{ }
 55
 56
 57// returns TRUE if an object was selected 
 58BOOL LLToolObjPicker::handleMouseDown(S32 x, S32 y, MASK mask)
 59{
 60	LLRootView* viewp = gViewerWindow->getRootView();
 61	BOOL handled = viewp->handleMouseDown(x, y, mask);
 62
 63	mHitObjectID.setNull();
 64
 65	if (! handled)
 66	{
 67		// didn't click in any UI object, so must have clicked in the world
 68		gViewerWindow->pickAsync(x, y, mask, pickCallback);
 69		handled = TRUE;
 70	}
 71	else
 72	{
 73		if (hasMouseCapture())
 74		{
 75			setMouseCapture(FALSE);
 76		}
 77		else
 78		{
 79			llwarns << "PickerTool doesn't have mouse capture on mouseDown" << llendl;	
 80		}
 81	}
 82
 83	// Pass mousedown to base class
 84	LLTool::handleMouseDown(x, y, mask);
 85
 86	return handled;
 87}
 88
 89void LLToolObjPicker::pickCallback(const LLPickInfo& pick_info)
 90{
 91	LLToolObjPicker::getInstance()->mHitObjectID = pick_info.mObjectID;
 92	LLToolObjPicker::getInstance()->mPicked = pick_info.mObjectID.notNull();
 93}
 94
 95
 96BOOL LLToolObjPicker::handleMouseUp(S32 x, S32 y, MASK mask)
 97{
 98	LLView* viewp = gViewerWindow->getRootView();
 99	BOOL handled = viewp->handleHover(x, y, mask);
100	if (handled)
101	{
102		// let UI handle this
103	}
104
105	LLTool::handleMouseUp(x, y, mask);
106	if (hasMouseCapture())
107	{
108		setMouseCapture(FALSE);
109	}
110	else
111	{
112		llwarns << "PickerTool doesn't have mouse capture on mouseUp" << llendl;	
113	}
114	return handled;
115}
116
117
118BOOL LLToolObjPicker::handleHover(S32 x, S32 y, MASK mask)
119{
120	LLView *viewp = gViewerWindow->getRootView();
121	BOOL handled = viewp->handleHover(x, y, mask);
122	if (!handled) 
123	{
124		// Used to do pick on hover.  Now we just always display the cursor.
125		ECursorType cursor = UI_CURSOR_ARROWLOCKED;
126
127		cursor = UI_CURSOR_TOOLPICKOBJECT3;
128
129		gViewerWindow->setCursor(cursor);
130	}
131	return handled;
132}
133
134
135void LLToolObjPicker::onMouseCaptureLost()
136{
137	if (mExitCallback)
138	{
139		mExitCallback(mExitCallbackData);
140
141		mExitCallback = NULL;
142		mExitCallbackData = NULL;
143	}
144
145	mPicked = FALSE;
146	mHitObjectID.setNull();
147}
148
149// virtual
150void LLToolObjPicker::setExitCallback(void (*callback)(void *), void *callback_data)
151{
152	mExitCallback = callback;
153	mExitCallbackData = callback_data;
154}
155
156// virtual
157void LLToolObjPicker::handleSelect()
158{
159	LLTool::handleSelect();
160	setMouseCapture(TRUE);
161}
162
163// virtual
164void LLToolObjPicker::handleDeselect()
165{
166	if (hasMouseCapture())
167	{
168		LLTool::handleDeselect();
169		setMouseCapture(FALSE);
170	}
171}
172
173
174