lljoystickbutton.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /**
  2. * @file lljoystickbutton.h
  3. * @brief LLJoystick 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_LLJOYSTICKBUTTON_H
  33. #define LL_LLJOYSTICKBUTTON_H
  34. #include "llbutton.h"
  35. #include "llcoord.h"
  36. #include "llviewertexture.h"
  37. typedef enum e_joystick_quadrant
  38. {
  39. JQ_ORIGIN,
  40. JQ_UP,
  41. JQ_DOWN,
  42. JQ_LEFT,
  43. JQ_RIGHT
  44. } EJoystickQuadrant;
  45. class LLJoystick : public LLButton
  46. {
  47. public:
  48. LLJoystick(const std::string& name, LLRect rect,
  49. const std::string& default_image,
  50. const std::string& selected_image, EJoystickQuadrant initial);
  51. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  52. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  53. bool handleHover(S32 x, S32 y, MASK mask) override;
  54. virtual void onMouseUp() {}
  55. virtual void onHeldDown() = 0;
  56. F32 getElapsedHeldDownTime();
  57. // Called by llbutton callback handler
  58. static void onHeldDown(void* userdata);
  59. LL_INLINE void setInitialQuadrant(EJoystickQuadrant initial)
  60. {
  61. mInitialQuadrant = initial;
  62. }
  63. LLXMLNodePtr getXML(bool save_children = true) const override;
  64. static std::string nameFromQuadrant(const EJoystickQuadrant quadrant);
  65. static EJoystickQuadrant quadrantFromName(const std::string& name);
  66. static EJoystickQuadrant selectQuadrant(LLXMLNodePtr node);
  67. protected:
  68. virtual void updateSlop(); // Recomputes slop margins
  69. protected:
  70. EJoystickQuadrant mInitialQuadrant; // mousedown = click in this quadrant
  71. LLCoordGL mInitialOffset; // pretend mouse started here
  72. LLCoordGL mLastMouse; // where was mouse on last hover event
  73. LLCoordGL mFirstMouse; // when mouse clicked, where was it
  74. S32 mVertSlopNear; // where the slop regions end
  75. S32 mVertSlopFar; // where the slop regions end
  76. S32 mHorizSlopNear; // where the slop regions end
  77. S32 mHorizSlopFar; // where the slop regions end
  78. LLFrameTimer mHeldDownTimer;
  79. bool mHeldDown;
  80. };
  81. // Turn agent left and right, move forward and back
  82. class LLJoystickAgentTurn : public LLJoystick
  83. {
  84. public:
  85. LLJoystickAgentTurn(const std::string& name, LLRect rect,
  86. const std::string& default_image,
  87. const std::string& selected_image,
  88. EJoystickQuadrant initial)
  89. : LLJoystick(name, rect, default_image, selected_image, initial)
  90. {
  91. }
  92. void onHeldDown() override;
  93. const std::string& getTag() const override;
  94. LLXMLNodePtr getXML(bool save_children = true) const override;
  95. static LLView* fromXML(LLXMLNodePtr node, LLView* parent,
  96. LLUICtrlFactory* factory);
  97. };
  98. // Slide left and right, move forward and back
  99. class LLJoystickAgentSlide : public LLJoystick
  100. {
  101. public:
  102. LLJoystickAgentSlide(const std::string& name, LLRect rect,
  103. const std::string& default_image,
  104. const std::string& selected_image,
  105. EJoystickQuadrant initial)
  106. : LLJoystick(name, rect, default_image, selected_image, initial)
  107. {
  108. }
  109. void onHeldDown() override;
  110. void onMouseUp() override;
  111. const std::string& getTag() const override;
  112. LLXMLNodePtr getXML(bool save_children = true) const override;
  113. static LLView* fromXML(LLXMLNodePtr node, LLView* parent,
  114. LLUICtrlFactory* factory);
  115. };
  116. // Rotate camera around the focus point
  117. class LLJoystickCameraRotate : public LLJoystick
  118. {
  119. public:
  120. LLJoystickCameraRotate(const std::string& name, LLRect rect,
  121. const std::string& out_img,
  122. const std::string& in_img);
  123. void setToggleState(bool left, bool top, bool right, bool bottom);
  124. void draw() override;
  125. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  126. void onHeldDown() override;
  127. protected:
  128. F32 getOrbitRate();
  129. void updateSlop() override;
  130. void drawRotatedImage(LLGLTexture* image, S32 rotations);
  131. protected:
  132. bool mInLeft;
  133. bool mInTop;
  134. bool mInRight;
  135. bool mInBottom;
  136. };
  137. // Track the camera focus point forward/backward and side to side
  138. class LLJoystickCameraTrack : public LLJoystickCameraRotate
  139. {
  140. public:
  141. LLJoystickCameraTrack(const std::string& name, LLRect rect,
  142. const std::string& out_img,
  143. const std::string& in_img)
  144. : LLJoystickCameraRotate(name, rect, out_img, in_img)
  145. {
  146. }
  147. void onHeldDown() override;
  148. };
  149. // Zoom the camera in and out
  150. class LLJoystickCameraZoom : public LLJoystick
  151. {
  152. public:
  153. LLJoystickCameraZoom(const std::string& name, LLRect rect,
  154. const std::string& out_img,
  155. const std::string& plus_in_img,
  156. const std::string& minus_in_img);
  157. void setToggleState(bool top, bool bottom);
  158. void draw() override;
  159. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  160. void onHeldDown() override;
  161. protected:
  162. F32 getOrbitRate();
  163. void updateSlop() override;
  164. protected:
  165. LLUIImagePtr mPlusInImage;
  166. LLUIImagePtr mMinusInImage;
  167. bool mInTop;
  168. bool mInBottom;
  169. };
  170. #endif // LL_LLJOYSTICKBUTTON_H