OSDL::Events::Joystick Class Reference

Models a basic joystick, including relevant axes, hats, balls and buttons. More...

#include <OSDLJoystick.h>

Inheritance diagram for OSDL::Events::Joystick:
Inheritance graph
[legend]
Collaboration diagram for OSDL::Events::Joystick:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Joystick (JoystickNumber index)
 Constructs a new joystick manager.
virtual ~Joystick () throw ()
 Virtual destructor, closing corresponding joystick device.
virtual const std::string & getName () const
 Returns the implementation dependent name of this joystick.
virtual bool isOpen () const
 Tells whether this joystick is currently opened.
virtual void open ()
 Opens the joystick, so that it can be used.
virtual void close ()
 Closes the joystick.
virtual JoystickAxesCount getNumberOfAxes () const
 Returns the number of joystick axes.
virtual JoystickTrackballsCount getNumberOfTrackballs () const
 Returns the number of joystick trackballs.
virtual JoystickHatsCount getNumberOfHats () const
 Returns the number of joystick hats.
virtual JoystickButtonsCount getNumberOfButtons () const
 Returns the number of joystick buttons.
virtual AxisPosition getAbscissaPosition () const
 Returns the absolute position of the X axis.
virtual AxisPosition getOrdinatePosition () const
 Returns the absolute position of the Y axis.
virtual AxisPosition getPositionOfAxis (JoystickAxesCount index) const
 Returns the absolute position of the specified axis.
virtual HatPosition getPositionOfHat (JoystickHatsCount index) const
 Returns the absolute position of the specified hat.
virtual bool isButtonPressed (JoystickButtonsCount buttonNumber) const
 Tells whether specified joystick button is pressed.
virtual bool getPositionOfTrackball (JoystickTrackballsCount ball, BallMotion &deltaX, BallMotion &deltaY) const
 Returns the relative position of the specified trackball.
virtual void update ()
 Updates the description of this joystick (trackballs, hats, buttons, etc.
virtual const std::string toString (Ceylan::VerbosityLevels level=Ceylan::high) const
 Returns an user-friendly description of the state of this object.
virtual OSDL::MVC::ControllergetActualController () const
 Returns the actual (OSDL) controller this input device should be linked to.

Protected Member Functions

virtual JoystickNumber getIndex () const
 Returns the index of this joystick in the platform list.
virtual void axisChanged (const JoystickAxisEvent &joystickEvent)
 Called whenever an axis of this joystick changed, and notifies the linked controller, if any.
virtual void trackballChanged (const JoystickTrackballEvent &joystickEvent)
 Called whenever a trackball of this joystick changed, and notifies the linked controller, if any.
virtual void hatChanged (const JoystickHatEvent &joystickEvent)
 Called whenever a hat of this joystick changed, and notifies the linked controller, if any.
virtual void buttonPressed (const JoystickButtonEvent &joystickEvent)
 Called whenever a button of this joystick was pressed, and notifies the linked controller, if any.
virtual void buttonReleased (const JoystickButtonEvent &joystickEvent)
 Called whenever a button of this joystick was released, and notifies the linked controller, if any.

Protected Attributes

std::string _name
 The implementation dependent name of this joystick, if any.
JoystickNumber _index
 The number of this joystick in platform list.
LowLevelJoystick_internalJoystick
 The internal raw joystick being used.
JoystickAxesCount _axisCount
 The number of axes for this joystick.
JoystickTrackballsCount _trackballCount
 The number of trackballs for this joystick.
JoystickHatsCount _hatCount
 The number of hats for this joystick.
JoystickButtonsCount _buttonCount
 The number of buttons for this joystick.

Private Member Functions

 Joystick (const Joystick &source)
 Copy constructor made private to ensure that it will never be called.
Joystickoperator= (const Joystick &source)
 Assignment operator made private to ensure that it will never be called.

Friends

class OSDL::Events::JoystickHandler

Detailed Description

Models a basic joystick, including relevant axes, hats, balls and buttons.

Usually, joystick directions should be interpreted this way:

All events for this joystick are propagated to the associated controller, if any, which allows to finely master all available informations, at the expense of a higher complexity on the controller part.

For usual needs, ClassicalJoystick child class should be more convenient, since it is a higher-level (but a little less general-purpose) model.

See also:
ClassicalJoystick

Definition at line 97 of file OSDLJoystick.h.


Constructor & Destructor Documentation

Joystick::Joystick ( JoystickNumber  index  )  [explicit]

Constructs a new joystick manager.

Dummy values will be returned by non-static methods in case there is no SDL support available.

Parameters:
index the index of this joystick in platform list.
Exceptions:
JoystickException if the operation failed or is not supported.

It is not a problem as these methods cannot be called: constructors always throw exceptions in that case, thus no instance can be available for these method calls.

Definition at line 85 of file OSDLJoystick.cc.

References _name.

Joystick::~Joystick (  )  throw () [virtual]

Virtual destructor, closing corresponding joystick device.

Definition at line 116 of file OSDLJoystick.cc.

References close(), and isOpen().

OSDL::Events::Joystick::Joystick ( const Joystick source  )  [explicit, private]

Copy constructor made private to ensure that it will never be called.

The compiler should complain whenever this undefined constructor is called, implicitly or not.


Member Function Documentation

void Joystick::axisChanged ( const JoystickAxisEvent joystickEvent  )  [protected, virtual]

Called whenever an axis of this joystick changed, and notifies the linked controller, if any.

Parameters:
joystickEvent the corresponding joystick event.
Note:
Expected to be triggered by the Joystick handler.

Reimplemented in OSDL::Events::ClassicalJoystick.

Definition at line 210 of file OSDLJoystick.cc.

References OSDL::Events::EventsModule::DescribeEvent(), OSDL::Events::InputDevice::getActualController(), OSDL::MVC::Controller::joystickAxisChanged(), and OSDL_JOYSTICK_LOG.

Referenced by OSDL::Events::JoystickHandler::axisChanged().

void Joystick::buttonPressed ( const JoystickButtonEvent joystickEvent  )  [protected, virtual]

Called whenever a button of this joystick was pressed, and notifies the linked controller, if any.

Parameters:
joystickEvent the corresponding joystick event.
Note:
Expected to be triggered by the Joystick handler.

Reimplemented in OSDL::Events::ClassicalJoystick.

Definition at line 258 of file OSDLJoystick.cc.

References OSDL::Events::EventsModule::DescribeEvent(), OSDL::Events::InputDevice::getActualController(), OSDL::MVC::Controller::joystickButtonPressed(), and OSDL_JOYSTICK_LOG.

Referenced by OSDL::Events::JoystickHandler::buttonPressed().

void Joystick::buttonReleased ( const JoystickButtonEvent joystickEvent  )  [protected, virtual]

Called whenever a button of this joystick was released, and notifies the linked controller, if any.

Parameters:
joystickEvent the corresponding joystick event.
Note:
Expected to be triggered by the Joystick handler.

Reimplemented in OSDL::Events::ClassicalJoystick.

Definition at line 274 of file OSDLJoystick.cc.

References OSDL::Events::EventsModule::DescribeEvent(), OSDL::Events::InputDevice::getActualController(), OSDL::MVC::Controller::joystickButtonReleased(), and OSDL_JOYSTICK_LOG.

Referenced by OSDL::Events::JoystickHandler::buttonReleased().

void Joystick::close (  )  [virtual]

Closes the joystick.

Exceptions:
JoystickException if the joystick was not open.

Definition at line 190 of file OSDLJoystick.cc.

References _internalJoystick, and isOpen().

Referenced by ~Joystick().

AxisPosition Joystick::getAbscissaPosition (  )  const [virtual]

Returns the absolute position of the X axis.

Note:
On most modern joysticks the X axis is represented by axis 0, which is the axis that is used by this method.
Joystick must be already open.

Definition at line 350 of file OSDLJoystick.cc.

References _axisCount, _internalJoystick, and isOpen().

OSDL::MVC::Controller & InputDevice::getActualController (  )  const [virtual, inherited]

Returns the actual (OSDL) controller this input device should be linked to.

Exceptions:
EventException if this input device is not linked to any controller, or if the controller is not an OSDL one.
See also:
isLinkedToController

Definition at line 63 of file OSDLInputDevice.cc.

Referenced by axisChanged(), OSDL::Events::ClassicalJoystick::axisChanged(), OSDL::Events::Mouse::buttonPressed(), buttonPressed(), OSDL::Events::ClassicalJoystick::buttonPressed(), OSDL::Events::Mouse::buttonReleased(), buttonReleased(), OSDL::Events::ClassicalJoystick::buttonReleased(), OSDL::Events::Mouse::focusGained(), OSDL::Events::Mouse::focusLost(), hatChanged(), OSDL::Events::Mouse::mouseMoved(), and trackballChanged().

JoystickNumber Joystick::getIndex (  )  const [protected, virtual]

Returns the index of this joystick in the platform list.

Note:
Should be useless.

Definition at line 509 of file OSDLJoystick.cc.

References _index, _internalJoystick, and OSDL::Video::Pixels::toString().

const string & Joystick::getName (  )  const [virtual]

Returns the implementation dependent name of this joystick.

Definition at line 134 of file OSDLJoystick.cc.

References _name.

JoystickAxesCount Joystick::getNumberOfAxes (  )  const [virtual]

Returns the number of joystick axes.

Note:
The joystick must already have been opened.

Definition at line 290 of file OSDLJoystick.cc.

References _axisCount, and isOpen().

JoystickButtonsCount Joystick::getNumberOfButtons (  )  const [virtual]

Returns the number of joystick buttons.

Note:
The joystick must already have been opened.

Definition at line 335 of file OSDLJoystick.cc.

References _buttonCount, and isOpen().

JoystickHatsCount Joystick::getNumberOfHats (  )  const [virtual]

Returns the number of joystick hats.

Note:
The joystick must already have been opened.

Definition at line 320 of file OSDLJoystick.cc.

References _hatCount, and isOpen().

JoystickTrackballsCount Joystick::getNumberOfTrackballs (  )  const [virtual]

Returns the number of joystick trackballs.

Note:
The joystick must already have been opened.

Definition at line 305 of file OSDLJoystick.cc.

References _trackballCount, and isOpen().

AxisPosition Joystick::getOrdinatePosition (  )  const [virtual]

Returns the absolute position of the Y axis.

Note:
On most modern joysticks the Y axis is represented by axis 1, which is the axis that is used by this method.
Joystick must be already open.

Definition at line 378 of file OSDLJoystick.cc.

References _axisCount, _internalJoystick, and isOpen().

AxisPosition Joystick::getPositionOfAxis ( JoystickAxesCount  index  )  const [virtual]

Returns the absolute position of the specified axis.

Parameters:
index the index of the axis for this joystick.
Returns:
the axis position.
Exceptions:
JoystickException if the joystick is not already opened or if index is out of bounds.

Definition at line 406 of file OSDLJoystick.cc.

References _axisCount, _internalJoystick, isOpen(), and OSDL::Video::Pixels::toString().

HatPosition Joystick::getPositionOfHat ( JoystickHatsCount  index  )  const [virtual]

Returns the absolute position of the specified hat.

Parameters:
index the index of the hat for this joystick.
Returns:
the hat position.
Exceptions:
JoystickException if the joystick is not already open or if index is out of bounds.

Definition at line 431 of file OSDLJoystick.cc.

References _hatCount, _internalJoystick, isOpen(), and OSDL::Video::Pixels::toString().

bool Joystick::getPositionOfTrackball ( JoystickTrackballsCount  ball,
BallMotion deltaX,
BallMotion deltaY 
) const [virtual]

Returns the relative position of the specified trackball.

Parameters:
ball the number of the ball for this joystick.
deltaX the abscissa motion delta, since last call to this method, will be stored here.
deltaY the ordinate motion delta, since last call to this method, will be stored here.
Returns:
true iff the operation succeeded.
Exceptions:
JoystickException if the joystick is not already open or if index is out of bounds.
Note:
Trackballs can only return relative motion since the last call of this method.

Definition at line 481 of file OSDLJoystick.cc.

References _internalJoystick, _trackballCount, isOpen(), and OSDL::Video::Pixels::toString().

void Joystick::hatChanged ( const JoystickHatEvent joystickEvent  )  [protected, virtual]

Called whenever a hat of this joystick changed, and notifies the linked controller, if any.

Parameters:
joystickEvent the corresponding joystick event.
Note:
Expected to be triggered by the Joystick handler.

Definition at line 242 of file OSDLJoystick.cc.

References OSDL::Events::EventsModule::DescribeEvent(), OSDL::Events::InputDevice::getActualController(), OSDL::MVC::Controller::joystickHatChanged(), and OSDL_JOYSTICK_LOG.

Referenced by OSDL::Events::JoystickHandler::hatChanged().

bool Joystick::isButtonPressed ( JoystickButtonsCount  buttonNumber  )  const [virtual]

Tells whether specified joystick button is pressed.

Parameters:
buttonNumber the number of the button for this joystick.
Returns:
true iff the button is currently pressed.
Exceptions:
JoystickException if the joystick is not already open or if the button number is out of bounds.

Definition at line 456 of file OSDLJoystick.cc.

References _buttonCount, _internalJoystick, isOpen(), and OSDL::Video::Pixels::toString().

bool Joystick::isOpen (  )  const [virtual]
void Joystick::open (  )  [virtual]

Opens the joystick, so that it can be used.

Exceptions:
JoystickException if the joystick was already open.

Definition at line 171 of file OSDLJoystick.cc.

References _index, _internalJoystick, isOpen(), and update().

Referenced by OSDL::Events::JoystickHandler::openJoystick().

Joystick& OSDL::Events::Joystick::operator= ( const Joystick source  )  [private]

Assignment operator made private to ensure that it will never be called.

The compiler should complain whenever this undefined operator is called, implicitly or not.

Reimplemented in OSDL::Events::ClassicalJoystick.

const string Joystick::toString ( Ceylan::VerbosityLevels  level = Ceylan::high  )  const [virtual]

Returns an user-friendly description of the state of this object.

Parameters:
level the requested verbosity level.
Note:
Text output format is determined from overall settings.
See also:
Ceylan::TextDisplayable

Reimplemented from OSDL::Events::InputDevice.

Reimplemented in OSDL::Events::ClassicalJoystick.

Definition at line 559 of file OSDLJoystick.cc.

References _axisCount, _buttonCount, _hatCount, _index, _name, _trackballCount, and isOpen().

Referenced by isOpen().

void Joystick::trackballChanged ( const JoystickTrackballEvent joystickEvent  )  [protected, virtual]

Called whenever a trackball of this joystick changed, and notifies the linked controller, if any.

Parameters:
joystickEvent the corresponding joystick event.
Note:
Expected to be triggered by the Joystick handler.

Definition at line 226 of file OSDLJoystick.cc.

References OSDL::Events::EventsModule::DescribeEvent(), OSDL::Events::InputDevice::getActualController(), OSDL::MVC::Controller::joystickTrackballChanged(), and OSDL_JOYSTICK_LOG.

Referenced by OSDL::Events::JoystickHandler::trackballChanged().

void Joystick::update (  )  [virtual]

Updates the description of this joystick (trackballs, hats, buttons, etc.

)

Note:
The joystick must be open.

Definition at line 543 of file OSDLJoystick.cc.

References _axisCount, _buttonCount, _hatCount, _internalJoystick, and _trackballCount.

Referenced by open().


Friends And Related Function Documentation

friend class OSDL::Events::JoystickHandler [friend]

Reimplemented in OSDL::Events::ClassicalJoystick.

Definition at line 107 of file OSDLJoystick.h.


Member Data Documentation

The number of axes for this joystick.

Definition at line 455 of file OSDLJoystick.h.

Referenced by getAbscissaPosition(), getNumberOfAxes(), getOrdinatePosition(), getPositionOfAxis(), toString(), and update().

The number of buttons for this joystick.

Definition at line 470 of file OSDLJoystick.h.

Referenced by getNumberOfButtons(), isButtonPressed(), toString(), and update().

The number of hats for this joystick.

Definition at line 465 of file OSDLJoystick.h.

Referenced by getNumberOfHats(), getPositionOfHat(), toString(), and update().

The number of this joystick in platform list.

Definition at line 445 of file OSDLJoystick.h.

Referenced by getIndex(), isOpen(), open(), and toString().

std::string OSDL::Events::Joystick::_name [protected]

The implementation dependent name of this joystick, if any.

Definition at line 440 of file OSDLJoystick.h.

Referenced by getName(), Joystick(), and toString().

The number of trackballs for this joystick.

Definition at line 460 of file OSDLJoystick.h.

Referenced by getNumberOfTrackballs(), getPositionOfTrackball(), toString(), and update().


The documentation for this class was generated from the following files:
Generated on Mon Nov 29 14:05:51 2010 for OSDL by  doxygen 1.6.3