PageRenderTime 81ms CodeModel.GetById 30ms app.highlight 15ms RepoModel.GetById 26ms app.codeStats 0ms

/indra/newview/lltoolselectrect.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 207 lines | 134 code | 35 blank | 38 comment | 18 complexity | 58aec77059a911bfb751193e6df362a1 MD5 | raw file
  1/** 
  2 * @file lltoolselectrect.cpp
  3 * @brief A tool to select multiple objects with a screen-space rectangle.
  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// File includes
 30#include "lltoolselectrect.h"
 31
 32// Library includes
 33#include "llgl.h"
 34#include "llrender.h"
 35#include "lldarray.h"
 36
 37// Viewer includes
 38#include "llviewercontrol.h"
 39#include "llui.h"
 40#include "llselectmgr.h"
 41#include "lltoolmgr.h"
 42#include "llviewerobject.h"
 43#include "llviewerobjectlist.h"
 44#include "llviewerwindow.h"
 45#include "llviewercamera.h"
 46
 47#include "llglheaders.h"
 48
 49// Globals
 50const S32 SLOP_RADIUS = 5;
 51
 52
 53//
 54// Member functions
 55//
 56
 57LLToolSelectRect::LLToolSelectRect( LLToolComposite* composite )
 58	:
 59	LLToolSelect( composite ),
 60	mDragStartX(0),
 61	mDragStartY(0),
 62	mDragEndX(0),
 63	mDragEndY(0),
 64	mDragLastWidth(0),
 65	mDragLastHeight(0),
 66	mMouseOutsideSlop(FALSE)
 67
 68{ }
 69
 70
 71void dialog_refresh_all(void);
 72
 73BOOL LLToolSelectRect::handleMouseDown(S32 x, S32 y, MASK mask)
 74{
 75	handlePick(gViewerWindow->pickImmediate(x, y, TRUE));
 76
 77	LLTool::handleMouseDown(x, y, mask);
 78
 79	return mPick.getObject().notNull();
 80}
 81
 82void LLToolSelectRect::handlePick(const LLPickInfo& pick)
 83{
 84	mPick = pick;
 85
 86	// start dragging rectangle
 87	setMouseCapture( TRUE );
 88
 89	mDragStartX = pick.mMousePt.mX;
 90	mDragStartY = pick.mMousePt.mY;
 91	mDragEndX = pick.mMousePt.mX;
 92	mDragEndY = pick.mMousePt.mY;
 93
 94	mMouseOutsideSlop = FALSE;
 95}
 96
 97
 98BOOL LLToolSelectRect::handleMouseUp(S32 x, S32 y, MASK mask)
 99{
100	setMouseCapture( FALSE );
101
102	if(	mMouseOutsideSlop )
103	{
104		mDragLastWidth = 0;
105		mDragLastHeight = 0;
106
107		mMouseOutsideSlop = FALSE;
108		
109		if (mask == MASK_CONTROL)
110		{
111			LLSelectMgr::getInstance()->deselectHighlightedObjects();
112		}
113		else
114		{
115			LLSelectMgr::getInstance()->selectHighlightedObjects();
116		}
117		return TRUE;
118	}
119	else
120	{
121		return LLToolSelect::handleMouseUp(x, y, mask);
122	}
123}
124
125
126BOOL LLToolSelectRect::handleHover(S32 x, S32 y, MASK mask)
127{
128	if(	hasMouseCapture() )
129	{
130		if (mMouseOutsideSlop || outsideSlop(x, y, mDragStartX, mDragStartY))
131		{
132			if (!mMouseOutsideSlop && !(mask & MASK_SHIFT) && !(mask & MASK_CONTROL))
133			{
134				// just started rect select, and not adding to current selection
135				LLSelectMgr::getInstance()->deselectAll();
136			}
137			mMouseOutsideSlop = TRUE;
138			mDragEndX = x;
139			mDragEndY = y;
140
141			handleRectangleSelection(x, y, mask);
142		}
143		else
144		{
145			return LLToolSelect::handleHover(x, y, mask);
146		}
147
148		lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolSelectRect (active)" << llendl;		
149	}
150	else
151	{
152		lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolSelectRect (inactive)" << llendl;		
153	}
154
155	gViewerWindow->setCursor(UI_CURSOR_ARROW);
156	return TRUE;
157}
158
159
160void LLToolSelectRect::draw()
161{
162	if(	hasMouseCapture() && mMouseOutsideSlop)
163	{
164		if (gKeyboard->currentMask(TRUE) == MASK_CONTROL)
165		{
166			gGL.color4f(1.f, 0.f, 0.f, 1.f);
167		}
168		else
169		{
170			gGL.color4f(1.f, 1.f, 0.f, 1.f);
171		}
172		gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
173		gl_rect_2d(
174			llmin(mDragStartX, mDragEndX),
175			llmax(mDragStartY, mDragEndY),
176			llmax(mDragStartX, mDragEndX),
177			llmin(mDragStartY, mDragEndY),
178			FALSE);
179		if (gKeyboard->currentMask(TRUE) == MASK_CONTROL)
180		{
181			gGL.color4f(1.f, 0.f, 0.f, 0.1f);
182		}
183		else
184		{
185			gGL.color4f(1.f, 1.f, 0.f, 0.1f);
186		}
187		gl_rect_2d(
188			llmin(mDragStartX, mDragEndX),
189			llmax(mDragStartY, mDragEndY),
190			llmax(mDragStartX, mDragEndX),
191			llmin(mDragStartY, mDragEndY));
192	}
193}
194
195// true if x,y outside small box around start_x,start_y
196BOOL LLToolSelectRect::outsideSlop(S32 x, S32 y, S32 start_x, S32 start_y)
197{
198	S32 dx = x - start_x;
199	S32 dy = y - start_y;
200
201	return (dx <= -SLOP_RADIUS || SLOP_RADIUS <= dx || dy <= -SLOP_RADIUS || SLOP_RADIUS <= dy);
202}
203
204
205//
206// Static functions
207//