input_actions/binding/
binding.rs1use crate::{
2 binding, device, event, source,
3 source::{Axis, Button, Key, MouseButton},
4};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8pub enum Source {
9 Mouse(binding::Mouse),
10 Keyboard(Key),
11 Gamepad(device::GamepadKind, binding::Gamepad),
12}
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
16pub enum Mouse {
17 Button(MouseButton),
18 Move,
19 Scroll,
20}
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
24pub enum Gamepad {
25 Button(Button),
26 Axis(Axis),
27}
28
29impl Source {
30 pub fn kind(&self) -> source::Kind {
32 match *self {
33 Self::Mouse(_) => source::Kind::Button,
34 Self::Keyboard(_) => source::Kind::Button,
35 Self::Gamepad(_, binding::Gamepad::Button(_)) => source::Kind::Button,
36 Self::Gamepad(_, binding::Gamepad::Axis(_)) => source::Kind::Axis,
37 }
38 }
39
40 pub fn device_kind(&self) -> device::Kind {
42 match *self {
43 Self::Mouse(_) => device::Kind::Mouse,
44 Self::Keyboard(_) => device::Kind::Keyboard,
45 Self::Gamepad(gamepad, _) => device::Kind::Gamepad(gamepad),
46 }
47 }
48
49 pub fn bound(self) -> Binding {
51 self.with_modifier(1.0)
52 }
53
54 pub fn with_modifier(self, modifier: f32) -> Binding {
56 Binding {
57 source: self,
58 modifier,
59 }
60 }
61}
62
63#[derive(Debug, Clone, Copy)]
66pub struct Binding {
67 pub source: Source,
68 pub modifier: f32,
72}
73
74impl Binding {
75 pub(crate) fn apply(&self, event: event::Event) -> event::Event {
76 let mut event = event;
77 match &mut event.state {
78 event::State::ButtonState(_btn_state) => {}
79 event::State::MouseMove(_x, _y) => {}
80 event::State::MouseScroll(_x, _y) => {}
81 event::State::ValueChanged(value) => *value *= self.modifier,
82 }
83 event
84 }
85}