include/SDL_joystick.h
author Sam Lantinga <slouken@libsdl.org>
Mon, 26 Nov 2012 16:37:54 -0800
changeset 6690 9548c8a58103
parent 6138 4c64952a58fb
child 6707 70eeb7e3ec2f
permissions -rw-r--r--
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
slouken@0
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6138
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
slouken@0
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@0
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@0
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@0
    20
*/
slouken@0
    21
slouken@1895
    22
/**
slouken@3407
    23
 *  \file SDL_joystick.h
slouken@3407
    24
 *  
slouken@3407
    25
 *  Include file for SDL joystick event handling
slouken@6690
    26
 *
slouken@6690
    27
 * The term "device_index" identifies currently plugged in joystick devices between 0 and SDL_NumJoysticks, with the exact joystick
slouken@6690
    28
 *   behind a device_index changing as joysticks are plugged and unplugged.
slouken@6690
    29
 *
slouken@6690
    30
 * The term "instance_id" is the current instantiation of a joystick device in the system, if the joystick is removed and then re-inserted
slouken@6690
    31
 *   then it will get a new instance_id, instance_id's are monotonically increasing identifiers of a joystick plugged in.
slouken@6690
    32
 *
slouken@6690
    33
 * The term JoystickGUID is a stable 128-bit identifier for a joystick device that does not change over time, it identifies class of 
slouken@6690
    34
 *   the device (a X360 wired controller for example). This identifier is platform dependent.
slouken@6690
    35
 *
slouken@6690
    36
 *
slouken@1895
    37
 */
slouken@0
    38
slouken@0
    39
#ifndef _SDL_joystick_h
slouken@0
    40
#define _SDL_joystick_h
slouken@0
    41
slouken@1356
    42
#include "SDL_stdinc.h"
slouken@1358
    43
#include "SDL_error.h"
slouken@0
    44
slouken@0
    45
#include "begin_code.h"
slouken@0
    46
/* Set up for C function definitions, even when using C++ */
slouken@0
    47
#ifdef __cplusplus
slouken@1895
    48
/* *INDENT-OFF* */
slouken@0
    49
extern "C" {
slouken@1895
    50
/* *INDENT-ON* */
slouken@0
    51
#endif
slouken@0
    52
slouken@3407
    53
/**
slouken@3407
    54
 *  \file SDL_joystick.h
slouken@3407
    55
 *
slouken@3407
    56
 *  In order to use these functions, SDL_Init() must have been called
slouken@3407
    57
 *  with the ::SDL_INIT_JOYSTICK flag.  This causes SDL to scan the system
slouken@3407
    58
 *  for joysticks, and load appropriate drivers.
slouken@3407
    59
 */
slouken@0
    60
slouken@0
    61
/* The joystick structure used to identify an SDL joystick */
slouken@0
    62
struct _SDL_Joystick;
slouken@0
    63
typedef struct _SDL_Joystick SDL_Joystick;
slouken@0
    64
slouken@6690
    65
typedef int SDL_JoystickID;
slouken@6690
    66
	
slouken@0
    67
/* Function prototypes */
slouken@3407
    68
/**
slouken@6690
    69
 *  Count the number of joysticks attached to the system right now
slouken@0
    70
 */
slouken@337
    71
extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
slouken@0
    72
slouken@3407
    73
/**
slouken@3407
    74
 *  Get the implementation dependent name of a joystick.
slouken@3407
    75
 *  This can be called before any joysticks are opened.
slouken@3407
    76
 *  If no name can be found, this function returns NULL.
slouken@0
    77
 */
slouken@6690
    78
extern DECLSPEC const char *SDLCALL SDL_JoystickNameForIndex(int device_index);
slouken@0
    79
slouken@3407
    80
/**
slouken@3407
    81
 *  Open a joystick for use.  
slouken@3407
    82
 *  The index passed as an argument refers tothe N'th joystick on the system.  
slouken@3407
    83
 *  This index is the value which will identify this joystick in future joystick
slouken@3407
    84
 *  events.
slouken@3407
    85
 *  
slouken@3407
    86
 *  \return A joystick identifier, or NULL if an error occurred.
slouken@0
    87
 */
slouken@1895
    88
extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index);
slouken@0
    89
slouken@3407
    90
/**
slouken@6690
    91
 *  Return the name for this currently opened joystick.
slouken@6690
    92
 *  If no name can be found, this function returns NULL.
slouken@0
    93
 */
slouken@6690
    94
extern DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick * joystick);
slouken@6690
    95
	
slouken@6690
    96
/* A structure that encodes the stable unique id for a joystick device */
slouken@6690
    97
typedef struct
slouken@6690
    98
{
slouken@6690
    99
	Uint8 data[16];
slouken@6690
   100
} JoystickGUID;
slouken@6690
   101
slouken@6690
   102
/**
slouken@6690
   103
 *  Return the GUID for the joystick at this index
slouken@6690
   104
 */
slouken@6690
   105
extern DECLSPEC JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index);
slouken@6690
   106
slouken@6690
   107
/**
slouken@6690
   108
 *  Return the GUID for this opened joystick
slouken@6690
   109
 */
slouken@6690
   110
extern DECLSPEC JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick * joystick);
slouken@6690
   111
slouken@6690
   112
/**
slouken@6690
   113
 *  Return a string representation for this guid. You are responsible for freeing memory from this call
slouken@6690
   114
 */
slouken@6690
   115
extern DECLSPEC char *SDLCALL SDL_JoystickGetGUIDString(JoystickGUID guid);
slouken@6690
   116
slouken@6690
   117
/**
slouken@6690
   118
 *  convert a string into a joystick formatted guid
slouken@6690
   119
 */
slouken@6690
   120
extern DECLSPEC JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID);
slouken@6690
   121
slouken@6690
   122
slouken@6690
   123
/**
slouken@6690
   124
 *  Returns 1 if the joystick has been opened and currently connected, or 0 if it has not.
slouken@6690
   125
 */
slouken@6690
   126
extern DECLSPEC int SDLCALL SDL_JoystickGetAttached(SDL_Joystick * joystick);
slouken@0
   127
slouken@3407
   128
/**
slouken@3407
   129
 *  Get the device index of an opened joystick.
slouken@0
   130
 */
slouken@6690
   131
extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick * joystick);
slouken@0
   132
slouken@3407
   133
/**
slouken@3407
   134
 *  Get the number of general axis controls on a joystick.
slouken@0
   135
 */
slouken@1895
   136
extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick * joystick);
slouken@0
   137
slouken@3407
   138
/**
slouken@3407
   139
 *  Get the number of trackballs on a joystick.
slouken@3407
   140
 *  
slouken@3407
   141
 *  Joystick trackballs have only relative motion events associated
slouken@3407
   142
 *  with them and their state cannot be polled.
slouken@0
   143
 */
slouken@1895
   144
extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick * joystick);
slouken@0
   145
slouken@3407
   146
/**
slouken@3407
   147
 *  Get the number of POV hats on a joystick.
slouken@0
   148
 */
slouken@1895
   149
extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick * joystick);
slouken@0
   150
slouken@3407
   151
/**
slouken@3407
   152
 *  Get the number of buttons on a joystick.
slouken@0
   153
 */
slouken@1895
   154
extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick * joystick);
slouken@0
   155
slouken@3407
   156
/**
slouken@3407
   157
 *  Update the current state of the open joysticks.
slouken@3407
   158
 *  
slouken@3407
   159
 *  This is called automatically by the event loop if any joystick
slouken@3407
   160
 *  events are enabled.
slouken@0
   161
 */
slouken@337
   162
extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
slouken@0
   163
slouken@3407
   164
/**
slouken@3407
   165
 *  Enable/disable joystick event polling.
slouken@3407
   166
 *  
slouken@3407
   167
 *  If joystick events are disabled, you must call SDL_JoystickUpdate()
slouken@3407
   168
 *  yourself and check the state of the joystick when you want joystick
slouken@3407
   169
 *  information.
slouken@3407
   170
 *  
slouken@3407
   171
 *  The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE.
slouken@0
   172
 */
slouken@337
   173
extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
slouken@0
   174
slouken@3407
   175
/**
slouken@3407
   176
 *  Get the current state of an axis control on a joystick.
slouken@3407
   177
 *  
slouken@3407
   178
 *  The state is a value ranging from -32768 to 32767.
slouken@3407
   179
 *  
slouken@3407
   180
 *  The axis indices start at index 0.
slouken@0
   181
 */
slouken@1895
   182
extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick * joystick,
slouken@1895
   183
                                                   int axis);
slouken@0
   184
slouken@3407
   185
/**
slouken@3407
   186
 *  \name Hat positions
slouken@0
   187
 */
slouken@3407
   188
/*@{*/
slouken@0
   189
#define SDL_HAT_CENTERED	0x00
slouken@0
   190
#define SDL_HAT_UP		0x01
slouken@0
   191
#define SDL_HAT_RIGHT		0x02
slouken@0
   192
#define SDL_HAT_DOWN		0x04
slouken@0
   193
#define SDL_HAT_LEFT		0x08
slouken@0
   194
#define SDL_HAT_RIGHTUP		(SDL_HAT_RIGHT|SDL_HAT_UP)
slouken@0
   195
#define SDL_HAT_RIGHTDOWN	(SDL_HAT_RIGHT|SDL_HAT_DOWN)
slouken@0
   196
#define SDL_HAT_LEFTUP		(SDL_HAT_LEFT|SDL_HAT_UP)
slouken@0
   197
#define SDL_HAT_LEFTDOWN	(SDL_HAT_LEFT|SDL_HAT_DOWN)
slouken@3407
   198
/*@}*/
slouken@3407
   199
slouken@3407
   200
/**
slouken@3407
   201
 *  Get the current state of a POV hat on a joystick.
slouken@3407
   202
 *
slouken@3407
   203
 *  The hat indices start at index 0.
slouken@3407
   204
 *  
slouken@3407
   205
 *  \return The return value is one of the following positions:
slouken@3407
   206
 *           - ::SDL_HAT_CENTERED
slouken@3407
   207
 *           - ::SDL_HAT_UP
slouken@3407
   208
 *           - ::SDL_HAT_RIGHT
slouken@3407
   209
 *           - ::SDL_HAT_DOWN
slouken@3407
   210
 *           - ::SDL_HAT_LEFT
slouken@3407
   211
 *           - ::SDL_HAT_RIGHTUP
slouken@3407
   212
 *           - ::SDL_HAT_RIGHTDOWN
slouken@3407
   213
 *           - ::SDL_HAT_LEFTUP
slouken@3407
   214
 *           - ::SDL_HAT_LEFTDOWN
slouken@0
   215
 */
slouken@1895
   216
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick * joystick,
slouken@1895
   217
                                                 int hat);
slouken@0
   218
slouken@3407
   219
/**
slouken@3407
   220
 *  Get the ball axis change since the last poll.
slouken@3407
   221
 *  
slouken@3407
   222
 *  \return 0, or -1 if you passed it invalid parameters.
slouken@3407
   223
 *  
slouken@3407
   224
 *  The ball indices start at index 0.
slouken@0
   225
 */
slouken@1895
   226
extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick * joystick,
slouken@1895
   227
                                                int ball, int *dx, int *dy);
slouken@0
   228
slouken@3407
   229
/**
slouken@3407
   230
 *  Get the current state of a button on a joystick.
slouken@3407
   231
 *  
slouken@3407
   232
 *  The button indices start at index 0.
slouken@0
   233
 */
slouken@1895
   234
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick * joystick,
slouken@1895
   235
                                                    int button);
slouken@0
   236
slouken@3407
   237
/**
slouken@3407
   238
 *  Close a joystick previously opened with SDL_JoystickOpen().
slouken@0
   239
 */
slouken@1895
   240
extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick);
slouken@0
   241
slouken@0
   242
slouken@0
   243
/* Ends C function definitions when using C++ */
slouken@0
   244
#ifdef __cplusplus
slouken@1895
   245
/* *INDENT-OFF* */
slouken@0
   246
}
slouken@1895
   247
/* *INDENT-ON* */
slouken@0
   248
#endif
slouken@0
   249
#include "close_code.h"
slouken@0
   250
slouken@0
   251
#endif /* _SDL_joystick_h */
slouken@1895
   252
slouken@1895
   253
/* vi: set ts=4 sw=4 expandtab: */