PROTO::KLUDGE  0.1
Quick prototyping library for games using SDL and OpenGL.
pk::GameController Class Reference

Convenience class for abstracting functionality that already exists in SDL. More...

#include <GameController.hpp>

Collaboration diagram for pk::GameController:
Collaboration graph

Public Member Functions

 GameController (int id)
 Preferred constructor initializing a controller by id, making multiplayer support a bit more sane. More...
 
virtual ~GameController ()
 
int getID ()
 Get the id for the game pad. More...
 
const char * getControllerName ()
 Get the name for the game pad. More...
 
SDL_bool isConnected ()
 Get the connection status for the game pad. More...
 
void setDeadZone (int deadzone)
 Get the dead zone for the game pad's joystick(s). More...
 
int getDeadZone ()
 Get the dead zone for the game pad. More...
 
Sint16 getAxisState (int axis)
 Get the axis state for the game pad. More...
 
Uint8 getButtonState (int button)
 Get the button state for the game pad. More...
 

Private Member Functions

 GameController ()
 Default constructor - INACCESSIBLE! More...
 
void close ()
 Calls SDL close routine, cleaning up for the controller without intervention. This function is called in the destructor. Do not call this directly, rely on controller going out of scope or, if using dynamic memory, delete as normal. More...
 

Private Attributes

SDL_GameController * m_controller
 A handle to the SDL_GameController. More...
 
int m_deadzone
 The value stored for the game controller's axis dead zone. More...
 
int m_id
 The id corresponding to the game controller. More...
 
const char * m_name
 The name given by SDL to the game controller. More...
 

Detailed Description

Convenience class for abstracting functionality that already exists in SDL.

Constructor & Destructor Documentation

◆ GameController() [1/2]

pk::GameController::GameController ( )
inlineprivate

Default constructor - INACCESSIBLE!

◆ GameController() [2/2]

pk::GameController::GameController ( int  id)

Preferred constructor initializing a controller by id, making multiplayer support a bit more sane.

Parameters
intid - the id you wish to assign to the GameController object.

◆ ~GameController()

virtual pk::GameController::~GameController ( )
virtual

Member Function Documentation

◆ close()

void pk::GameController::close ( )
private

Calls SDL close routine, cleaning up for the controller without intervention. This function is called in the destructor. Do not call this directly, rely on controller going out of scope or, if using dynamic memory, delete as normal.

◆ getAxisState()

Sint16 pk::GameController::getAxisState ( int  axis)
inline

Get the axis state for the game pad.

Parameters
intaxis - the axis (see GameControllerAxis enum) you wish to query for the current value.
Returns
Sint16 - an SDL Sint16 corresponding to the controller's axis value. See GameControllerAxis enum for valid states to pass in. See SDL documentation for output ranges.

◆ getButtonState()

Uint8 pk::GameController::getButtonState ( int  button)
inline

Get the button state for the game pad.

Parameters
intbutton - the button (see GameControllerButton enum) you wish to query for the current value.
Returns
Uint8 - an SDL Uint8 corresponding to the controller's axis value. See GameControllerButton enum for valid states to pass in. Returns 1 for pressed state or 0 for not pressed (or error) state.

◆ getControllerName()

const char * pk::GameController::getControllerName ( )
inline

Get the name for the game pad.

Returns
const char* - a C-style string corresponding to the controller name.

◆ getDeadZone()

int pk::GameController::getDeadZone ( )
inline

Get the dead zone for the game pad.

Returns
int - an int corresponding to the controller's dead zone.

◆ getID()

int pk::GameController::getID ( )
inline

Get the id for the game pad.

Returns
int - a plain old int corresponding to the controller id.

◆ isConnected()

SDL_bool pk::GameController::isConnected ( )
inline

Get the connection status for the game pad.

Returns
SDL_bool - an SDL boolean corresponding to the controller's connection status.

◆ setDeadZone()

void pk::GameController::setDeadZone ( int  deadzone)
inline

Get the dead zone for the game pad's joystick(s).

Parameters
intdeadzone - a plain old int that you wish to assign as the controller's dead zone.

Member Data Documentation

◆ m_controller

SDL_GameController* pk::GameController::m_controller
private

A handle to the SDL_GameController.

◆ m_deadzone

int pk::GameController::m_deadzone
private

The value stored for the game controller's axis dead zone.

◆ m_id

int pk::GameController::m_id
private

The id corresponding to the game controller.

◆ m_name

const char* pk::GameController::m_name
private

The name given by SDL to the game controller.


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