Handler for all detected joysticks. More...
#include <OSDLJoystickHandler.h>
Public Member Functions | |
JoystickHandler (bool useClassicalJoysticks=true) | |
Constructs a new joystick handler. | |
virtual | ~JoystickHandler () throw () |
Virtual destructor. | |
virtual void | update () |
Auto-detects and registers any attached joystick. | |
virtual void | openJoystick (JoystickNumber index) |
Opens joystick of specified index. | |
virtual void | linkToController (JoystickNumber index, OSDL::MVC::Controller &controller) |
Links specified joystick to specified controller, so that any further joystick-related event will be sent to the controller. | |
virtual const std::string | toString (Ceylan::VerbosityLevels level=Ceylan::high) const |
Returns an user-friendly description of the state of this object. | |
Static Public Member Functions | |
static JoystickNumber | GetAvailableJoystickCount () |
Returns the number of available joysticks, i.e. | |
Protected Member Functions | |
virtual void | axisChanged (const JoystickAxisEvent &joystickEvent) const |
Called whenever a joystick axis changed, so that its controller, if any, is notified. | |
virtual void | trackballChanged (const JoystickTrackballEvent &joystickEvent) const |
Called whenever a joystick trackball changed, so that its controller, if any, is notified. | |
virtual void | hatChanged (const JoystickHatEvent &joystickEvent) const |
Called whenever a joystick hat changed, so that its controller, if any, is notified. | |
virtual void | buttonPressed (const JoystickButtonEvent &joystickEvent) const |
Called whenever a joystick button was pressed, so that its controller, if any, is notified. | |
virtual void | buttonReleased (const JoystickButtonEvent &joystickEvent) const |
Called whenever a joystick button was released, so that its controller, if any, is notified. | |
virtual void | blank () |
Blanks this joystick handler, i.e. | |
virtual void | checkJoystickAt (JoystickNumber index) const |
Checks that the joystick at the specified index exists and is opened. | |
Protected Attributes | |
JoystickNumber | _joystickCount |
Records how many joysticks are known by this handler. | |
Joystick ** | _joysticks |
Records all known joysticks. | |
bool | _useClassicalJoysticks |
Tells whether complex joysticks (if false) or classical joysticks (if true) should be created. | |
Private Member Functions | |
JoystickHandler (const JoystickHandler &source) | |
Copy constructor made private to ensure that it will never be called. | |
JoystickHandler & | operator= (const JoystickHandler &source) |
Assignment operator made private to ensure that it will never be called. | |
Friends | |
class | OSDL::Events::EventsModule |
Handler for all detected joysticks.
Joystick indexes range from 0 (included) to GetAvailableJoystickCount() (excluded).
Definition at line 82 of file OSDLJoystickHandler.h.
JoystickHandler::JoystickHandler | ( | bool | useClassicalJoysticks = true |
) | [explicit] |
Constructs a new joystick handler.
useClassicalJoysticks | tells whether detected joysticks should be managed as complex joysticks (powerful interface, but it requires the controller to take in charge this complexity) or classical joysticks (for usual needs, comes with preset behaviours which ease controller work). |
InputDeviceHandlerException | if the initialization of the joystick subsystem failed. |
Definition at line 88 of file OSDLJoystickHandler.cc.
References OSDL::CommonModule::BackendSuccess, OSDL::Utils::getBackendLastError(), update(), and OSDL::CommonModule::UseVideo.
JoystickHandler::~JoystickHandler | ( | ) | throw () [virtual] |
Virtual destructor.
Definition at line 125 of file OSDLJoystickHandler.cc.
References blank(), and OSDL::CommonModule::UseJoystick.
OSDL::Events::JoystickHandler::JoystickHandler | ( | const JoystickHandler & | 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.
void JoystickHandler::axisChanged | ( | const JoystickAxisEvent & | joystickEvent | ) | const [protected, virtual] |
Called whenever a joystick axis changed, so that its controller, if any, is notified.
Definition at line 298 of file OSDLJoystickHandler.cc.
References _joysticks, OSDL::Events::Joystick::axisChanged(), and checkJoystickAt().
Referenced by OSDL::Events::EventsModule::onJoystickAxisChanged().
void JoystickHandler::blank | ( | ) | [protected, virtual] |
Blanks this joystick handler, i.e.
makes it forget all previously known joysticks.
Definition at line 387 of file OSDLJoystickHandler.cc.
References _joystickCount, and _joysticks.
Referenced by update(), and ~JoystickHandler().
void JoystickHandler::buttonPressed | ( | const JoystickButtonEvent & | joystickEvent | ) | const [protected, virtual] |
Called whenever a joystick button was pressed, so that its controller, if any, is notified.
Definition at line 351 of file OSDLJoystickHandler.cc.
References _joysticks, OSDL::Events::Joystick::buttonPressed(), and checkJoystickAt().
Referenced by OSDL::Events::EventsModule::onJoystickButtonPressed().
void JoystickHandler::buttonReleased | ( | const JoystickButtonEvent & | joystickEvent | ) | const [protected, virtual] |
Called whenever a joystick button was released, so that its controller, if any, is notified.
Definition at line 369 of file OSDLJoystickHandler.cc.
References _joysticks, OSDL::Events::Joystick::buttonReleased(), and checkJoystickAt().
Referenced by OSDL::Events::EventsModule::onJoystickButtonReleased().
void JoystickHandler::checkJoystickAt | ( | JoystickNumber | index | ) | const [protected, virtual] |
Checks that the joystick at the specified index exists and is opened.
index | the index of the joystick to check. |
Definition at line 408 of file OSDLJoystickHandler.cc.
References _joystickCount, and _joysticks.
Referenced by axisChanged(), buttonPressed(), buttonReleased(), hatChanged(), and trackballChanged().
JoystickNumber JoystickHandler::GetAvailableJoystickCount | ( | ) | [static] |
Returns the number of available joysticks, i.e.
the joysticks currently attached to the system.
Definition at line 276 of file OSDLJoystickHandler.cc.
Referenced by linkToController(), openJoystick(), and update().
void JoystickHandler::hatChanged | ( | const JoystickHatEvent & | joystickEvent | ) | const [protected, virtual] |
Called whenever a joystick hat changed, so that its controller, if any, is notified.
Definition at line 334 of file OSDLJoystickHandler.cc.
References _joysticks, checkJoystickAt(), and OSDL::Events::Joystick::hatChanged().
Referenced by OSDL::Events::EventsModule::onJoystickHatChanged().
void JoystickHandler::linkToController | ( | JoystickNumber | index, | |
OSDL::MVC::Controller & | controller | |||
) | [virtual] |
Links specified joystick to specified controller, so that any further joystick-related event will be sent to the controller.
Removes automatically any link previously defined between this joystick and any other controller.
index | the index of the joystick that shall be linked to the controller. | |
controller | the OSDL controller which will be notified of joystick changes. |
JoystickException | if index is out of bounds. |
Definition at line 212 of file OSDLJoystickHandler.cc.
References _joystickCount, _joysticks, GetAvailableJoystickCount(), and OSDL::Video::Pixels::toString().
void JoystickHandler::openJoystick | ( | JoystickNumber | index | ) | [virtual] |
Opens joystick of specified index.
If joystick is already opened, does nothing.
index | the index of the joystick to open. |
JoystickException | if index is out of bounds. |
Definition at line 179 of file OSDLJoystickHandler.cc.
References _joystickCount, _joysticks, GetAvailableJoystickCount(), OSDL::Events::Joystick::open(), and OSDL::Video::Pixels::toString().
JoystickHandler& OSDL::Events::JoystickHandler::operator= | ( | const JoystickHandler & | 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.
const string JoystickHandler::toString | ( | Ceylan::VerbosityLevels | level = Ceylan::high |
) | const [virtual] |
Returns an user-friendly description of the state of this object.
level | the requested verbosity level. |
Definition at line 245 of file OSDLJoystickHandler.cc.
References _joystickCount, _joysticks, and OSDL::Video::Pixels::toString().
Referenced by OSDL::Events::EventsModule::toString().
void JoystickHandler::trackballChanged | ( | const JoystickTrackballEvent & | joystickEvent | ) | const [protected, virtual] |
Called whenever a joystick trackball changed, so that its controller, if any, is notified.
Definition at line 316 of file OSDLJoystickHandler.cc.
References _joysticks, checkJoystickAt(), and OSDL::Events::Joystick::trackballChanged().
Referenced by OSDL::Events::EventsModule::onJoystickTrackballChanged().
void JoystickHandler::update | ( | ) | [virtual] |
Auto-detects and registers any attached joystick.
Definition at line 145 of file OSDLJoystickHandler.cc.
References _joystickCount, _joysticks, _useClassicalJoysticks, blank(), GetAvailableJoystickCount(), and OSDL::Video::Pixels::toString().
Referenced by JoystickHandler().
friend class OSDL::Events::EventsModule [friend] |
Definition at line 91 of file OSDLJoystickHandler.h.
Records how many joysticks are known by this handler.
Definition at line 302 of file OSDLJoystickHandler.h.
Referenced by blank(), checkJoystickAt(), linkToController(), openJoystick(), toString(), and update().
Joystick** OSDL::Events::JoystickHandler::_joysticks [protected] |
Records all known joysticks.
A dynamic array is preferred to a list for performance reasons.
(read it as Joystick * _joysticks[])
Definition at line 315 of file OSDLJoystickHandler.h.
Referenced by axisChanged(), blank(), buttonPressed(), buttonReleased(), checkJoystickAt(), hatChanged(), linkToController(), openJoystick(), toString(), trackballChanged(), and update().
bool OSDL::Events::JoystickHandler::_useClassicalJoysticks [protected] |
Tells whether complex joysticks (if false) or classical joysticks (if true) should be created.
Definition at line 324 of file OSDLJoystickHandler.h.
Referenced by update().