commonlibsse_ng\re\t/
ThumbstickEvent.rs

1use crate::re::BSFixedString::BSFixedString;
2use crate::re::IDEvent::{IDEvent, IDEventVtbl};
3use crate::re::InputDevices::{INPUT_DEVICE, INPUT_DEVICE_SE};
4use crate::re::offsets_rtti::RTTI_ThumbstickEvent;
5use crate::re::offsets_vtable::VTABLE_ThumbstickEvent;
6use crate::rel::ResolvableAddress as _;
7use crate::rel::id::{DataBaseError, VariantID};
8
9#[repr(C)]
10#[derive(Debug, PartialEq)]
11pub struct ThumbstickEvent {
12    pub __base: IDEvent, // 0x00
13    pub xValue: i32,     // 0x28
14    pub yValue: i32,     // 0x2C
15}
16const _: () = assert!(core::mem::size_of::<ThumbstickEvent>() == 0x30);
17
18impl ThumbstickEvent {
19    /// Address & offset of RTTI for `ThumbstickEvent`.
20    pub const RTTI: VariantID = RTTI_ThumbstickEvent;
21
22    /// Address & offset of Virtual function table.
23    pub const VTABLE: [VariantID; 1] = VTABLE_ThumbstickEvent;
24
25    /// # Errors
26    pub fn vtable() -> Result<&'static ThumbstickEventVtbl, DataBaseError> {
27        Self::VTABLE[0].address().map(|vtable| unsafe { vtable.cast().as_ref() })
28    }
29
30    #[inline]
31    pub fn init_with_xy(&mut self, id: InputType, x: i32, y: i32) {
32        self.init_with_xy_device(id, INPUT_DEVICE_SE::Gamepad.into(), x, y);
33    }
34
35    #[inline]
36    pub fn init_with_xy_device(&mut self, id: InputType, device: INPUT_DEVICE, x: i32, y: i32) {
37        self.init_with_xy_event(id, device, x, y, BSFixedString::new(c""));
38    }
39
40    #[inline]
41    pub fn init_with_xy_event(
42        &mut self,
43        id: InputType,
44        device: INPUT_DEVICE,
45        x: i32,
46        y: i32,
47        user_event: BSFixedString,
48    ) {
49        self.xValue = x;
50        self.yValue = y;
51        self.__base.__base.device = device;
52        self.__base.idCode = id as u32;
53        self.__base.userEvent = user_event;
54    }
55
56    /// Is left ThumbStick event?
57    #[inline]
58    pub const fn is_left(&self) -> bool {
59        self.__base.idCode == (InputType::LeftThumbstick as u32)
60    }
61
62    /// Is right ThumbStick event?
63    #[inline]
64    pub const fn is_right(&self) -> bool {
65        self.__base.idCode == (InputType::RightThumbstick as u32)
66    }
67}
68
69pub struct ThumbstickEventVtbl {
70    pub __base: IDEventVtbl, // 0x00
71}
72
73#[commonlibsse_ng_derive_internal::ffi_enum]
74#[repr(u32)]
75#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
76pub enum InputType {
77    LeftThumbstick = 0x0B,
78    RightThumbstick = 0x0C,
79}