PageRenderTime 32ms CodeModel.GetById 2ms app.highlight 25ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/newview/lltoolselectland.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 234 lines | 147 code | 48 blank | 39 comment | 14 complexity | 321976769abbc730c34e60afcd1fc55d MD5 | raw file
  1/** 
  2 * @file lltoolselectland.cpp
  3 * @brief LLToolSelectLand class implementation
  4 *
  5 * $LicenseInfo:firstyear=2002&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 "lltoolselectland.h"
 30
 31// indra includes
 32#include "llparcel.h"
 33
 34// Viewer includes
 35#include "llviewercontrol.h"
 36#include "llfloatertools.h"
 37#include "llselectmgr.h"
 38#include "llstatusbar.h"
 39#include "llviewerparcelmgr.h"
 40#include "llviewerwindow.h"
 41
 42//
 43// Member functions
 44//
 45
 46LLToolSelectLand::LLToolSelectLand( )
 47:	LLTool( std::string("Parcel") ),
 48	mDragStartGlobal(),
 49	mDragEndGlobal(),
 50	mDragEndValid(FALSE),
 51	mDragStartX(0),
 52	mDragStartY(0),
 53	mDragEndX(0),
 54	mDragEndY(0),
 55	mMouseOutsideSlop(FALSE),
 56	mWestSouthBottom(),
 57	mEastNorthTop()
 58{ }
 59
 60LLToolSelectLand::~LLToolSelectLand()
 61{
 62}
 63
 64
 65BOOL LLToolSelectLand::handleMouseDown(S32 x, S32 y, MASK mask)
 66{
 67	BOOL hit_land = gViewerWindow->mousePointOnLandGlobal(x, y, &mDragStartGlobal);
 68	if (hit_land)
 69	{
 70		setMouseCapture( TRUE );
 71
 72		mDragStartX = x;
 73		mDragStartY = y;
 74		mDragEndX = x;
 75		mDragEndY = y;
 76
 77		mDragEndValid		= TRUE;
 78		mDragEndGlobal		= mDragStartGlobal;
 79
 80		sanitize_corners(mDragStartGlobal, mDragEndGlobal, mWestSouthBottom, mEastNorthTop);
 81
 82		mWestSouthBottom -= LLVector3d( PARCEL_GRID_STEP_METERS/2, PARCEL_GRID_STEP_METERS/2, 0 );
 83		mEastNorthTop += LLVector3d( PARCEL_GRID_STEP_METERS/2, PARCEL_GRID_STEP_METERS/2, 0 );
 84
 85		roundXY(mWestSouthBottom);
 86		roundXY(mEastNorthTop);
 87
 88		mMouseOutsideSlop = TRUE; //FALSE;
 89
 90		LLViewerParcelMgr::getInstance()->deselectLand();
 91	}
 92
 93	return hit_land;
 94}
 95
 96
 97BOOL LLToolSelectLand::handleDoubleClick(S32 x, S32 y, MASK mask)
 98{
 99	LLVector3d pos_global;
100	BOOL hit_land = gViewerWindow->mousePointOnLandGlobal(x, y, &pos_global);
101	if (hit_land)
102	{
103		// Auto-select this parcel
104		LLViewerParcelMgr::getInstance()->selectParcelAt( pos_global );
105		return TRUE;
106	}
107	return FALSE;
108}
109
110
111BOOL LLToolSelectLand::handleMouseUp(S32 x, S32 y, MASK mask)
112{
113	if(	hasMouseCapture() )
114	{
115		setMouseCapture( FALSE );
116
117		if (mMouseOutsideSlop && mDragEndValid)
118		{
119			// Take the drag start and end locations, then map the southwest
120			// point down to the next grid location, and the northeast point up
121			// to the next grid location.
122
123			sanitize_corners(mDragStartGlobal, mDragEndGlobal, mWestSouthBottom, mEastNorthTop);
124
125			mWestSouthBottom -= LLVector3d( PARCEL_GRID_STEP_METERS/2, PARCEL_GRID_STEP_METERS/2, 0 );
126			mEastNorthTop += LLVector3d( PARCEL_GRID_STEP_METERS/2, PARCEL_GRID_STEP_METERS/2, 0 );
127
128			roundXY(mWestSouthBottom);
129			roundXY(mEastNorthTop);
130
131			// Don't auto-select entire parcel.
132			mSelection = LLViewerParcelMgr::getInstance()->selectLand( mWestSouthBottom, mEastNorthTop, FALSE );
133		}
134
135		mMouseOutsideSlop = FALSE;
136		mDragEndValid = FALSE;
137		
138		return TRUE;
139	}
140	return FALSE;
141}
142
143
144BOOL LLToolSelectLand::handleHover(S32 x, S32 y, MASK mask)
145{
146	if(	hasMouseCapture() )
147	{
148		if (mMouseOutsideSlop || outsideSlop(x, y, mDragStartX, mDragStartY))
149		{
150			mMouseOutsideSlop = TRUE;
151
152			// Must do this every frame, in case the camera moved or the land moved
153			// since last frame.
154
155			// If doesn't hit land, doesn't change old value
156			LLVector3d land_global;
157			BOOL hit_land = gViewerWindow->mousePointOnLandGlobal(x, y, &land_global);
158			if (hit_land)
159			{
160				mDragEndValid = TRUE;
161				mDragEndGlobal = land_global;
162
163				sanitize_corners(mDragStartGlobal, mDragEndGlobal, mWestSouthBottom, mEastNorthTop);
164
165				mWestSouthBottom -= LLVector3d( PARCEL_GRID_STEP_METERS/2, PARCEL_GRID_STEP_METERS/2, 0 );
166				mEastNorthTop += LLVector3d( PARCEL_GRID_STEP_METERS/2, PARCEL_GRID_STEP_METERS/2, 0 );
167
168				roundXY(mWestSouthBottom);
169				roundXY(mEastNorthTop);
170
171				lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolSelectLand (active, land)" << llendl;
172				gViewerWindow->setCursor(UI_CURSOR_ARROW);
173			}
174			else
175			{
176				mDragEndValid = FALSE;
177				lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolSelectLand (active, no land)" << llendl;
178				gViewerWindow->setCursor(UI_CURSOR_NO);
179			}
180
181			mDragEndX = x;
182			mDragEndY = y;
183		}
184		else
185		{
186			lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolSelectLand (active, in slop)" << llendl;
187			gViewerWindow->setCursor(UI_CURSOR_ARROW);
188		}
189	}
190	else
191	{
192		lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolSelectLand (inactive)" << llendl;		
193		gViewerWindow->setCursor(UI_CURSOR_ARROW);
194	}
195
196	return TRUE;
197}
198
199
200void LLToolSelectLand::render()
201{
202	if(	hasMouseCapture() && /*mMouseOutsideSlop &&*/ mDragEndValid)
203	{
204		LLViewerParcelMgr::getInstance()->renderRect( mWestSouthBottom, mEastNorthTop );
205	}
206}
207
208void LLToolSelectLand::handleSelect()
209{
210	gFloaterTools->setStatusText("selectland");
211}
212
213
214void LLToolSelectLand::handleDeselect()
215{
216	mSelection = NULL;
217}
218
219
220void LLToolSelectLand::roundXY(LLVector3d &vec)
221{
222	vec.mdV[VX] = llround( vec.mdV[VX], (F64)PARCEL_GRID_STEP_METERS );
223	vec.mdV[VY] = llround( vec.mdV[VY], (F64)PARCEL_GRID_STEP_METERS );
224}
225
226
227// true if x,y outside small box around start_x,start_y
228BOOL LLToolSelectLand::outsideSlop(S32 x, S32 y, S32 start_x, S32 start_y)
229{
230	S32 dx = x - start_x;
231	S32 dy = y - start_y;
232
233	return (dx <= -2 || 2 <= dx || dy <= -2 || 2 <= dy);
234}