joystick.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: joystick.h
  3. // Purpose: interface of wxJoystick
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxJoystick
  9. wxJoystick allows an application to control one or more joysticks.
  10. @library{wxadv}
  11. @category{misc}
  12. @see wxJoystickEvent
  13. */
  14. class wxJoystick : public wxObject
  15. {
  16. public:
  17. /**
  18. Constructor.
  19. @a joystick may be one of wxJOYSTICK1, wxJOYSTICK2, indicating the joystick
  20. controller of interest.
  21. */
  22. wxJoystick(int joystick = wxJOYSTICK1);
  23. /**
  24. Destroys the wxJoystick object.
  25. */
  26. virtual ~wxJoystick();
  27. /**
  28. Returns the state of the joystick buttons.
  29. Every button is mapped to a single bit in the returned integer, with the
  30. first button being mapped to the least significant bit, and so on.
  31. A bitlist of wxJOY_BUTTONn identifiers, where n is 1, 2, 3 or 4 is available
  32. for historical reasons.
  33. */
  34. int GetButtonState() const;
  35. /**
  36. Returns the state of the specified joystick button.
  37. @param id
  38. The button id to report, from 0 to GetNumberButtons() - 1
  39. */
  40. bool GetButtonState(unsigned int id) const;
  41. /**
  42. Returns the manufacturer id.
  43. */
  44. int GetManufacturerId() const;
  45. /**
  46. Returns the movement threshold, the number of steps outside which the joystick
  47. is deemed to have
  48. moved.
  49. */
  50. int GetMovementThreshold() const;
  51. /**
  52. Returns the number of axes for this joystick.
  53. */
  54. int GetNumberAxes() const;
  55. /**
  56. Returns the number of buttons for this joystick.
  57. */
  58. int GetNumberButtons() const;
  59. /**
  60. Returns the number of joysticks currently attached to the computer.
  61. */
  62. static int GetNumberJoysticks();
  63. /**
  64. Returns the point-of-view position, expressed in continuous, one-hundredth of a
  65. degree units.
  66. Returns -1 on error.
  67. */
  68. int GetPOVCTSPosition() const;
  69. /**
  70. Returns the point-of-view position, expressed in continuous, one-hundredth of a
  71. degree units, but limited to return 0, 9000, 18000 or 27000.
  72. Returns -1 on error.
  73. */
  74. int GetPOVPosition() const;
  75. /**
  76. Returns the maximum polling frequency.
  77. */
  78. int GetPollingMax() const;
  79. /**
  80. Returns the minimum polling frequency.
  81. */
  82. int GetPollingMin() const;
  83. /**
  84. Returns the x, y position of the joystick.
  85. */
  86. wxPoint GetPosition() const;
  87. /**
  88. Returns the position of the specified joystick axis.
  89. @param axis
  90. The joystick axis to report, from 0 to GetNumberAxes() - 1.
  91. */
  92. int GetPosition(unsigned int axis) const;
  93. /**
  94. Returns the product id for the joystick.
  95. */
  96. int GetProductId() const;
  97. /**
  98. Returns the product name for the joystick.
  99. */
  100. wxString GetProductName() const;
  101. /**
  102. Returns the maximum rudder position.
  103. */
  104. int GetRudderMax() const;
  105. /**
  106. Returns the minimum rudder position.
  107. */
  108. int GetRudderMin() const;
  109. /**
  110. Returns the rudder position.
  111. */
  112. int GetRudderPosition() const;
  113. /**
  114. Returns the maximum U position.
  115. */
  116. int GetUMax() const;
  117. /**
  118. Returns the minimum U position.
  119. */
  120. int GetUMin() const;
  121. /**
  122. Gets the position of the fifth axis of the joystick, if it exists.
  123. */
  124. int GetUPosition() const;
  125. /**
  126. Returns the maximum V position.
  127. */
  128. int GetVMax() const;
  129. /**
  130. Returns the minimum V position.
  131. */
  132. int GetVMin() const;
  133. /**
  134. Gets the position of the sixth axis of the joystick, if it exists.
  135. */
  136. int GetVPosition() const;
  137. /**
  138. Returns the maximum x position.
  139. */
  140. int GetXMax() const;
  141. /**
  142. Returns the minimum x position.
  143. */
  144. int GetXMin() const;
  145. /**
  146. Returns the maximum y position.
  147. */
  148. int GetYMax() const;
  149. /**
  150. Returns the minimum y position.
  151. */
  152. int GetYMin() const;
  153. /**
  154. Returns the maximum z position.
  155. */
  156. int GetZMax() const;
  157. /**
  158. Returns the minimum z position.
  159. */
  160. int GetZMin() const;
  161. /**
  162. Returns the z position of the joystick.
  163. */
  164. int GetZPosition() const;
  165. /**
  166. Returns @true if the joystick has a point of view control.
  167. */
  168. bool HasPOV() const;
  169. /**
  170. Returns @true if the joystick point-of-view supports discrete values
  171. (centered, forward, backward, left, and right).
  172. */
  173. bool HasPOV4Dir() const;
  174. /**
  175. Returns @true if the joystick point-of-view supports continuous degree bearings.
  176. */
  177. bool HasPOVCTS() const;
  178. /**
  179. Returns @true if there is a rudder attached to the computer.
  180. */
  181. bool HasRudder() const;
  182. /**
  183. Returns @true if the joystick has a U axis.
  184. */
  185. bool HasU() const;
  186. /**
  187. Returns @true if the joystick has a V axis.
  188. */
  189. bool HasV() const;
  190. /**
  191. Returns @true if the joystick has a Z axis.
  192. */
  193. bool HasZ() const;
  194. /**
  195. Returns @true if the joystick is functioning.
  196. */
  197. bool IsOk() const;
  198. /**
  199. Releases the capture set by @b SetCapture.
  200. @return @true if the capture release succeeded.
  201. @see SetCapture(), wxJoystickEvent
  202. */
  203. bool ReleaseCapture();
  204. /**
  205. Sets the capture to direct joystick events to @a win.
  206. @param win
  207. The window that will receive joystick events.
  208. @param pollingFreq
  209. If zero, movement events are sent when above the threshold.
  210. If greater than zero, events are received every @a pollingFreq milliseconds.
  211. @return @true if the capture succeeded.
  212. @see ReleaseCapture(), wxJoystickEvent
  213. */
  214. bool SetCapture(wxWindow* win, int pollingFreq = 0);
  215. /**
  216. Sets the movement threshold, the number of steps outside which the joystick is
  217. deemed to have moved.
  218. */
  219. void SetMovementThreshold(int threshold);
  220. };