Added SDL_HapticIndex. gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Tue, 08 Jul 2008 19:23:03 +0000
branchgsoc2008_force_feedback
changeset 2505abfcba0f3bd1
parent 2504 e68c99a19a2f
child 2506 ba8e99fe92c1
Added SDL_HapticIndex.
include/SDL_haptic.h
src/haptic/SDL_haptic.c
     1.1 --- a/include/SDL_haptic.h	Mon Jul 07 18:42:10 2008 +0000
     1.2 +++ b/include/SDL_haptic.h	Tue Jul 08 19:23:03 2008 +0000
     1.3 @@ -636,11 +636,25 @@
     1.4   *    \param device_index Index of the device to open.
     1.5   *    \return Device identifier or NULL on error.
     1.6   *
     1.7 + * \sa SDL_HapticIndex
     1.8   * \sa SDL_HapticOpenFromJoystick
     1.9   * \sa SDL_HapticClose
    1.10   */
    1.11  extern DECLSPEC SDL_Haptic * SDL_HapticOpen(int device_index);
    1.12  
    1.13 +
    1.14 +/**
    1.15 + * \fn int SDL_HapticIndex(SDL_Haptic * haptic)
    1.16 + *
    1.17 + * \brief Gets the index of a haptic device.
    1.18 + *
    1.19 + *    \param haptic Haptic device to get the index of.
    1.20 + *    \return The index of the haptic device or -1 on error.
    1.21 + *
    1.22 + * \sa SDL_HapticOpen
    1.23 + */
    1.24 +extern DECLSPEC int SDL_HapticIndex(SDL_Haptic * haptic);
    1.25 +
    1.26  /**
    1.27   * \fn int SDL_JoystickIsHaptic(SDL_Joystick * joystick)
    1.28   *
     2.1 --- a/src/haptic/SDL_haptic.c	Mon Jul 07 18:42:10 2008 +0000
     2.2 +++ b/src/haptic/SDL_haptic.c	Tue Jul 08 19:23:03 2008 +0000
     2.3 @@ -59,6 +59,24 @@
     2.4  
     2.5  
     2.6  /*
     2.7 + * Checks to see if the haptic device is valid
     2.8 + */
     2.9 +static int
    2.10 +ValidHaptic(SDL_Haptic ** haptic)
    2.11 +{
    2.12 +   int valid;
    2.13 +   
    2.14 +   if (*haptic == NULL) {
    2.15 +      SDL_SetError("Haptic device hasn't been opened yet");
    2.16 +      valid = 0;
    2.17 +   } else {
    2.18 +      valid = 1;
    2.19 +   }
    2.20 +   return valid;
    2.21 +}
    2.22 +
    2.23 +
    2.24 +/*
    2.25   * Returns the number of available devices.
    2.26   */
    2.27  int
    2.28 @@ -131,6 +149,20 @@
    2.29  
    2.30  
    2.31  /*
    2.32 + * Returns the index to a haptic device.
    2.33 + */
    2.34 +int
    2.35 +SDL_HapticIndex(SDL_Haptic * haptic)
    2.36 +{
    2.37 +   if (!ValidHaptic(&haptic)) {
    2.38 +      return -1;
    2.39 +   }
    2.40 +
    2.41 +   return haptic->index;
    2.42 +}
    2.43 +
    2.44 +
    2.45 +/*
    2.46   * Returns SDL_TRUE if joystick has haptic features.
    2.47   */
    2.48  int
    2.49 @@ -204,24 +236,6 @@
    2.50  
    2.51  
    2.52  /*
    2.53 - * Checks to see if the haptic device is valid
    2.54 - */
    2.55 -static int
    2.56 -ValidHaptic(SDL_Haptic ** haptic)
    2.57 -{
    2.58 -   int valid;
    2.59 -
    2.60 -   if (*haptic == NULL) {
    2.61 -      SDL_SetError("Haptic device hasn't been opened yet");
    2.62 -      valid = 0;
    2.63 -   } else {
    2.64 -      valid = 1;
    2.65 -   }
    2.66 -   return valid;
    2.67 -}
    2.68 -
    2.69 -
    2.70 -/*
    2.71   * Closes a SDL_Haptic device.
    2.72   */
    2.73  void