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

Generated on Thu Jul 1 06:09:22 2010 for Second Life Viewer by  doxygen 1.4.7