1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Module for touch interface interactions.

use crate::{c_float, c_int, stdinc::*};

/// Used with touch events.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct SDL_TouchID(pub Sint64);

/// Used to identify a finger object.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct SDL_FingerID(pub Sint64);

/// The types of a touch device.
///
/// See `SDL_TOUCH_DEVICE_*` constants.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct SDL_TouchDeviceType(pub i32);

/// The "invalid" touch type. Used for error values and such.
pub const SDL_TOUCH_DEVICE_INVALID: SDL_TouchDeviceType =
  SDL_TouchDeviceType(-1);
/// Touch screen with window-relative coordinates
pub const SDL_TOUCH_DEVICE_DIRECT: SDL_TouchDeviceType = SDL_TouchDeviceType(0);
/// Trackpad with absolute device coordinates
pub const SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE: SDL_TouchDeviceType =
  SDL_TouchDeviceType(1);
/// Trackpad with screen cursor-relative coordinates
pub const SDL_TOUCH_DEVICE_INDIRECT_RELATIVE: SDL_TouchDeviceType =
  SDL_TouchDeviceType(2);

/// Info for a finger object.
#[derive(Debug, Clone, Copy, Default, PartialEq, PartialOrd)]
#[repr(C)]
#[allow(missing_docs)]
pub struct SDL_Finger {
  pub id: SDL_FingerID,
  pub x: c_float,
  pub y: c_float,
  pub pressure: c_float,
}

/// Used as the device ID for *mouse events* simulated with touch input.
pub const SDL_TOUCH_MOUSEID: u32 = -1_i32 as u32;

/// Used as the `SDL_TouchID` for *touch events* simulated with mouse input.
pub const SDL_MOUSE_TOUCHID: SDL_TouchID = SDL_TouchID(-1);

extern "C" {
  /// Get the number of registered touch devices.
  pub fn SDL_GetNumTouchDevices();

  /// Get the touch ID with the given index, or 0 if the index is invalid.
  pub fn SDL_GetTouchDevice(index: c_int) -> SDL_TouchID;

  /// Get the type of the given touch device.
  pub fn SDL_GetTouchDeviceType(touchID: SDL_TouchID) -> SDL_TouchDeviceType;

  /// Get the number of active fingers for a given touch device.
  pub fn SDL_GetNumTouchFingers(touchID: SDL_TouchID) -> c_int;

  /// Get the finger object of the given touch, with the given index.
  pub fn SDL_GetTouchFinger(
    touchID: SDL_TouchID, index: c_int,
  ) -> *mut SDL_Finger;
}