Code Map
module lib.sdl2.gamecontroller;
enum SDL_CONTROLLER_BINDTYPE_NONE;
enum SDL_CONTROLLER_BINDTYPE_BUTTON;
enum SDL_CONTROLLER_BINDTYPE_AXIS;
enum SDL_CONTROLLER_BINDTYPE_HAT;
enum SDL_CONTROLLER_AXIS_INVALID;
enum SDL_CONTROLLER_AXIS_LEFTX;
enum SDL_CONTROLLER_AXIS_LEFTY;
enum SDL_CONTROLLER_AXIS_RIGHTX;
enum SDL_CONTROLLER_AXIS_RIGHTY;
enum SDL_CONTROLLER_AXIS_TRIGGERLEFT;
enum SDL_CONTROLLER_AXIS_TRIGGERRIGHT;
enum SDL_CONTROLLER_AXIS_MAX;
enum SDL_CONTROLLER_BUTTON_INVALID;
enum SDL_CONTROLLER_BUTTON_A;
enum SDL_CONTROLLER_BUTTON_B;
enum SDL_CONTROLLER_BUTTON_X;
enum SDL_CONTROLLER_BUTTON_Y;
enum SDL_CONTROLLER_BUTTON_BACK;
enum SDL_CONTROLLER_BUTTON_GUIDE;
enum SDL_CONTROLLER_BUTTON_START;
enum SDL_CONTROLLER_BUTTON_LEFTSTICK;
enum SDL_CONTROLLER_BUTTON_RIGHTSTICK;
enum SDL_CONTROLLER_BUTTON_LEFTSHOULDER;
enum SDL_CONTROLLER_BUTTON_RIGHTSHOULDER;
enum SDL_CONTROLLER_BUTTON_DPAD_UP;
enum SDL_CONTROLLER_BUTTON_DPAD_DOWN;
enum SDL_CONTROLLER_BUTTON_DPAD_LEFT;
enum SDL_CONTROLLER_BUTTON_DPAD_RIGHT;
enum SDL_CONTROLLER_BUTTON_MAX;
alias SDL_GameControllerBindType = i32;
//! The list of axes available from a controller
alias SDL_GameControllerAxis = i32;
//! The list of buttons available from a controller
alias SDL_GameControllerButton = i32;
//! \file SDL_gamecontroller.h
struct SDL_GameController
{
}
//! Get the SDL joystick layer binding for this controller button/axis
//! mapping
struct SDL_GameControllerButtonBind
{
public:
union _value
{
public:
struct _hat
{
public:
hat: i32;
hat_mask: i32;
}
public:
button: i32;
axis: i32;
hat: _hat;
}
public:
bindType: SDL_GameControllerBindType;
value: _value;
}
//! To count the number of game controllers in the system for the
//! following: int nJoysticks = SDL_NumJoysticks(); int nGameControllers =
//! 0; for ( int i = 0; i < nJoysticks; i++ ) { if ( SDL_IsGameController(i)
//! ) { nGameControllers++; } }
fn SDL_GameControllerAddMapping(mappingString: const(const(char)*)) i32;
//! Get a mapping string for a GUID
fn SDL_GameControllerMappingForGUID(guid: SDL_JoystickGUID) char*;
//! Get a mapping string for an open GameController
fn SDL_GameControllerMapping(gamecontroller: SDL_GameController*) char*;
//! Is the joystick on this index supported by the game controller
//! interface?
fn SDL_IsGameController(joystick_index: i32) SDL_bool;
//! Get the implementation dependent name of a game controller. This can be
//! called before any controllers are opened. If no name can be found, this
//! function returns NULL.
fn SDL_GameControllerNameForIndex(joystick_index: i32) char*;
//! Open a game controller for use. The index passed as an argument refers
//! to the N'th game controller on the system. This index is the value
//! which will identify this controller in future controller events.
fn SDL_GameControllerOpen(joystick_index: i32) SDL_GameController*;
//! Return the name for this currently opened controller
fn SDL_GameControllerName(gamecontroller: SDL_GameController*) char*;
//! Returns SDL_TRUE if the controller has been opened and currently
//! connected, or SDL_FALSE if it has not.
fn SDL_GameControllerGetAttached(gamecontroller: SDL_GameController*) SDL_bool;
//! Get the underlying joystick object used by a controller
fn SDL_GameControllerGetJoystick(gamecontroller: SDL_GameController*) SDL_Joystick*;
//! Enable/disable controller event polling.
fn SDL_GameControllerEventState(state: i32) i32;
//! Update the current state of the open game controllers.
fn SDL_GameControllerUpdate();
//! turn this string into a axis mapping
fn SDL_GameControllerGetAxisFromString(pchString: const(const(char)*)) SDL_GameControllerAxis;
//! turn this axis enum into a string mapping
fn SDL_GameControllerGetStringForAxis(axis: SDL_GameControllerAxis) char*;
//! Get the SDL joystick layer binding for this controller button mapping
fn SDL_GameControllerGetBindForAxis(gamecontroller: SDL_GameController*, axis: SDL_GameControllerAxis) SDL_GameControllerButtonBind;
//! Get the current state of an axis control on a game controller.
fn SDL_GameControllerGetAxis(gamecontroller: SDL_GameController*, axis: SDL_GameControllerAxis) Sint16;
//! turn this string into a button mapping
fn SDL_GameControllerGetButtonFromString(pchString: const(const(char)*)) SDL_GameControllerButton;
//! turn this button enum into a string mapping
fn SDL_GameControllerGetStringForButton(button: SDL_GameControllerButton) char*;
//! Get the SDL joystick layer binding for this controller button mapping
fn SDL_GameControllerGetBindForButton(gamecontroller: SDL_GameController*, button: SDL_GameControllerButton) SDL_GameControllerButtonBind;
//! Get the current state of a button on a game controller.
fn SDL_GameControllerGetButton(gamecontroller: SDL_GameController*, button: SDL_GameControllerButton) Uint8;
//! Close a controller previously opened with SDL_GameControllerOpen().
fn SDL_GameControllerClose(gamecontroller: SDL_GameController*);
\file SDL_gamecontroller.h
In order to use these functions, SDL_Init() must have been called with the ::SDL_INIT_JOYSTICK flag. This causes SDL to scan the system for game controllers, and load appropriate drivers.
If you would like to receive controller updates while the application is in the background, you should set the following hint before calling SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
Get the SDL joystick layer binding for this controller button/axis mapping
To count the number of game controllers in the system for the following: int nJoysticks = SDL_NumJoysticks(); int nGameControllers = 0; for ( int i = 0; i < nJoysticks; i++ ) { if ( SDL_IsGameController(i) ) { nGameControllers++; } }
Using the SDL_HINT_GAMECONTROLLERCONFIG hint or the SDL_GameControllerAddMapping you can add support for controllers SDL is unaware of or cause an existing controller to have a different binding. The format is: guid,name,mappings
Where GUID is the string value from SDL_JoystickGetGUIDString(), name is the human readable string for the device and mappings are controller mappings to joystick ones. Under Windows there is a reserved GUID of "xinput" that covers any XInput devices. The mapping format for joystick is: bX - a joystick button, index X hX.Y - hat X with value Y aX - axis X of the joystick Buttons can be used as a controller axis and vice versa.
This string shows an example of a valid mapping for a controller "341a3608000000000000504944564944,Afterglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7",
Add or update an existing mapping configuration
\return 1 if mapping is added, 0 if updated, -1 on error
Get a mapping string for a GUID
\return the mapping string. Must be freed with SDL_free. Returns NULL if no mapping is available
Get a mapping string for an open GameController
\return the mapping string. Must be freed with SDL_free. Returns NULL if no mapping is available
Is the joystick on this index supported by the game controller interface?
Get the implementation dependent name of a game controller. This can be called before any controllers are opened. If no name can be found, this function returns NULL.
Open a game controller for use. The index passed as an argument refers to the N'th game controller on the system. This index is the value which will identify this controller in future controller events.
\return A controller identifier, or NULL if an error occurred.
Return the name for this currently opened controller
Returns SDL_TRUE if the controller has been opened and currently connected, or SDL_FALSE if it has not.
Get the underlying joystick object used by a controller
Enable/disable controller event polling.
If controller events are disabled, you must call SDL_GameControllerUpdate() yourself and check the state of the controller when you want controller information.
The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE.
Update the current state of the open game controllers.
This is called automatically by the event loop if any game controller events are enabled.
The list of axes available from a controller
turn this string into a axis mapping
turn this axis enum into a string mapping
Get the SDL joystick layer binding for this controller button mapping
Get the current state of an axis control on a game controller.
The state is a value ranging from -32768 to 32767.
The axis indices start at index 0.
The list of buttons available from a controller
turn this string into a button mapping
turn this button enum into a string mapping
Get the SDL joystick layer binding for this controller button mapping
Get the current state of a button on a game controller.
The button indices start at index 0.
Close a controller previously opened with SDL_GameControllerOpen().