include/SDL_gamecontroller.h
author David Ludwig <dludwig@pobox.com>
Mon, 01 Apr 2013 21:33:06 -0400
changeset 8453 499aa167ea79
parent 6885 700f1b25f77f
child 6917 47dc155b774d
permissions -rw-r--r--
WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
slouken@6690
     1
/*
slouken@6690
     2
  Simple DirectMedia Layer
slouken@6885
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
slouken@6690
     4
slouken@6690
     5
  This software is provided 'as-is', without any express or implied
slouken@6690
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@6690
     7
  arising from the use of this software.
slouken@6690
     8
slouken@6690
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@6690
    10
  including commercial applications, and to alter it and redistribute it
slouken@6690
    11
  freely, subject to the following restrictions:
slouken@6690
    12
slouken@6690
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@6690
    14
     claim that you wrote the original software. If you use this software
slouken@6690
    15
     in a product, an acknowledgment in the product documentation would be
slouken@6690
    16
     appreciated but is not required.
slouken@6690
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@6690
    18
     misrepresented as being the original software.
slouken@6690
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@6690
    20
*/
slouken@6690
    21
slouken@6690
    22
/**
slouken@6690
    23
 *  \file SDL_gamecontroller.h
jorgen@6873
    24
 *
slouken@6690
    25
 *  Include file for SDL game controller event handling
slouken@6690
    26
 */
slouken@6690
    27
slouken@6690
    28
#ifndef _SDL_gamecontroller_h
slouken@6690
    29
#define _SDL_gamecontroller_h
slouken@6690
    30
slouken@6690
    31
#include "SDL_stdinc.h"
slouken@6690
    32
#include "SDL_error.h"
slouken@6690
    33
#include "SDL_joystick.h"
slouken@6690
    34
slouken@6690
    35
#include "begin_code.h"
slouken@6690
    36
/* Set up for C function definitions, even when using C++ */
slouken@6690
    37
#ifdef __cplusplus
slouken@6690
    38
/* *INDENT-OFF* */
slouken@6690
    39
extern "C" {
slouken@6690
    40
/* *INDENT-ON* */
slouken@6690
    41
#endif
slouken@6690
    42
slouken@6690
    43
/**
slouken@6690
    44
 *  \file SDL_gamecontroller.h
slouken@6690
    45
 *
slouken@6690
    46
 *  In order to use these functions, SDL_Init() must have been called
slouken@6690
    47
 *  with the ::SDL_INIT_JOYSTICK flag.  This causes SDL to scan the system
slouken@6690
    48
 *  for game controllers, and load appropriate drivers.
slouken@6690
    49
 */
slouken@6690
    50
slouken@6690
    51
/* The gamecontroller structure used to identify an SDL game controller */
slouken@6690
    52
struct _SDL_GameController;
slouken@6690
    53
typedef struct _SDL_GameController SDL_GameController;
slouken@6690
    54
slouken@6690
    55
jorgen@6873
    56
typedef enum
slouken@6690
    57
{
slouken@6690
    58
	SDL_CONTROLLER_BINDTYPE_NONE = 0,
slouken@6690
    59
	SDL_CONTROLLER_BINDTYPE_BUTTON,
slouken@6690
    60
	SDL_CONTROLLER_BINDTYPE_AXIS,
slouken@6795
    61
	SDL_CONTROLLER_BINDTYPE_HAT
slouken@6690
    62
} SDL_CONTROLLER_BINDTYPE;
slouken@6690
    63
/**
slouken@6690
    64
 *  get the sdl joystick layer binding for this controller button/axis mapping
slouken@6690
    65
 */
slouken@6690
    66
struct _SDL_GameControllerHatBind
slouken@6690
    67
{
slouken@6690
    68
	int hat;
slouken@6690
    69
	int hat_mask;
slouken@6690
    70
};
slouken@6690
    71
slouken@6690
    72
typedef struct _SDL_GameControllerButtonBind
slouken@6690
    73
{
slouken@6690
    74
	SDL_CONTROLLER_BINDTYPE m_eBindType;
slouken@6690
    75
	union
slouken@6690
    76
	{
slouken@6690
    77
		int button;
slouken@6690
    78
		int axis;
slouken@6690
    79
		struct _SDL_GameControllerHatBind hat;
slouken@6690
    80
	};
slouken@6690
    81
slouken@6690
    82
} SDL_GameControllerButtonBind;
slouken@6690
    83
slouken@6690
    84
slouken@6690
    85
/**
slouken@6690
    86
 *  To count the number of game controllers in the system for the following:
slouken@6690
    87
 *	int nJoysticks = SDL_NumJoysticks();
slouken@6690
    88
 *	int nGameControllers = 0;
slouken@6690
    89
 *	for ( int i = 0; i < nJoysticks; i++ ) {
slouken@6690
    90
 *		if ( SDL_IsGameController(i) ) {
slouken@6690
    91
 *			nGameControllers++;
slouken@6690
    92
 *		}
slouken@6690
    93
 *  }
slouken@6690
    94
 *
slouken@6690
    95
 *  Using the SDL_HINT_GAMECONTROLLERCONFIG hint you can add support for controllers SDL is unaware of or cause an existing controller to have a different binding. The format is:
slouken@6690
    96
 *	guid,name,mappings
slouken@6690
    97
 *
slouken@6690
    98
 *  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.
slouken@6690
    99
 *  Under Windows there is a reserved GUID of "xinput" that covers any XInput devices.
jorgen@6873
   100
 *	The mapping format for joystick is:
slouken@6690
   101
 *		bX - a joystick button, index X
slouken@6690
   102
 *		hX.Y - hat X with value Y
slouken@6690
   103
 *		aX - axis X of the joystick
slouken@6690
   104
 *  Buttons can be used as a controller axis and vice versa.
slouken@6690
   105
 *
slouken@6690
   106
 *  This string shows an example of a valid mapping for a controller
slouken@6690
   107
 * 	"341a3608000000000000504944564944,Aferglow 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",
slouken@6690
   108
 *
slouken@6690
   109
 */
slouken@6690
   110
slouken@6690
   111
slouken@6690
   112
/**
slouken@6690
   113
 *  Is the joystick on this index supported by the game controller interface?
slouken@6690
   114
 */
jorgen@6871
   115
extern DECLSPEC SDL_bool SDLCALL SDL_IsGameController(int joystick_index);
slouken@6690
   116
slouken@6690
   117
slouken@6690
   118
/**
slouken@6690
   119
 *  Get the implementation dependent name of a game controller.
slouken@6690
   120
 *  This can be called before any controllers are opened.
slouken@6690
   121
 *  If no name can be found, this function returns NULL.
slouken@6690
   122
 */
slouken@6690
   123
extern DECLSPEC const char *SDLCALL SDL_GameControllerNameForIndex(int joystick_index);
slouken@6690
   124
slouken@6690
   125
/**
jorgen@6873
   126
 *  Open a game controller for use.
jorgen@6873
   127
 *  The index passed as an argument refers to the N'th game controller on the system.
slouken@6690
   128
 *  This index is the value which will identify this controller in future controller
slouken@6690
   129
 *  events.
jorgen@6873
   130
 *
slouken@6690
   131
 *  \return A controller identifier, or NULL if an error occurred.
slouken@6690
   132
 */
slouken@6690
   133
extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerOpen(int joystick_index);
slouken@6690
   134
slouken@6690
   135
/**
slouken@6690
   136
 *  Return the name for this currently opened controller
slouken@6690
   137
 */
jorgen@6873
   138
extern DECLSPEC const char *SDLCALL SDL_GameControllerName(SDL_GameController *gamecontroller);
jorgen@6873
   139
slouken@6690
   140
/**
jorgen@6873
   141
 *  Returns SDL_TRUE if the controller has been opened and currently connected,
jorgen@6873
   142
 *  or SDL_FALSE if it has not.
slouken@6690
   143
 */
jorgen@6873
   144
extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerGetAttached(SDL_GameController *gamecontroller);
slouken@6690
   145
slouken@6690
   146
/**
slouken@6690
   147
 *  Get the underlying joystick object used by a controller
slouken@6690
   148
 */
jorgen@6873
   149
extern DECLSPEC SDL_Joystick *SDLCALL SDL_GameControllerGetJoystick(SDL_GameController *gamecontroller);
slouken@6690
   150
slouken@6690
   151
/**
slouken@6690
   152
 *  Enable/disable controller event polling.
jorgen@6873
   153
 *
slouken@6690
   154
 *  If controller events are disabled, you must call SDL_GameControllerUpdate()
slouken@6690
   155
 *  yourself and check the state of the controller when you want controller
slouken@6690
   156
 *  information.
jorgen@6873
   157
 *
slouken@6690
   158
 *  The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE.
slouken@6690
   159
 */
slouken@6690
   160
extern DECLSPEC int SDLCALL SDL_GameControllerEventState(int state);
slouken@6690
   161
slouken@6690
   162
/**
slouken@6690
   163
 *  The list of axii available from a controller
slouken@6690
   164
 */
jorgen@6873
   165
typedef enum
slouken@6690
   166
{
slouken@6690
   167
	SDL_CONTROLLER_AXIS_INVALID = -1,
slouken@6690
   168
	SDL_CONTROLLER_AXIS_LEFTX,
slouken@6690
   169
	SDL_CONTROLLER_AXIS_LEFTY,
slouken@6690
   170
	SDL_CONTROLLER_AXIS_RIGHTX,
slouken@6690
   171
	SDL_CONTROLLER_AXIS_RIGHTY,
slouken@6690
   172
	SDL_CONTROLLER_AXIS_TRIGGERLEFT,
slouken@6690
   173
	SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
slouken@6690
   174
	SDL_CONTROLLER_AXIS_MAX
slouken@6690
   175
} SDL_CONTROLLER_AXIS;
slouken@6690
   176
slouken@6690
   177
/**
slouken@6690
   178
 *  turn this string into a axis mapping
slouken@6690
   179
 */
slouken@6690
   180
extern DECLSPEC SDL_CONTROLLER_AXIS SDLCALL SDL_GameControllerGetAxisFromString(const char *pchString);
slouken@6690
   181
slouken@6690
   182
/**
slouken@6690
   183
 *  get the sdl joystick layer binding for this controller button mapping
slouken@6690
   184
 */
jorgen@6873
   185
extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
jorgen@6873
   186
SDL_GameControllerGetBindForAxis(SDL_GameController *gamecontroller,
jorgen@6873
   187
                                 SDL_CONTROLLER_AXIS button);
slouken@6690
   188
slouken@6690
   189
/**
slouken@6690
   190
 *  Get the current state of an axis control on a game controller.
jorgen@6873
   191
 *
slouken@6690
   192
 *  The state is a value ranging from -32768 to 32767.
jorgen@6873
   193
 *
slouken@6690
   194
 *  The axis indices start at index 0.
slouken@6690
   195
 */
jorgen@6873
   196
extern DECLSPEC Sint16 SDLCALL
jorgen@6873
   197
SDL_GameControllerGetAxis(SDL_GameController *gamecontroller,
jorgen@6873
   198
                          SDL_CONTROLLER_AXIS axis);
slouken@6690
   199
slouken@6690
   200
/**
slouken@6690
   201
 *  The list of buttons available from a controller
slouken@6690
   202
 */
slouken@6690
   203
typedef enum
slouken@6690
   204
{
slouken@6690
   205
	SDL_CONTROLLER_BUTTON_INVALID = -1,
slouken@6690
   206
	SDL_CONTROLLER_BUTTON_A,
slouken@6690
   207
	SDL_CONTROLLER_BUTTON_B,
slouken@6690
   208
	SDL_CONTROLLER_BUTTON_X,
slouken@6690
   209
	SDL_CONTROLLER_BUTTON_Y,
slouken@6690
   210
	SDL_CONTROLLER_BUTTON_BACK,
slouken@6690
   211
	SDL_CONTROLLER_BUTTON_GUIDE,
slouken@6690
   212
	SDL_CONTROLLER_BUTTON_START,
slouken@6690
   213
	SDL_CONTROLLER_BUTTON_LEFTSTICK,
slouken@6690
   214
	SDL_CONTROLLER_BUTTON_RIGHTSTICK,
slouken@6690
   215
	SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
slouken@6690
   216
	SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
slouken@6690
   217
	SDL_CONTROLLER_BUTTON_DPAD_UP,
slouken@6690
   218
	SDL_CONTROLLER_BUTTON_DPAD_DOWN,
slouken@6690
   219
	SDL_CONTROLLER_BUTTON_DPAD_LEFT,
slouken@6690
   220
	SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
slouken@6690
   221
	SDL_CONTROLLER_BUTTON_MAX
slouken@6690
   222
} SDL_CONTROLLER_BUTTON;
slouken@6690
   223
slouken@6690
   224
/**
slouken@6690
   225
 *  turn this string into a button mapping
slouken@6690
   226
 */
slouken@6690
   227
extern DECLSPEC SDL_CONTROLLER_BUTTON SDLCALL SDL_GameControllerGetButtonFromString(const char *pchString);
slouken@6690
   228
slouken@6690
   229
slouken@6690
   230
/**
slouken@6690
   231
 *  get the sdl joystick layer binding for this controller button mapping
slouken@6690
   232
 */
jorgen@6873
   233
extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
jorgen@6873
   234
SDL_GameControllerGetBindForButton(SDL_GameController *gamecontroller,
jorgen@6873
   235
                                   SDL_CONTROLLER_BUTTON button);
slouken@6690
   236
slouken@6690
   237
slouken@6690
   238
/**
slouken@6690
   239
 *  Get the current state of a button on a game controller.
jorgen@6873
   240
 *
slouken@6690
   241
 *  The button indices start at index 0.
slouken@6690
   242
 */
jorgen@6873
   243
extern DECLSPEC Uint8 SDLCALL SDL_GameControllerGetButton(SDL_GameController *gamecontroller,
jorgen@6873
   244
                                                          SDL_CONTROLLER_BUTTON button);
slouken@6690
   245
slouken@6690
   246
/**
slouken@6690
   247
 *  Close a controller previously opened with SDL_GameControllerOpen().
slouken@6690
   248
 */
jorgen@6873
   249
extern DECLSPEC void SDLCALL SDL_GameControllerClose(SDL_GameController *gamecontroller);
slouken@6690
   250
slouken@6690
   251
slouken@6690
   252
/* Ends C function definitions when using C++ */
slouken@6690
   253
#ifdef __cplusplus
slouken@6690
   254
/* *INDENT-OFF* */
slouken@6690
   255
}
slouken@6690
   256
/* *INDENT-ON* */
slouken@6690
   257
#endif
slouken@6690
   258
#include "close_code.h"
slouken@6690
   259
slouken@6690
   260
#endif /* _SDL_gamecontroller_h */
slouken@6690
   261
slouken@6690
   262
/* vi: set ts=4 sw=4 expandtab: */