QJoysticks
A simple way to use joysticks with your Qt application
Public Slots | Signals | Public Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
SDL_Joysticks Class Reference

Translates SDL events into QJoysticks events. More...

#include <SDL_Joysticks.h>

Inheritance diagram for SDL_Joysticks:

Public Slots

void rumble (const QJoystickRumble &request)
 

Signals

void countChanged ()
 
void POVEvent (const QJoystickPOVEvent &event)
 
void axisEvent (const QJoystickAxisEvent &event)
 
void buttonEvent (const QJoystickButtonEvent &event)
 

Public Member Functions

 SDL_Joysticks ()
 
QList< QJoystickDevice * > joysticks ()
 

Private Slots

void update ()
 
void configureJoystick (const SDL_Event *event)
 

Private Member Functions

int getDynamicID (int id)
 
QJoystickDevicegetJoystick (int id)
 
QJoystickPOVEvent getPOVEvent (const SDL_Event *sdl_event)
 
QJoystickAxisEvent getAxisEvent (const SDL_Event *sdl_event)
 
QJoystickButtonEvent getButtonEvent (const SDL_Event *sdl_event)
 

Private Attributes

int m_tracker
 
QList< QJoystickDevicem_joysticks
 

Detailed Description

Translates SDL events into QJoysticks events.

This class is in charge of managing and operating real joysticks through the SDL API. The implementation procedure is the same for every operating system.

The only thing that differs from each operating system is the backup mapping applied in the case that we do not know what mapping to apply to a joystick.

Note
The joystick values are refreshed every 20 milliseconds through a simple event loop.

Constructor & Destructor Documentation

SDL_Joysticks::SDL_Joysticks ( )
explicit

Load a different generic/backup mapping for each operating system.

References update().

Member Function Documentation

void SDL_Joysticks::configureJoystick ( const SDL_Event *  event)
privateslot

Checks if the joystick referenced by the event can be initialized. If not, the function will apply a generic mapping to the joystick and attempt to initialize the joystick again.

Referenced by update().

QJoystickAxisEvent SDL_Joysticks::getAxisEvent ( const SDL_Event *  sdl_event)
private

Reads the contents of the given event and constructs a new QJoystickAxisEvent to be used with the QJoysticks system.

References QJoystickAxisEvent::axis, and getJoystick().

Referenced by update().

QJoystickButtonEvent SDL_Joysticks::getButtonEvent ( const SDL_Event *  sdl_event)
private

Reads the contents of the given event and constructs a new QJoystickButtonEvent to be used with the QJoysticks system.

References QJoystickButtonEvent::button, and getJoystick().

Referenced by update().

int SDL_Joysticks::getDynamicID ( int  id)
private

Returns a joystick ID compatible with the QJoysticks system. SDL assigns an ID to each joystick based on the order that they are attached, but it does not decrease the ID counter when a joystick is removed.

As noted earlier, the QJoysticks maintains an ID system similar to the one used by a QList, since it eases the operation with most Qt classes and widgets.

Referenced by getJoystick().

QJoystickDevice * SDL_Joysticks::getJoystick ( int  id)
private

Returns the josytick device registered with the given id. If no joystick with the given id is found, then the function will warn the user through the console.

References QJoystickDevice::blacklisted, getDynamicID(), QJoystickDevice::id, QJoystickDevice::name, QJoystickDevice::numAxes, QJoystickDevice::numButtons, and QJoystickDevice::numPOVs.

Referenced by getAxisEvent(), getButtonEvent(), getPOVEvent(), and joysticks().

QJoystickPOVEvent SDL_Joysticks::getPOVEvent ( const SDL_Event *  sdl_event)
private

Reads the contents of the given event and constructs a new QJoystickPOVEvent to be used with the QJoysticks system.

References getJoystick(), and QJoystickPOVEvent::pov.

Referenced by update().

QList< QJoystickDevice * > SDL_Joysticks::joysticks ( )

Returns a list with all the registered joystick devices

References getJoystick().

void SDL_Joysticks::rumble ( const QJoystickRumble request)
slot

Based on the data contained in the request, this function will instruct the appropiate joystick to rumble for

References QJoystickDevice::id, QJoystickRumble::joystick, QJoystickRumble::length, and QJoystickRumble::strength.

void SDL_Joysticks::update ( )
privateslot

Polls for new SDL events and reacts to each event accordingly.

References configureJoystick(), getAxisEvent(), getButtonEvent(), and getPOVEvent().

Referenced by SDL_Joysticks().


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