zengine_input/
input.rs

1use crate::device::{
2    Key, MouseButton, {ControllerButton, Which},
3};
4use serde::Deserialize;
5
6/// Rappresent an Axis
7#[derive(Debug, Deserialize, Eq, PartialEq, Clone)]
8pub enum Axis {
9    /// X axis
10    X,
11    /// Y axis
12    Y,
13}
14
15/// Rappresent an Input from the User
16#[derive(Debug, Deserialize, Eq, PartialEq, Clone)]
17pub enum Input {
18    /// Triggered when the user press a keyboard key
19    Keyboard {
20        /// indicates which keyboard key has been pressed
21        key: Key,
22    },
23    /// Triggered when the user moves the mouse
24    MouseMotion {
25        /// indicates the event motion axis
26        axis: Axis,
27    },
28    /// Triggered when the user uses the mouse wheel
29    MouseWheel {
30        /// indicates the event wheel axis
31        axis: Axis,
32    },
33    /// Triggered when the user press a mouse button
34    MouseButton {
35        /// indicate which button has been pressed
36        button: MouseButton,
37    },
38    // Triggered when the user uses a gamepad stick
39    ControllerStick {
40        /// gamepad device id
41        device_id: usize,
42        /// indicates which stick as been used
43        which: Which,
44        /// indicates the event motion axis
45        axis: Axis,
46    },
47    /// Triggered when the user uses a gamepad trigger
48    ControllerTrigger {
49        /// gamepad device id
50        device_id: usize,
51        /// indicates which trigger as been used
52        which: Which,
53    },
54    /// Triggered when the user uses a gamepad button
55    ControllerButton {
56        /// gamepad device id
57        device_id: usize,
58        /// indicate which gamepad button has been pressed
59        button: ControllerButton,
60    },
61    /// Triggered then the user touch the screen (only on supported platform)
62    Touch {
63        /// indixate the axis of the touch event
64        axis: Axis,
65    },
66}
67
68/// Rappresent an input event composed by the input type and its value
69#[derive(Debug)]
70pub struct InputEvent {
71    pub input: Input,
72    pub value: f32,
73}