SDL_mouse.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. SDL - Simple DirectMedia Layer
  3. Copyright (C) 1997-2010 Sam Lantinga
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. Sam Lantinga
  16. [email protected]
  17. */
  18. /**
  19. * \file SDL_mouse.h
  20. *
  21. * Include file for SDL mouse event handling.
  22. *
  23. * Please note that this ONLY discusses "mice" with the notion of the
  24. * desktop GUI. You (usually) have one system cursor, and the OS hides
  25. * the hardware details from you. If you plug in 10 mice, all ten move that
  26. * one cursor. For many applications and games, this is perfect, and this
  27. * API has served hundreds of SDL programs well since its birth.
  28. *
  29. * It's not the whole picture, though. If you want more lowlevel control,
  30. * SDL offers a different API, that gives you visibility into each input
  31. * device, multi-touch interfaces, etc.
  32. *
  33. * Those two APIs are incompatible, and you usually should not use both
  34. * at the same time. But for legacy purposes, this API refers to a "mouse"
  35. * when it actually means the system pointer and not a physical mouse.
  36. *
  37. * The other API is in SDL_input.h
  38. */
  39. #ifndef _SDL_mouse_h
  40. #define _SDL_mouse_h
  41. #include "SDL_stdinc.h"
  42. #include "SDL_error.h"
  43. #include "SDL_video.h"
  44. #include "begin_code.h"
  45. /* Set up for C function definitions, even when using C++ */
  46. #ifdef __cplusplus
  47. /* *INDENT-OFF* */
  48. extern "C" {
  49. /* *INDENT-ON* */
  50. #endif
  51. typedef struct SDL_Cursor SDL_Cursor; /* Implementation dependent */
  52. /* Function prototypes */
  53. /**
  54. * \brief Get the window which currently has mouse focus.
  55. */
  56. extern DECLSPEC SDL_Window * SDLCALL SDL_GetMouseFocus(void);
  57. /**
  58. * \brief Retrieve the current state of the mouse.
  59. *
  60. * The current button state is returned as a button bitmask, which can
  61. * be tested using the SDL_BUTTON(X) macros, and x and y are set to the
  62. * mouse cursor position relative to the focus window for the currently
  63. * selected mouse. You can pass NULL for either x or y.
  64. */
  65. extern DECLSPEC Uint8 SDLCALL SDL_GetMouseState(int *x, int *y);
  66. /**
  67. * \brief Retrieve the relative state of the mouse.
  68. *
  69. * The current button state is returned as a button bitmask, which can
  70. * be tested using the SDL_BUTTON(X) macros, and x and y are set to the
  71. * mouse deltas since the last call to SDL_GetRelativeMouseState().
  72. */
  73. extern DECLSPEC Uint8 SDLCALL SDL_GetRelativeMouseState(int *x, int *y);
  74. /**
  75. * \brief Moves the mouse to the given position within the window.
  76. *
  77. * \param window The window to move the mouse into, or NULL for the current mouse focus
  78. * \param x The x coordinate within the window
  79. * \param y The y coordinate within the window
  80. *
  81. * \note This function generates a mouse motion event
  82. */
  83. extern DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_Window * window,
  84. int x, int y);
  85. /**
  86. * \brief Set relative mouse mode.
  87. *
  88. * \param enabled Whether or not to enable relative mode
  89. *
  90. * \return 0 on success, or -1 if relative mode is not supported.
  91. *
  92. * While the mouse is in relative mode, the cursor is hidden, and the
  93. * driver will try to report continuous motion in the current window.
  94. * Only relative motion events will be delivered, the mouse position
  95. * will not change.
  96. *
  97. * \note This function will flush any pending mouse motion.
  98. *
  99. * \sa SDL_GetRelativeMouseMode()
  100. */
  101. extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled);
  102. /**
  103. * \brief Query whether relative mouse mode is enabled.
  104. *
  105. * \sa SDL_SetRelativeMouseMode()
  106. */
  107. extern DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode(void);
  108. /**
  109. * \brief Create a cursor, using the specified bitmap data and
  110. * mask (in MSB format).
  111. *
  112. * The cursor width must be a multiple of 8 bits.
  113. *
  114. * The cursor is created in black and white according to the following:
  115. * <table>
  116. * <tr><td> data </td><td> mask </td><td> resulting pixel on screen </td></tr>
  117. * <tr><td> 0 </td><td> 1 </td><td> White </td></tr>
  118. * <tr><td> 1 </td><td> 1 </td><td> Black </td></tr>
  119. * <tr><td> 0 </td><td> 0 </td><td> Transparent </td></tr>
  120. * <tr><td> 1 </td><td> 0 </td><td> Inverted color if possible, black
  121. * if not. </td></tr>
  122. * </table>
  123. *
  124. * \sa SDL_FreeCursor()
  125. */
  126. extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateCursor(const Uint8 * data,
  127. const Uint8 * mask,
  128. int w, int h, int hot_x,
  129. int hot_y);
  130. /**
  131. * \brief Set the active cursor.
  132. */
  133. extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor * cursor);
  134. /**
  135. * \brief Return the active cursor.
  136. */
  137. extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetCursor(void);
  138. /**
  139. * \brief Frees a cursor created with SDL_CreateCursor().
  140. *
  141. * \sa SDL_CreateCursor()
  142. */
  143. extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor * cursor);
  144. /**
  145. * \brief Toggle whether or not the cursor is shown.
  146. *
  147. * \param toggle 1 to show the cursor, 0 to hide it, -1 to query the current
  148. * state.
  149. *
  150. * \return 1 if the cursor is shown, or 0 if the cursor is hidden.
  151. */
  152. extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
  153. /**
  154. * Used as a mask when testing buttons in buttonstate.
  155. * - Button 1: Left mouse button
  156. * - Button 2: Middle mouse button
  157. * - Button 3: Right mouse button
  158. */
  159. #define SDL_BUTTON(X) (1 << ((X)-1))
  160. #define SDL_BUTTON_LEFT 1
  161. #define SDL_BUTTON_MIDDLE 2
  162. #define SDL_BUTTON_RIGHT 3
  163. #define SDL_BUTTON_X1 4
  164. #define SDL_BUTTON_X2 5
  165. #define SDL_BUTTON_LMASK SDL_BUTTON(SDL_BUTTON_LEFT)
  166. #define SDL_BUTTON_MMASK SDL_BUTTON(SDL_BUTTON_MIDDLE)
  167. #define SDL_BUTTON_RMASK SDL_BUTTON(SDL_BUTTON_RIGHT)
  168. #define SDL_BUTTON_X1MASK SDL_BUTTON(SDL_BUTTON_X1)
  169. #define SDL_BUTTON_X2MASK SDL_BUTTON(SDL_BUTTON_X2)
  170. /* Ends C function definitions when using C++ */
  171. #ifdef __cplusplus
  172. /* *INDENT-OFF* */
  173. }
  174. /* *INDENT-ON* */
  175. #endif
  176. #include "close_code.h"
  177. #endif /* _SDL_mouse_h */
  178. /* vi: set ts=4 sw=4 expandtab: */