1b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet/*
2b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    SDL - Simple DirectMedia Layer
34458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall    Copyright (C) 1997-2012 Sam Lantinga
4b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
5b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    This library is free software; you can redistribute it and/or
6b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    modify it under the terms of the GNU Lesser General Public
7b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    License as published by the Free Software Foundation; either
8b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    version 2.1 of the License, or (at your option) any later version.
9b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
10b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    This library is distributed in the hope that it will be useful,
11b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    but WITHOUT ANY WARRANTY; without even the implied warranty of
12b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    Lesser General Public License for more details.
14b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
15b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    You should have received a copy of the GNU Lesser General Public
16b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    License along with this library; if not, write to the Free Software
17b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
19b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    Sam Lantinga
20b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    slouken@libsdl.org
21b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet*/
22b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
234458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/** @file SDL_joystick.h
244458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  Include file for SDL joystick event handling
254458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall */
26b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
27b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#ifndef _SDL_joystick_h
28b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define _SDL_joystick_h
29b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
30b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#include "SDL_stdinc.h"
31b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#include "SDL_error.h"
32b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
33b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#include "begin_code.h"
34b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet/* Set up for C function definitions, even when using C++ */
35b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#ifdef __cplusplus
36b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern "C" {
37b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif
38b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
394458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/** @file SDL_joystick.h
404458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  @note In order to use these functions, SDL_Init() must have been called
414458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *        with the SDL_INIT_JOYSTICK flag.  This causes SDL to scan the system
424458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *        for joysticks, and load appropriate drivers.
434458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall */
44b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
454458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/** The joystick structure used to identify an SDL joystick */
46b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetstruct _SDL_Joystick;
47b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohettypedef struct _SDL_Joystick SDL_Joystick;
48b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
49b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet/* Function prototypes */
504458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
51b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Count the number of joysticks attached to the system
52b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */
53b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
54b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
554458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
56b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Get the implementation dependent name of a joystick.
574458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *
58b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * This can be called before any joysticks are opened.
59b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * If no name can be found, this function returns NULL.
60b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */
61b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC const char * SDLCALL SDL_JoystickName(int device_index);
62b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
634458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
644458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * Open a joystick for use.
654458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *
664458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * @param[in] device_index
674458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * The index passed as an argument refers to
68b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * the N'th joystick on the system.  This index is the value which will
69b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * identify this joystick in future joystick events.
70b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet *
714458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * @return This function returns a joystick identifier, or NULL if an error occurred.
72b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */
73b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC SDL_Joystick * SDLCALL SDL_JoystickOpen(int device_index);
74b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
754458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
76b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Returns 1 if the joystick has been opened, or 0 if it has not.
77b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */
78b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC int SDLCALL SDL_JoystickOpened(int device_index);
79b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
804458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
81b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Get the device index of an opened joystick.
82b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */
83b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC int SDLCALL SDL_JoystickIndex(SDL_Joystick *joystick);
84b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
854458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
86b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Get the number of general axis controls on a joystick
87b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */
88b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick *joystick);
89b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
904458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
91b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Get the number of trackballs on a joystick
924458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *
93b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Joystick trackballs have only relative motion events associated
94b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * with them and their state cannot be polled.
95b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */
96b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick *joystick);
97b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
984458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
99b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Get the number of POV hats on a joystick
100b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */
101b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick *joystick);
102b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
1034458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
104b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Get the number of buttons on a joystick
105b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */
106b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick *joystick);
107b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
1084458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
109b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Update the current state of the open joysticks.
1104458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *
111b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * This is called automatically by the event loop if any joystick
112b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * events are enabled.
113b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */
114b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
115b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
1164458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
117b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Enable/disable joystick event polling.
1184458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *
119b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * If joystick events are disabled, you must call SDL_JoystickUpdate()
120b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * yourself and check the state of the joystick when you want joystick
121b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * information.
1224458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *
1234458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * @param[in] state The state can be one of SDL_QUERY, SDL_ENABLE or SDL_IGNORE.
124b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */
125b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
126b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
1274458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
128b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Get the current state of an axis control on a joystick
1294458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *
1304458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * @param[in] axis The axis indices start at index 0.
1314458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *
1324458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * @return The state is a value ranging from -32768 to 32767.
133b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */
134b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick *joystick, int axis);
135b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
1364458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
1374458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  @name Hat Positions
1384458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  The return value of SDL_JoystickGetHat() is one of the following positions:
139b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */
1404458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/*@{*/
141b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define SDL_HAT_CENTERED	0x00
142b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define SDL_HAT_UP		0x01
143b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define SDL_HAT_RIGHT		0x02
144b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define SDL_HAT_DOWN		0x04
145b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define SDL_HAT_LEFT		0x08
146b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define SDL_HAT_RIGHTUP		(SDL_HAT_RIGHT|SDL_HAT_UP)
147b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define SDL_HAT_RIGHTDOWN	(SDL_HAT_RIGHT|SDL_HAT_DOWN)
148b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define SDL_HAT_LEFTUP		(SDL_HAT_LEFT|SDL_HAT_UP)
149b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define SDL_HAT_LEFTDOWN	(SDL_HAT_LEFT|SDL_HAT_DOWN)
1504458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/*@}*/
1514458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall
1524458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
1534458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  Get the current state of a POV hat on a joystick
1544458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *
1554458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  @param[in] hat The hat indices start at index 0.
156b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */
157b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick *joystick, int hat);
158b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
1594458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
160b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Get the ball axis change since the last poll
1614458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *
1624458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * @param[in] ball The ball indices start at index 0.
1634458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *
1644458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * @return This returns 0, or -1 if you passed it invalid parameters.
165b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */
166b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick *joystick, int ball, int *dx, int *dy);
167b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
1684458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
169b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Get the current state of a button on a joystick
1704458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *
1714458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * @param[in] button The button indices start at index 0.
172b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */
173b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick *joystick, int button);
174b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
1754458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
176b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Close a joystick previously opened with SDL_JoystickOpen()
177b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */
178b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick *joystick);
179b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
180b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
181b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet/* Ends C function definitions when using C++ */
182b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#ifdef __cplusplus
183b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet}
184b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif
185b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#include "close_code.h"
186b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
187b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif /* _SDL_joystick_h */
188