lltoolcomp.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /**
  2. * @file lltoolcomp.h
  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. #ifndef LL_TOOLCOMP_H
  33. #define LL_TOOLCOMP_H
  34. #include "lltool.h"
  35. class LLManip;
  36. class LLPickInfo;
  37. class LLTextBox;
  38. class LLToolGun;
  39. class LLToolGrabBase;
  40. class LLToolPlacer;
  41. class LLToolSelect;
  42. class LLToolSelectRect;
  43. class LLView;
  44. class LLToolComposite : public LLTool
  45. {
  46. protected:
  47. LOG_CLASS(LLToolComposite);
  48. public:
  49. LLToolComposite(const std::string& name);
  50. ~LLToolComposite() override = default;
  51. // Sets the current tool:
  52. bool handleMouseDown(S32 x, S32 y, MASK mask) override = 0;
  53. // Returns to the default tool:
  54. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  55. bool handleDoubleClick(S32 x, S32 y, MASK mask) override = 0;
  56. // Map virtual functions to the currently active internal tool:
  57. LL_INLINE bool handleHover(S32 x, S32 y, MASK mask) override
  58. {
  59. return mCur->handleHover(x, y, mask);
  60. }
  61. LL_INLINE bool handleScrollWheel(S32 x, S32 y, S32 clicks) override
  62. {
  63. return mCur->handleScrollWheel(x, y, clicks);
  64. }
  65. LL_INLINE bool handleRightMouseDown(S32 x, S32 y, MASK mask) override
  66. {
  67. return mCur->handleRightMouseDown(x, y, mask);
  68. }
  69. LL_INLINE LLViewerObject* getEditingObject() override { return mCur->getEditingObject(); }
  70. LL_INLINE LLVector3d getEditingPointGlobal() override { return mCur->getEditingPointGlobal(); }
  71. LL_INLINE bool isEditing() override { return mCur->isEditing(); }
  72. LL_INLINE void stopEditing() override { mCur->stopEditing(); mCur = mDefault; }
  73. LL_INLINE bool clipMouseWhenDown() override { return mCur->clipMouseWhenDown(); }
  74. void handleSelect() override;
  75. LL_INLINE void handleDeselect() override { mCur->handleDeselect(); mCur = mDefault; mSelected = false; }
  76. LL_INLINE void render() override { mCur->render(); }
  77. LL_INLINE void draw() override { mCur->draw(); }
  78. LL_INLINE bool handleKey(KEY key, MASK mask) override { return mCur->handleKey(key, mask); }
  79. void onMouseCaptureLost() override;
  80. LL_INLINE void screenPointToLocal(S32 scr_x, S32 scr_y, S32* loc_x,
  81. S32* loc_y) const override
  82. {
  83. mCur->screenPointToLocal(scr_x, scr_y, loc_x, loc_y);
  84. }
  85. LL_INLINE void localPointToScreen(S32 loc_x, S32 loc_y, S32* scr_x,
  86. S32* scr_y) const override
  87. {
  88. mCur->localPointToScreen(loc_x, loc_y, scr_x, scr_y);
  89. }
  90. bool isSelecting();
  91. protected:
  92. void setCurrentTool(LLTool* new_tool);
  93. LL_INLINE LLTool* getCurrentTool() { return mCur; }
  94. // In hover handler, call this to auto-switch tools:
  95. void setToolFromMask(MASK mask, LLTool* normal);
  96. protected:
  97. // The tool to which we are delegating:
  98. LLTool* mCur;
  99. LLTool* mDefault;
  100. LLManip* mManip;
  101. LLToolSelectRect* mSelectRect;
  102. bool mSelected;
  103. bool mMouseDown;
  104. public:
  105. static const std::string sNameComp;
  106. };
  107. class LLToolCompInspect final : public LLToolComposite
  108. {
  109. protected:
  110. LOG_CLASS(LLToolCompInspect);
  111. public:
  112. LLToolCompInspect();
  113. ~LLToolCompInspect() override;
  114. // Overridden from LLToolComposite
  115. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  116. bool handleDoubleClick(S32 x, S32 y, MASK mask) override;
  117. static void pickCallback(const LLPickInfo& pick_info);
  118. };
  119. class LLToolCompTranslate final : public LLToolComposite
  120. {
  121. protected:
  122. LOG_CLASS(LLToolCompTranslate);
  123. public:
  124. LLToolCompTranslate();
  125. ~LLToolCompTranslate() override;
  126. // This is an object edit tool
  127. LL_INLINE bool isObjectEditTool() const override { return true; }
  128. // Overridden from LLToolComposite
  129. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  130. bool handleDoubleClick(S32 x, S32 y, MASK mask) override;
  131. bool handleHover(S32 x, S32 y, MASK mask) override;
  132. // Returns to the default tool:
  133. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  134. void render() override;
  135. LLTool* getOverrideTool(MASK mask) override;
  136. static void pickCallback(const LLPickInfo& pick_info);
  137. };
  138. class LLToolCompScale final : public LLToolComposite
  139. {
  140. protected:
  141. LOG_CLASS(LLToolCompScale);
  142. public:
  143. LLToolCompScale();
  144. ~LLToolCompScale() override;
  145. // This is an object edit tool
  146. LL_INLINE bool isObjectEditTool() const override { return true; }
  147. // Overridden from LLToolComposite
  148. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  149. bool handleDoubleClick(S32 x, S32 y, MASK mask) override;
  150. bool handleHover(S32 x, S32 y, MASK mask) override;
  151. // Returns to the default tool:
  152. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  153. void render() override;
  154. LLTool* getOverrideTool(MASK mask) override;
  155. static void pickCallback(const LLPickInfo& pick_info);
  156. };
  157. class LLToolCompRotate final : public LLToolComposite
  158. {
  159. protected:
  160. LOG_CLASS(LLToolCompRotate);
  161. public:
  162. LLToolCompRotate();
  163. ~LLToolCompRotate() override;
  164. // This is an object edit tool
  165. LL_INLINE bool isObjectEditTool() const override { return true; }
  166. // Overridden from LLToolComposite
  167. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  168. bool handleDoubleClick(S32 x, S32 y, MASK mask) override;
  169. bool handleHover(S32 x, S32 y, MASK mask) override;
  170. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  171. void render() override;
  172. LLTool* getOverrideTool(MASK mask) override;
  173. static void pickCallback(const LLPickInfo& pick_info);
  174. };
  175. class LLToolCompCreate final : public LLToolComposite
  176. {
  177. protected:
  178. LOG_CLASS(LLToolCompCreate);
  179. public:
  180. LLToolCompCreate();
  181. ~LLToolCompCreate() override;
  182. // Overridden from LLToolComposite
  183. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  184. bool handleDoubleClick(S32 x, S32 y, MASK mask) override;
  185. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  186. static void pickCallback(const LLPickInfo& pick_info);
  187. protected:
  188. LLToolPlacer* mPlacer;
  189. bool mObjectPlacedOnMouseDown;
  190. };
  191. class LLToolCompGun final : public LLToolComposite
  192. {
  193. protected:
  194. LOG_CLASS(LLToolCompGun);
  195. public:
  196. LLToolCompGun();
  197. ~LLToolCompGun() override;
  198. // Overridden from LLToolComposite
  199. bool handleHover(S32 x, S32 y, MASK mask) override;
  200. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  201. bool handleDoubleClick(S32 x, S32 y, MASK mask) override;
  202. bool handleRightMouseDown(S32 x, S32 y, MASK mask) override;
  203. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  204. bool handleScrollWheel(S32 x, S32 y, S32 clicks) override;
  205. void onMouseCaptureLost() override;
  206. void handleSelect() override;
  207. void handleDeselect() override;
  208. LL_INLINE LLTool* getOverrideTool(MASK mask) override { return NULL; }
  209. protected:
  210. LLToolGun* mGun;
  211. LLToolGrabBase* mGrab;
  212. };
  213. extern LLToolCompInspect gToolCompInspect;
  214. extern LLToolCompTranslate gToolCompTranslate;
  215. extern LLToolCompScale gToolCompScale;
  216. extern LLToolCompRotate gToolCompRotate;
  217. extern LLToolCompCreate gToolCompCreate;
  218. extern LLToolCompGun gToolCompGun;
  219. #endif // LL_TOOLCOMP_H