changeset 2505:abfcba0f3bd1 gsoc2008_force_feedback

Added SDL_HapticIndex.
author Edgar Simo <bobbens@gmail.com>
date Tue, 08 Jul 2008 19:23:03 +0000
parents e68c99a19a2f
children ba8e99fe92c1
files include/SDL_haptic.h src/haptic/SDL_haptic.c
diffstat 2 files changed, 46 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- 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)
  *
--- 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