include/SDL_joystick.h
author Ryan C. Gordon <icculus@icculus.org>
Wed, 21 Nov 2012 23:00:06 -0500
changeset 6680 9d3df1f5c542
parent 6138 4c64952a58fb
child 6690 9548c8a58103
permissions -rw-r--r--
Removed some tab chars.
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@1895
    26
 */
slouken@0
    27
slouken@0
    28
#ifndef _SDL_joystick_h
slouken@0
    29
#define _SDL_joystick_h
slouken@0
    30
slouken@1356
    31
#include "SDL_stdinc.h"
slouken@1358
    32
#include "SDL_error.h"
slouken@0
    33
slouken@0
    34
#include "begin_code.h"
slouken@0
    35
/* Set up for C function definitions, even when using C++ */
slouken@0
    36
#ifdef __cplusplus
slouken@1895
    37
/* *INDENT-OFF* */
slouken@0
    38
extern "C" {
slouken@1895
    39
/* *INDENT-ON* */
slouken@0
    40
#endif
slouken@0
    41
slouken@3407
    42
/**
slouken@3407
    43
 *  \file SDL_joystick.h
slouken@3407
    44
 *
slouken@3407
    45
 *  In order to use these functions, SDL_Init() must have been called
slouken@3407
    46
 *  with the ::SDL_INIT_JOYSTICK flag.  This causes SDL to scan the system
slouken@3407
    47
 *  for joysticks, and load appropriate drivers.
slouken@3407
    48
 */
slouken@0
    49
slouken@0
    50
/* The joystick structure used to identify an SDL joystick */
slouken@0
    51
struct _SDL_Joystick;
slouken@0
    52
typedef struct _SDL_Joystick SDL_Joystick;
slouken@0
    53
slouken@0
    54
slouken@0
    55
/* Function prototypes */
slouken@3407
    56
/**
slouken@3407
    57
 *  Count the number of joysticks attached to the system
slouken@0
    58
 */
slouken@337
    59
extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
slouken@0
    60
slouken@3407
    61
/**
slouken@3407
    62
 *  Get the implementation dependent name of a joystick.
slouken@3407
    63
 *  This can be called before any joysticks are opened.
slouken@3407
    64
 *  If no name can be found, this function returns NULL.
slouken@0
    65
 */
slouken@1895
    66
extern DECLSPEC const char *SDLCALL SDL_JoystickName(int device_index);
slouken@0
    67
slouken@3407
    68
/**
slouken@3407
    69
 *  Open a joystick for use.  
slouken@3407
    70
 *  The index passed as an argument refers tothe N'th joystick on the system.  
slouken@3407
    71
 *  This index is the value which will identify this joystick in future joystick
slouken@3407
    72
 *  events.
slouken@3407
    73
 *  
slouken@3407
    74
 *  \return A joystick identifier, or NULL if an error occurred.
slouken@0
    75
 */
slouken@1895
    76
extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index);
slouken@0
    77
slouken@3407
    78
/**
slouken@3407
    79
 *  Returns 1 if the joystick has been opened, or 0 if it has not.
slouken@0
    80
 */
slouken@337
    81
extern DECLSPEC int SDLCALL SDL_JoystickOpened(int device_index);
slouken@0
    82
slouken@3407
    83
/**
slouken@3407
    84
 *  Get the device index of an opened joystick.
slouken@0
    85
 */
slouken@1895
    86
extern DECLSPEC int SDLCALL SDL_JoystickIndex(SDL_Joystick * joystick);
slouken@0
    87
slouken@3407
    88
/**
slouken@3407
    89
 *  Get the number of general axis controls on a joystick.
slouken@0
    90
 */
slouken@1895
    91
extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick * joystick);
slouken@0
    92
slouken@3407
    93
/**
slouken@3407
    94
 *  Get the number of trackballs on a joystick.
slouken@3407
    95
 *  
slouken@3407
    96
 *  Joystick trackballs have only relative motion events associated
slouken@3407
    97
 *  with them and their state cannot be polled.
slouken@0
    98
 */
slouken@1895
    99
extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick * joystick);
slouken@0
   100
slouken@3407
   101
/**
slouken@3407
   102
 *  Get the number of POV hats on a joystick.
slouken@0
   103
 */
slouken@1895
   104
extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick * joystick);
slouken@0
   105
slouken@3407
   106
/**
slouken@3407
   107
 *  Get the number of buttons on a joystick.
slouken@0
   108
 */
slouken@1895
   109
extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick * joystick);
slouken@0
   110
slouken@3407
   111
/**
slouken@3407
   112
 *  Update the current state of the open joysticks.
slouken@3407
   113
 *  
slouken@3407
   114
 *  This is called automatically by the event loop if any joystick
slouken@3407
   115
 *  events are enabled.
slouken@0
   116
 */
slouken@337
   117
extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
slouken@0
   118
slouken@3407
   119
/**
slouken@3407
   120
 *  Enable/disable joystick event polling.
slouken@3407
   121
 *  
slouken@3407
   122
 *  If joystick events are disabled, you must call SDL_JoystickUpdate()
slouken@3407
   123
 *  yourself and check the state of the joystick when you want joystick
slouken@3407
   124
 *  information.
slouken@3407
   125
 *  
slouken@3407
   126
 *  The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE.
slouken@0
   127
 */
slouken@337
   128
extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
slouken@0
   129
slouken@3407
   130
/**
slouken@3407
   131
 *  Get the current state of an axis control on a joystick.
slouken@3407
   132
 *  
slouken@3407
   133
 *  The state is a value ranging from -32768 to 32767.
slouken@3407
   134
 *  
slouken@3407
   135
 *  The axis indices start at index 0.
slouken@0
   136
 */
slouken@1895
   137
extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick * joystick,
slouken@1895
   138
                                                   int axis);
slouken@0
   139
slouken@3407
   140
/**
slouken@3407
   141
 *  \name Hat positions
slouken@0
   142
 */
slouken@3407
   143
/*@{*/
slouken@0
   144
#define SDL_HAT_CENTERED	0x00
slouken@0
   145
#define SDL_HAT_UP		0x01
slouken@0
   146
#define SDL_HAT_RIGHT		0x02
slouken@0
   147
#define SDL_HAT_DOWN		0x04
slouken@0
   148
#define SDL_HAT_LEFT		0x08
slouken@0
   149
#define SDL_HAT_RIGHTUP		(SDL_HAT_RIGHT|SDL_HAT_UP)
slouken@0
   150
#define SDL_HAT_RIGHTDOWN	(SDL_HAT_RIGHT|SDL_HAT_DOWN)
slouken@0
   151
#define SDL_HAT_LEFTUP		(SDL_HAT_LEFT|SDL_HAT_UP)
slouken@0
   152
#define SDL_HAT_LEFTDOWN	(SDL_HAT_LEFT|SDL_HAT_DOWN)
slouken@3407
   153
/*@}*/
slouken@3407
   154
slouken@3407
   155
/**
slouken@3407
   156
 *  Get the current state of a POV hat on a joystick.
slouken@3407
   157
 *
slouken@3407
   158
 *  The hat indices start at index 0.
slouken@3407
   159
 *  
slouken@3407
   160
 *  \return The return value is one of the following positions:
slouken@3407
   161
 *           - ::SDL_HAT_CENTERED
slouken@3407
   162
 *           - ::SDL_HAT_UP
slouken@3407
   163
 *           - ::SDL_HAT_RIGHT
slouken@3407
   164
 *           - ::SDL_HAT_DOWN
slouken@3407
   165
 *           - ::SDL_HAT_LEFT
slouken@3407
   166
 *           - ::SDL_HAT_RIGHTUP
slouken@3407
   167
 *           - ::SDL_HAT_RIGHTDOWN
slouken@3407
   168
 *           - ::SDL_HAT_LEFTUP
slouken@3407
   169
 *           - ::SDL_HAT_LEFTDOWN
slouken@0
   170
 */
slouken@1895
   171
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick * joystick,
slouken@1895
   172
                                                 int hat);
slouken@0
   173
slouken@3407
   174
/**
slouken@3407
   175
 *  Get the ball axis change since the last poll.
slouken@3407
   176
 *  
slouken@3407
   177
 *  \return 0, or -1 if you passed it invalid parameters.
slouken@3407
   178
 *  
slouken@3407
   179
 *  The ball indices start at index 0.
slouken@0
   180
 */
slouken@1895
   181
extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick * joystick,
slouken@1895
   182
                                                int ball, int *dx, int *dy);
slouken@0
   183
slouken@3407
   184
/**
slouken@3407
   185
 *  Get the current state of a button on a joystick.
slouken@3407
   186
 *  
slouken@3407
   187
 *  The button indices start at index 0.
slouken@0
   188
 */
slouken@1895
   189
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick * joystick,
slouken@1895
   190
                                                    int button);
slouken@0
   191
slouken@3407
   192
/**
slouken@3407
   193
 *  Close a joystick previously opened with SDL_JoystickOpen().
slouken@0
   194
 */
slouken@1895
   195
extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick);
slouken@0
   196
slouken@0
   197
slouken@0
   198
/* Ends C function definitions when using C++ */
slouken@0
   199
#ifdef __cplusplus
slouken@1895
   200
/* *INDENT-OFF* */
slouken@0
   201
}
slouken@1895
   202
/* *INDENT-ON* */
slouken@0
   203
#endif
slouken@0
   204
#include "close_code.h"
slouken@0
   205
slouken@0
   206
#endif /* _SDL_joystick_h */
slouken@1895
   207
slouken@1895
   208
/* vi: set ts=4 sw=4 expandtab: */