lltoolselectland.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "lltoolselectland.h"
00035 
00036 // indra includes
00037 #include "llparcel.h"
00038 
00039 // Viewer includes
00040 #include "llagent.h"
00041 #include "llviewercontrol.h"
00042 #include "llfloatertools.h"
00043 #include "llselectmgr.h"
00044 #include "llstatusbar.h"
00045 #include "lltoolview.h"
00046 #include "llviewerparcelmgr.h"
00047 #include "llviewerwindow.h"
00048 
00049 //
00050 // Member functions
00051 //
00052 
00053 LLToolSelectLand::LLToolSelectLand( )
00054 :       LLTool( "Parcel" ),
00055         mDragStartGlobal(),
00056         mDragEndGlobal(),
00057         mDragEndValid(FALSE),
00058         mDragStartX(0),
00059         mDragStartY(0),
00060         mDragEndX(0),
00061         mDragEndY(0),
00062         mMouseOutsideSlop(FALSE),
00063         mWestSouthBottom(),
00064         mEastNorthTop(),
00065         mLastShowParcelOwners(FALSE)
00066 { }
00067 
00068 LLToolSelectLand::~LLToolSelectLand()
00069 {
00070 }
00071 
00072 
00073 BOOL LLToolSelectLand::handleMouseDown(S32 x, S32 y, MASK mask)
00074 {
00075         BOOL hit_land = gViewerWindow->mousePointOnLandGlobal(x, y, &mDragStartGlobal);
00076         if (hit_land)
00077         {
00078                 setMouseCapture( TRUE );
00079 
00080                 mDragStartX = x;
00081                 mDragStartY = y;
00082                 mDragEndX = x;
00083                 mDragEndY = y;
00084 
00085                 mDragEndValid           = TRUE;
00086                 mDragEndGlobal          = mDragStartGlobal;
00087 
00088                 sanitize_corners(mDragStartGlobal, mDragEndGlobal, mWestSouthBottom, mEastNorthTop);
00089 
00090                 mWestSouthBottom -= LLVector3d( PARCEL_GRID_STEP_METERS/2, PARCEL_GRID_STEP_METERS/2, 0 );
00091                 mEastNorthTop += LLVector3d( PARCEL_GRID_STEP_METERS/2, PARCEL_GRID_STEP_METERS/2, 0 );
00092 
00093                 roundXY(mWestSouthBottom);
00094                 roundXY(mEastNorthTop);
00095 
00096                 mMouseOutsideSlop = TRUE; //FALSE;
00097 
00098                 LLViewerParcelMgr::getInstance()->deselectLand();
00099         }
00100 
00101         return hit_land;
00102 }
00103 
00104 
00105 BOOL LLToolSelectLand::handleDoubleClick(S32 x, S32 y, MASK mask)
00106 {
00107         LLVector3d pos_global;
00108         BOOL hit_land = gViewerWindow->mousePointOnLandGlobal(x, y, &pos_global);
00109         if (hit_land)
00110         {
00111                 // Auto-select this parcel
00112                 LLViewerParcelMgr::getInstance()->selectParcelAt( pos_global );
00113                 return TRUE;
00114         }
00115         return FALSE;
00116 }
00117 
00118 
00119 BOOL LLToolSelectLand::handleMouseUp(S32 x, S32 y, MASK mask)
00120 {
00121         if(     hasMouseCapture() )
00122         {
00123                 setMouseCapture( FALSE );
00124 
00125                 if (mMouseOutsideSlop && mDragEndValid)
00126                 {
00127                         // Take the drag start and end locations, then map the southwest
00128                         // point down to the next grid location, and the northeast point up
00129                         // to the next grid location.
00130 
00131                         sanitize_corners(mDragStartGlobal, mDragEndGlobal, mWestSouthBottom, mEastNorthTop);
00132 
00133                         mWestSouthBottom -= LLVector3d( PARCEL_GRID_STEP_METERS/2, PARCEL_GRID_STEP_METERS/2, 0 );
00134                         mEastNorthTop += LLVector3d( PARCEL_GRID_STEP_METERS/2, PARCEL_GRID_STEP_METERS/2, 0 );
00135 
00136                         roundXY(mWestSouthBottom);
00137                         roundXY(mEastNorthTop);
00138 
00139                         // Don't auto-select entire parcel.
00140                         mSelection = LLViewerParcelMgr::getInstance()->selectLand( mWestSouthBottom, mEastNorthTop, FALSE );
00141                 }
00142 
00143                 mMouseOutsideSlop = FALSE;
00144                 mDragEndValid = FALSE;
00145                 
00146                 return TRUE;
00147         }
00148         return FALSE;
00149 }
00150 
00151 
00152 BOOL LLToolSelectLand::handleHover(S32 x, S32 y, MASK mask)
00153 {
00154         if(     hasMouseCapture() )
00155         {
00156                 if (mMouseOutsideSlop || outsideSlop(x, y, mDragStartX, mDragStartY))
00157                 {
00158                         mMouseOutsideSlop = TRUE;
00159 
00160                         // Must do this every frame, in case the camera moved or the land moved
00161                         // since last frame.
00162 
00163                         // If doesn't hit land, doesn't change old value
00164                         LLVector3d land_global;
00165                         BOOL hit_land = gViewerWindow->mousePointOnLandGlobal(x, y, &land_global);
00166                         if (hit_land)
00167                         {
00168                                 mDragEndValid = TRUE;
00169                                 mDragEndGlobal = land_global;
00170 
00171                                 sanitize_corners(mDragStartGlobal, mDragEndGlobal, mWestSouthBottom, mEastNorthTop);
00172 
00173                                 mWestSouthBottom -= LLVector3d( PARCEL_GRID_STEP_METERS/2, PARCEL_GRID_STEP_METERS/2, 0 );
00174                                 mEastNorthTop += LLVector3d( PARCEL_GRID_STEP_METERS/2, PARCEL_GRID_STEP_METERS/2, 0 );
00175 
00176                                 roundXY(mWestSouthBottom);
00177                                 roundXY(mEastNorthTop);
00178 
00179                                 lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolSelectLand (active, land)" << llendl;
00180                                 gViewerWindow->getWindow()->setCursor(UI_CURSOR_ARROW);
00181                         }
00182                         else
00183                         {
00184                                 mDragEndValid = FALSE;
00185                                 lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolSelectLand (active, no land)" << llendl;
00186                                 gViewerWindow->getWindow()->setCursor(UI_CURSOR_NO);
00187                         }
00188 
00189                         mDragEndX = x;
00190                         mDragEndY = y;
00191                 }
00192                 else
00193                 {
00194                         lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolSelectLand (active, in slop)" << llendl;
00195                         gViewerWindow->getWindow()->setCursor(UI_CURSOR_ARROW);
00196                 }
00197         }
00198         else
00199         {
00200                 lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolSelectLand (inactive)" << llendl;                
00201                 gViewerWindow->getWindow()->setCursor(UI_CURSOR_ARROW);
00202         }
00203 
00204         return TRUE;
00205 }
00206 
00207 
00208 void LLToolSelectLand::render()
00209 {
00210         if(     hasMouseCapture() && /*mMouseOutsideSlop &&*/ mDragEndValid)
00211         {
00212                 LLViewerParcelMgr::getInstance()->renderRect( mWestSouthBottom, mEastNorthTop );
00213         }
00214 }
00215 
00216 void LLToolSelectLand::handleSelect()
00217 {
00218         gFloaterTools->setStatusText("selectland");
00219         mLastShowParcelOwners = gSavedSettings.getBOOL("ShowParcelOwners");
00220         gSavedSettings.setBOOL("ShowParcelOwners", mLastShowParcelOwners);
00221 }
00222 
00223 
00224 void LLToolSelectLand::handleDeselect()
00225 {
00226         mSelection = NULL;
00227         mLastShowParcelOwners = gSavedSettings.getBOOL("ShowParcelOwners");
00228         //LLViewerParcelMgr::getInstance()->deselectLand();
00229         gSavedSettings.setBOOL("ShowParcelOwners", mLastShowParcelOwners);
00230 }
00231 
00232 
00233 void LLToolSelectLand::roundXY(LLVector3d &vec)
00234 {
00235         vec.mdV[VX] = llround( vec.mdV[VX], (F64)PARCEL_GRID_STEP_METERS );
00236         vec.mdV[VY] = llround( vec.mdV[VY], (F64)PARCEL_GRID_STEP_METERS );
00237 }
00238 
00239 
00240 // true if x,y outside small box around start_x,start_y
00241 BOOL LLToolSelectLand::outsideSlop(S32 x, S32 y, S32 start_x, S32 start_y)
00242 {
00243         S32 dx = x - start_x;
00244         S32 dy = y - start_y;
00245 
00246         return (dx <= -2 || 2 <= dx || dy <= -2 || 2 <= dy);
00247 }

Generated on Fri May 16 08:34:08 2008 for SecondLife by  doxygen 1.5.5