diff options
Diffstat (limited to 'linden/indra/newview/lltoolmgr.cpp')
-rw-r--r-- | linden/indra/newview/lltoolmgr.cpp | 208 |
1 files changed, 80 insertions, 128 deletions
diff --git a/linden/indra/newview/lltoolmgr.cpp b/linden/indra/newview/lltoolmgr.cpp index 68a3e77..b6e14a2 100644 --- a/linden/indra/newview/lltoolmgr.cpp +++ b/linden/indra/newview/lltoolmgr.cpp | |||
@@ -53,7 +53,6 @@ LLToolMgr* gToolMgr = NULL; | |||
53 | // Used when app not active to avoid processing hover. | 53 | // Used when app not active to avoid processing hover. |
54 | LLTool* gToolNull = NULL; | 54 | LLTool* gToolNull = NULL; |
55 | 55 | ||
56 | LLToolset* gCurrentToolset = NULL; | ||
57 | LLToolset* gBasicToolset = NULL; | 56 | LLToolset* gBasicToolset = NULL; |
58 | LLToolset* gCameraToolset = NULL; | 57 | LLToolset* gCameraToolset = NULL; |
59 | //LLToolset* gLandToolset = NULL; | 58 | //LLToolset* gLandToolset = NULL; |
@@ -65,10 +64,12 @@ LLToolset* gFaceEditToolset = NULL; | |||
65 | 64 | ||
66 | LLToolMgr::LLToolMgr() | 65 | LLToolMgr::LLToolMgr() |
67 | : | 66 | : |
68 | mCurrentTool(NULL), | 67 | mBaseTool(NULL), |
69 | mSavedTool(NULL), | 68 | mSavedTool(NULL), |
70 | mTransientTool( NULL ), | 69 | mTransientTool( NULL ), |
71 | mOverrideTool( NULL ) | 70 | mOverrideTool( NULL ), |
71 | mSelectedTool( NULL ), | ||
72 | mCurrentToolset( NULL ) | ||
72 | { | 73 | { |
73 | gToolNull = new LLTool(NULL); // Does nothing | 74 | gToolNull = new LLTool(NULL); // Does nothing |
74 | setCurrentTool(gToolNull); | 75 | setCurrentTool(gToolNull); |
@@ -78,8 +79,6 @@ LLToolMgr::LLToolMgr() | |||
78 | // gLandToolset = new LLToolset(); | 79 | // gLandToolset = new LLToolset(); |
79 | gMouselookToolset = new LLToolset(); | 80 | gMouselookToolset = new LLToolset(); |
80 | gFaceEditToolset = new LLToolset(); | 81 | gFaceEditToolset = new LLToolset(); |
81 | |||
82 | gCurrentToolset = gBasicToolset; | ||
83 | } | 82 | } |
84 | 83 | ||
85 | void LLToolMgr::initTools() | 84 | void LLToolMgr::initTools() |
@@ -197,8 +196,8 @@ void LLToolMgr::initTools() | |||
197 | gToolObjPicker = new LLToolObjPicker(); | 196 | gToolObjPicker = new LLToolObjPicker(); |
198 | 197 | ||
199 | // On startup, use "select" tool | 198 | // On startup, use "select" tool |
199 | setCurrentToolset(gBasicToolset); | ||
200 | gBasicToolset->selectTool( gToolPie ); | 200 | gBasicToolset->selectTool( gToolPie ); |
201 | useSelectedTool( gBasicToolset ); | ||
202 | } | 201 | } |
203 | 202 | ||
204 | LLToolMgr::~LLToolMgr() | 203 | LLToolMgr::~LLToolMgr() |
@@ -267,138 +266,103 @@ LLToolMgr::~LLToolMgr() | |||
267 | gToolNull = NULL; | 266 | gToolNull = NULL; |
268 | } | 267 | } |
269 | 268 | ||
270 | |||
271 | void LLToolMgr::useSelectedTool( LLToolset* vp ) | ||
272 | { | ||
273 | setCurrentTool( vp->getSelectedTool() ); | ||
274 | } | ||
275 | |||
276 | BOOL LLToolMgr::usingTransientTool() | 269 | BOOL LLToolMgr::usingTransientTool() |
277 | { | 270 | { |
278 | return mTransientTool ? TRUE : FALSE; | 271 | return mTransientTool ? TRUE : FALSE; |
279 | } | 272 | } |
280 | 273 | ||
281 | void LLToolMgr::setCurrentTool( LLTool* tool ) | 274 | void LLToolMgr::setCurrentToolset(LLToolset* current) |
282 | { | 275 | { |
283 | if (tool == mCurrentTool) | 276 | if (!current) return; |
277 | |||
278 | // switching toolsets? | ||
279 | if (current != mCurrentToolset) | ||
284 | { | 280 | { |
285 | // didn't change tool, so don't mess with | 281 | // deselect current tool |
286 | // handleSelect or handleDeselect | 282 | if (mSelectedTool) |
287 | return; | 283 | { |
284 | mSelectedTool->handleDeselect(); | ||
285 | } | ||
286 | mCurrentToolset = current; | ||
287 | // select first tool of new toolset only if toolset changed | ||
288 | mCurrentToolset->selectFirstTool(); | ||
288 | } | 289 | } |
290 | // update current tool based on new toolset | ||
291 | setCurrentTool( mCurrentToolset->getSelectedTool() ); | ||
292 | } | ||
293 | |||
294 | LLToolset* LLToolMgr::getCurrentToolset() | ||
295 | { | ||
296 | return mCurrentToolset; | ||
297 | } | ||
289 | 298 | ||
299 | void LLToolMgr::setCurrentTool( LLTool* tool ) | ||
300 | { | ||
290 | if (mTransientTool) | 301 | if (mTransientTool) |
291 | { | 302 | { |
292 | mTransientTool->handleDeselect(); | ||
293 | mTransientTool = NULL; | 303 | mTransientTool = NULL; |
294 | } | 304 | } |
295 | else if( mCurrentTool ) | ||
296 | { | ||
297 | mCurrentTool->handleDeselect(); | ||
298 | } | ||
299 | 305 | ||
300 | mCurrentTool = tool; | 306 | mBaseTool = tool; |
301 | if (mCurrentTool) | 307 | updateToolStatus(); |
302 | { | ||
303 | mCurrentTool->handleSelect(); | ||
304 | } | ||
305 | } | 308 | } |
306 | 309 | ||
307 | LLTool* LLToolMgr::getCurrentTool(MASK override_mask) | 310 | LLTool* LLToolMgr::getCurrentTool() |
308 | { | 311 | { |
309 | // In mid-drag, always keep the current tool | 312 | MASK override_mask = gKeyboard->currentMask(TRUE); |
310 | if (gToolTranslate->hasMouseCapture() | ||
311 | || gToolRotate->hasMouseCapture() | ||
312 | || gToolStretch->hasMouseCapture()) | ||
313 | { | ||
314 | // might have gotten here by overriding another tool | ||
315 | if (mOverrideTool) | ||
316 | { | ||
317 | return mOverrideTool; | ||
318 | } | ||
319 | else | ||
320 | { | ||
321 | return mCurrentTool; | ||
322 | } | ||
323 | } | ||
324 | 313 | ||
314 | LLTool* cur_tool = NULL; | ||
315 | // always use transient tools if available | ||
325 | if (mTransientTool) | 316 | if (mTransientTool) |
326 | { | 317 | { |
327 | mOverrideTool = NULL; | 318 | mOverrideTool = NULL; |
328 | return mTransientTool; | 319 | cur_tool = mTransientTool; |
329 | } | 320 | } |
330 | 321 | // tools currently grabbing mouse input will stay active | |
331 | if (mCurrentTool == gToolGun) | 322 | else if (mSelectedTool && mSelectedTool->hasMouseCapture()) |
332 | { | 323 | { |
333 | mOverrideTool = NULL; | 324 | cur_tool = mSelectedTool; |
334 | return mCurrentTool; | ||
335 | } | 325 | } |
336 | 326 | else | |
337 | // ALT always gets you the camera tool | ||
338 | if (override_mask & MASK_ALT) | ||
339 | { | 327 | { |
340 | mOverrideTool = gToolCamera; | 328 | mOverrideTool = mBaseTool ? mBaseTool->getOverrideTool(override_mask) : NULL; |
341 | return mOverrideTool; | ||
342 | } | ||
343 | 329 | ||
344 | if (mCurrentTool == gToolCamera) | 330 | // use override tool if available otherwise drop back to base tool |
345 | { | 331 | cur_tool = mOverrideTool ? mOverrideTool : mBaseTool; |
346 | // ...can't switch out of camera | ||
347 | mOverrideTool = NULL; | ||
348 | return mCurrentTool; | ||
349 | } | ||
350 | else if (mCurrentTool == gToolGrab) | ||
351 | { | ||
352 | // ...can't switch out of grab | ||
353 | mOverrideTool = NULL; | ||
354 | return mCurrentTool; | ||
355 | } | 332 | } |
356 | else if (mCurrentTool == gToolInspect) | 333 | |
357 | { | 334 | //update tool selection status |
358 | // ...can't switch out of grab | 335 | if (mSelectedTool != cur_tool) |
359 | mOverrideTool = NULL; | ||
360 | return mCurrentTool; | ||
361 | } | ||
362 | else | ||
363 | { | 336 | { |
364 | // ...can switch between editing tools | 337 | if (mSelectedTool) |
365 | if (override_mask == MASK_CONTROL) | ||
366 | { | ||
367 | // Control lifts when in the pie tool, otherwise switches to rotate | ||
368 | if (mCurrentTool == gToolPie) | ||
369 | { | ||
370 | mOverrideTool = gToolGrab; | ||
371 | } | ||
372 | else | ||
373 | { | ||
374 | mOverrideTool = gToolRotate; | ||
375 | } | ||
376 | return mOverrideTool; | ||
377 | } | ||
378 | else if (override_mask == (MASK_CONTROL | MASK_SHIFT)) | ||
379 | { | 338 | { |
380 | // Shift-Control spins when in the pie tool, otherwise switches to scale | 339 | mSelectedTool->handleDeselect(); |
381 | if (mCurrentTool == gToolPie) | ||
382 | { | ||
383 | mOverrideTool = gToolGrab; | ||
384 | } | ||
385 | else | ||
386 | { | ||
387 | mOverrideTool = gToolStretch; | ||
388 | } | ||
389 | return mOverrideTool; | ||
390 | } | 340 | } |
391 | else | 341 | if (cur_tool) |
392 | { | 342 | { |
393 | mOverrideTool = NULL; | 343 | cur_tool->handleSelect(); |
394 | return mCurrentTool; | ||
395 | } | 344 | } |
345 | mSelectedTool = cur_tool; | ||
396 | } | 346 | } |
347 | |||
348 | return mSelectedTool; | ||
349 | } | ||
350 | |||
351 | LLTool* LLToolMgr::getBaseTool() | ||
352 | { | ||
353 | return mBaseTool; | ||
354 | } | ||
355 | |||
356 | void LLToolMgr::updateToolStatus() | ||
357 | { | ||
358 | // call getcurrenttool() to calculate active tool and call handleSelect() and handleDeselect() immediately | ||
359 | // when active tool changes | ||
360 | getCurrentTool(); | ||
397 | } | 361 | } |
398 | 362 | ||
399 | BOOL LLToolMgr::inEdit() | 363 | BOOL LLToolMgr::inEdit() |
400 | { | 364 | { |
401 | return mCurrentTool != gToolPie && mCurrentTool != gToolNull; | 365 | return mBaseTool != gToolPie && mBaseTool != gToolNull; |
402 | } | 366 | } |
403 | 367 | ||
404 | void LLToolMgr::setTransientTool(LLTool* tool) | 368 | void LLToolMgr::setTransientTool(LLTool* tool) |
@@ -411,34 +375,26 @@ void LLToolMgr::setTransientTool(LLTool* tool) | |||
411 | { | 375 | { |
412 | if (mTransientTool) | 376 | if (mTransientTool) |
413 | { | 377 | { |
414 | mTransientTool->handleDeselect(); | ||
415 | mTransientTool = NULL; | 378 | mTransientTool = NULL; |
416 | } | 379 | } |
417 | else if (mCurrentTool) | ||
418 | { | ||
419 | mCurrentTool->handleDeselect(); | ||
420 | } | ||
421 | 380 | ||
422 | mTransientTool = tool; | 381 | mTransientTool = tool; |
423 | mTransientTool->handleSelect(); | ||
424 | } | 382 | } |
383 | |||
384 | updateToolStatus(); | ||
425 | } | 385 | } |
426 | 386 | ||
427 | void LLToolMgr::clearTransientTool() | 387 | void LLToolMgr::clearTransientTool() |
428 | { | 388 | { |
429 | if (mTransientTool) | 389 | if (mTransientTool) |
430 | { | 390 | { |
431 | mTransientTool->handleDeselect(); | ||
432 | mTransientTool = NULL; | 391 | mTransientTool = NULL; |
433 | if (mCurrentTool) | 392 | if (!mBaseTool) |
434 | { | ||
435 | mCurrentTool->handleSelect(); | ||
436 | } | ||
437 | else | ||
438 | { | 393 | { |
439 | llwarns << "mCurrentTool is NULL" << llendl; | 394 | llwarns << "mBaseTool is NULL" << llendl; |
440 | } | 395 | } |
441 | } | 396 | } |
397 | updateToolStatus(); | ||
442 | } | 398 | } |
443 | 399 | ||
444 | 400 | ||
@@ -447,26 +403,19 @@ void LLToolMgr::clearTransientTool() | |||
447 | // release this locking. | 403 | // release this locking. |
448 | void LLToolMgr::onAppFocusLost() | 404 | void LLToolMgr::onAppFocusLost() |
449 | { | 405 | { |
450 | if (mCurrentTool | 406 | mSavedTool = mBaseTool; |
451 | && mCurrentTool == gToolGun) | 407 | mBaseTool = gToolNull; |
452 | { | 408 | updateToolStatus(); |
453 | mCurrentTool->handleDeselect(); | ||
454 | } | ||
455 | mSavedTool = mCurrentTool; | ||
456 | mCurrentTool = gToolNull; | ||
457 | } | 409 | } |
458 | 410 | ||
459 | void LLToolMgr::onAppFocusGained() | 411 | void LLToolMgr::onAppFocusGained() |
460 | { | 412 | { |
461 | if (mSavedTool) | 413 | if (mSavedTool) |
462 | { | 414 | { |
463 | if (mSavedTool == gToolGun) | 415 | mBaseTool = mSavedTool; |
464 | { | ||
465 | mCurrentTool->handleSelect(); | ||
466 | } | ||
467 | mCurrentTool = mSavedTool; | ||
468 | mSavedTool = NULL; | 416 | mSavedTool = NULL; |
469 | } | 417 | } |
418 | updateToolStatus(); | ||
470 | } | 419 | } |
471 | 420 | ||
472 | ///////////////////////////////////////////////////// | 421 | ///////////////////////////////////////////////////// |
@@ -510,7 +459,10 @@ BOOL LLToolset::isToolSelected( S32 index ) | |||
510 | void LLToolset::selectFirstTool() | 459 | void LLToolset::selectFirstTool() |
511 | { | 460 | { |
512 | mSelectedTool = mToolList.getFirstData(); | 461 | mSelectedTool = mToolList.getFirstData(); |
513 | gToolMgr->setCurrentTool( mSelectedTool ); | 462 | if (gToolMgr) |
463 | { | ||
464 | gToolMgr->setCurrentTool( mSelectedTool ); | ||
465 | } | ||
514 | } | 466 | } |
515 | 467 | ||
516 | 468 | ||
@@ -559,5 +511,5 @@ void LLToolset::selectPrevTool() | |||
559 | void select_tool( void *tool_pointer ) | 511 | void select_tool( void *tool_pointer ) |
560 | { | 512 | { |
561 | LLTool *tool = (LLTool *)tool_pointer; | 513 | LLTool *tool = (LLTool *)tool_pointer; |
562 | gCurrentToolset->selectTool( tool ); | 514 | gToolMgr->getCurrentToolset()->selectTool( tool ); |
563 | } | 515 | } |