Path: blob/main/system/include/SDL/SDL_joystick.h
6169 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2011 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/2021/**22* \file SDL_joystick.h23*24* Include file for SDL joystick event handling25*/2627#ifndef _SDL_joystick_h28#define _SDL_joystick_h2930#include "SDL_stdinc.h"31#include "SDL_error.h"3233#include "begin_code.h"34/* Set up for C function definitions, even when using C++ */35#ifdef __cplusplus36/* *INDENT-OFF* */37extern "C" {38/* *INDENT-ON* */39#endif4041/**42* \file SDL_joystick.h43*44* In order to use these functions, SDL_Init() must have been called45* with the ::SDL_INIT_JOYSTICK flag. This causes SDL to scan the system46* for joysticks, and load appropriate drivers.47*/4849/* The joystick structure used to identify an SDL joystick */50struct _SDL_Joystick;51typedef struct _SDL_Joystick SDL_Joystick;525354/* Function prototypes */55/**56* Count the number of joysticks attached to the system57*/58extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);5960/**61* Get the implementation dependent name of a joystick.62* This can be called before any joysticks are opened.63* If no name can be found, this function returns NULL.64*/65extern DECLSPEC const char *SDLCALL SDL_JoystickName(int device_index);6667/**68* Open a joystick for use.69* The index passed as an argument refers tothe N'th joystick on the system.70* This index is the value which will identify this joystick in future joystick71* events.72*73* \return A joystick identifier, or NULL if an error occurred.74*/75extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index);7677/**78* Returns 1 if the joystick has been opened, or 0 if it has not.79*/80extern DECLSPEC int SDLCALL SDL_JoystickOpened(int device_index);8182/**83* Get the device index of an opened joystick.84*/85extern DECLSPEC int SDLCALL SDL_JoystickIndex(SDL_Joystick * joystick);8687/**88* Get the number of general axis controls on a joystick.89*/90extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick * joystick);9192/**93* Get the number of trackballs on a joystick.94*95* Joystick trackballs have only relative motion events associated96* with them and their state cannot be polled.97*/98extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick * joystick);99100/**101* Get the number of POV hats on a joystick.102*/103extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick * joystick);104105/**106* Get the number of buttons on a joystick.107*/108extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick * joystick);109110/**111* Update the current state of the open joysticks.112*113* This is called automatically by the event loop if any joystick114* events are enabled.115*/116extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);117118/**119* Enable/disable joystick event polling.120*121* If joystick events are disabled, you must call SDL_JoystickUpdate()122* yourself and check the state of the joystick when you want joystick123* information.124*125* The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE.126*/127extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);128129/**130* Get the current state of an axis control on a joystick.131*132* The state is a value ranging from -32768 to 32767.133*134* The axis indices start at index 0.135*/136extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick * joystick,137int axis);138139/**140* \name Hat positions141*/142/*@{*/143#define SDL_HAT_CENTERED 0x00144#define SDL_HAT_UP 0x01145#define SDL_HAT_RIGHT 0x02146#define SDL_HAT_DOWN 0x04147#define SDL_HAT_LEFT 0x08148#define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)149#define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)150#define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)151#define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)152/*@}*/153154/**155* Get the current state of a POV hat on a joystick.156*157* The hat indices start at index 0.158*159* \return The return value is one of the following positions:160* - ::SDL_HAT_CENTERED161* - ::SDL_HAT_UP162* - ::SDL_HAT_RIGHT163* - ::SDL_HAT_DOWN164* - ::SDL_HAT_LEFT165* - ::SDL_HAT_RIGHTUP166* - ::SDL_HAT_RIGHTDOWN167* - ::SDL_HAT_LEFTUP168* - ::SDL_HAT_LEFTDOWN169*/170extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick * joystick,171int hat);172173/**174* Get the ball axis change since the last poll.175*176* \return 0, or -1 if you passed it invalid parameters.177*178* The ball indices start at index 0.179*/180extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick * joystick,181int ball, int *dx, int *dy);182183/**184* Get the current state of a button on a joystick.185*186* The button indices start at index 0.187*/188extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick * joystick,189int button);190191/**192* Close a joystick previously opened with SDL_JoystickOpen().193*/194extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick);195196197/* Ends C function definitions when using C++ */198#ifdef __cplusplus199/* *INDENT-OFF* */200}201/* *INDENT-ON* */202#endif203#include "close_code.h"204205#endif /* _SDL_joystick_h */206207/* vi: set ts=4 sw=4 expandtab: */208209210