00001 00032 #include "llviewerprecompiledheaders.h" 00033 00034 #include "lltoolmgr.h" 00035 00036 #include "lltool.h" 00037 // tools and manipulators 00038 #include "llmanipscale.h" 00039 #include "lltoolbrush.h" 00040 #include "lltoolcomp.h" 00041 #include "lltooldraganddrop.h" 00042 #include "lltoolface.h" 00043 #include "lltoolfocus.h" 00044 #include "lltoolgrab.h" 00045 #include "lltoolindividual.h" 00046 #include "lltoolmorph.h" 00047 #include "lltoolpie.h" 00048 #include "lltoolplacer.h" 00049 #include "lltoolselect.h" 00050 #include "lltoolselectland.h" 00051 #include "lltoolobjpicker.h" 00052 #include "lltoolpipette.h" 00053 00054 // Globals (created and destroyed by LLAgent) 00055 LLToolMgr* gToolMgr = NULL; 00056 00057 // Used when app not active to avoid processing hover. 00058 LLTool* gToolNull = NULL; 00059 00060 LLToolset* gBasicToolset = NULL; 00061 LLToolset* gCameraToolset = NULL; 00062 //LLToolset* gLandToolset = NULL; 00063 LLToolset* gMouselookToolset = NULL; 00064 LLToolset* gFaceEditToolset = NULL; 00065 00067 // LLToolMgr 00068 00069 LLToolMgr::LLToolMgr() 00070 : 00071 mBaseTool(NULL), 00072 mSavedTool(NULL), 00073 mTransientTool( NULL ), 00074 mOverrideTool( NULL ), 00075 mSelectedTool( NULL ), 00076 mCurrentToolset( NULL ) 00077 { 00078 gToolNull = new LLTool(NULL); // Does nothing 00079 setCurrentTool(gToolNull); 00080 00081 gBasicToolset = new LLToolset(); 00082 gCameraToolset = new LLToolset(); 00083 // gLandToolset = new LLToolset(); 00084 gMouselookToolset = new LLToolset(); 00085 gFaceEditToolset = new LLToolset(); 00086 } 00087 00088 void LLToolMgr::initTools() 00089 { 00090 // Initialize all the tools 00091 // Variables that are reused for each tool 00092 LLTool* tool = NULL; 00093 00094 // 00095 // Pie tool (not visible in UI, implicit) 00096 // 00097 gToolPie = new LLToolPie(); 00098 00099 gBasicToolset->addTool( gToolPie ); 00100 // gCameraToolset->addTool( gToolPie ); 00101 // gLandToolset->addTool( gToolPie ); 00102 00103 // Camera tool 00104 gToolCamera = new LLToolCamera(); 00105 gBasicToolset ->addTool( gToolCamera ); 00106 gCameraToolset->addTool( gToolCamera ); 00107 00108 // 00109 // Grab tool 00110 // 00111 gToolGrab = new LLToolGrab(); 00112 tool = gToolGrab; 00113 00114 gBasicToolset->addTool( tool ); 00115 00116 // 00117 // Translation tool 00118 // 00119 gToolTranslate = new LLToolCompTranslate(); 00120 tool = gToolTranslate; 00121 00122 gBasicToolset->addTool( tool ); 00123 00124 // 00125 // Scale ("Stretch") tool 00126 // 00127 gToolStretch = new LLToolCompScale(); 00128 tool = gToolStretch; 00129 00130 00131 // 00132 // Rotation tool 00133 // 00134 gToolRotate = new LLToolCompRotate(); 00135 tool = gToolRotate; 00136 00137 00138 // 00139 // Face tool 00140 // 00141 gToolFace = new LLToolFace(); 00142 tool = gToolFace; 00143 00144 // 00145 // Pipette tool 00146 // 00147 gToolPipette = new LLToolPipette(); 00148 00149 // 00150 // Individual object selector 00151 // 00152 gToolIndividual = new LLToolIndividual(); 00153 00154 00155 // 00156 // Create object tool 00157 // 00158 gToolCreate = new LLToolCompCreate(); 00159 tool = gToolCreate; 00160 00161 gBasicToolset->addTool( tool ); 00162 00163 // 00164 // Land brush tool 00165 // 00166 gToolLand = new LLToolBrushLand(); 00167 tool = gToolLand; 00168 00169 gBasicToolset->addTool( tool ); 00170 00171 00172 // 00173 // Land select tool 00174 // 00175 gToolParcel = new LLToolSelectLand(); 00176 tool = gToolParcel; 00177 00178 // 00179 // Gun tool 00180 // 00181 gToolGun = new LLToolCompGun(); 00182 gMouselookToolset->addTool( gToolGun ); 00183 00184 // 00185 // Inspect tool 00186 // 00187 gToolInspect = new LLToolCompInspect(); 00188 gBasicToolset->addTool( gToolInspect ); 00189 00190 // 00191 // Face edit tool 00192 // 00193 // gToolMorph = new LLToolMorph(); 00194 // gFaceEditToolset->addTool( gToolMorph ); 00195 gFaceEditToolset->addTool( gToolCamera ); 00196 00197 // Drag and drop tool 00198 gToolDragAndDrop = new LLToolDragAndDrop(); 00199 00200 gToolObjPicker = new LLToolObjPicker(); 00201 00202 // On startup, use "select" tool 00203 setCurrentToolset(gBasicToolset); 00204 gBasicToolset->selectTool( gToolPie ); 00205 } 00206 00207 LLToolMgr::~LLToolMgr() 00208 { 00209 delete gToolPie; 00210 gToolPie = NULL; 00211 00212 delete gToolInspect; 00213 gToolInspect = NULL; 00214 00215 delete gToolGun; 00216 gToolGun = NULL; 00217 00218 delete gToolCamera; 00219 gToolCamera = NULL; 00220 00221 // delete gToolMorph; 00222 // gToolMorph = NULL; 00223 00224 delete gToolDragAndDrop; 00225 gToolDragAndDrop = NULL; 00226 00227 delete gBasicToolset; 00228 gBasicToolset = NULL; 00229 00230 delete gToolGrab; 00231 gToolGrab = NULL; 00232 00233 delete gToolRotate; 00234 gToolRotate = NULL; 00235 00236 delete gToolTranslate; 00237 gToolTranslate = NULL; 00238 00239 delete gToolStretch; 00240 gToolStretch = NULL; 00241 00242 delete gToolIndividual; 00243 gToolIndividual = NULL; 00244 00245 delete gToolPipette; 00246 gToolPipette = NULL; 00247 00248 delete gToolCreate; 00249 gToolCreate = NULL; 00250 00251 delete gToolFace; 00252 gToolFace = NULL; 00253 00254 delete gToolLand; 00255 gToolLand = NULL; 00256 00257 delete gToolParcel; 00258 gToolParcel = NULL; 00259 00260 delete gToolObjPicker; 00261 gToolObjPicker = NULL; 00262 00263 delete gMouselookToolset; 00264 gMouselookToolset = NULL; 00265 00266 delete gFaceEditToolset; 00267 gFaceEditToolset = NULL; 00268 00269 delete gCameraToolset; 00270 gCameraToolset = NULL; 00271 00272 delete gToolNull; 00273 gToolNull = NULL; 00274 } 00275 00276 BOOL LLToolMgr::usingTransientTool() 00277 { 00278 return mTransientTool ? TRUE : FALSE; 00279 } 00280 00281 void LLToolMgr::setCurrentToolset(LLToolset* current) 00282 { 00283 if (!current) return; 00284 00285 // switching toolsets? 00286 if (current != mCurrentToolset) 00287 { 00288 // deselect current tool 00289 if (mSelectedTool) 00290 { 00291 mSelectedTool->handleDeselect(); 00292 } 00293 mCurrentToolset = current; 00294 // select first tool of new toolset only if toolset changed 00295 mCurrentToolset->selectFirstTool(); 00296 } 00297 // update current tool based on new toolset 00298 setCurrentTool( mCurrentToolset->getSelectedTool() ); 00299 } 00300 00301 LLToolset* LLToolMgr::getCurrentToolset() 00302 { 00303 return mCurrentToolset; 00304 } 00305 00306 void LLToolMgr::setCurrentTool( LLTool* tool ) 00307 { 00308 if (mTransientTool) 00309 { 00310 mTransientTool = NULL; 00311 } 00312 00313 mBaseTool = tool; 00314 updateToolStatus(); 00315 } 00316 00317 LLTool* LLToolMgr::getCurrentTool() 00318 { 00319 MASK override_mask = gKeyboard->currentMask(TRUE); 00320 00321 LLTool* cur_tool = NULL; 00322 // always use transient tools if available 00323 if (mTransientTool) 00324 { 00325 mOverrideTool = NULL; 00326 cur_tool = mTransientTool; 00327 } 00328 // tools currently grabbing mouse input will stay active 00329 else if (mSelectedTool && mSelectedTool->hasMouseCapture()) 00330 { 00331 cur_tool = mSelectedTool; 00332 } 00333 else 00334 { 00335 mOverrideTool = mBaseTool ? mBaseTool->getOverrideTool(override_mask) : NULL; 00336 00337 // use override tool if available otherwise drop back to base tool 00338 cur_tool = mOverrideTool ? mOverrideTool : mBaseTool; 00339 } 00340 00341 LLTool* prev_tool = mSelectedTool; 00342 // Set the selected tool to avoid infinite recursion 00343 mSelectedTool = cur_tool; 00344 00345 //update tool selection status 00346 if (prev_tool != cur_tool) 00347 { 00348 if (prev_tool) 00349 { 00350 prev_tool->handleDeselect(); 00351 } 00352 if (cur_tool) 00353 { 00354 cur_tool->handleSelect(); 00355 } 00356 } 00357 00358 return mSelectedTool; 00359 } 00360 00361 LLTool* LLToolMgr::getBaseTool() 00362 { 00363 return mBaseTool; 00364 } 00365 00366 void LLToolMgr::updateToolStatus() 00367 { 00368 // call getcurrenttool() to calculate active tool and call handleSelect() and handleDeselect() immediately 00369 // when active tool changes 00370 getCurrentTool(); 00371 } 00372 00373 BOOL LLToolMgr::inEdit() 00374 { 00375 return mBaseTool != gToolPie && mBaseTool != gToolNull; 00376 } 00377 00378 void LLToolMgr::setTransientTool(LLTool* tool) 00379 { 00380 if (!tool) 00381 { 00382 clearTransientTool(); 00383 } 00384 else 00385 { 00386 if (mTransientTool) 00387 { 00388 mTransientTool = NULL; 00389 } 00390 00391 mTransientTool = tool; 00392 } 00393 00394 updateToolStatus(); 00395 } 00396 00397 void LLToolMgr::clearTransientTool() 00398 { 00399 if (mTransientTool) 00400 { 00401 mTransientTool = NULL; 00402 if (!mBaseTool) 00403 { 00404 llwarns << "mBaseTool is NULL" << llendl; 00405 } 00406 } 00407 updateToolStatus(); 00408 } 00409 00410 00411 // The "gun tool", used for handling mouselook, captures the mouse and 00412 // locks it within the window. When the app loses focus we need to 00413 // release this locking. 00414 void LLToolMgr::onAppFocusLost() 00415 { 00416 mSavedTool = mBaseTool; 00417 mBaseTool = gToolNull; 00418 updateToolStatus(); 00419 } 00420 00421 void LLToolMgr::onAppFocusGained() 00422 { 00423 if (mSavedTool) 00424 { 00425 mBaseTool = mSavedTool; 00426 mSavedTool = NULL; 00427 } 00428 updateToolStatus(); 00429 } 00430 00432 // LLToolset 00433 00434 void LLToolset::addTool(LLTool* tool) 00435 { 00436 llassert( !mToolList.checkData( tool ) ); // check for duplicates 00437 00438 mToolList.addDataAtEnd( tool ); 00439 if( !mSelectedTool ) 00440 { 00441 mSelectedTool = tool; 00442 } 00443 } 00444 00445 00446 void LLToolset::selectTool(LLTool* tool) 00447 { 00448 mSelectedTool = tool; 00449 gToolMgr->setCurrentTool( mSelectedTool ); 00450 } 00451 00452 00453 void LLToolset::selectToolByIndex( S32 index ) 00454 { 00455 LLTool *tool = mToolList.getNthData( index ); 00456 if (tool) 00457 { 00458 mSelectedTool = tool; 00459 gToolMgr->setCurrentTool( tool ); 00460 } 00461 } 00462 00463 BOOL LLToolset::isToolSelected( S32 index ) 00464 { 00465 return (mToolList.getNthData( index ) == mSelectedTool); 00466 } 00467 00468 00469 void LLToolset::selectFirstTool() 00470 { 00471 mSelectedTool = mToolList.getFirstData(); 00472 if (gToolMgr) 00473 { 00474 gToolMgr->setCurrentTool( mSelectedTool ); 00475 } 00476 } 00477 00478 00479 void LLToolset::selectNextTool() 00480 { 00481 LLTool* next = NULL; 00482 for( LLTool* cur = mToolList.getFirstData(); cur; cur = mToolList.getNextData() ) 00483 { 00484 if( cur == mSelectedTool ) 00485 { 00486 next = mToolList.getNextData(); 00487 break; 00488 } 00489 } 00490 00491 if( !next ) 00492 { 00493 next = mToolList.getFirstData(); 00494 } 00495 00496 mSelectedTool = next; 00497 gToolMgr->setCurrentTool( mSelectedTool ); 00498 } 00499 00500 void LLToolset::selectPrevTool() 00501 { 00502 LLTool* prev = NULL; 00503 for( LLTool* cur = mToolList.getLastData(); cur; cur = mToolList.getPreviousData() ) 00504 { 00505 if( cur == mSelectedTool ) 00506 { 00507 prev = mToolList.getPreviousData(); 00508 break; 00509 } 00510 } 00511 00512 if( !prev ) 00513 { 00514 prev = mToolList.getLastData(); 00515 } 00516 00517 mSelectedTool = prev; 00518 gToolMgr->setCurrentTool( mSelectedTool ); 00519 } 00520 00521 void select_tool( void *tool_pointer ) 00522 { 00523 LLTool *tool = (LLTool *)tool_pointer; 00524 gToolMgr->getCurrentToolset()->selectTool( tool ); 00525 }