lltool.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /**
  2. * @file lltool.h
  3. * @brief LLTool class header file
  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_LLTOOL_H
  33. #define LL_LLTOOL_H
  34. #include "llcoord.h"
  35. #include "llfocusmgr.h"
  36. #include "llkeyboard.h"
  37. #include "llmousehandler.h"
  38. #include "llvector3.h"
  39. #include "llvector3d.h"
  40. class LLPanel;
  41. class LLToolComposite;
  42. class LLView;
  43. class LLViewerObject;
  44. class LLTool : public LLMouseHandler
  45. {
  46. protected:
  47. LOG_CLASS(LLTool);
  48. public:
  49. LLTool(const std::string& name, LLToolComposite* composite = NULL);
  50. ~LLTool() override;
  51. // *HACK: to support LLFocusMgr
  52. LL_INLINE virtual bool isView() const override { return false; }
  53. // Virtual functions inherited from LLMouseHandler
  54. bool handleHover(S32 x, S32 y, MASK mask) override;
  55. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  56. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  57. LL_INLINE bool handleMiddleMouseDown(S32, S32, MASK) override
  58. {
  59. // By default, do not handle it
  60. return false;
  61. }
  62. LL_INLINE bool handleMiddleMouseUp(S32, S32, MASK) override
  63. {
  64. // By default, do not handle it
  65. return false;
  66. }
  67. LL_INLINE bool handleScrollWheel(S32, S32, S32) override
  68. {
  69. // By default, do not handle it
  70. return false;
  71. }
  72. LL_INLINE bool handleDoubleClick(S32, S32, MASK) override
  73. {
  74. // By default, do not handle it
  75. return false;
  76. }
  77. LL_INLINE bool handleRightMouseDown(S32, S32, MASK) override
  78. {
  79. // By default, do not handle it
  80. return false;
  81. }
  82. LL_INLINE bool handleRightMouseUp(S32, S32, MASK) override
  83. {
  84. // By default, do not handle it
  85. return false;
  86. }
  87. LL_INLINE bool handleToolTip(S32, S32, std::string&, LLRect*) override
  88. {
  89. // By default, do not handle it
  90. return false;
  91. }
  92. // Tools should permit tips even when the mouse is down, as that is pretty
  93. // normal for tools
  94. LL_INLINE EShowToolTip getShowToolTip() override { return SHOW_ALWAYS; }
  95. LL_INLINE void screenPointToLocal(S32 screen_x, S32 screen_y, S32* local_x,
  96. S32* local_y) const override
  97. {
  98. *local_x = screen_x;
  99. *local_y = screen_y;
  100. }
  101. LL_INLINE void localPointToScreen(S32 local_x, S32 local_y, S32* screen_x,
  102. S32* screen_y) const override
  103. {
  104. *screen_x = local_x;
  105. *screen_y = local_y;
  106. }
  107. LL_INLINE std::string getName() const override { return mName; }
  108. // New virtual functions
  109. // Override to return true whenever this tool is meant to edit objects.
  110. // Used by LLFloaterTools. HB
  111. LL_INLINE virtual bool isObjectEditTool() const { return false; }
  112. LL_INLINE virtual LLViewerObject* getEditingObject() { return NULL; }
  113. LL_INLINE virtual LLVector3d getEditingPointGlobal() { return LLVector3d(); }
  114. LL_INLINE virtual bool isEditing() { return getEditingObject() != NULL; }
  115. LL_INLINE virtual void stopEditing() {}
  116. LL_INLINE virtual bool clipMouseWhenDown() { return true; }
  117. // Does stuff when your tool is selected
  118. LL_INLINE virtual void handleSelect() {}
  119. // Cleans up when your tool is deselected
  120. LL_INLINE virtual void handleDeselect() {}
  121. virtual LLTool* getOverrideTool(MASK mask);
  122. // Returns true if this is a tool that should always be rendered regardless
  123. // of selection.
  124. LL_INLINE virtual bool isAlwaysRendered() { return false; }
  125. // Draws tool specific 3D content in world
  126. LL_INLINE virtual void render() {}
  127. // Draws tool specific 2D overlay
  128. LL_INLINE virtual void draw() {}
  129. LL_INLINE virtual bool handleKey(KEY key, MASK mask) { return false; }
  130. // Note: NOT virtual. Subclasses should call this version.
  131. void setMouseCapture(bool b);
  132. LL_INLINE bool hasMouseCapture() override
  133. {
  134. return gFocusMgr.getMouseCapture() ==
  135. (mComposite ? (LLTool*)mComposite : this);
  136. }
  137. // Override this one as needed.
  138. LL_INLINE void onMouseCaptureLost() override {}
  139. protected:
  140. // Composite will handle mouse captures.
  141. LLToolComposite* mComposite;
  142. std::string mName;
  143. public:
  144. static const std::string sNameNull;
  145. };
  146. #endif