lltoolcomp.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  1. /**
  2. * @file lltoolcomp.cpp
  3. * @brief Composite tools
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "lltoolcomp.h"
  34. #include "llmenugl.h" // For right-click menu hack
  35. #include "llgl.h"
  36. #include "llagent.h"
  37. #include "llfloatertools.h"
  38. #include "llmanip.h"
  39. #include "llmaniprotate.h"
  40. #include "llmanipscale.h"
  41. #include "llmaniptranslate.h"
  42. #include "llselectmgr.h"
  43. #include "lltoolfocus.h"
  44. #include "lltoolgrab.h"
  45. #include "lltoolmgr.h"
  46. #include "lltoolplacer.h"
  47. #include "lltoolselectrect.h"
  48. #include "llviewercontrol.h"
  49. #include "llviewermenu.h"
  50. #include "llviewerobject.h"
  51. #include "llviewerwindow.h"
  52. LLToolCompInspect gToolCompInspect;
  53. LLToolCompTranslate gToolCompTranslate;
  54. LLToolCompScale gToolCompScale;
  55. LLToolCompRotate gToolCompRotate;
  56. LLToolCompCreate gToolCompCreate;
  57. LLToolCompGun gToolCompGun;
  58. //-----------------------------------------------------------------------------
  59. // LLToolGun
  60. // Used to be in its own lltoolgun.h/cpp module, but is only used by LLToolComp
  61. // and therefore moved here. HB
  62. //-----------------------------------------------------------------------------
  63. class LLToolGun final : public LLTool
  64. {
  65. public:
  66. LLToolGun(LLToolComposite* composite)
  67. : LLTool("gun", composite),
  68. mIsSelected(false)
  69. {
  70. }
  71. void draw() override;
  72. void handleSelect() override;
  73. void handleDeselect() override;
  74. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  75. bool handleHover(S32 x, S32 y, MASK mask) override;
  76. LL_INLINE LLTool* getOverrideTool(MASK) override { return NULL; }
  77. LL_INLINE bool clipMouseWhenDown() override { return false; }
  78. private:
  79. bool mIsSelected;
  80. };
  81. void LLToolGun::handleSelect()
  82. {
  83. if (gViewerWindowp)
  84. {
  85. gViewerWindowp->hideCursor();
  86. gViewerWindowp->moveCursorToCenter();
  87. gWindowp->setMouseClipping(true);
  88. }
  89. mIsSelected = true;
  90. }
  91. void LLToolGun::handleDeselect()
  92. {
  93. if (gViewerWindowp)
  94. {
  95. gViewerWindowp->moveCursorToCenter();
  96. gViewerWindowp->showCursor();
  97. gWindowp->setMouseClipping(false);
  98. }
  99. mIsSelected = false;
  100. }
  101. bool LLToolGun::handleMouseDown(S32 x, S32 y, MASK mask)
  102. {
  103. gGrabTransientTool = this;
  104. gToolMgr.getCurrentToolset()->selectTool(&gToolGrab);
  105. return gToolGrab.handleMouseDown(x, y, mask);
  106. }
  107. bool LLToolGun::handleHover(S32 x, S32 y, MASK mask)
  108. {
  109. if (!gViewerWindowp) return false;
  110. if (mIsSelected && gAgent.cameraMouselook())
  111. {
  112. constexpr F32 NOMINAL_MOUSE_SENSITIVITY = 0.0025f;
  113. static LLCachedControl<F32> sensitivity(gSavedSettings,
  114. "MouseSensitivity");
  115. F32 mouse_sensitivity = clamp_rescale((F32)sensitivity,
  116. 0.f, 15.f, 0.5f, 2.75f)
  117. * NOMINAL_MOUSE_SENSITIVITY;
  118. // Move the view with the mouse
  119. // Get mouse movement delta
  120. S32 dx = -gViewerWindowp->getCurrentMouseDX();
  121. S32 dy = -gViewerWindowp->getCurrentMouseDY();
  122. if (dx != 0 || dy != 0)
  123. {
  124. // ...actually moved off center
  125. static LLCachedControl<bool> invert_mouse(gSavedSettings,
  126. "InvertMouse");
  127. if (invert_mouse)
  128. {
  129. gAgent.pitch(mouse_sensitivity * -dy);
  130. }
  131. else
  132. {
  133. gAgent.pitch(mouse_sensitivity * dy);
  134. }
  135. LLVector3 skyward = gAgent.getReferenceUpVector();
  136. gAgent.rotate(mouse_sensitivity * dx, skyward.mV[VX],
  137. skyward.mV[VY], skyward.mV[VZ]);
  138. gViewerWindowp->moveCursorToCenter();
  139. gViewerWindowp->hideCursor();
  140. }
  141. LL_DEBUGS("UserInput") << "hover handled by LLToolGun (mouselook)"
  142. << LL_ENDL;
  143. }
  144. else
  145. {
  146. LL_DEBUGS("UserInput") << "hover handled by LLToolGun (not mouselook)"
  147. << LL_ENDL;
  148. }
  149. // *HACK to avoid assert: error checking system makes sure that the cursor
  150. // is set during every handleHover. This is actually a no-op since the
  151. // cursor is hidden.
  152. gViewerWindowp->setCursor(UI_CURSOR_ARROW);
  153. return true;
  154. }
  155. void LLToolGun::draw()
  156. {
  157. if (!gViewerWindowp) return;
  158. static LLUIImagePtr crosshair = LLUI::getUIImage("UIImgCrosshairsUUID");
  159. if (crosshair.isNull())
  160. {
  161. llerrs << "Missing cross-hair image: verify the viewer installation !"
  162. << llendl;
  163. }
  164. static S32 image_width = crosshair->getWidth();
  165. static S32 image_height = crosshair->getHeight();
  166. static LLCachedControl<bool> show_crosshairs(gSavedSettings,
  167. "ShowCrosshairs");
  168. if (show_crosshairs)
  169. {
  170. crosshair->draw((gViewerWindowp->getWindowWidth() - image_width) / 2,
  171. (gViewerWindowp->getWindowHeight() -
  172. image_height) / 2);
  173. }
  174. }
  175. //-----------------------------------------------------------------------------
  176. // LLToolComposite
  177. //-----------------------------------------------------------------------------
  178. //static
  179. void LLToolComposite::setCurrentTool(LLTool* new_tool)
  180. {
  181. if (mCur != new_tool)
  182. {
  183. if (mSelected)
  184. {
  185. mCur->handleDeselect();
  186. mCur = new_tool;
  187. mCur->handleSelect();
  188. }
  189. else
  190. {
  191. mCur = new_tool;
  192. }
  193. }
  194. }
  195. LLToolComposite::LLToolComposite(const std::string& name)
  196. : LLTool(name),
  197. mCur(gToolNull),
  198. mDefault(gToolNull),
  199. mSelected(false),
  200. mMouseDown(false),
  201. mManip(NULL),
  202. mSelectRect(NULL)
  203. {
  204. }
  205. // Returns to the default tool
  206. bool LLToolComposite::handleMouseUp(S32 x, S32 y, MASK mask)
  207. {
  208. bool handled = mCur->handleMouseUp(x, y, mask);
  209. if (handled)
  210. {
  211. setCurrentTool(mDefault);
  212. }
  213. return handled;
  214. }
  215. void LLToolComposite::onMouseCaptureLost()
  216. {
  217. mCur->onMouseCaptureLost();
  218. setCurrentTool(mDefault);
  219. }
  220. bool LLToolComposite::isSelecting()
  221. {
  222. return mCur == mSelectRect;
  223. }
  224. void LLToolComposite::handleSelect()
  225. {
  226. if (!gSavedSettings.getBool("EditLinkedParts"))
  227. {
  228. gSelectMgr.promoteSelectionToRoot();
  229. }
  230. mCur = mDefault;
  231. mCur->handleSelect();
  232. mSelected = true;
  233. }
  234. //-----------------------------------------------------------------------------
  235. // LLToolCompInspect
  236. //-----------------------------------------------------------------------------
  237. LLToolCompInspect::LLToolCompInspect()
  238. : LLToolComposite("Inspect")
  239. {
  240. mSelectRect = new LLToolSelectRect(this);
  241. mDefault = mSelectRect;
  242. }
  243. LLToolCompInspect::~LLToolCompInspect()
  244. {
  245. delete mSelectRect;
  246. mSelectRect = NULL;
  247. }
  248. bool LLToolCompInspect::handleMouseDown(S32 x, S32 y, MASK mask)
  249. {
  250. mMouseDown = true;
  251. gViewerWindowp->pickAsync(x, y, mask, pickCallback);
  252. return true;
  253. }
  254. void LLToolCompInspect::pickCallback(const LLPickInfo& pick_info)
  255. {
  256. LLToolCompInspect* self = &gToolCompInspect;
  257. LLViewerObject* hit_obj = pick_info.getObject();
  258. if (!self->mMouseDown)
  259. {
  260. static LLCachedControl<bool> linked_parts(gSavedSettings,
  261. "EditLinkedParts");
  262. // Fast click on object, but mouse is already up... just do select
  263. self->mSelectRect->handleObjectSelection(pick_info, linked_parts,
  264. false);
  265. return;
  266. }
  267. if (hit_obj)
  268. {
  269. if (gSelectMgr.getSelection()->getObjectCount())
  270. {
  271. gEditMenuHandlerp = &gSelectMgr;
  272. }
  273. self->setCurrentTool(self->mSelectRect);
  274. self->mSelectRect->handlePick(pick_info);
  275. }
  276. else
  277. {
  278. self->setCurrentTool(self->mSelectRect);
  279. self->mSelectRect->handlePick(pick_info);
  280. }
  281. }
  282. bool LLToolCompInspect::handleDoubleClick(S32 x, S32 y, MASK mask)
  283. {
  284. return true;
  285. }
  286. //-----------------------------------------------------------------------------
  287. // LLToolCompTranslate
  288. //-----------------------------------------------------------------------------
  289. LLToolCompTranslate::LLToolCompTranslate()
  290. : LLToolComposite("Move")
  291. {
  292. mManip = new LLManipTranslate(this);
  293. mSelectRect = new LLToolSelectRect(this);
  294. mCur = mManip;
  295. mDefault = mManip;
  296. }
  297. LLToolCompTranslate::~LLToolCompTranslate()
  298. {
  299. delete mManip;
  300. mManip = NULL;
  301. delete mSelectRect;
  302. mSelectRect = NULL;
  303. }
  304. bool LLToolCompTranslate::handleHover(S32 x, S32 y, MASK mask)
  305. {
  306. if (!mCur->hasMouseCapture())
  307. {
  308. setCurrentTool(mManip);
  309. }
  310. return mCur->handleHover(x, y, mask);
  311. }
  312. bool LLToolCompTranslate::handleMouseDown(S32 x, S32 y, MASK mask)
  313. {
  314. mMouseDown = true;
  315. gViewerWindowp->pickAsync(x, y, mask, pickCallback, true);
  316. return true;
  317. }
  318. void LLToolCompTranslate::pickCallback(const LLPickInfo& pick_info)
  319. {
  320. LLToolCompTranslate* self = &gToolCompTranslate;
  321. LLViewerObject* hit_obj = pick_info.getObject();
  322. self->mManip->highlightManipulators(pick_info.mMousePt.mX,
  323. pick_info.mMousePt.mY);
  324. if (!self->mMouseDown)
  325. {
  326. static LLCachedControl<bool> linked_parts(gSavedSettings,
  327. "EditLinkedParts");
  328. // Fast click on object, but mouse is already up...just do select
  329. self->mSelectRect->handleObjectSelection(pick_info, linked_parts,
  330. false);
  331. return;
  332. }
  333. if (hit_obj || self->mManip->getHighlightedPart() != LLManip::LL_NO_PART)
  334. {
  335. if (self->mManip->getSelection()->getObjectCount())
  336. {
  337. gEditMenuHandlerp = &gSelectMgr;
  338. }
  339. bool can_move = self->mManip->canAffectSelection();
  340. if (can_move &&
  341. LLManip::LL_NO_PART != self->mManip->getHighlightedPart())
  342. {
  343. self->setCurrentTool(self->mManip);
  344. self->mManip->handleMouseDownOnPart(pick_info.mMousePt.mX,
  345. pick_info.mMousePt.mY,
  346. pick_info.mKeyMask);
  347. }
  348. else
  349. {
  350. self->setCurrentTool(self->mSelectRect);
  351. self->mSelectRect->handlePick(pick_info);
  352. #if 0 // *TODO: add toggle to trigger old click-drag functionality
  353. self->mManip->handleMouseDownOnPart(XY_part, x, y, mask);
  354. #endif
  355. }
  356. }
  357. else
  358. {
  359. self->setCurrentTool(self->mSelectRect);
  360. self->mSelectRect->handlePick(pick_info);
  361. }
  362. }
  363. bool LLToolCompTranslate::handleMouseUp(S32 x, S32 y, MASK mask)
  364. {
  365. mMouseDown = false;
  366. return LLToolComposite::handleMouseUp(x, y, mask);
  367. }
  368. LLTool* LLToolCompTranslate::getOverrideTool(MASK mask)
  369. {
  370. if (mask == MASK_CONTROL)
  371. {
  372. return &gToolCompRotate;
  373. }
  374. if (mask == (MASK_CONTROL | MASK_SHIFT))
  375. {
  376. return &gToolCompScale;
  377. }
  378. return LLToolComposite::getOverrideTool(mask);
  379. }
  380. bool LLToolCompTranslate::handleDoubleClick(S32 x, S32 y, MASK mask)
  381. {
  382. if (mManip->getSelection()->isEmpty() &&
  383. mManip->getHighlightedPart() == LLManip::LL_NO_PART)
  384. {
  385. // You should already have an object selected from the mousedown.
  386. // If so, show its properties
  387. if (gFloaterToolsp)
  388. {
  389. gFloaterToolsp->showPanel(LLFloaterTools::PANEL_CONTENTS);
  390. }
  391. return true;
  392. }
  393. // Nothing selected means the first mouse click was probably bad, so try
  394. // again. This also consumes the event to prevent things like double-click
  395. // teleport from triggering.
  396. return handleMouseDown(x, y, mask);
  397. }
  398. void LLToolCompTranslate::render()
  399. {
  400. mCur->render(); // removing this will not draw the RGB arrows and guidelines
  401. if (mCur != mManip)
  402. {
  403. LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
  404. mManip->renderGuidelines();
  405. }
  406. }
  407. //-----------------------------------------------------------------------------
  408. // LLToolCompScale
  409. //-----------------------------------------------------------------------------
  410. LLToolCompScale::LLToolCompScale()
  411. : LLToolComposite("Stretch")
  412. {
  413. mManip = new LLManipScale(this);
  414. mSelectRect = new LLToolSelectRect(this);
  415. mCur = mManip;
  416. mDefault = mManip;
  417. }
  418. LLToolCompScale::~LLToolCompScale()
  419. {
  420. delete mManip;
  421. delete mSelectRect;
  422. }
  423. bool LLToolCompScale::handleHover(S32 x, S32 y, MASK mask)
  424. {
  425. if (!mCur->hasMouseCapture())
  426. {
  427. setCurrentTool(mManip);
  428. }
  429. return mCur->handleHover(x, y, mask);
  430. }
  431. bool LLToolCompScale::handleMouseDown(S32 x, S32 y, MASK mask)
  432. {
  433. mMouseDown = true;
  434. gViewerWindowp->pickAsync(x, y, mask, pickCallback);
  435. return true;
  436. }
  437. void LLToolCompScale::pickCallback(const LLPickInfo& pick_info)
  438. {
  439. LLToolCompScale* self = &gToolCompScale;
  440. LLViewerObject* hit_obj = pick_info.getObject();
  441. self->mManip->highlightManipulators(pick_info.mMousePt.mX,
  442. pick_info.mMousePt.mY);
  443. if (!self->mMouseDown)
  444. {
  445. static LLCachedControl<bool> linked_parts(gSavedSettings,
  446. "EditLinkedParts");
  447. // Fast click on object, but mouse is already up... just do select
  448. self->mSelectRect->handleObjectSelection(pick_info, linked_parts,
  449. false);
  450. return;
  451. }
  452. if (hit_obj || self->mManip->getHighlightedPart() != LLManip::LL_NO_PART)
  453. {
  454. if (self->mManip->getSelection()->getObjectCount())
  455. {
  456. gEditMenuHandlerp = &gSelectMgr;
  457. }
  458. if (LLManip::LL_NO_PART != self->mManip->getHighlightedPart())
  459. {
  460. self->setCurrentTool(self->mManip);
  461. self->mManip->handleMouseDownOnPart(pick_info.mMousePt.mX,
  462. pick_info.mMousePt.mY,
  463. pick_info.mKeyMask);
  464. }
  465. else
  466. {
  467. self->setCurrentTool(self->mSelectRect);
  468. self->mSelectRect->handlePick(pick_info);
  469. }
  470. }
  471. else
  472. {
  473. self->setCurrentTool(self->mSelectRect);
  474. self->mSelectRect->handlePick(pick_info);
  475. }
  476. }
  477. bool LLToolCompScale::handleMouseUp(S32 x, S32 y, MASK mask)
  478. {
  479. mMouseDown = false;
  480. return LLToolComposite::handleMouseUp(x, y, mask);
  481. }
  482. LLTool* LLToolCompScale::getOverrideTool(MASK mask)
  483. {
  484. if (mask == MASK_CONTROL)
  485. {
  486. return &gToolCompRotate;
  487. }
  488. return LLToolComposite::getOverrideTool(mask);
  489. }
  490. bool LLToolCompScale::handleDoubleClick(S32 x, S32 y, MASK mask)
  491. {
  492. if (!mManip->getSelection()->isEmpty() &&
  493. mManip->getHighlightedPart() == LLManip::LL_NO_PART)
  494. {
  495. // You should already have an object selected from the mousedown.
  496. // If so, show its properties
  497. if (gFloaterToolsp)
  498. {
  499. gFloaterToolsp->showPanel(LLFloaterTools::PANEL_CONTENTS);
  500. }
  501. return true;
  502. }
  503. // Nothing selected means the first mouse click was probably bad, so try
  504. // again.
  505. return handleMouseDown(x, y, mask);
  506. }
  507. void LLToolCompScale::render()
  508. {
  509. mCur->render();
  510. if (mCur != mManip)
  511. {
  512. LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
  513. mManip->renderGuidelines();
  514. }
  515. }
  516. //-----------------------------------------------------------------------------
  517. // LLToolCompCreate
  518. //-----------------------------------------------------------------------------
  519. LLToolCompCreate::LLToolCompCreate()
  520. : LLToolComposite("Create")
  521. {
  522. mPlacer = new LLToolPlacer();
  523. mSelectRect = new LLToolSelectRect(this);
  524. mCur = mPlacer;
  525. mDefault = mPlacer;
  526. mObjectPlacedOnMouseDown = false;
  527. }
  528. LLToolCompCreate::~LLToolCompCreate()
  529. {
  530. delete mPlacer;
  531. delete mSelectRect;
  532. }
  533. bool LLToolCompCreate::handleMouseDown(S32 x, S32 y, MASK mask)
  534. {
  535. bool handled = false;
  536. mMouseDown = true;
  537. if (mask == MASK_SHIFT || mask == MASK_CONTROL)
  538. {
  539. gViewerWindowp->pickAsync(x, y, mask, pickCallback);
  540. handled = true;
  541. }
  542. else
  543. {
  544. setCurrentTool(mPlacer);
  545. handled = mPlacer->placeObject(x, y, mask);
  546. }
  547. mObjectPlacedOnMouseDown = true;
  548. return handled;
  549. }
  550. void LLToolCompCreate::pickCallback(const LLPickInfo& pick_info)
  551. {
  552. // *NOTE: We mask off shift and control, so you cannot select multiple
  553. // objects at once with the create tool.
  554. MASK mask = (pick_info.mKeyMask & ~MASK_SHIFT);
  555. mask = (mask & ~MASK_CONTROL);
  556. LLToolCompCreate* self = &gToolCompCreate;
  557. self->setCurrentTool(self->mSelectRect);
  558. self->mSelectRect->handlePick(pick_info);
  559. }
  560. bool LLToolCompCreate::handleDoubleClick(S32 x, S32 y, MASK mask)
  561. {
  562. return handleMouseDown(x, y, mask);
  563. }
  564. bool LLToolCompCreate::handleMouseUp(S32 x, S32 y, MASK mask)
  565. {
  566. bool handled = false;
  567. if (mMouseDown && !mObjectPlacedOnMouseDown && mask != MASK_SHIFT &&
  568. mask != MASK_CONTROL)
  569. {
  570. setCurrentTool(mPlacer);
  571. handled = mPlacer->placeObject(x, y, mask);
  572. }
  573. mObjectPlacedOnMouseDown = false;
  574. mMouseDown = false;
  575. if (!handled)
  576. {
  577. handled = LLToolComposite::handleMouseUp(x, y, mask);
  578. }
  579. return handled;
  580. }
  581. //-----------------------------------------------------------------------------
  582. // LLToolCompRotate
  583. //-----------------------------------------------------------------------------
  584. LLToolCompRotate::LLToolCompRotate()
  585. : LLToolComposite("Rotate")
  586. {
  587. mManip = new LLManipRotate(this);
  588. mSelectRect = new LLToolSelectRect(this);
  589. mCur = mManip;
  590. mDefault = mManip;
  591. }
  592. LLToolCompRotate::~LLToolCompRotate()
  593. {
  594. delete mManip;
  595. delete mSelectRect;
  596. }
  597. bool LLToolCompRotate::handleHover(S32 x, S32 y, MASK mask)
  598. {
  599. if (!mCur->hasMouseCapture())
  600. {
  601. setCurrentTool(mManip);
  602. }
  603. return mCur->handleHover(x, y, mask);
  604. }
  605. bool LLToolCompRotate::handleMouseDown(S32 x, S32 y, MASK mask)
  606. {
  607. mMouseDown = true;
  608. gViewerWindowp->pickAsync(x, y, mask, pickCallback);
  609. return true;
  610. }
  611. void LLToolCompRotate::pickCallback(const LLPickInfo& pick_info)
  612. {
  613. LLToolCompRotate* self = &gToolCompRotate;
  614. LLViewerObject* hit_obj = pick_info.getObject();
  615. self->mManip->highlightManipulators(pick_info.mMousePt.mX,
  616. pick_info.mMousePt.mY);
  617. if (!self->mMouseDown)
  618. {
  619. // Fast click on object, but mouse is already up... Just do select
  620. static LLCachedControl<bool> linked_parts(gSavedSettings,
  621. "EditLinkedParts");
  622. self->mSelectRect->handleObjectSelection(pick_info, linked_parts,
  623. false);
  624. return;
  625. }
  626. if (hit_obj || self->mManip->getHighlightedPart() != LLManip::LL_NO_PART)
  627. {
  628. if (self->mManip->getSelection()->getObjectCount())
  629. {
  630. gEditMenuHandlerp = &gSelectMgr;
  631. }
  632. if (LLManip::LL_NO_PART != self->mManip->getHighlightedPart())
  633. {
  634. self->setCurrentTool(self->mManip);
  635. self->mManip->handleMouseDownOnPart(pick_info.mMousePt.mX,
  636. pick_info.mMousePt.mY,
  637. pick_info.mKeyMask);
  638. }
  639. else
  640. {
  641. self->setCurrentTool(self->mSelectRect);
  642. self->mSelectRect->handlePick(pick_info);
  643. }
  644. }
  645. else
  646. {
  647. self->setCurrentTool(self->mSelectRect);
  648. self->mSelectRect->handlePick(pick_info);
  649. }
  650. }
  651. bool LLToolCompRotate::handleMouseUp(S32 x, S32 y, MASK mask)
  652. {
  653. mMouseDown = false;
  654. return LLToolComposite::handleMouseUp(x, y, mask);
  655. }
  656. LLTool* LLToolCompRotate::getOverrideTool(MASK mask)
  657. {
  658. if (mask == (MASK_CONTROL | MASK_SHIFT))
  659. {
  660. return &gToolCompScale;
  661. }
  662. return LLToolComposite::getOverrideTool(mask);
  663. }
  664. bool LLToolCompRotate::handleDoubleClick(S32 x, S32 y, MASK mask)
  665. {
  666. if (!mManip->getSelection()->isEmpty() &&
  667. mManip->getHighlightedPart() == LLManip::LL_NO_PART)
  668. {
  669. // You should already have an object selected from the mousedown.
  670. // If so, show its properties
  671. if (gFloaterToolsp)
  672. {
  673. gFloaterToolsp->showPanel(LLFloaterTools::PANEL_CONTENTS);
  674. }
  675. return true;
  676. }
  677. // Nothing selected means the first mouse click was probably bad, so try
  678. // again.
  679. return handleMouseDown(x, y, mask);
  680. }
  681. void LLToolCompRotate::render()
  682. {
  683. mCur->render();
  684. if (mCur != mManip)
  685. {
  686. LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
  687. mManip->renderGuidelines();
  688. }
  689. }
  690. //-----------------------------------------------------------------------------
  691. // LLToolCompGun
  692. //-----------------------------------------------------------------------------
  693. LLToolCompGun::LLToolCompGun()
  694. : LLToolComposite("Mouselook")
  695. {
  696. mGun = new LLToolGun(this);
  697. mGrab = new LLToolGrabBase(this);
  698. setCurrentTool(mGun);
  699. mDefault = mGun;
  700. }
  701. LLToolCompGun::~LLToolCompGun()
  702. {
  703. delete mGun;
  704. mGun = NULL;
  705. delete mGrab;
  706. mGrab = NULL;
  707. }
  708. bool LLToolCompGun::handleHover(S32 x, S32 y, MASK mask)
  709. {
  710. // Note: if the tool changed, we can't delegate the current mouse event
  711. // after the change because tools can modify the mouse during selection and
  712. // deselection.
  713. // Instead we let the current tool handle the event and then make the change.
  714. // The new tool will take effect on the next frame.
  715. mCur->handleHover(x, y, mask);
  716. // If mouse button not down...
  717. if (!gViewerWindowp->getLeftMouseDown())
  718. {
  719. // Let ALT switch from gun to grab
  720. if (mCur == mGun && (mask & MASK_ALT))
  721. {
  722. setCurrentTool((LLTool*)mGrab);
  723. }
  724. else if (mCur == mGrab && !(mask & MASK_ALT))
  725. {
  726. setCurrentTool((LLTool*)mGun);
  727. setMouseCapture(true);
  728. }
  729. }
  730. return true;
  731. }
  732. bool LLToolCompGun::handleMouseDown(S32 x, S32 y, MASK mask)
  733. {
  734. // if the left button is grabbed, don't put up the pie menu
  735. if (gAgent.leftButtonGrabbed())
  736. {
  737. gAgent.setControlFlags(AGENT_CONTROL_ML_LBUTTON_DOWN);
  738. return false;
  739. }
  740. // On mousedown, start grabbing
  741. gGrabTransientTool = this;
  742. gToolMgr.getCurrentToolset()->selectTool((LLTool*)mGrab);
  743. return gToolGrab.handleMouseDown(x, y, mask);
  744. }
  745. bool LLToolCompGun::handleDoubleClick(S32 x, S32 y, MASK mask)
  746. {
  747. // if the left button is grabbed, don't put up the pie menu
  748. if (gAgent.leftButtonGrabbed())
  749. {
  750. gAgent.setControlFlags(AGENT_CONTROL_ML_LBUTTON_DOWN);
  751. return false;
  752. }
  753. // On mousedown, start grabbing
  754. gGrabTransientTool = this;
  755. gToolMgr.getCurrentToolset()->selectTool((LLTool*)mGrab);
  756. return gToolGrab.handleDoubleClick(x, y, mask);
  757. }
  758. bool LLToolCompGun::handleRightMouseDown(S32 x, S32 y, MASK mask)
  759. {
  760. #if 0 // JC - suppress context menu 8/29/2002
  761. // On right mouse, go through some convoluted steps to make the build menu
  762. // appear.
  763. setCurrentTool(gToolNull);
  764. // This should return false, meaning the context menu will be shown.
  765. return false;
  766. #else
  767. // Returning true suppresses the context menu
  768. return true;
  769. #endif
  770. }
  771. bool LLToolCompGun::handleMouseUp(S32 x, S32 y, MASK mask)
  772. {
  773. gAgent.setControlFlags(AGENT_CONTROL_ML_LBUTTON_UP);
  774. setCurrentTool((LLTool*)mGun);
  775. return true;
  776. }
  777. void LLToolCompGun::onMouseCaptureLost()
  778. {
  779. if (mComposite)
  780. {
  781. mComposite->onMouseCaptureLost();
  782. return;
  783. }
  784. mCur->onMouseCaptureLost();
  785. }
  786. void LLToolCompGun::handleSelect()
  787. {
  788. LLToolComposite::handleSelect();
  789. setMouseCapture(true);
  790. }
  791. void LLToolCompGun::handleDeselect()
  792. {
  793. LLToolComposite::handleDeselect();
  794. setMouseCapture(false);
  795. }
  796. bool LLToolCompGun::handleScrollWheel(S32 x, S32 y, S32 clicks)
  797. {
  798. if (clicks > 0)
  799. {
  800. gAgent.changeCameraToDefault();
  801. }
  802. return true;
  803. }