use crate::{
binding, device, event, source,
source::{Axis, Button, Key, MouseButton},
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Source {
Mouse(binding::Mouse),
Keyboard(Key),
Gamepad(device::GamepadKind, binding::Gamepad),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Mouse {
Button(MouseButton),
Move,
Scroll,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Gamepad {
Button(Button),
Axis(Axis),
}
impl Source {
pub fn kind(&self) -> source::Kind {
match *self {
Self::Mouse(_) => source::Kind::Button,
Self::Keyboard(_) => source::Kind::Button,
Self::Gamepad(_, binding::Gamepad::Button(_)) => source::Kind::Button,
Self::Gamepad(_, binding::Gamepad::Axis(_)) => source::Kind::Axis,
}
}
pub fn device_kind(&self) -> device::Kind {
match *self {
Self::Mouse(_) => device::Kind::Mouse,
Self::Keyboard(_) => device::Kind::Keyboard,
Self::Gamepad(gamepad, _) => device::Kind::Gamepad(gamepad),
}
}
pub fn bound(self) -> Binding {
self.with_modifier(1.0)
}
pub fn with_modifier(self, modifier: f32) -> Binding {
Binding {
source: self,
modifier,
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct Binding {
pub source: Source,
pub modifier: f32,
}
impl Binding {
pub(crate) fn apply(&self, event: event::Event) -> event::Event {
let mut event = event;
match &mut event.state {
event::State::ButtonState(_btn_state) => {}
event::State::MouseMove(_x, _y) => {}
event::State::MouseScroll(_x, _y) => {}
event::State::ValueChanged(value) => *value *= self.modifier,
}
event
}
}