# gvr::GestureApi

`#include <gvr_gesture.h>`

This is a convenience C++ wrapper for the Gesture C API.

## Summary

This wrapper strategy prevents ABI compatibility issues between compilers by ensuring that the interface between client code and the implementation code in libgvr_gesture.so is a pure C interface. The translation from C++ calls to C calls provided by this wrapper runs entirely in the client's binary and is compiled by the client's compiler.

If you are using multiple controllers, you will need to create multiple [GestureApi](https://developers.google.com/vr/reference/android-ndk/class/gvr/gesture-api#classgvr_1_1_gesture_api) objects, one for each controller.

Methods in this class are only documented insofar as the C++ wrapping logic is concerned; for information about the method itself, please refer to the corresponding function in the C API.

Example API usage:

Initialization:

```
GestureApi gesture_api;
```

<br />

Usage:

```
// Get the controller state from client
ControllerState* controller_state = ...

// Detect the gestures.
gesture_api.Update(controller_state);

// Get the number of detected gestures
int num_gestures = gesture_api.GetGestureCount();

for (int i = 0; i < num_gestures; i ++) {
  Gesture* gesture_ptr = gesture_api.GetGesture(i);
  switch (gesture_api.GetGestureType(gesture_ptr)) {
    case GVR_GESTURE_SWIPE:
      // Handle swipe gesture.
      break;
    case GVR_GESTURE_SCROLL_START:
      // Handle the start of a sequence of scroll gestures.
      break;
    case GVR_GESTURE_SCROLL_UPDATE:
      // Handle an update in a sequence of scroll gestures.
      break;
    case GVR_GESTURE_SCROLL_END:
      // Handle the end of a sequence of scroll gestures.
      break;
    default:
      // Unexpected gesture type.
      break;
   }
}
```

<br />

### Inheritance

Inherits from: [gvr::WrapperBase\< gvr_gesture_context, gvr_gesture_context_destroy \>](https://developers.google.com/vr/reference/android-ndk/class/gvr/wrapper-base)

| ### Constructors and Destructors ||
|---|---|
| `https://developers.google.com/vr/reference/android-ndk/class/gvr/gesture-api#classgvr_1_1_gesture_api_1a58f79edae1dc3178f20daa5b453a43a5()` Creates a [GestureApi](https://developers.google.com/vr/reference/android-ndk/class/gvr/gesture-api#classgvr_1_1_gesture_api) object. ||

| ### Public functions ||
|---|---|
| `https://developers.google.com/vr/reference/android-ndk/class/gvr/gesture-api#classgvr_1_1_gesture_api_1a40e6baad5defe3d9ede795868f331504(const https://developers.google.com/vr/reference/android-ndk/class/gvr/controller-state#classgvr_1_1_controller_state *controller_state, https://developers.google.com/vr/reference/android-ndk/group/types#group__types_1ga25a81f172e4de5c794b8f3ddb6194f41 button) const ` | `bool` Returns whether long press on the given controller button is detected. |
| `https://developers.google.com/vr/reference/android-ndk/class/gvr/gesture-api#classgvr_1_1_gesture_api_1a0c69ff78044f12c54ac13e38bdf2f12b(const Gesture *gesture) const ` | `https://developers.google.com/vr/reference/android-ndk/struct/gvr-vec2f#structgvr__vec2f` Returns gesture displacement. |
| `https://developers.google.com/vr/reference/android-ndk/class/gvr/gesture-api#classgvr_1_1_gesture_api_1ac443afb1109567be7ae52946e11d7fd1(int index) const ` | `const Gesture *` Returns the gesture at given index. |
| `https://developers.google.com/vr/reference/android-ndk/class/gvr/gesture-api#classgvr_1_1_gesture_api_1aa2f950722d07b63ea98cb0d2b60cfb0a() const ` | `int` Returns the number of gestures detected. |
| `https://developers.google.com/vr/reference/android-ndk/class/gvr/gesture-api#classgvr_1_1_gesture_api_1a75367beeee504dc0eed412107f3cc0ea(const Gesture *gesture) const ` | `https://developers.google.com/vr/reference/android-ndk/group/gesture#group___gesture_1gaae634fdca873e59114514c1c34b134fa` Returns the direction of current gesture. |
| `https://developers.google.com/vr/reference/android-ndk/class/gvr/gesture-api#classgvr_1_1_gesture_api_1ab5ab926c36f5e7247cf23ca43a7fc16d(const Gesture *gesture) const ` | `https://developers.google.com/vr/reference/android-ndk/group/gesture#group___gesture_1ga6f2394469b17860e95412cd19603a90f` Returns the type of the given gesture. |
| `https://developers.google.com/vr/reference/android-ndk/class/gvr/gesture-api#classgvr_1_1_gesture_api_1a00cf44c349a1eb152e8006400ffabe89(const Gesture *gesture) const ` | `https://developers.google.com/vr/reference/android-ndk/struct/gvr-vec2f#structgvr__vec2f` Returns gesture velocity. |
| `https://developers.google.com/vr/reference/android-ndk/class/gvr/gesture-api#classgvr_1_1_gesture_api_1a5e836ec5bf521cf717caa419ee830643()` | `void` Restarts gesture detection. |
| `https://developers.google.com/vr/reference/android-ndk/class/gvr/gesture-api#classgvr_1_1_gesture_api_1ac7c360d8874cd6e033a2b1d184d40252(const https://developers.google.com/vr/reference/android-ndk/class/gvr/controller-state#classgvr_1_1_controller_state *controller_state)` | `void` Updates gesture context based on current controller state. |

## Public functions

### GestureApi

```
 GestureApi()
```
Creates a [GestureApi](https://developers.google.com/vr/reference/android-ndk/class/gvr/gesture-api#classgvr_1_1_gesture_api) object.

It is properly initialized and can handle gesture detection immediately.

### GetButtonLongPress

```
bool GetButtonLongPress(
  const ControllerState *controller_state,
  ControllerButton button
) const 
```
Returns whether long press on the given controller button is detected.

For more information, see [gvr_get_button_long_press()](https://developers.google.com/vr/reference/android-ndk/group/gesture#group___gesture_1ga11eb904fbd0a3c9982fec9ba73437b70).

### GetDisplacement

```
gvr_vec2f GetDisplacement(
  const Gesture *gesture
) const 
```
Returns gesture displacement.

For more information, see [gvr_gesture_get_displacement()](https://developers.google.com/vr/reference/android-ndk/group/gesture#group___gesture_1ga12088254c858dec5c56cc9200ecf13fd).

### GetGesture

```
const Gesture * GetGesture(
  int index
) const 
```
Returns the gesture at given index.

For more information, see [gvr_gesture_get()](https://developers.google.com/vr/reference/android-ndk/group/gesture#group___gesture_1gab6156f8925dbe3027318f2b56e585d00).

### GetGestureCount

```
int GetGestureCount() const 
```
Returns the number of gestures detected.

For more information, see [gvr_gesture_get_count()](https://developers.google.com/vr/reference/android-ndk/group/gesture#group___gesture_1ga22c6de4d7013d5ff69a9d33ff7b48236).

### GetGestureDirection

```
GestureDirection GetGestureDirection(
  const Gesture *gesture
) const 
```
Returns the direction of current gesture.

For more information, see [gvr_gesture_get_direction()](https://developers.google.com/vr/reference/android-ndk/group/gesture#group___gesture_1gafe4d1fe96bfcfc7ab2bec78e52515c05).

### GetGestureType

```
GestureType GetGestureType(
  const Gesture *gesture
) const 
```
Returns the type of the given gesture.

For more information, see [gvr_gesture_get_type()](https://developers.google.com/vr/reference/android-ndk/group/gesture#group___gesture_1ga4152d41c83571b02de3ff7ac2267bd58).

### GetVelocity

```
gvr_vec2f GetVelocity(
  const Gesture *gesture
) const 
```
Returns gesture velocity.

For more information, see [gvr_gesture_get_velocity()](https://developers.google.com/vr/reference/android-ndk/group/gesture#group___gesture_1ga0d88077725148a2c02935f592d5c439f).

### Restart

```
void Restart()
```
Restarts gesture detection.

For more information, see [gvr_gesture_restart()](https://developers.google.com/vr/reference/android-ndk/group/gesture#group___gesture_1ga38867fb99c76a629bc1e93093da725b0).

### Update

```
void Update(
  const ControllerState *controller_state
)
```
Updates gesture context based on current controller state.

For more information, see [gvr_gesture_update()](https://developers.google.com/vr/reference/android-ndk/group/gesture#group___gesture_1ga828a68be30e6eaa9e9af9b364ce340e0).