blib/lib/SDL2/mouse.pm untested

filter: Statementstmt 0.0% 0 / 62 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod n/a totaltotal 0.0% 0 / 68 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package SDL2::mouse 0.01 {
2 use SDL2::Utils;
3 use experimental 'signatures';
4 #
5 use SDL2::stdinc;
6 use SDL2::error;
7 use SDL2::video;
8 #
9 package SDL2::Cursor 0.01 {
10 use SDL2::Utils;
11 our $TYPE = has();
12 };
13 #
14 enum SDL_SystemCursor => [
15 qw[
16 SDL_SYSTEM_CURSOR_ARROW
17 SDL_SYSTEM_CURSOR_IBEAM
18 SDL_SYSTEM_CURSOR_WAIT
19 SDL_SYSTEM_CURSOR_CROSSHAIR
20 SDL_SYSTEM_CURSOR_WAITARROW
21 SDL_SYSTEM_CURSOR_SIZENWSE
22 SDL_SYSTEM_CURSOR_SIZENESW
23 SDL_SYSTEM_CURSOR_SIZEWE
24 SDL_SYSTEM_CURSOR_SIZENS
25 SDL_SYSTEM_CURSOR_SIZEALL
26 SDL_SYSTEM_CURSOR_NO
27 SDL_SYSTEM_CURSOR_HAND
28 SDL_NUM_SYSTEM_CURSORS
29 ]
30 ],
31 SDL_MouseWheelDirection => [qw[SDL_MOUSEWHEEL_NORMAL SDL_MOUSEWHEEL_FLIPPED]];
32 attach mouse => {
33 SDL_GetMouseFocus => [ [], 'SDL_Window' ],
34 SDL_GetMouseState => [ [ 'int*', 'int*' ], 'uint32' ],
35 SDL_GetGlobalMouseState => [ [ 'int*', 'int*' ], 'uint32' ],
36 SDL_GetRelativeMouseState => [ [ 'int*', 'int*' ], 'uint32' ],
37 SDL_WarpMouseInWindow => [ [ 'SDL_Window', 'int', 'int' ] ],
38 SDL_WarpMouseGlobal => [ [ 'int', 'int' ] ],
39 SDL_SetRelativeMouseMode => [ ['SDL_bool'], 'int' ],
40 SDL_CaptureMouse => [ ['SDL_bool'] => 'int' ],
41 SDL_GetRelativeMouseMode => [ [], 'SDL_bool' ],
42 SDL_CreateCursor => [ [ 'uint8[]', 'uint8[]', 'int', 'int', 'int', 'int' ], 'SDL_Cursor' ],
43 SDL_CreateColorCursor => [ [ 'SDL_Surface', 'int', 'int' ], 'SDL_Cursor' ],
44 SDL_CreateSystemCursor => [ ['SDL_SystemCursor'], 'SDL_Cursor' ],
45 SDL_SetCursor => [ ['SDL_Cursor'] ],
46 SDL_GetCursor => [ [], 'SDL_Cursor' ],
47 SDL_GetDefaultCursor => [ [], 'SDL_Cursor' ],
48 SDL_FreeCursor => [ ['SDL_Cursor'] ],
49 SDL_ShowCursor => [ ['int'], 'int' ],
50 };
51 define mouse => [
52 [ SDL_BUTTON => sub ($X) { ( 1 << ( ($X) - 1 ) ) } ],
53 [ SDL_BUTTON_LEFT => 1 ],
54 [ SDL_BUTTON_MIDDLE => 2 ],
55 [ SDL_BUTTON_RIGHT => 3 ],
56 [ SDL_BUTTON_X1 => 4 ],
57 [ SDL_BUTTON_X2 => 5 ],
58 [ SDL_BUTTON_LMASK => sub () { SDL2::FFI::SDL_BUTTON( SDL2::FFI::SDL_BUTTON_LEFT() ) } ],
59 [ SDL_BUTTON_MMASK => sub () { SDL2::FFI::SDL_BUTTON( SDL2::FFI::SDL_BUTTON_MIDDLE() ) } ],
60 [ SDL_BUTTON_RMASK => sub () { SDL2::FFI::SDL_BUTTON( SDL2::FFI::SDL_BUTTON_RIGHT() ) } ],
61 [ SDL_BUTTON_X1MASK => sub () { SDL2::FFI::SDL_BUTTON( SDL2::FFI::SDL_BUTTON_X1() ) } ],
62 [ SDL_BUTTON_X2MASK => sub () { SDL2::FFI::SDL_BUTTON( SDL2::FFI::SDL_BUTTON_X2() ) } ]
63 ];
64  
65 =encoding utf-8
66  
67 =head1 NAME
68  
69 SDL2::mouse - SDL Mouse Event Handling
70  
71 =head1 SYNOPSIS
72  
73 use SDL2 qw[:mouse];
74  
75 =head1 DESCRIPTION
76  
77 SDL2::keyboard
78  
79 =head1 Functions
80  
81 These may be imported by name or with the C<:mouse> tag.
82  
83 =head2 C<SDL_GetMouseFocus( )>
84  
85 Get the window which currently has mouse focus.
86  
87 Returns the window with mouse focus.
88  
89 =head2 C<SDL_GetMouseState( ... )>
90  
91 Retrieve the current state of the mouse.
92  
93 The current button state is returned as a button bitmask, which can be tested
94 using the C<SDL_BUTTON(X)> function (where C<X> is generally 1 for the left, 2
95 for middle, 3 for the right button), and C<x> and C<y> are set to the mouse
96 cursor position relative to the focus window. You can pass NULL for either C<x>
97 or C<y>.
98  
99 Expected parameters include:
100  
101 =over
102  
103 =item C<x> - the x coordinate of the mouse cursor position relative to the focus window
104  
105 =item C<y> - the y coordinate of the mouse cursor position relative to the focus window
106  
107 =back
108  
109 Returns a 32-bit button bitmask of the current button state.
110  
111 =head2 C<SDL_GetGlobalMouseState( ... )>
112  
113 Get the current state of the mouse in relation to the desktop.
114  
115 This works similarly to L<< C<SDL_GetMouseState( ... )>|/C<SDL_GetMouseState(
116 ... )> >>, but the coordinates will be reported relative to the top-left of the
117 desktop. This can be useful if you need to track the mouse outside of a
118 specific window and L<< C<SDL_CaptureMouse( ... )>|/C<SDL_CaptureMouse( ... )>
119 >> doesn't fit your needs. For example, it could be useful if you need to track
120 the mouse while dragging a window, where coordinates relative to a window might
121 not be in sync at all times.
122  
123 Note: L<< C<SDL_GetMouseState( ... )>|/C<SDL_GetMouseState( ... )> >> returns
124 the mouse position as SDL understands it from the last pump of the event queue.
125 This function, however, queries the OS for the current mouse position, and as
126 such, might be a slightly less efficient function. Unless you know what you're
127 doing and have a good reason to use this function, you probably want L<<
128 C<SDL_GetMouseState( ... )>|/C<SDL_GetMouseState( ... )> >> instead.
129  
130 Expected parameters include:
131  
132 =over
133  
134 =item C<x> - filled in with the current X coord relative to the desktop; can be C<undef>
135  
136 =item C<y> - filled in with the current Y coord relative to the desktop; can be C<undef>
137  
138 =back
139  
140 Returns the current button state as a bitmask which can be tested using C<the
141 SDL_BUTTON( X )> macros.
142  
143 =head2 C<SDL_GetRelativeMouseState( ... )>
144  
145 Retrieve the relative state of the mouse.
146  
147 The current button state is returned as a button bitmask, which can be tested
148 using the C<SDL_BUTTON( X )> functions (where C<X> is generally 1 for the left,
149 2 for middle, 3 for the right button), and C<x> and C<y> are set to the mouse
150 deltas since the last call to SDL_GetRelativeMouseState() or since event
151 initialization. You can pass C<undef> for either C<x> or C<y>.
152  
153 Expected parameters include:
154  
155 =over
156  
157 =item C<x> - a pointer filled with the last recorded x coordinate of the mouse
158  
159 =item C<y> - a pointer filled with the last recorded y coordinate of the mouse
160  
161 =back
162  
163 =head2 C<SDL_WarpMouseInWindow( ... )>
164  
165 Move the mouse cursor to the given position within the window.
166  
167 This function generates a mouse motion event.
168  
169 Expected parameters include:
170  
171 =over
172  
173 =item C<window> - the window to move the mouse into, or C<undef> for the current mouse focus
174  
175 =item C<x> - the x coordinate within the window
176  
177 =item C<y> - the y coordinate within the window
178  
179 =back
180  
181 =head2 C<SDL_WarpMouseGlobal( ... )>
182  
183 Move the mouse to the given position in global screen space.
184  
185 This function generates a mouse motion event.
186  
187 A failure of this function usually means that it is unsupported by a platform.
188  
189 Expected parameters include:
190  
191 =over
192  
193 =item C<x> - the x coordinate
194  
195 =item C<y> - the y coordinate
196  
197 =back
198  
199 Returns C<0> on success or a negative error code on failure; call
200 C<SDL_GetError( )> for more information.
201  
202 =head2 C<SDL_SetRelativeMouseMode( ... )>
203  
204 Set relative mouse mode.
205  
206 While the mouse is in relative mode, the cursor is hidden, and the driver will
207 try to report continuous motion in the current window. Only relative motion
208 events will be delivered, the mouse position will not change.
209  
210 This function will flush any pending mouse motion.
211  
212 Expected parameters include:
213  
214 =over
215  
216 =item C<enabled> - C<SDL_TRUE> to enable relative mode, C<SDL_FALSE> to disable
217  
218 =back
219  
220 Returns C<0> on success or a negative error code on failure; call
221 C<SDL_GetError( )> for more information.
222  
223 If relative mode is not supported, this returns C<-1>.
224  
225 =head2 C<SDL_CaptureMouse( ... )>
226  
227 Capture the mouse and to track input outside an SDL window.
228  
229 Capturing enables your app to obtain mouse events globally, instead of just
230 within your window. Not all video targets support this function. When capturing
231 is enabled, the current window will get all mouse events, but unlike relative
232 mode, no change is made to the cursor and it is not restrained to your window.
233  
234 This function may also deny mouse input to other windows--both those in your
235 application and others on the system--so you should use this function
236 sparingly, and in small bursts. For example, you might want to track the mouse
237 while the user is dragging something, until the user releases a mouse button.
238 It is not recommended that you capture the mouse for long periods of time, such
239 as the entire time your app is running. For that, you should probably use L<<
240 C<SDL_SetRelativeMouseMode( ... )>|/C<SDL_SetRelativeMouseMode( ... )> >> or
241 C<SDL_SetWindowGrab( ... )>, depending on your goals.
242  
243 While captured, mouse events still report coordinates relative to the current
244 (foreground) window, but those coordinates may be outside the bounds of the
245 window (including negative values). Capturing is only allowed for the
246 foreground window. If the window loses focus while capturing, the capture will
247 be disabled automatically.
248  
249 While capturing is enabled, the current window will have the
250 C<SDL_WINDOW_MOUSE_CAPTURE> flag set.
251  
252 Expected parameters include:
253  
254 =over
255  
256 =item C<enabled> - C<SDL_TRUE> to enable capturing, C<SDL_FALSE> to disable.
257  
258 =back
259  
260 Returns C<0> on success or C<-1> if not supported; call C<SDL_GetError( )> for
261 more information.
262  
263 =head2 C<SDL_GetRelativeMouseMode( )>
264  
265 Query whether relative mouse mode is enabled.
266  
267 Returns C<SDL_TRUE> if relative mode is enabled or C<SDL_FALSE> otherwise.
268  
269 =head2 C<SDL_CreateCursor( ... )>
270  
271 Create a cursor using the specified bitmap data and mask (in MSB format).
272  
273 C<mask> has to be in MSB (Most Significant Bit) format.
274  
275 The cursor width (C<w>) must be a multiple of 8 bits.
276  
277 The cursor is created in black and white according to the following:
278  
279 =over
280  
281 =item - data=0, mask=1: white
282  
283 =item - data=1, mask=1: black
284  
285 =item - data=0, mask=1: transparent
286  
287 =item - data=1, mask=0: inverted color if possible, black if not.
288  
289 =back
290  
291 Cursors created with this function must be freed with L<< C<SDL_FreeCursor( ...
292 )>|/C<SDL_FreeCursor( ... )> >>.
293  
294 If you want to have a color cursor, or create your cursor from an
295 L<SDL2::Surface>, you should use L<< C<SDL_CreateColorCursor( ...
296 )>|/C<SDL_CreateColorCursor( ... )> >>. Alternately, you can hide the cursor
297 and draw your own as part of your game's rendering, but it will be bound to the
298 framerate.
299  
300 Also, since SDL 2.0.0, L<< C<SDL_CreateSystemCursor( ...
301 )>|/C<SDL_CreateSystemCursor( ... )> >> is available, which provides twelve
302 readily available system cursors to pick from.
303  
304 Expected parameters include:
305  
306 =over
307  
308 =item C<data> - the color value for each pixel of the cursor
309  
310 =item C<mask> - the mask value for each pixel of the cursor
311  
312 =item C<w> - the width of the cursor
313  
314 =item C<h> - the height of the cursor
315  
316 =item C<hot_x> - the X-axis location of the upper left corner of the cursor relative to the actual mouse position
317  
318 =item C<hot_y> - the Y-axis location of the upper left corner of the cursor relative to the actual mouse position
319  
320 =back
321  
322 Returns a new cursor with the specified parameters on success or C<undef> on
323 failure; call C<SDL_GetError( )> for more information.
324  
325 =head2 C<SDL_CreateColorCursor( ... )>
326  
327 Create a color cursor.
328  
329 Expected parameters include:
330  
331 =over
332  
333 =item C<surface> - an L<SDL2::Surface> structure representing the cursor image
334  
335 =item C<hot_x> - the x position of the cursor hot spot
336  
337 =item C<hot_y> - the y position of the cursor hot spot
338  
339 =back
340  
341 Returns the new cursor on success or NULL on failure; call C<SDL_GetError( )>
342 for more information.
343  
344 =head2 C<SDL_CreateSystemCursor( ... )>
345  
346 Create a system cursor.
347  
348 Expected parameters include:
349  
350 =over
351  
352 =item C<id> - an L<< C<SDL_SystemCursor>|/C<SDL_SystemCursor> >> enum value
353  
354 =back
355  
356 Returns a cursor on success or NULL on failure; call C<SDL_GetError( )> for
357 more information.
358  
359 =head2 C<SDL_SetCursor( ... )>
360  
361 Set the active cursor.
362  
363 This function sets the currently active cursor to the specified one. If the
364 cursor is currently visible, the change will be immediately represented on the
365 display. C<SDL_SetCursor( undef )> can be used to force cursor redraw, if this
366 is desired for any reason.
367  
368 Expected parameters include:
369  
370 =over
371  
372 =item C<cursor> - a cursor to make active
373  
374 =back
375  
376 =head2 C<SDL_GetCursor( )>
377  
378 Get the active cursor.
379  
380 This function returns a pointer to the current cursor which is owned by the
381 library. It is not necessary to free the cursor with L<< C<SDL_FreeCursor( ...
382 )>|/C<SDL_FreeCursor( ... )> >>.
383  
384 Returns the active cursor or C<undef> if there is no mouse.
385  
386 =head2 C<SDL_GetDefaultCursor( )>
387  
388 Get the default cursor.
389  
390 Returns the default cursor on success or C<undef> on failure.
391  
392 =head2 C<SDL_FreeCursor( ... )>
393  
394 Free a previously-created cursor.
395  
396 Use this function to free cursor resources created with L<< C<SDL_CreateCursor(
397 ... )>|/C<SDL_CreateCursor( ... )> >>, L<< C<SDL_CreateColorCursor( ...
398 )>|/C<SDL_CreateColorCursor( ... )> >> or L<< C<SDL_CreateSystemCursor( ...
399 )>|/C<SDL_CreateSystemCursor( ... )> >>.
400  
401 Expected parameters include:
402  
403 =over
404  
405 =item C<cursor> - the cursor to free
406  
407 =back
408  
409 =head2 C<SDL_ShowCursor( ... )>
410  
411 Toggle whether or not the cursor is shown.
412  
413 The cursor starts off displayed but can be turned off. Passing C<SDL_ENABLE>
414 displays the cursor and passing C<SDL_DISABLE> hides it.
415  
416 The current state of the mouse cursor can be queried by passing C<SDL_QUERY>;
417 either C<SDL_DISABLE> or C<SDL_ENABLE> will be returned.
418  
419 Expected parameters include:
420  
421 =over
422  
423 =item C<toggle> - C<SDL_ENABLE> to show the cursor, C<SDL_DISABLE> to hide it, C<SDL_QUERY> to query the current state without changing it
424  
425 =back
426  
427 Returns C<SDL_ENABLE> if the cursor is shown, or C<SDL_DISABLE> if the cursor
428 is hidden, or a negative error code on failure; call C<SDL_GetError( )> for
429 more information.
430  
431 =head1 Defined values and Enumerations
432  
433 These may be imported with their given tags or C<:mouse>.
434  
435 =head2 C<SDL_SystemCursor>
436  
437 Cursor types for L<< C<SDL_CreateSystemCursor( ...
438 )>|/C<SDL_CreateSystemCursor( ... )> >>. They may be imported with the
439 C<:systemCursor> tag.
440  
441 =over
442  
443 =item C<SDL_SYSTEM_CURSOR_ARROW> - Arrow
444  
445 =item C<SDL_SYSTEM_CURSOR_IBEAM> - I-beam
446  
447 =item C<SDL_SYSTEM_CURSOR_WAIT> - Wait
448  
449 =item C<SDL_SYSTEM_CURSOR_CROSSHAIR> - Crosshair
450  
451 =item C<SDL_SYSTEM_CURSOR_WAITARROW> - Small wait cursor (or Wait if not available)
452  
453 =item C<SDL_SYSTEM_CURSOR_SIZENWSE> - Double arrow pointing northwest and southeast
454  
455 =item C<SDL_SYSTEM_CURSOR_SIZENESW> - Double arrow pointing northeast and southwest
456  
457 =item C<SDL_SYSTEM_CURSOR_SIZEWE> - Double arrow pointing west and east
458  
459 =item C<SDL_SYSTEM_CURSOR_SIZENS> - Double arrow pointing north and south
460  
461 =item C<SDL_SYSTEM_CURSOR_SIZEALL> - Four pointed arrow pointing north, south, east, and west
462  
463 =item C<SDL_SYSTEM_CURSOR_NO> - Slashed circle or crossbones
464  
465 =item C<SDL_SYSTEM_CURSOR_HAND> - Hand
466  
467 =item C<SDL_NUM_SYSTEM_CURSORS>
468  
469 =back
470  
471 =head2 C<SDL_MouseWheelDirection>
472  
473 Scroll direction types for the Scroll event. These may be imported with the
474 C<:mouseWheelDirection> tag.
475  
476 =over
477  
478 =item C<SDL_MOUSEWHEEL_NORMAL> - The scroll direction is normal
479  
480 =item C<SDL_MOUSEWHEEL_FLIPPED> - The scroll direction is flipped / natural
481  
482 =back
483  
484 =head2 Button Masks
485  
486 These functions return values which can be used as a mask when testing buttons
487 in buttonstate.
488  
489 =over
490  
491 =item - Button 1: Left mouse button
492  
493 =item - Button 2: Middle mouse button
494  
495 =item - Button 3: Right mouse button
496  
497 =back
498  
499 =over
500  
501 =item C<SDL_BUTTON( ... )> - expects one of the following values
502  
503 =item C<SDL_BUTTON_LEFT>
504  
505 =item C<SDL_BUTTON_MIDDLE>
506  
507 =item C<SDL_BUTTON_RIGHT>
508  
509 =item C<SDL_BUTTON_X1>
510  
511 =item C<SDL_BUTTON_X2>
512  
513 =item C<SDL_BUTTON_LMASK>
514  
515 =item C<SDL_BUTTON_MMASK>
516  
517 =item C<SDL_BUTTON_RMASK>
518  
519 =item C<SDL_BUTTON_X1MASK>
520  
521 =item C<SDL_BUTTON_X2MASK>
522  
523 =back
524  
525 =head1 LICENSE
526  
527 Copyright (C) Sanko Robinson.
528  
529 This library is free software; you can redistribute it and/or modify it under
530 the terms found in the Artistic License 2. Other copyrights, terms, and
531 conditions may apply to data transmitted through this module.
532  
533 =head1 AUTHOR
534  
535 Sanko Robinson E<lt>sanko@cpan.orgE<gt>
536  
537 =begin stopwords
538  
539 bitmask coord bitmap framerate buttonstate
540  
541 =end stopwords
542  
543 =cut
544  
545 };
546 1;