/indra/newview/lljoystickbutton.h

https://bitbucket.org/lindenlab/viewer-beta/ · C++ Header · 180 lines · 115 code · 30 blank · 35 comment · 0 complexity · 059c41043e46c18399e4a05c251abd97 MD5 · raw file

  1. /**
  2. * @file lljoystickbutton.h
  3. * @brief LLJoystick class definition
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLJOYSTICKBUTTON_H
  27. #define LL_LLJOYSTICKBUTTON_H
  28. #include "llbutton.h"
  29. #include "llcoord.h"
  30. #include "llviewertexture.h"
  31. typedef enum e_joystick_quadrant
  32. {
  33. JQ_ORIGIN,
  34. JQ_UP,
  35. JQ_DOWN,
  36. JQ_LEFT,
  37. JQ_RIGHT
  38. } EJoystickQuadrant;
  39. struct QuadrantNames : public LLInitParam::TypeValuesHelper<EJoystickQuadrant, QuadrantNames>
  40. {
  41. static void declareValues();
  42. };
  43. class LLJoystick
  44. : public LLButton
  45. {
  46. public:
  47. struct Params
  48. : public LLInitParam::Block<Params, LLButton::Params>
  49. {
  50. Optional<EJoystickQuadrant, QuadrantNames> quadrant;
  51. Params()
  52. : quadrant("quadrant", JQ_ORIGIN)
  53. {
  54. changeDefault(label, "");
  55. }
  56. };
  57. LLJoystick(const Params&);
  58. virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask);
  59. virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask);
  60. virtual BOOL handleHover(S32 x, S32 y, MASK mask);
  61. virtual void onMouseUp() {}
  62. virtual void onHeldDown() = 0;
  63. F32 getElapsedHeldDownTime();
  64. static void onBtnHeldDown(void *userdata); // called by llbutton callback handler
  65. void setInitialQuadrant(EJoystickQuadrant initial) { mInitialQuadrant = initial; };
  66. /**
  67. * Checks if click location is inside joystick circle.
  68. *
  69. * Image containing circle is square and this square has adherent points with joystick
  70. * circle. Make sure to change method according to shape other than square.
  71. */
  72. bool pointInCircle(S32 x, S32 y) const;
  73. static std::string nameFromQuadrant(const EJoystickQuadrant quadrant);
  74. static EJoystickQuadrant quadrantFromName(const std::string& name);
  75. static EJoystickQuadrant selectQuadrant(LLXMLNodePtr node);
  76. protected:
  77. virtual void updateSlop(); // recompute slop margins
  78. protected:
  79. EJoystickQuadrant mInitialQuadrant; // mousedown = click in this quadrant
  80. LLCoordGL mInitialOffset; // pretend mouse started here
  81. LLCoordGL mLastMouse; // where was mouse on last hover event
  82. LLCoordGL mFirstMouse; // when mouse clicked, where was it
  83. S32 mVertSlopNear; // where the slop regions end
  84. S32 mVertSlopFar; // where the slop regions end
  85. S32 mHorizSlopNear; // where the slop regions end
  86. S32 mHorizSlopFar; // where the slop regions end
  87. BOOL mHeldDown;
  88. LLFrameTimer mHeldDownTimer;
  89. };
  90. // Turn agent left and right, move forward and back
  91. class LLJoystickAgentTurn
  92. : public LLJoystick
  93. {
  94. public:
  95. struct Params : public LLJoystick::Params {};
  96. LLJoystickAgentTurn(const Params& p) : LLJoystick(p) {}
  97. virtual void onHeldDown();
  98. };
  99. // Slide left and right, move forward and back
  100. class LLJoystickAgentSlide
  101. : public LLJoystick
  102. {
  103. public:
  104. struct Params : public LLJoystick::Params {};
  105. LLJoystickAgentSlide(const Params& p) : LLJoystick(p) {}
  106. virtual void onHeldDown();
  107. virtual void onMouseUp();
  108. };
  109. // Rotate camera around the focus point
  110. class LLJoystickCameraRotate
  111. : public LLJoystick
  112. {
  113. public:
  114. struct Params
  115. : public LLInitParam::Block<Params, LLJoystick::Params>
  116. {
  117. Params()
  118. {
  119. changeDefault(held_down_delay.seconds, 0.0);
  120. }
  121. };
  122. LLJoystickCameraRotate(const LLJoystickCameraRotate::Params&);
  123. virtual void setToggleState( BOOL left, BOOL top, BOOL right, BOOL bottom );
  124. virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask);
  125. virtual void onHeldDown();
  126. virtual void draw();
  127. protected:
  128. F32 getOrbitRate();
  129. virtual void updateSlop();
  130. void drawRotatedImage( LLPointer<LLUIImage> 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
  139. : public LLJoystickCameraRotate
  140. {
  141. public:
  142. struct Params
  143. : public LLInitParam::Block<Params, LLJoystickCameraRotate::Params>
  144. {
  145. Params();
  146. };
  147. LLJoystickCameraTrack(const LLJoystickCameraTrack::Params&);
  148. virtual void onHeldDown();
  149. };
  150. #endif // LL_LLJOYSTICKBUTTON_H