diff --git a/window/Cargo.toml b/window/Cargo.toml index 4ea77c228..ebb74662d 100644 --- a/window/Cargo.toml +++ b/window/Cargo.toml @@ -8,6 +8,7 @@ description = "Cross platform window setup and render" license = "MIT" [dependencies] +bitflags = "1.0" failure = "0.1" failure_derive = "0.1" lazy_static = "1.3" diff --git a/window/src/input.rs b/window/src/input.rs new file mode 100644 index 000000000..fa358ec91 --- /dev/null +++ b/window/src/input.rs @@ -0,0 +1,135 @@ +use bitflags::*; + +/// Which key is pressed. Not all of these are probable to appear +/// on most systems. A lot of this list is @wez trawling docs and +/// making an entry for things that might be possible in this first pass. +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum KeyCode { + /// The decoded unicode character + Char(char), + + Hyper, + Super, + Meta, + + /// Ctrl-break on windows + Cancel, + Backspace, + Tab, + Clear, + Enter, + Shift, + Escape, + LeftShift, + RightShift, + Control, + LeftControl, + RightControl, + Alt, + LeftAlt, + RightAlt, + Menu, + LeftMenu, + RightMenu, + Pause, + CapsLock, + PageUp, + PageDown, + End, + Home, + LeftArrow, + RightArrow, + UpArrow, + DownArrow, + Select, + Print, + Execute, + PrintScreen, + Insert, + Delete, + Help, + LeftWindows, + RightWindows, + Applications, + Sleep, + Numpad0, + Numpad1, + Numpad2, + Numpad3, + Numpad4, + Numpad5, + Numpad6, + Numpad7, + Numpad8, + Numpad9, + Multiply, + Add, + Separator, + Subtract, + Decimal, + Divide, + /// F1-F24 are possible + Function(u8), + NumLock, + ScrollLock, + BrowserBack, + BrowserForward, + BrowserRefresh, + BrowserStop, + BrowserSearch, + BrowserFavorites, + BrowserHome, + VolumeMute, + VolumeDown, + VolumeUp, + MediaNextTrack, + MediaPrevTrack, + MediaStop, + MediaPlayPause, + ApplicationLeftArrow, + ApplicationRightArrow, + ApplicationUpArrow, + ApplicationDownArrow, +} + +bitflags! { + #[derive(Default)] + pub struct Modifiers: u8 { + const NONE = 0; + const SHIFT = 1<<1; + const ALT = 1<<2; + const CTRL = 1<<3; + const SUPER = 1<<4; + } +} +bitflags! { + #[derive(Default)] + pub struct MouseButtons: u8 { + const NONE = 0; + const LEFT = 1<<1; + const RIGHT = 1<<2; + const MIDDLE = 1<<3; + const VERT_WHEEL = 1<<4; + const HORZ_WHEEL = 1<<5; + /// if set then the wheel movement was in the positive + /// direction, else the negative direction + const WHEEL_POSITIVE = 1<<6; + } +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct MouseEvent { + pub x: u16, + pub y: u16, + pub mouse_buttons: MouseButtons, + pub modifiers: Modifiers, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct KeyEvent { + /// Which key was pressed + pub key: KeyCode, + + /// Which modifiers are down + pub modifiers: Modifiers, +} diff --git a/window/src/lib.rs b/window/src/lib.rs index 9063d3ceb..32c287148 100644 --- a/window/src/lib.rs +++ b/window/src/lib.rs @@ -1,10 +1,12 @@ pub mod bitmaps; pub mod color; +pub mod input; pub mod os; pub use bitmaps::BitmapImage; pub use color::Color; +pub use input::*; pub use os::*; /// Compositing operator.