sdlmouse.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. //from "sdl_mouse.h"
  2. type
  3. PPSDL_Cursor = ^PSDL_Cursor;
  4. PSDL_Cursor = type Pointer; {**< Implementation dependent *}
  5. {**
  6. * Cursor types for SDL_CreateSystemCursor.
  7. *}
  8. type
  9. PPSDL_SystemCursor = ^PSDL_SystemCursor;
  10. PSDL_SystemCursor = ^TSDL_SystemCursor;
  11. TSDL_SystemCursor = type Integer;
  12. const
  13. SDL_SYSTEM_CURSOR_ARROW = TSDL_SystemCursor(0); // Arrow
  14. SDL_SYSTEM_CURSOR_IBEAM = TSDL_SystemCursor(1); // I-beam
  15. SDL_SYSTEM_CURSOR_WAIT = TSDL_SystemCursor(2); // Wait
  16. SDL_SYSTEM_CURSOR_CROSSHAIR = TSDL_SystemCursor(3); // Crosshair
  17. SDL_SYSTEM_CURSOR_WAITARROW = TSDL_SystemCursor(4); // Small wait cursor (or Wait if not available)
  18. SDL_SYSTEM_CURSOR_SIZENWSE = TSDL_SystemCursor(5); // Double arrow pointing northwest and southeast
  19. SDL_SYSTEM_CURSOR_SIZENESW = TSDL_SystemCursor(6); // Double arrow pointing northeast and southwest
  20. SDL_SYSTEM_CURSOR_SIZEWE = TSDL_SystemCursor(7); // Double arrow pointing west and east
  21. SDL_SYSTEM_CURSOR_SIZENS = TSDL_SystemCursor(8); // Double arrow pointing north and south
  22. SDL_SYSTEM_CURSOR_SIZEALL = TSDL_SystemCursor(9); // Four pointed arrow pointing north, south, east, and west
  23. SDL_SYSTEM_CURSOR_NO = TSDL_SystemCursor(10); // Slashed circle or crossbones
  24. SDL_SYSTEM_CURSOR_HAND = TSDL_SystemCursor(11); // Hand
  25. SDL_NUM_SYSTEM_CURSORS = TSDL_SystemCursor(12);
  26. type
  27. PPSDL_MouseWheelDirection = ^PSDL_MouseWheelDirection;
  28. PSDL_MouseWheelDirection = ^TSDL_MouseWheelDirection;
  29. TSDL_MouseWheelDirection = type Integer;
  30. const
  31. SDL_MOUSEWHEEL_NORMAL = TSDL_MouseWheelDirection(0); {**< The scroll direction is normal *}
  32. SDL_MOUSEWHEEL_FLIPPED = TSDL_MouseWheelDirection(1); {**< The scroll direction is flipped / natural *}
  33. {* Function prototypes *}
  34. {**
  35. * Get the window which currently has mouse focus.
  36. *
  37. * \returns the window with mouse focus.
  38. *
  39. * \since This function is available since SDL 2.0.0.
  40. *}
  41. function SDL_GetMouseFocus: PSDL_Window; cdecl;
  42. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetMouseFocus' {$ENDIF}{$ENDIF};
  43. {**
  44. * Retrieve the current state of the mouse.
  45. *
  46. * The current button state is returned as a button bitmask, which can be
  47. * tested using the `SDL_BUTTON(X)` macros (where `X` is generally 1 for the
  48. * left, 2 for middle, 3 for the right button), and `x` and `y` are set to the
  49. * mouse cursor position relative to the focus window. You can pass NULL for
  50. * either `x` or `y`.
  51. *
  52. * \param x the x coordinate of the mouse cursor position relative to the
  53. * focus window
  54. * \param y the y coordinate of the mouse cursor position relative to the
  55. * focus window
  56. * \returns a 32-bit button bitmask of the current button state.
  57. *
  58. * \since This function is available since SDL 2.0.0.
  59. *
  60. * \sa SDL_GetGlobalMouseState
  61. * \sa SDL_GetRelativeMouseState
  62. * \sa SDL_PumpEvents
  63. *}
  64. function SDL_GetMouseState(x: pcint; y: pcint): cuint32; cdecl;
  65. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetMouseState' {$ENDIF}{$ENDIF};
  66. {**
  67. * Get the current state of the mouse in relation to the desktop.
  68. *
  69. * This works similarly to SDL_GetMouseState(), but the coordinates will be
  70. * reported relative to the top-left of the desktop. This can be useful if you
  71. * need to track the mouse outside of a specific window and SDL_CaptureMouse()
  72. * doesn't fit your needs. For example, it could be useful if you need to
  73. * track the mouse while dragging a window, where coordinates relative to a
  74. * window might not be in sync at all times.
  75. *
  76. * Note: SDL_GetMouseState() returns the mouse position as SDL understands it
  77. * from the last pump of the event queue. This function, however, queries the
  78. * OS for the current mouse position, and as such, might be a slightly less
  79. * efficient function. Unless you know what you're doing and have a good
  80. * reason to use this function, you probably want SDL_GetMouseState() instead.
  81. *
  82. * \param x filled in with the current X coord relative to the desktop; can be
  83. * NULL
  84. * \param y filled in with the current Y coord relative to the desktop; can be
  85. * NULL
  86. * \returns the current button state as a bitmask which can be tested using
  87. * the SDL_BUTTON(X) macros.
  88. *
  89. * \since This function is available since SDL 2.0.4.
  90. *
  91. * \sa SDL_CaptureMouse
  92. *}
  93. function SDL_GetGlobalMouseState(x, y: pcint32): cuint32; cdecl;
  94. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetGlobalMouseState' {$ENDIF}{$ENDIF};
  95. {**
  96. * Retrieve the relative state of the mouse.
  97. *
  98. * The current button state is returned as a button bitmask, which can be
  99. * tested using the `SDL_BUTTON(X)` macros (where `X` is generally 1 for the
  100. * left, 2 for middle, 3 for the right button), and `x` and `y` are set to the
  101. * mouse deltas since the last call to SDL_GetRelativeMouseState() or since
  102. * event initialization. You can pass NULL for either `x` or `y`.
  103. *
  104. * \param x a pointer filled with the last recorded x coordinate of the mouse
  105. * \param y a pointer filled with the last recorded y coordinate of the mouse
  106. * \returns a 32-bit button bitmask of the relative button state.
  107. *
  108. * \since This function is available since SDL 2.0.0.
  109. *
  110. * \sa SDL_GetMouseState
  111. *}
  112. function SDL_GetRelativeMouseState(x: pcint; y: pcint): cuint32; cdecl;
  113. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetRelativeMouseState' {$ENDIF}{$ENDIF};
  114. {**
  115. * Move the mouse cursor to the given position within the window.
  116. *
  117. * This function generates a mouse motion event if relative mode is not
  118. * enabled. If relative mode is enabled, you can force mouse events for the
  119. * warp by setting the SDL_HINT_MOUSE_RELATIVE_WARP_MOTION hint.
  120. *
  121. * Note that this function will appear to succeed, but not actually move the
  122. * mouse when used over Microsoft Remote Desktop.
  123. *
  124. * \param window the window to move the mouse into, or NULL for the current
  125. * mouse focus
  126. * \param x the x coordinate within the window
  127. * \param y the y coordinate within the window
  128. *
  129. * \since This function is available since SDL 2.0.0.
  130. *
  131. * \sa SDL_WarpMouseGlobal
  132. *}
  133. procedure SDL_WarpMouseInWindow(window: PSDL_Window; x: cint; y: cint); cdecl;
  134. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_WarpMouseInWindow' {$ENDIF}{$ENDIF};
  135. {**
  136. * Move the mouse to the given position in global screen space.
  137. *
  138. * This function generates a mouse motion event.
  139. *
  140. * A failure of this function usually means that it is unsupported by a
  141. * platform.
  142. *
  143. * Note that this function will appear to succeed, but not actually move the
  144. * mouse when used over Microsoft Remote Desktop.
  145. *
  146. * \param x the x coordinate
  147. * \param y the y coordinate
  148. * \returns 0 on success or a negative error code on failure; call
  149. * SDL_GetError() for more information.
  150. *
  151. * \since This function is available since SDL 2.0.4.
  152. *
  153. * \sa SDL_WarpMouseInWindow
  154. *}
  155. function SDL_WarpMouseGlobal(x, y: cint): cint; cdecl;
  156. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_WarpMouseGlobal' {$ENDIF}{$ENDIF};
  157. {**
  158. * Set relative mouse mode.
  159. *
  160. * While the mouse is in relative mode, the cursor is hidden, and the driver
  161. * will try to report continuous motion in the current window. Only relative
  162. * motion events will be delivered, the mouse position will not change.
  163. *
  164. * Note that this function will not be able to provide continuous relative
  165. * motion when used over Microsoft Remote Desktop, instead motion is limited
  166. * to the bounds of the screen.
  167. *
  168. * This function will flush any pending mouse motion.
  169. *
  170. * \param enabled SDL_TRUE to enable relative mode, SDL_FALSE to disable.
  171. * \returns 0 on success or a negative error code on failure; call
  172. * SDL_GetError() for more information.
  173. *
  174. * If relative mode is not supported, this returns -1.
  175. *
  176. * \since This function is available since SDL 2.0.0.
  177. *
  178. * \sa SDL_GetRelativeMouseMode
  179. *}
  180. function SDL_SetRelativeMouseMode(enabled: TSDL_Bool): cint; cdecl;
  181. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SetRelativeMouseMode' {$ENDIF}{$ENDIF};
  182. {**
  183. * Capture the mouse and to track input outside an SDL window.
  184. *
  185. * Capturing enables your app to obtain mouse events globally, instead of just
  186. * within your window. Not all video targets support this function. When
  187. * capturing is enabled, the current window will get all mouse events, but
  188. * unlike relative mode, no change is made to the cursor and it is not
  189. * restrained to your window.
  190. *
  191. * This function may also deny mouse input to other windows--both those in
  192. * your application and others on the system--so you should use this function
  193. * sparingly, and in small bursts. For example, you might want to track the
  194. * mouse while the user is dragging something, until the user releases a mouse
  195. * button. It is not recommended that you capture the mouse for long periods
  196. * of time, such as the entire time your app is running. For that, you should
  197. * probably use SDL_SetRelativeMouseMode() or SDL_SetWindowGrab(), depending
  198. * on your goals.
  199. *
  200. * While captured, mouse events still report coordinates relative to the
  201. * current (foreground) window, but those coordinates may be outside the
  202. * bounds of the window (including negative values). Capturing is only allowed
  203. * for the foreground window. If the window loses focus while capturing, the
  204. * capture will be disabled automatically.
  205. *
  206. * While capturing is enabled, the current window will have the
  207. * `SDL_WINDOW_MOUSE_CAPTURE` flag set.
  208. *
  209. * Please note that as of SDL 2.0.22, SDL will attempt to "auto capture" the
  210. * mouse while the user is pressing a button; this is to try and make mouse
  211. * behavior more consistent between platforms, and deal with the common case
  212. * of a user dragging the mouse outside of the window. This means that if you
  213. * are calling SDL_CaptureMouse() only to deal with this situation, you no
  214. * longer have to (although it is safe to do so). If this causes problems for
  215. * your app, you can disable auto capture by setting the
  216. * `SDL_HINT_MOUSE_AUTO_CAPTURE` hint to zero.
  217. *
  218. * \param enabled SDL_TRUE to enable capturing, SDL_FALSE to disable.
  219. * \returns 0 on success or -1 if not supported; call SDL_GetError() for more
  220. * information.
  221. *
  222. * \since This function is available since SDL 2.0.4.
  223. *
  224. * \sa SDL_GetGlobalMouseState
  225. *}
  226. function SDL_CaptureMouse(enabled: TSDL_Bool): cint; cdecl;
  227. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CaptureMouse' {$ENDIF}{$ENDIF};
  228. {**
  229. * Query whether relative mouse mode is enabled.
  230. *
  231. * \returns SDL_TRUE if relative mode is enabled or SDL_FALSE otherwise.
  232. *
  233. * \since This function is available since SDL 2.0.0.
  234. *
  235. * \sa SDL_SetRelativeMouseMode
  236. *}
  237. function SDL_GetRelativeMouseMode: TSDL_Bool; cdecl;
  238. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetRelativeMouseMode' {$ENDIF}{$ENDIF};
  239. {**
  240. * Create a cursor using the specified bitmap data and mask (in MSB format).
  241. *
  242. * `mask` has to be in MSB (Most Significant Bit) format.
  243. *
  244. * The cursor width (`w`) must be a multiple of 8 bits.
  245. *
  246. * The cursor is created in black and white according to the following:
  247. *
  248. * - data=0, mask=1: white
  249. * - data=1, mask=1: black
  250. * - data=0, mask=0: transparent
  251. * - data=1, mask=0: inverted color if possible, black if not.
  252. *
  253. * Cursors created with this function must be freed with SDL_FreeCursor().
  254. *
  255. * If you want to have a color cursor, or create your cursor from an
  256. * SDL_Surface, you should use SDL_CreateColorCursor(). Alternately, you can
  257. * hide the cursor and draw your own as part of your game's rendering, but it
  258. * will be bound to the framerate.
  259. *
  260. * Also, since SDL 2.0.0, SDL_CreateSystemCursor() is available, which
  261. * provides twelve readily available system cursors to pick from.
  262. *
  263. * \param data the color value for each pixel of the cursor
  264. * \param mask the mask value for each pixel of the cursor
  265. * \param w the width of the cursor
  266. * \param h the height of the cursor
  267. * \param hot_x the X-axis location of the upper left corner of the cursor
  268. * relative to the actual mouse position
  269. * \param hot_y the Y-axis location of the upper left corner of the cursor
  270. * relative to the actual mouse position
  271. * \returns a new cursor with the specified parameters on success or NULL on
  272. * failure; call SDL_GetError() for more information.
  273. *
  274. * \since This function is available since SDL 2.0.0.
  275. *
  276. * \sa SDL_FreeCursor
  277. * \sa SDL_SetCursor
  278. * \sa SDL_ShowCursor
  279. *}
  280. function SDL_CreateCursor(
  281. const data: pcuint8;
  282. const mask: pcuint8;
  283. w: cint; h: cint;
  284. hot_x: cint; hot_y: cint): PSDL_Cursor; cdecl;
  285. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CreateCursor' {$ENDIF}{$ENDIF};
  286. {**
  287. * Create a color cursor.
  288. *
  289. * \param surface an SDL_Surface structure representing the cursor image
  290. * \param hot_x the x position of the cursor hot spot
  291. * \param hot_y the y position of the cursor hot spot
  292. * \returns the new cursor on success or NULL on failure; call SDL_GetError()
  293. * for more information.
  294. *
  295. * \since This function is available since SDL 2.0.0.
  296. *
  297. * \sa SDL_CreateCursor
  298. * \sa SDL_FreeCursor
  299. *}
  300. function SDL_CreateColorCursor(
  301. surface: PSDL_Surface;
  302. hot_x: cint;
  303. hot_y: cint): PSDL_Cursor; cdecl;
  304. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CreateColorCursor' {$ENDIF}{$ENDIF};
  305. {**
  306. * Create a system cursor.
  307. *
  308. * \param id an SDL_SystemCursor enum value
  309. * \returns a cursor on success or NULL on failure; call SDL_GetError() for
  310. * more information.
  311. *
  312. * \since This function is available since SDL 2.0.0.
  313. *
  314. * \sa SDL_FreeCursor
  315. *}
  316. function SDL_CreateSystemCursor(id: TSDL_SystemCursor): PSDL_Cursor; cdecl;
  317. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CreateSystemCursor' {$ENDIF}{$ENDIF};
  318. {**
  319. * Set the active cursor.
  320. *
  321. * This function sets the currently active cursor to the specified one. If the
  322. * cursor is currently visible, the change will be immediately represented on
  323. * the display. SDL_SetCursor(NULL) can be used to force cursor redraw, if
  324. * this is desired for any reason.
  325. *
  326. * \param cursor a cursor to make active
  327. *
  328. * \since This function is available since SDL 2.0.0.
  329. *
  330. * \sa SDL_CreateCursor
  331. * \sa SDL_GetCursor
  332. * \sa SDL_ShowCursor
  333. *}
  334. procedure SDL_SetCursor(cursor: PSDL_Cursor); cdecl;
  335. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SetCursor' {$ENDIF}{$ENDIF};
  336. {**
  337. * Get the active cursor.
  338. *
  339. * This function returns a pointer to the current cursor which is owned by the
  340. * library. It is not necessary to free the cursor with SDL_FreeCursor().
  341. *
  342. * \returns the active cursor or NULL if there is no mouse.
  343. *
  344. * \since This function is available since SDL 2.0.0.
  345. *
  346. * \sa SDL_SetCursor
  347. *}
  348. function SDL_GetCursor: PSDL_Cursor; cdecl;
  349. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetCursor' {$ENDIF}{$ENDIF};
  350. {**
  351. * Get the default cursor.
  352. *
  353. * \returns the default cursor on success or NULL on failure.
  354. *
  355. * \since This function is available since SDL 2.0.0.
  356. *
  357. * \sa SDL_CreateSystemCursor
  358. *}
  359. function SDL_GetDefaultCursor: PSDL_Cursor; cdecl;
  360. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetDefaultCursor' {$ENDIF}{$ENDIF};
  361. {**
  362. * Free a previously-created cursor.
  363. *
  364. * Use this function to free cursor resources created with SDL_CreateCursor(),
  365. * SDL_CreateColorCursor() or SDL_CreateSystemCursor().
  366. *
  367. * \param cursor the cursor to free
  368. *
  369. * \since This function is available since SDL 2.0.0.
  370. *
  371. * \sa SDL_CreateColorCursor
  372. * \sa SDL_CreateCursor
  373. * \sa SDL_CreateSystemCursor
  374. *}
  375. procedure SDL_FreeCursor(cursor: PSDL_Cursor); cdecl;
  376. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_FreeCursor' {$ENDIF}{$ENDIF};
  377. {**
  378. * Toggle whether or not the cursor is shown.
  379. *
  380. * The cursor starts off displayed but can be turned off. Passing `SDL_ENABLE`
  381. * displays the cursor and passing `SDL_DISABLE` hides it.
  382. *
  383. * The current state of the mouse cursor can be queried by passing
  384. * `SDL_QUERY`; either `SDL_DISABLE` or `SDL_ENABLE` will be returned.
  385. *
  386. * \param toggle `SDL_ENABLE` to show the cursor, `SDL_DISABLE` to hide it,
  387. * `SDL_QUERY` to query the current state without changing it.
  388. * \returns `SDL_ENABLE` if the cursor is shown, or `SDL_DISABLE` if the
  389. * cursor is hidden, or a negative error code on failure; call
  390. * SDL_GetError() for more information.
  391. *
  392. * \since This function is available since SDL 2.0.0.
  393. *
  394. * \sa SDL_CreateCursor
  395. * \sa SDL_SetCursor
  396. *}
  397. function SDL_ShowCursor(toggle: cint): cint; cdecl;
  398. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ShowCursor' {$ENDIF}{$ENDIF};
  399. {**
  400. * Used as a mask when testing buttons in buttonstate.
  401. * - Button 1: Left mouse button
  402. * - Button 2: Middle mouse button
  403. * - Button 3: Right mouse button
  404. *}
  405. function SDL_Button(X: cint): cint; {$IFNDEF DELPHI} inline; {$ELSE} {$IFDEF DELPHI10UP} inline; {$ENDIF} {$ENDIF}
  406. const
  407. SDL_BUTTON_LEFT = 1;
  408. SDL_BUTTON_MIDDLE = 2;
  409. SDL_BUTTON_RIGHT = 3;
  410. SDL_BUTTON_X1 = 4;
  411. SDL_BUTTON_X2 = 5;
  412. { Pascal Conv.: For better performance instead of using the
  413. SDL_Button(X) macro, the following defines are
  414. implemented directly. }
  415. SDL_BUTTON_LMASK = 1 shl ((SDL_BUTTON_LEFT) - 1);
  416. SDL_BUTTON_MMASK = 1 shl ((SDL_BUTTON_MIDDLE) - 1);
  417. SDL_BUTTON_RMASK = 1 shl ((SDL_BUTTON_RIGHT) - 1);
  418. SDL_BUTTON_X1MASK = 1 shl ((SDL_BUTTON_X1) - 1);
  419. SDL_BUTTON_X2MASK = 1 shl ((SDL_BUTTON_X2) - 1);