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
use std::{marker::PhantomData, ops::Deref, ptr::NonNull};
use crate::bind;
use super::Haptic;
#[derive(Debug)]
pub struct MouseHaptic {
haptic: Haptic,
}
impl MouseHaptic {
#[must_use]
pub fn new() -> Option<Self> {
let is_supported = unsafe { bind::SDL_MouseIsHaptic() as bind::SDL_bool == bind::SDL_TRUE };
if !is_supported {
return None;
}
let ptr = unsafe { bind::SDL_HapticOpenFromMouse() };
Some(Self {
haptic: Haptic {
ptr: NonNull::new(ptr).unwrap(),
},
})
}
}
impl Deref for MouseHaptic {
type Target = Haptic;
fn deref(&self) -> &Self::Target {
&self.haptic
}
}
impl Drop for MouseHaptic {
fn drop(&mut self) {
unsafe { bind::SDL_HapticClose(self.ptr.as_ptr()) }
}
}