mx::mxJoystick Class Reference

List of all members.

Public Member Functions

 mxJoystick (int joy_index=0)
 mxJoystick (SDL_Joystick *stick)
 ~mxJoystick ()
void initJoystick (int id)
void freeJoystick ()
const bool isOpen () const
const std::string joystickName () const
const bool joystickGetButton (int button) const
const int joystickGetAxis (int axis) const
const int joystickGetHat (int hat) const
const int joystickGetBall (int ball, int &x, int &y)

Static Public Member Functions

static const int joystickNum ()
static const void joystickUpdate ()

Protected Attributes

SDL_Joystick * stick
int index


Detailed Description

encapsulate SDL_Joystick *

Definition at line 30 of file mxjoystick.h.


Constructor & Destructor Documentation

mx::mxJoystick::mxJoystick ( int  joy_index = 0  ) 

default constructor

Definition at line 23 of file mxjoystick.cpp.

References initJoystick(), and stick.

00024         {
00025                 stick = 0;
00026 
00027                 initJoystick(id);
00028 
00029         }

mx::mxJoystick::mxJoystick ( SDL_Joystick *  stick  ) 

constructor

Parameters:
already opened Joystick

Definition at line 31 of file mxjoystick.cpp.

References freeJoystick(), and index.

00032         {
00033 
00034                 if(this->stick != 0)
00035                 {
00036                         freeJoystick();
00037                 }
00038 
00039                 this->stick = stick;
00040                 index = SDL_JoystickIndex(this->stick);
00041         }

mx::mxJoystick::~mxJoystick (  ) 

destructor

Definition at line 44 of file mxjoystick.cpp.

References freeJoystick().

00045         {
00046                 freeJoystick();
00047         }


Member Function Documentation

void mx::mxJoystick::freeJoystick (  ) 

freeJoystick free the Joystick

Definition at line 66 of file mxjoystick.cpp.

References stick.

Referenced by mxJoystick(), and ~mxJoystick().

00067         {
00068                 SDL_JoystickClose(stick);
00069                 stick = 0;
00070         }

void mx::mxJoystick::initJoystick ( int  id  ) 

initJoystick initialize joystick

Definition at line 50 of file mxjoystick.cpp.

References index, and stick.

Referenced by mxJoystick().

00051         {
00052 
00053                 stick = SDL_JoystickOpen(id);
00054                 SDL_JoystickEventState(SDL_ENABLE);
00055 
00056                 if(stick == 0)
00057                 {
00058                         std::cout << "could not open joystick id: " << id << "\n";
00059                 }
00060 
00061                 index = id;
00062 
00063         }

const bool mx::mxJoystick::isOpen (  )  const [inline]

isOpen is Joystick already Open?

Definition at line 46 of file mxjoystick.h.

References index.

00046 { return SDL_JoystickOpened(index) ? true : false; }

const int mx::mxJoystick::joystickGetAxis ( int  axis  )  const

joystickGetAxis get axis position

Parameters:
axis which axis
Returns:
axis position

Definition at line 77 of file mxjoystick.cpp.

References stick.

00078         {
00079                 return static_cast<int>(SDL_JoystickGetAxis(stick, axis));
00080         }

const int mx::mxJoystick::joystickGetBall ( int  ball,
int &  x,
int &  y 
)

joystickGetBall

Parameters:
ball which ball
x x pos
y y pos

Definition at line 87 of file mxjoystick.cpp.

References stick.

00088         {
00089                 return static_cast<int>( SDL_JoystickGetBall(stick, ball, &x, &y) );
00090         }

const bool mx::mxJoystick::joystickGetButton ( int  button  )  const

joystickGetButton get if button is down

Parameters:
button which button
Returns:
boolean for if button is down

Definition at line 72 of file mxjoystick.cpp.

References stick.

00073         {
00074                 return SDL_JoystickGetButton(stick, button) ? true : false;
00075         }

const int mx::mxJoystick::joystickGetHat ( int  hat  )  const

joystickGetHat get position of hat

Parameters:
hat which hat
Returns:
position of hat

Definition at line 82 of file mxjoystick.cpp.

References stick.

00083         {
00084                 return static_cast<int>(SDL_JoystickGetHat(stick, hat));
00085         }

const std::string mx::mxJoystick::joystickName (  )  const [inline]

joystickName

Returns:
Joystick Name

Definition at line 48 of file mxjoystick.h.

References index.

00048 { return SDL_JoystickName(index); }

static const int mx::mxJoystick::joystickNum (  )  [inline, static]

joystickNum

Returns:
number of Joystick's

Definition at line 74 of file mxjoystick.h.

00074 { return SDL_NumJoysticks(); }

static const void mx::mxJoystick::joystickUpdate (  )  [inline, static]

joystickUpdate update joystick's

Definition at line 77 of file mxjoystick.h.

00077 { SDL_JoystickUpdate(); }


Member Data Documentation

int mx::mxJoystick::index [protected]

current joystick index

Definition at line 83 of file mxjoystick.h.

Referenced by initJoystick(), isOpen(), joystickName(), and mxJoystick().

SDL_Joystick* mx::mxJoystick::stick [protected]

SDL_Joystick * data

Definition at line 81 of file mxjoystick.h.

Referenced by freeJoystick(), initJoystick(), joystickGetAxis(), joystickGetBall(), joystickGetButton(), joystickGetHat(), and mxJoystick().


The documentation for this class was generated from the following files:

Generated on Wed Jun 10 14:52:02 2009 for libmx by  doxygen 1.5.8