include/SDL_joystick.h
author Sam Lantinga <slouken@libsdl.org>
Sun, 06 Oct 2002 20:31:34 +0000
changeset 515 230b156829ed
parent 337 9154ec9ca3d2
child 769 b8d311d90021
permissions -rw-r--r--
*** empty log message ***
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@297
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@0
     6
    modify it under the terms of the GNU Library General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@0
     8
    version 2 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@0
    13
    Library General Public License for more details.
slouken@0
    14
slouken@0
    15
    You should have received a copy of the GNU Library General Public
slouken@0
    16
    License along with this library; if not, write to the Free
slouken@0
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@251
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@0
    22
slouken@0
    23
#ifdef SAVE_RCSID
slouken@0
    24
static char rcsid =
slouken@0
    25
 "@(#) $Id$";
slouken@0
    26
#endif
slouken@0
    27
slouken@0
    28
/* Include file for SDL joystick event handling */
slouken@0
    29
slouken@0
    30
#ifndef _SDL_joystick_h
slouken@0
    31
#define _SDL_joystick_h
slouken@0
    32
slouken@0
    33
#include "SDL_types.h"
slouken@0
    34
slouken@0
    35
#include "begin_code.h"
slouken@0
    36
/* Set up for C function definitions, even when using C++ */
slouken@0
    37
#ifdef __cplusplus
slouken@0
    38
extern "C" {
slouken@0
    39
#endif
slouken@0
    40
slouken@0
    41
/* In order to use these functions, SDL_Init() must have been called
slouken@0
    42
   with the SDL_INIT_JOYSTICK flag.  This causes SDL to scan the system
slouken@0
    43
   for joysticks, and load appropriate drivers.
slouken@0
    44
*/
slouken@0
    45
slouken@0
    46
/* The joystick structure used to identify an SDL joystick */
slouken@0
    47
struct _SDL_Joystick;
slouken@0
    48
typedef struct _SDL_Joystick SDL_Joystick;
slouken@0
    49
slouken@0
    50
slouken@0
    51
/* Function prototypes */
slouken@0
    52
/*
slouken@0
    53
 * Count the number of joysticks attached to the system
slouken@0
    54
 */
slouken@337
    55
extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
slouken@0
    56
slouken@0
    57
/*
slouken@0
    58
 * Get the implementation dependent name of a joystick.
slouken@0
    59
 * This can be called before any joysticks are opened.
slouken@0
    60
 * If no name can be found, this function returns NULL.
slouken@0
    61
 */
slouken@337
    62
extern DECLSPEC const char * SDLCALL SDL_JoystickName(int device_index);
slouken@0
    63
slouken@0
    64
/*
slouken@0
    65
 * Open a joystick for use - the index passed as an argument refers to
slouken@0
    66
 * the N'th joystick on the system.  This index is the value which will
slouken@0
    67
 * identify this joystick in future joystick events.
slouken@0
    68
 *
slouken@0
    69
 * This function returns a joystick identifier, or NULL if an error occurred.
slouken@0
    70
 */
slouken@337
    71
extern DECLSPEC SDL_Joystick * SDLCALL SDLCALL SDL_JoystickOpen(int device_index);
slouken@0
    72
slouken@0
    73
/*
slouken@0
    74
 * Returns 1 if the joystick has been opened, or 0 if it has not.
slouken@0
    75
 */
slouken@337
    76
extern DECLSPEC int SDLCALL SDL_JoystickOpened(int device_index);
slouken@0
    77
slouken@0
    78
/*
slouken@0
    79
 * Get the device index of an opened joystick.
slouken@0
    80
 */
slouken@337
    81
extern DECLSPEC int SDLCALL SDL_JoystickIndex(SDL_Joystick *joystick);
slouken@0
    82
slouken@0
    83
/*
slouken@0
    84
 * Get the number of general axis controls on a joystick
slouken@0
    85
 */
slouken@337
    86
extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick *joystick);
slouken@0
    87
slouken@0
    88
/*
slouken@0
    89
 * Get the number of trackballs on a joystick
slouken@0
    90
 * Joystick trackballs have only relative motion events associated
slouken@0
    91
 * with them and their state cannot be polled.
slouken@0
    92
 */
slouken@337
    93
extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick *joystick);
slouken@0
    94
slouken@0
    95
/*
slouken@0
    96
 * Get the number of POV hats on a joystick
slouken@0
    97
 */
slouken@337
    98
extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick *joystick);
slouken@0
    99
slouken@0
   100
/*
slouken@0
   101
 * Get the number of buttons on a joystick
slouken@0
   102
 */
slouken@337
   103
extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick *joystick);
slouken@0
   104
slouken@0
   105
/*
slouken@0
   106
 * Update the current state of the open joysticks.
slouken@0
   107
 * This is called automatically by the event loop if any joystick
slouken@0
   108
 * events are enabled.
slouken@0
   109
 */
slouken@337
   110
extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
slouken@0
   111
slouken@0
   112
/*
slouken@0
   113
 * Enable/disable joystick event polling.
slouken@0
   114
 * If joystick events are disabled, you must call SDL_JoystickUpdate()
slouken@0
   115
 * yourself and check the state of the joystick when you want joystick
slouken@0
   116
 * information.
slouken@0
   117
 * The state can be one of SDL_QUERY, SDL_ENABLE or SDL_IGNORE.
slouken@0
   118
 */
slouken@337
   119
extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
slouken@0
   120
slouken@0
   121
/*
slouken@0
   122
 * Get the current state of an axis control on a joystick
slouken@0
   123
 * The state is a value ranging from -32768 to 32767.
slouken@0
   124
 * The axis indices start at index 0.
slouken@0
   125
 */
slouken@337
   126
extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick *joystick, int axis);
slouken@0
   127
slouken@0
   128
/*
slouken@0
   129
 * Get the current state of a POV hat on a joystick
slouken@0
   130
 * The return value is one of the following positions:
slouken@0
   131
 */
slouken@0
   132
#define SDL_HAT_CENTERED	0x00
slouken@0
   133
#define SDL_HAT_UP		0x01
slouken@0
   134
#define SDL_HAT_RIGHT		0x02
slouken@0
   135
#define SDL_HAT_DOWN		0x04
slouken@0
   136
#define SDL_HAT_LEFT		0x08
slouken@0
   137
#define SDL_HAT_RIGHTUP		(SDL_HAT_RIGHT|SDL_HAT_UP)
slouken@0
   138
#define SDL_HAT_RIGHTDOWN	(SDL_HAT_RIGHT|SDL_HAT_DOWN)
slouken@0
   139
#define SDL_HAT_LEFTUP		(SDL_HAT_LEFT|SDL_HAT_UP)
slouken@0
   140
#define SDL_HAT_LEFTDOWN	(SDL_HAT_LEFT|SDL_HAT_DOWN)
slouken@0
   141
/*
slouken@0
   142
 * The hat indices start at index 0.
slouken@0
   143
 */
slouken@337
   144
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick *joystick, int hat);
slouken@0
   145
slouken@0
   146
/*
slouken@0
   147
 * Get the ball axis change since the last poll
slouken@0
   148
 * This returns 0, or -1 if you passed it invalid parameters.
slouken@0
   149
 * The ball indices start at index 0.
slouken@0
   150
 */
slouken@337
   151
extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick *joystick, int ball, int *dx, int *dy);
slouken@0
   152
slouken@0
   153
/*
slouken@0
   154
 * Get the current state of a button on a joystick
slouken@0
   155
 * The button indices start at index 0.
slouken@0
   156
 */
slouken@337
   157
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick *joystick, int button);
slouken@0
   158
slouken@0
   159
/*
slouken@0
   160
 * Close a joystick previously opened with SDL_JoystickOpen()
slouken@0
   161
 */
slouken@337
   162
extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick *joystick);
slouken@0
   163
slouken@0
   164
slouken@0
   165
/* Ends C function definitions when using C++ */
slouken@0
   166
#ifdef __cplusplus
slouken@0
   167
}
slouken@0
   168
#endif
slouken@0
   169
#include "close_code.h"
slouken@0
   170
slouken@0
   171
#endif /* _SDL_joystick_h */