llmanip.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /**
  2. * @file llmanip.h
  3. * @brief LLManip class definition
  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_MANIP_H
  33. #define LL_MANIP_H
  34. #include "llsafehandle.h"
  35. #include "lltool.h"
  36. class LLView;
  37. class LLTextBox;
  38. class LLViewerObject;
  39. class LLToolComposite;
  40. class LLVector3;
  41. class LLObjectSelection;
  42. constexpr S32 MIN_DIVISION_PIXEL_WIDTH = 9;
  43. class LLManip : public LLTool
  44. {
  45. public:
  46. typedef enum e_manip_part
  47. {
  48. LL_NO_PART = 0,
  49. // Translation
  50. LL_X_ARROW,
  51. LL_Y_ARROW,
  52. LL_Z_ARROW,
  53. LL_YZ_PLANE,
  54. LL_XZ_PLANE,
  55. LL_XY_PLANE,
  56. // Scale
  57. LL_CORNER_NNN,
  58. LL_CORNER_NNP,
  59. LL_CORNER_NPN,
  60. LL_CORNER_NPP,
  61. LL_CORNER_PNN,
  62. LL_CORNER_PNP,
  63. LL_CORNER_PPN,
  64. LL_CORNER_PPP,
  65. // Faces
  66. LL_FACE_POSZ,
  67. LL_FACE_POSX,
  68. LL_FACE_POSY,
  69. LL_FACE_NEGX,
  70. LL_FACE_NEGY,
  71. LL_FACE_NEGZ,
  72. // Edges
  73. LL_EDGE_NEGX_NEGY,
  74. LL_EDGE_NEGX_POSY,
  75. LL_EDGE_POSX_NEGY,
  76. LL_EDGE_POSX_POSY,
  77. LL_EDGE_NEGY_NEGZ,
  78. LL_EDGE_NEGY_POSZ,
  79. LL_EDGE_POSY_NEGZ,
  80. LL_EDGE_POSY_POSZ,
  81. LL_EDGE_NEGZ_NEGX,
  82. LL_EDGE_NEGZ_POSX,
  83. LL_EDGE_POSZ_NEGX,
  84. LL_EDGE_POSZ_POSX,
  85. // Rotation Manip
  86. LL_ROT_GENERAL,
  87. LL_ROT_X,
  88. LL_ROT_Y,
  89. LL_ROT_Z,
  90. LL_ROT_ROLL
  91. } EManipPart;
  92. // For use in loops and range checking.
  93. typedef enum e_select_part_ranges
  94. {
  95. LL_ARROW_MIN = LL_X_ARROW,
  96. LL_ARROW_MAX = LL_Z_ARROW,
  97. LL_CORNER_MIN = LL_CORNER_NNN,
  98. LL_CORNER_MAX = LL_CORNER_PPP,
  99. LL_FACE_MIN = LL_FACE_POSZ,
  100. LL_FACE_MAX = LL_FACE_NEGZ,
  101. LL_EDGE_MIN = LL_EDGE_NEGX_NEGY,
  102. LL_EDGE_MAX = LL_EDGE_POSZ_POSX
  103. } EManipPartRanges;
  104. static void rebuild(LLViewerObject* vobj);
  105. LLManip(const std::string& name, LLToolComposite* composite);
  106. virtual bool handleMouseDownOnPart(S32 x, S32 y, MASK mask) = 0;
  107. void renderGuidelines(bool draw_x = true, bool draw_y = true,
  108. bool draw_z = true);
  109. static void renderXYZ(const LLVector3& vec);
  110. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  111. bool handleHover(S32 x, S32 y, MASK mask) override;
  112. virtual void highlightManipulators(S32 x, S32 y) = 0;
  113. void handleSelect() override;
  114. void handleDeselect() override;
  115. virtual bool canAffectSelection() = 0;
  116. LL_INLINE EManipPart getHighlightedPart() { return mHighlightedPart; }
  117. LLSafeHandle<LLObjectSelection> getSelection();
  118. protected:
  119. LLVector3 getSavedPivotPoint() const;
  120. LLVector3 getPivotPoint();
  121. void getManipNormal(LLViewerObject* object, EManipPart manip,
  122. LLVector3& normal);
  123. bool getManipAxis(LLViewerObject* object, EManipPart manip,
  124. LLVector3& axis);
  125. F32 getSubdivisionLevel(const LLVector3& reference_point,
  126. const LLVector3& translate_axis, F32 grid_scale,
  127. S32 min_pixel_spacing = MIN_DIVISION_PIXEL_WIDTH);
  128. void renderTickValue(const LLVector3& pos, F32 value,
  129. const std::string& suffix, const LLColor4& color);
  130. void renderTickText(const LLVector3& pos, const std::string& suffix);
  131. void updateGridSettings();
  132. bool getMousePointOnPlaneGlobal(LLVector3d& point, S32 x, S32 y,
  133. LLVector3d origin, LLVector3 normal) const;
  134. bool getMousePointOnPlaneAgent(LLVector3& point, S32 x, S32 y,
  135. LLVector3 origin, LLVector3 normal);
  136. bool nearestPointOnLineFromMouse(S32 x, S32 y, const LLVector3& b1,
  137. const LLVector3& b2, F32& a_param,
  138. F32& b_param);
  139. LLColor4 setupSnapGuideRenderPass(S32 pass);
  140. protected:
  141. LLFrameTimer mHelpTextTimer;
  142. LLSafeHandle<LLObjectSelection> mObjectSelection;
  143. EManipPart mHighlightedPart;
  144. EManipPart mManipPart;
  145. bool mInSnapRegime;
  146. static F32 sHelpTextVisibleTime;
  147. static F32 sHelpTextFadeTime;
  148. static S32 sNumTimesHelpTextShown;
  149. static S32 sMaxTimesShowHelpText;
  150. static F32 sGridMaxSubdivisionLevel;
  151. static F32 sGridMinSubdivisionLevel;
  152. static LLVector2 sTickLabelSpacing;
  153. };
  154. #endif