My personal project and infrastructure archive
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
nomicon/games/rstnode/rst-client/src/input/traits.rs

42 lines
1.3 KiB

use ggez::event::MouseButton as EzBtn;
/// Encodes a mouse button
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum MouseButton {
/// Left mouse
Left,
/// Right mouse
Right,
/// Middle mouse (or wheel)
Middle,
/// Additional mouse key-codes
Other(u16),
}
impl From<EzBtn> for MouseButton {
fn from(btn: EzBtn) -> Self {
match btn {
EzBtn::Left => Self::Left,
EzBtn::Right => Self::Right,
EzBtn::Middle => Self::Middle,
EzBtn::Other(c) => Self::Other(c),
}
}
}
/// A trait that represents an input event loop connection
///
/// Because `little-input` can be built built against different game
/// framework backends (ggez, ...), this trait abstracts over these
/// different APIs with this trait. This trait is implemented between
/// ggez and the `little-input` event arbiter.
pub trait InputDriver {
/// Mouse button pressed events
fn mouse_down(&mut self, x: f32, y: f32, btn: MouseButton) {}
/// Mouse button released events
fn mouse_up(&mut self, x: f32, y: f32, btn: MouseButton) {}
/// Mouse wheel response
fn scroll(&mut self, f: f32) {}
/// Mouse drag events (toggled by mouse_down events)
fn mouse_drag(&mut self, x: f32, y: f32, btn: MouseButton) {}
}