From fe47286610f81db7a9fb2693fd16ea59f9557ef7 Mon Sep 17 00:00:00 2001 From: Edgar Simo Date: Tue, 8 Jul 2008 19:23:03 +0000 Subject: [PATCH] Added SDL_HapticIndex. --- include/SDL_haptic.h | 14 ++++++++++++ src/haptic/SDL_haptic.c | 50 ++++++++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/include/SDL_haptic.h b/include/SDL_haptic.h index 89991e446..9cf437780 100644 --- a/include/SDL_haptic.h +++ b/include/SDL_haptic.h @@ -636,11 +636,25 @@ extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index); * \param device_index Index of the device to open. * \return Device identifier or NULL on error. * + * \sa SDL_HapticIndex * \sa SDL_HapticOpenFromJoystick * \sa SDL_HapticClose */ extern DECLSPEC SDL_Haptic * SDL_HapticOpen(int device_index); + +/** + * \fn int SDL_HapticIndex(SDL_Haptic * haptic) + * + * \brief Gets the index of a haptic device. + * + * \param haptic Haptic device to get the index of. + * \return The index of the haptic device or -1 on error. + * + * \sa SDL_HapticOpen + */ +extern DECLSPEC int SDL_HapticIndex(SDL_Haptic * haptic); + /** * \fn int SDL_JoystickIsHaptic(SDL_Joystick * joystick) * diff --git a/src/haptic/SDL_haptic.c b/src/haptic/SDL_haptic.c index 1c241e801..5345e32bf 100644 --- a/src/haptic/SDL_haptic.c +++ b/src/haptic/SDL_haptic.c @@ -58,6 +58,24 @@ SDL_HapticInit(void) } +/* + * Checks to see if the haptic device is valid + */ +static int +ValidHaptic(SDL_Haptic ** haptic) +{ + int valid; + + if (*haptic == NULL) { + SDL_SetError("Haptic device hasn't been opened yet"); + valid = 0; + } else { + valid = 1; + } + return valid; +} + + /* * Returns the number of available devices. */ @@ -130,6 +148,20 @@ SDL_HapticOpen(int device_index) } +/* + * Returns the index to a haptic device. + */ +int +SDL_HapticIndex(SDL_Haptic * haptic) +{ + if (!ValidHaptic(&haptic)) { + return -1; + } + + return haptic->index; +} + + /* * Returns SDL_TRUE if joystick has haptic features. */ @@ -203,24 +235,6 @@ SDL_HapticOpenFromJoystick(SDL_Joystick * joystick) } -/* - * Checks to see if the haptic device is valid - */ -static int -ValidHaptic(SDL_Haptic ** haptic) -{ - int valid; - - if (*haptic == NULL) { - SDL_SetError("Haptic device hasn't been opened yet"); - valid = 0; - } else { - valid = 1; - } - return valid; -} - - /* * Closes a SDL_Haptic device. */