sdljava.joystick
Class SDLJoystick

java.lang.Object
  extended by sdljava.joystick.SDLJoystick

public class SDLJoystick
extends java.lang.Object

Binding to the SDL Joystick routines.

Version:
$Id: SDLJoystick.java,v 1.3 2005/01/19 03:09:12 ivan_ganza Exp $
Author:
Ivan Z. Ganza

Field Summary
(package private)  SWIGTYPE_p__SDL_Joystick swigJoystick
           
 
Constructor Summary
private SDLJoystick(SWIGTYPE_p__SDL_Joystick swigJoystick)
           
 
Method Summary
protected  void finalize()
           
 void joystickClose()
          Closes a previously opened joystick
 int joystickGetAxis(int axis)
          Get the current state of an axis
 void joystickGetBall(int ball, java.lang.Integer dx, java.lang.Integer dy)
          Get relative trackball motion
 boolean joystickGetButton(int button)
          Get the current state of a given button on a given joystick
 HatState joystickGetHat(int hat)
          Get the current state of a joystick hat
 int joystickIndex()
          Get the index of an SDL_Joystick.
static java.lang.String joystickName(int index)
          Get joystick name
 int joystickNumAxes()
          Get the number of joystick axes
 int joystickNumBalls()
          Get the number of joystick trackballs
 int joystickNumButtons()
          Get the number of joystick Buttons
 int joystickNumHats()
          Get the number of joystick hats
static SDLJoystick joystickOpen(int index)
          Opens a joystick for use.
static boolean joystickOpened(int index)
          Determine if a joystick has been opened
static void joystickUpdate()
          Updates the state of all joysticks
static int numJoysticks()
          Count available joysticks.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

swigJoystick

SWIGTYPE_p__SDL_Joystick swigJoystick
Constructor Detail

SDLJoystick

private SDLJoystick(SWIGTYPE_p__SDL_Joystick swigJoystick)
Method Detail

numJoysticks

public static int numJoysticks()
Count available joysticks.

Counts the number of joysticks attached to the system.

Returns:
Returns the number of attached joysticks

joystickName

public static java.lang.String joystickName(int index)
Get joystick name

Get the implementation dependent name of joystick. The index parameter refers to the N'th joystick on the system.

Returns:
The joystick name

joystickOpen

public static SDLJoystick joystickOpen(int index)
                                throws SDLException
Opens a joystick for use. A joystick must be opened before it can be used

Parameters:
index - index refers to the N'th joystick in the system
Returns:
The joystick
Throws:
SDLException - if an error occured

joystickOpened

public static boolean joystickOpened(int index)
Determine if a joystick has been opened

Determines whether a joystick has already been opened within the application.

Parameters:
index - index refers to the N'th joystick on the system.
Returns:
if the joystick at index has been opened

joystickUpdate

public static void joystickUpdate()
Updates the state of all joysticks

Updates the state(position, buttons, etc.) of all open joysticks. If joystick events have been enabled with SDL_JoystickEventState then this is called automatically in the event loop.


joystickIndex

public int joystickIndex()
Get the index of an SDL_Joystick.

Returns:
Index number of the joystick.

joystickNumAxes

public int joystickNumAxes()
Get the number of joystick axes

Returns:
The number of axes

joystickNumBalls

public int joystickNumBalls()
Get the number of joystick trackballs

Returns:
The number of trackballs

joystickNumHats

public int joystickNumHats()
Get the number of joystick hats

Returns:
The number of hats

joystickNumButtons

public int joystickNumButtons()
Get the number of joystick Buttons

Returns:
The number of Buttons

joystickGetAxis

public int joystickGetAxis(int axis)
Get the current state of an axis

SDL_JoystickGetAxis returns the current state of the given axis on the given joystick.

On most modern joysticks the X axis is usually represented by axis 0 and the Y axis by axis 1. The value returned by SDL_JoystickGetAxis 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. It is worth noting that some joysticks use axes 2 and 3 for extra buttons.

Parameters:
axis - an int value
Returns:
the current position of the axis.

joystickGetHat

public HatState joystickGetHat(int hat)
Get the current state of a joystick hat

Parameters:
hat - The hat to get the state for
Returns:
the current state of the given hat on the given joystick.

joystickGetButton

public boolean joystickGetButton(int button)
Get the current state of a given button on a given joystick

Parameters:
button - an int value
Returns:
if the given button on the given joystick is pressed

joystickGetBall

public void joystickGetBall(int ball,
                            java.lang.Integer dx,
                            java.lang.Integer dy)
                     throws SDLException
Get relative trackball motion

Parameters:
ball - The ball
dx - The value of the x change will be placed here
dy - The value of the y change will be placed here
Throws:
SDLException - if an error occurs

joystickClose

public void joystickClose()
Closes a previously opened joystick


finalize

protected void finalize()
Overrides:
finalize in class java.lang.Object