.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "pods::SDL::Joystick 3pm" .TH pods::SDL::Joystick 3pm "2020-11-09" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" SDL::Joystick \-\- SDL Bindings for the Joystick device .SH "CATEGORY" .IX Header "CATEGORY" Core, Joystick .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use SDL; \& use SDL::Joystick; \& \& SDL::init_sub_system(SDL_INIT_JOYSTICK); \& \& die(\*(Aqno joystick found\*(Aq) unless(SDL::Joystick::num_joysticks()); \& \& my $joystick = SDL::Joystick\->new(0); .Ve .SH "METHODS" .IX Header "METHODS" .SS "num_joysticks" .IX Subsection "num_joysticks" .Vb 1 \& int SDL::Joystick::num_joysticks( void ); .Ve .PP Counts and returns available joysticks. .SS "name" .IX Subsection "name" .Vb 1 \& string SDL::Joystick::name( index ); .Ve .PP Get the implementation dependent name of joystick. The \f(CW\*(C`index\*(C'\fR parameter refers to the N'th joystick on the system. .PP .Vb 1 \& my $num_joysticks = SDL::Joystick::num_joysticks(); \& \& printf("%d joysticks found\en", $num_joysticks); \& \& for($i = 0; $i < $num_joysticks; $i++) \& { \& printf("%s\en", SDL::Joystick::name($i)); \& } .Ve .SS "new" .IX Subsection "new" .Vb 1 \& object SDL::Joystick\->new( index ); .Ve .PP Opens a joystick for use within \s-1SDL.\s0 The \f(CW\*(C`index\*(C'\fR refers to the N'th joystick in the system. A joystick must be opened before it can be used. .PP .Vb 2 \& # Initialize the joystick subsystem \& SDL::init_sub_system(SDL_INIT_JOYSTICK); \& \& # Check for joystick \& if(SDL::Joystick::num_joysticks() > 0) \& { \& # Open joystick \& my $joystick = SDL::Joystick\->new(0); \& \& if($joystick) \& { \& printf("Opened Joystick 0\en"); \& printf("Name: %s\en", SDL::Joystick::name(0)); \& printf("Number of Axes: %d\en", SDL::Joystick::num_axes($joystick)); \& printf("Number of Buttons: %d\en", SDL::Joystick::num_buttons($joystick)); \& printf("Number of Balls: %d\en", SDL::Joystick::num_balls($joystick)); \& } \& else \& { \& printf("Couldn\*(Aqt open Joystick 0\en"); \& } \& \& # Close if opened \& SDL::Joystick::close($joystick) if SDL::Joystick::opened(0); \& } .Ve .SS "opened" .IX Subsection "opened" .Vb 1 \& int SDL::Joystick::opened( index ); .Ve .PP Determines whether a joystick has already been opened within the application. \f(CW\*(C`index\*(C'\fR refers to the N'th joystick on the system. .PP Returns 1 if the joystick has been opened, or 0 if it has not. .SS "index" .IX Subsection "index" .Vb 1 \& int SDL::Joystick::index( object ); .Ve .PP Returns the \f(CW\*(C`index\*(C'\fR of a given \f(CW\*(C`SDL_Joystick\*(C'\fR structure. See SDL::Joystick::new .SS "num_axes" .IX Subsection "num_axes" .Vb 1 \& int SDL::Joystick::num_axes( object ); .Ve .PP Return the number of axes available from a previously opened joystick. See SDL::Joystick::new .SS "num_balls" .IX Subsection "num_balls" .Vb 1 \& int SDL::Joystick::num_balls( object ); .Ve .PP Return the number of trackballs available from a previously opened joystick. See SDL::Joystick::new .SS "num_hats" .IX Subsection "num_hats" .Vb 1 \& int SDL::Joystick::num_hats( object ); .Ve .PP Gets the number of joystick hats from a previously opened joystick. See SDL::Joystick::new .SS "num_buttons" .IX Subsection "num_buttons" .Vb 1 \& int SDL::Joystick::num_buttons( object ); .Ve .PP Gets the number of joystick buttons from a previously opened joystick. See SDL::Joystick::new .SS "update" .IX Subsection "update" .Vb 1 \& void SDL::Joystick::update(); .Ve .PP Updates the state(position, buttons, etc.) of all open joysticks. If joystick events have been enabled with \f(CW\*(C`SDL::Joystick::event_state\*(C'\fR then this is called automatically in the event loop. .SS "get_axis" .IX Subsection "get_axis" \&\f(CW\*(C`get_axis\*(C'\fR returns the current state of the given axis on the given joystick. .PP On most modern joysticks the X axis is usually represented by axis 0 and the Y axis by axis 1. The value returned by \f(CW\*(C`get_axis\*(C'\fR is a signed integer (\-32768 to 32767) representing the current position of the axis, it may be necessary to impose certain tolerances on these values to account for jitter. .PP \&\fBNote\fR: Some joysticks use axes 2 and 3 for extra buttons. .PP Returns a 16\-bit signed integer representing the current position of the axis. .PP .Vb 1 \& my $joystick = SDL::Joystick\->new(0); \& \& my $x_move = SDL::Joystick::get_axis($joystick, 0); \& my $y_move = SDL::Joystick::get_axis($joystick, 1); .Ve .SS "get_hat" .IX Subsection "get_hat" .Vb 1 \& int SDL::Joystick::get_hat( object, int ); .Ve .PP \&\f(CW\*(C`get_hat\*(C'\fR returns the current state of the given \f(CW\*(C`hat\*(C'\fR on the given \f(CW\*(C`joystick\*(C'\fR. .PP The current state is returned which is an \s-1OR\s0'd combination of one or more of the following: .IP "\(bu" 4 \&\f(CW\*(C`SDL_HAT_CENTERED\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`SDL_HAT_UP\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`SDL_HAT_RIGHT\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`SDL_HAT_DOWN\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`SDL_HAT_LEFT\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`SDL_HAT_RIGHTUP\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`SDL_HAT_RIGHTDOWN\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`SDL_HAT_LEFTUP\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`SDL_HAT_LEFTDOWN\*(C'\fR .PP .Vb 1 \& my $joystick = SDL::Joystick\->new(0); \& \& my $position = SDL::Joystick::get_hat($joystick, 0); \& \& print("hat is in position UP\en") if $position & SDL_HAT_UP; .Ve .SS "get_button" .IX Subsection "get_button" .Vb 1 \& int SDL::Joystick::get_button( object, int ); .Ve .PP \&\f(CW\*(C`get_button\*(C'\fR returns the current state of the given button on the given joystick. .PP Returns 1 if the button is pressed. Otherwise, 0. .PP .Vb 1 \& my $joystick = SDL::Joystick\->new(0); \& \& my $num_buttons = SDL::Joystick::num_buttons($joystick); \& \& for(my $i = 0; $i < $num_buttons; $i++) \& { \& printf("button %d is %s\en", $i, SDL::Joystick::get_button($joystick, $i) ? \*(Aqpressed\*(Aq : \*(Aqnot pressed\*(Aq); \& } \& \& SDL::Joystick::close($joystick) if SDL::Joystick::opened(0); .Ve .SS "get_ball" .IX Subsection "get_ball" .Vb 1 \& int SDL::Joystick::get_ball(SDL_Joystick $joystick, int $ball, int $dx, int $dy); .Ve .PP Get the ball axis change. .PP Trackballs can only return relative motion since the last call to SDL::Joystick::get_ball, these motion deltas are placed into \f(CW\*(C`dx\*(C'\fR and \f(CW\*(C`dy\*(C'\fR. .PP Returns 0 on success or \-1 on failure .PP .Vb 3 \& my $delta_x = 0; \& my $delta_y = 0; \& my $joystick = SDL::Joystick\->new(0); \& \& SDL::Joystick::update(); \& \& printf("TrackBall Read Error!\en") if(SDL::JoystickGetBall($joystick, 0, $delta_x, $delta_y) == \-1); \& printf("Trackball Delta\- X:%d, Y:%d\en", delta_x, delta_y); .Ve .SS "close" .IX Subsection "close" .Vb 1 \& void SDL::Joystick::close( object ); .Ve .PP Closes a previously opened joystick. See SDL::Joystick::new .PP .Vb 1 \& SDL::Joystick::close($joystick) if SDL::Joystick::opened(0); .Ve .SH "AUTHORS" .IX Header "AUTHORS" See \*(L"\s-1AUTHORS\*(R"\s0 in \s-1SDL\s0.