include/SDL_joystick.h
author Sam Lantinga <slouken@libsdl.org>
Mon, 10 Jul 2006 21:04:37 +0000
changeset 1895 c121d94672cb
parent 1358 c71e05b4dc2e
child 2859 99210400e8b9
permissions -rw-r--r--
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 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@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@251
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@0
    22
slouken@1895
    23
/**
slouken@1895
    24
 * \file SDL_joystick.h
slouken@1895
    25
 *
slouken@1895
    26
 * Include file for SDL joystick event handling
slouken@1895
    27
 */
slouken@0
    28
slouken@0
    29
#ifndef _SDL_joystick_h
slouken@0
    30
#define _SDL_joystick_h
slouken@0
    31
slouken@1356
    32
#include "SDL_stdinc.h"
slouken@1358
    33
#include "SDL_error.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@1895
    38
/* *INDENT-OFF* */
slouken@0
    39
extern "C" {
slouken@1895
    40
/* *INDENT-ON* */
slouken@0
    41
#endif
slouken@0
    42
slouken@0
    43
/* In order to use these functions, SDL_Init() must have been called
slouken@0
    44
   with the SDL_INIT_JOYSTICK flag.  This causes SDL to scan the system
slouken@0
    45
   for joysticks, and load appropriate drivers.
slouken@0
    46
*/
slouken@0
    47
slouken@0
    48
/* The joystick structure used to identify an SDL joystick */
slouken@0
    49
struct _SDL_Joystick;
slouken@0
    50
typedef struct _SDL_Joystick SDL_Joystick;
slouken@0
    51
slouken@0
    52
slouken@0
    53
/* Function prototypes */
slouken@0
    54
/*
slouken@0
    55
 * Count the number of joysticks attached to the system
slouken@0
    56
 */
slouken@337
    57
extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
slouken@0
    58
slouken@0
    59
/*
slouken@0
    60
 * Get the implementation dependent name of a joystick.
slouken@0
    61
 * This can be called before any joysticks are opened.
slouken@0
    62
 * If no name can be found, this function returns NULL.
slouken@0
    63
 */
slouken@1895
    64
extern DECLSPEC const char *SDLCALL SDL_JoystickName(int device_index);
slouken@0
    65
slouken@0
    66
/*
slouken@0
    67
 * Open a joystick for use - the index passed as an argument refers to
slouken@0
    68
 * the N'th joystick on the system.  This index is the value which will
slouken@0
    69
 * identify this joystick in future joystick events.
slouken@0
    70
 *
slouken@0
    71
 * This function returns a joystick identifier, or NULL if an error occurred.
slouken@0
    72
 */
slouken@1895
    73
extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index);
slouken@0
    74
slouken@0
    75
/*
slouken@0
    76
 * Returns 1 if the joystick has been opened, or 0 if it has not.
slouken@0
    77
 */
slouken@337
    78
extern DECLSPEC int SDLCALL SDL_JoystickOpened(int device_index);
slouken@0
    79
slouken@0
    80
/*
slouken@0
    81
 * Get the device index of an opened joystick.
slouken@0
    82
 */
slouken@1895
    83
extern DECLSPEC int SDLCALL SDL_JoystickIndex(SDL_Joystick * joystick);
slouken@0
    84
slouken@0
    85
/*
slouken@0
    86
 * Get the number of general axis controls on a joystick
slouken@0
    87
 */
slouken@1895
    88
extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick * joystick);
slouken@0
    89
slouken@0
    90
/*
slouken@0
    91
 * Get the number of trackballs on a joystick
slouken@0
    92
 * Joystick trackballs have only relative motion events associated
slouken@0
    93
 * with them and their state cannot be polled.
slouken@0
    94
 */
slouken@1895
    95
extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick * joystick);
slouken@0
    96
slouken@0
    97
/*
slouken@0
    98
 * Get the number of POV hats on a joystick
slouken@0
    99
 */
slouken@1895
   100
extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick * joystick);
slouken@0
   101
slouken@0
   102
/*
slouken@0
   103
 * Get the number of buttons on a joystick
slouken@0
   104
 */
slouken@1895
   105
extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick * joystick);
slouken@0
   106
slouken@0
   107
/*
slouken@0
   108
 * Update the current state of the open joysticks.
slouken@0
   109
 * This is called automatically by the event loop if any joystick
slouken@0
   110
 * events are enabled.
slouken@0
   111
 */
slouken@337
   112
extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
slouken@0
   113
slouken@0
   114
/*
slouken@0
   115
 * Enable/disable joystick event polling.
slouken@0
   116
 * If joystick events are disabled, you must call SDL_JoystickUpdate()
slouken@0
   117
 * yourself and check the state of the joystick when you want joystick
slouken@0
   118
 * information.
slouken@0
   119
 * The state can be one of SDL_QUERY, SDL_ENABLE or SDL_IGNORE.
slouken@0
   120
 */
slouken@337
   121
extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
slouken@0
   122
slouken@0
   123
/*
slouken@0
   124
 * Get the current state of an axis control on a joystick
slouken@0
   125
 * The state is a value ranging from -32768 to 32767.
slouken@0
   126
 * The axis indices start at index 0.
slouken@0
   127
 */
slouken@1895
   128
extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick * joystick,
slouken@1895
   129
                                                   int axis);
slouken@0
   130
slouken@0
   131
/*
slouken@0
   132
 * Get the current state of a POV hat on a joystick
slouken@0
   133
 * The return value is one of the following positions:
slouken@0
   134
 */
slouken@0
   135
#define SDL_HAT_CENTERED	0x00
slouken@0
   136
#define SDL_HAT_UP		0x01
slouken@0
   137
#define SDL_HAT_RIGHT		0x02
slouken@0
   138
#define SDL_HAT_DOWN		0x04
slouken@0
   139
#define SDL_HAT_LEFT		0x08
slouken@0
   140
#define SDL_HAT_RIGHTUP		(SDL_HAT_RIGHT|SDL_HAT_UP)
slouken@0
   141
#define SDL_HAT_RIGHTDOWN	(SDL_HAT_RIGHT|SDL_HAT_DOWN)
slouken@0
   142
#define SDL_HAT_LEFTUP		(SDL_HAT_LEFT|SDL_HAT_UP)
slouken@0
   143
#define SDL_HAT_LEFTDOWN	(SDL_HAT_LEFT|SDL_HAT_DOWN)
slouken@0
   144
/*
slouken@0
   145
 * The hat indices start at index 0.
slouken@0
   146
 */
slouken@1895
   147
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick * joystick,
slouken@1895
   148
                                                 int hat);
slouken@0
   149
slouken@0
   150
/*
slouken@0
   151
 * Get the ball axis change since the last poll
slouken@0
   152
 * This returns 0, or -1 if you passed it invalid parameters.
slouken@0
   153
 * The ball indices start at index 0.
slouken@0
   154
 */
slouken@1895
   155
extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick * joystick,
slouken@1895
   156
                                                int ball, int *dx, int *dy);
slouken@0
   157
slouken@0
   158
/*
slouken@0
   159
 * Get the current state of a button on a joystick
slouken@0
   160
 * The button indices start at index 0.
slouken@0
   161
 */
slouken@1895
   162
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick * joystick,
slouken@1895
   163
                                                    int button);
slouken@0
   164
slouken@0
   165
/*
slouken@0
   166
 * Close a joystick previously opened with SDL_JoystickOpen()
slouken@0
   167
 */
slouken@1895
   168
extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick);
slouken@0
   169
slouken@0
   170
slouken@0
   171
/* Ends C function definitions when using C++ */
slouken@0
   172
#ifdef __cplusplus
slouken@1895
   173
/* *INDENT-OFF* */
slouken@0
   174
}
slouken@1895
   175
/* *INDENT-ON* */
slouken@0
   176
#endif
slouken@0
   177
#include "close_code.h"
slouken@0
   178
slouken@0
   179
#endif /* _SDL_joystick_h */
slouken@1895
   180
slouken@1895
   181
/* vi: set ts=4 sw=4 expandtab: */