sgltk 0.6
Simple OpenGL Tool Kit
Loading...
Searching...
No Matches
sgltk::Joystick Class Reference

Manages and handles joysticks. More...

#include <joystick.h>

Public Member Functions

 Joystick (unsigned int device_id)
void set_button_state (int button, bool state)
 Sets the state of a button.
void mark_switch (int button, bool mark=true)
 Marks or unmarks a button as a switch. Switches will not be added to the buttons_pressed list.
void set_deadzone (unsigned int deadzone)
 Sets a dedzone for all axes.
int get_axis_value (unsigned int axis)
 Call this function to get the current value of an axis.
unsigned int get_hat_value (unsigned int hat)
 Call this function to get the current value of a hat.

Public Attributes

unsigned int id
 The joystick id. When a new joystick is attached it is assigned the first free ID starting at 0.
unsigned int instance_id
 The instance ID of the gamepad as provided by an SDL2 event.
std::string name
 The name of the joystick.
unsigned int num_axes
 The number of axes the joystick has.
unsigned int num_buttons
 The number of buttons the joystick has.
unsigned int num_hats
 The number of hats the joystick has.
unsigned int deadzone
 The axis deadzone.
std::vector< int > buttons_pressed
 A list of all buttons currently pressed.

Detailed Description

Manages and handles joysticks.

Note
You should never have to create or delete objects of this class directly

Definition at line 14 of file joystick.h.

Constructor & Destructor Documentation

◆ Joystick()

Joystick::Joystick ( unsigned int device_id)
Parameters
device_idThe device id as provided by the SDL_JOYDEVICEADDED event

Definition at line 8 of file joystick.cpp.

◆ ~Joystick()

Joystick::~Joystick ( )

Definition at line 38 of file joystick.cpp.

Member Function Documentation

◆ get_axis_value()

int Joystick::get_axis_value ( unsigned int axis)

Call this function to get the current value of an axis.

Parameters
axisThe axis to get the value of
Returns
The current value of the axis

Definition at line 79 of file joystick.cpp.

◆ get_hat_value()

unsigned int Joystick::get_hat_value ( unsigned int hat)

Call this function to get the current value of a hat.

Parameters
hatThe hat to get the value of
Returns
The current value of the hat

Definition at line 86 of file joystick.cpp.

◆ mark_switch()

void Joystick::mark_switch ( int button,
bool mark = true )

Marks or unmarks a button as a switch. Switches will not be added to the buttons_pressed list.

Parameters
buttonThe button to mark or unmark
markTrue to mark, false to unmark

Definition at line 61 of file joystick.cpp.

◆ set_button_state()

void Joystick::set_button_state ( int button,
bool state )

Sets the state of a button.

Parameters
buttonThe button the state of which is to be set
stateThe new state of the button

Definition at line 46 of file joystick.cpp.

◆ set_deadzone()

void Joystick::set_deadzone ( unsigned int deadzone)

Sets a dedzone for all axes.

Parameters
deadzoneThe deadzone

Definition at line 75 of file joystick.cpp.

Member Data Documentation

◆ buttons_pressed

std::vector<int> sgltk::Joystick::buttons_pressed

A list of all buttons currently pressed.

Definition at line 55 of file joystick.h.

◆ deadzone

unsigned int sgltk::Joystick::deadzone

The axis deadzone.

Definition at line 51 of file joystick.h.

◆ id

unsigned int sgltk::Joystick::id

The joystick id. When a new joystick is attached it is assigned the first free ID starting at 0.

Definition at line 26 of file joystick.h.

◆ instance_id

unsigned int sgltk::Joystick::instance_id

The instance ID of the gamepad as provided by an SDL2 event.

Definition at line 31 of file joystick.h.

◆ name

std::string sgltk::Joystick::name

The name of the joystick.

Definition at line 35 of file joystick.h.

◆ num_axes

unsigned int sgltk::Joystick::num_axes

The number of axes the joystick has.

Definition at line 39 of file joystick.h.

◆ num_buttons

unsigned int sgltk::Joystick::num_buttons

The number of buttons the joystick has.

Definition at line 43 of file joystick.h.

◆ num_hats

unsigned int sgltk::Joystick::num_hats

The number of hats the joystick has.

Definition at line 47 of file joystick.h.


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