aboutsummaryrefslogtreecommitdiff
path: root/src/button.rs
diff options
context:
space:
mode:
authorArne Dußin2021-01-17 13:33:04 +0100
committerArne Dußin2021-01-17 13:33:04 +0100
commit51b7747e62c189d430318c67368a5c84e50ece61 (patch)
tree328be6230d392027eb106fd963b5ec97b9034f9f /src/button.rs
parentb1179849c28e50c39ac3c94af9dda86ee24beca0 (diff)
downloadgraf_karto-51b7747e62c189d430318c67368a5c84e50ece61.tar.gz
graf_karto-51b7747e62c189d430318c67368a5c84e50ece61.zip
Input revamp to make keybindings controlable.input
Diffstat (limited to 'src/button.rs')
-rw-r--r--src/button.rs183
1 files changed, 0 insertions, 183 deletions
diff --git a/src/button.rs b/src/button.rs
deleted file mode 100644
index 846377e..0000000
--- a/src/button.rs
+++ /dev/null
@@ -1,183 +0,0 @@
-//! Reimplementation crate of the KeyboardKey and MouseButton structs of raylib, because they do
-//! not implement `serde::Serialize` and `serde::Deserialize`. If you have a better idea on how to
-//! handle it, feel free.
-
-use raylib::ffi::{KeyboardKey as rlKeyboardKey, MouseButton as rlMouseButton};
-use raylib::RaylibHandle;
-use serde::{Deserialize, Serialize};
-use std::mem;
-
-/// Enum to abstract the distinction of keyboard keys and mouse keys that raylib does away so the
-/// user has free reign over what key they use for what purpose.
-#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum Button {
- /// Button on the mouse with internal mouse button representation of raylib.
- Mouse(MouseButton),
- /// Keyboard button with internal keyboard key representation of raylib.
- Keyboard(KeyboardKey),
-}
-
-#[allow(missing_docs)]
-#[repr(u32)]
-#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum MouseButton {
- Left = 0,
- Right = 1,
- Middle = 2,
-}
-
-#[allow(missing_docs)]
-#[repr(u32)]
-#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum KeyboardKey {
- Apostrophe = 39,
- Comma = 44,
- Minus = 45,
- Period = 46,
- Slash = 47,
- Zero = 48,
- One = 49,
- Two = 50,
- Three = 51,
- Four = 52,
- Five = 53,
- Six = 54,
- Seven = 55,
- Eight = 56,
- Nine = 57,
- Semicolon = 59,
- Equal = 61,
- A = 65,
- B = 66,
- C = 67,
- D = 68,
- E = 69,
- F = 70,
- G = 71,
- H = 72,
- I = 73,
- J = 74,
- K = 75,
- L = 76,
- M = 77,
- N = 78,
- O = 79,
- P = 80,
- Q = 81,
- R = 82,
- S = 83,
- T = 84,
- U = 85,
- V = 86,
- W = 87,
- X = 88,
- Y = 89,
- Z = 90,
- Space = 32,
- Escape = 256,
- Enter = 257,
- Tab = 258,
- Backspace = 259,
- Insert = 260,
- Delete = 261,
- Right = 262,
- Left = 263,
- Down = 264,
- Up = 265,
- PageUp = 266,
- PageDown = 267,
- Home = 268,
- End = 269,
- CapsLock = 280,
- ScrollLock = 281,
- NumLock = 282,
- PrintScreen = 283,
- Pause = 284,
- F1 = 290,
- F2 = 291,
- F3 = 292,
- F4 = 293,
- F5 = 294,
- F6 = 295,
- F7 = 296,
- F8 = 297,
- F9 = 298,
- F10 = 299,
- F11 = 300,
- F12 = 301,
- LeftShift = 340,
- LeftControl = 341,
- LeftAlt = 342,
- LeftSuper = 343,
- RightShift = 344,
- RightControl = 345,
- RightAlt = 346,
- RightSuper = 347,
- Menu = 348,
- LeftBracket = 91,
- Backslash = 92,
- RightBracket = 93,
- Grave = 96,
- Keypad0 = 320,
- Keypad1 = 321,
- Keypad2 = 322,
- Keypad3 = 323,
- Keypad4 = 324,
- Keypad5 = 325,
- Keypad6 = 326,
- Keypad7 = 327,
- Keypad8 = 328,
- Keypad9 = 329,
- KeypadDecimal = 330,
- KeypadDivide = 331,
- KeypadMultiply = 332,
- KeypadSubtract = 333,
- KeypadAdd = 334,
- KeypadEnter = 335,
- KeypadEqual = 336,
-}
-
-impl Button {
- /// Check if this button is pressed. If `mouse_blocked` is true, mouse buttons are ignored which
- /// is useful when an element has captured the mouse, but other elements are still queried in the
- /// background.
- pub fn is_pressed(self, rl: &RaylibHandle, mouse_blocked: bool) -> bool {
- match self {
- Self::Mouse(button) => !mouse_blocked && rl.is_mouse_button_pressed(button.into()),
- Self::Keyboard(key) => rl.is_key_pressed(key.into()),
- }
- }
-}
-
-impl From<rlMouseButton> for Button {
- fn from(button: rlMouseButton) -> Self {
- Self::Mouse(MouseButton::from(button))
- }
-}
-impl From<rlKeyboardKey> for Button {
- fn from(key: rlKeyboardKey) -> Self {
- Self::Keyboard(KeyboardKey::from(key))
- }
-}
-
-impl From<rlMouseButton> for MouseButton {
- fn from(button: rlMouseButton) -> Self {
- unsafe { mem::transmute(button as u32) }
- }
-}
-impl Into<rlMouseButton> for MouseButton {
- fn into(self) -> rlMouseButton {
- unsafe { mem::transmute(self as u32) }
- }
-}
-
-impl From<rlKeyboardKey> for KeyboardKey {
- fn from(key: rlKeyboardKey) -> Self {
- unsafe { mem::transmute(key as u32) }
- }
-}
-impl Into<rlKeyboardKey> for KeyboardKey {
- fn into(self) -> rlKeyboardKey {
- unsafe { mem::transmute(self as u32) }
- }
-}