From e46b791ba1f780934997e645ef6724c0bb5d2493 Mon Sep 17 00:00:00 2001 From: Edgar Simo Date: Tue, 8 Jul 2008 19:35:10 +0000 Subject: [PATCH] Added SDL_HapticOpened(). --- include/SDL_haptic.h | 13 +++++++++++++ src/haptic/SDL_haptic.c | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/SDL_haptic.h b/include/SDL_haptic.h index 9cf437780..db3581c9c 100644 --- a/include/SDL_haptic.h +++ b/include/SDL_haptic.h @@ -642,6 +642,18 @@ extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index); */ extern DECLSPEC SDL_Haptic * SDL_HapticOpen(int device_index); +/** + * \fn int SDL_HapticOpened(int device_index) + * + * \brief Checks if the haptic device at index has been opened. + * + * \param device_index Index to check to see if it has been opened. + * \return 1 if it has been opened or 0 if it hasn't. + * + * \sa SDL_HapticOpen + * \sa SDL_HapticIndex + */ +extern DECLSPEC int SDL_HapticOpened(int device_index); /** * \fn int SDL_HapticIndex(SDL_Haptic * haptic) @@ -652,6 +664,7 @@ extern DECLSPEC SDL_Haptic * SDL_HapticOpen(int device_index); * \return The index of the haptic device or -1 on error. * * \sa SDL_HapticOpen + * \sa SDL_HapticOpened */ extern DECLSPEC int SDL_HapticIndex(SDL_Haptic * haptic); diff --git a/src/haptic/SDL_haptic.c b/src/haptic/SDL_haptic.c index 5345e32bf..3e61e6b26 100644 --- a/src/haptic/SDL_haptic.c +++ b/src/haptic/SDL_haptic.c @@ -148,6 +148,25 @@ SDL_HapticOpen(int device_index) } +/* + * Returns 1 if the device has been opened. + */ +int +SDL_HapticOpened(int device_index) +{ + int i, opened; + + opened = 0; + for (i=0; SDL_haptics[i]; i++) { + if (SDL_haptics[i]->index == (Uint8) device_index) { + opened = 1; + break; + } + } + return opened; +} + + /* * Returns the index to a haptic device. */