# HG changeset patch # User Edgar Simo # Date 1215544983 0 # Node ID abfcba0f3bd18baf7ee8f18398984a3c1ce4dd6c # Parent e68c99a19a2fa12bd2dbddb4cb6d22045665b8a1 Added SDL_HapticIndex. diff -r e68c99a19a2f -r abfcba0f3bd1 include/SDL_haptic.h --- a/include/SDL_haptic.h Mon Jul 07 18:42:10 2008 +0000 +++ b/include/SDL_haptic.h Tue Jul 08 19:23:03 2008 +0000 @@ -636,11 +636,25 @@ * \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 -r e68c99a19a2f -r abfcba0f3bd1 src/haptic/SDL_haptic.c --- a/src/haptic/SDL_haptic.c Mon Jul 07 18:42:10 2008 +0000 +++ b/src/haptic/SDL_haptic.c Tue Jul 08 19:23:03 2008 +0000 @@ -59,6 +59,24 @@ /* + * 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. */ int @@ -131,6 +149,20 @@ /* + * 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. */ int @@ -204,24 +236,6 @@ /* - * 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. */ void