From aaa3368ec7be5b1726dba580a44281c04634e973 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Thu, 1 Jun 2023 18:33:29 +0200 Subject: [PATCH 01/29] update winit, fail compilation :+1: --- Cargo.toml | 26 ++++++++++++++++++++++---- crates/bevy_animation/Cargo.toml | 4 +++- crates/bevy_winit/Cargo.toml | 8 +++++--- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 70817549915b7..4672b2474fb4b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,7 +71,11 @@ bevy_asset = ["bevy_internal/bevy_asset"] bevy_audio = ["bevy_internal/bevy_audio"] # Provides cameras and other basic render pipeline features -bevy_core_pipeline = ["bevy_internal/bevy_core_pipeline", "bevy_asset", "bevy_render"] +bevy_core_pipeline = [ + "bevy_internal/bevy_core_pipeline", + "bevy_asset", + "bevy_render", +] # Plugin for dynamic loading (using [libloading](https://crates.io/crates/libloading)) bevy_dynamic_plugin = ["bevy_internal/bevy_dynamic_plugin"] @@ -83,7 +87,12 @@ bevy_gilrs = ["bevy_internal/bevy_gilrs"] bevy_gltf = ["bevy_internal/bevy_gltf", "bevy_asset", "bevy_scene", "bevy_pbr"] # Adds PBR rendering -bevy_pbr = ["bevy_internal/bevy_pbr", "bevy_asset", "bevy_render", "bevy_core_pipeline"] +bevy_pbr = [ + "bevy_internal/bevy_pbr", + "bevy_asset", + "bevy_render", + "bevy_core_pipeline", +] # Provides rendering functionality bevy_render = ["bevy_internal/bevy_render"] @@ -98,7 +107,12 @@ bevy_sprite = ["bevy_internal/bevy_sprite", "bevy_render", "bevy_core_pipeline"] bevy_text = ["bevy_internal/bevy_text"] # A custom ECS-driven UI framework -bevy_ui = ["bevy_internal/bevy_ui", "bevy_core_pipeline", "bevy_text", "bevy_sprite"] +bevy_ui = [ + "bevy_internal/bevy_ui", + "bevy_core_pipeline", + "bevy_text", + "bevy_sprite", +] # winit window and input backend bevy_winit = ["bevy_internal/bevy_winit"] @@ -113,7 +127,11 @@ trace_chrome = ["trace", "bevy_internal/trace_chrome"] trace_tracy = ["trace", "bevy_internal/trace_tracy"] # Tracing support, with memory profiling, exposing a port for Tracy -trace_tracy_memory = ["trace", "bevy_internal/trace_tracy", "bevy_internal/trace_tracy_memory"] +trace_tracy_memory = [ + "trace", + "bevy_internal/trace_tracy", + "bevy_internal/trace_tracy_memory", +] # Tracing support trace = ["bevy_internal/trace"] diff --git a/crates/bevy_animation/Cargo.toml b/crates/bevy_animation/Cargo.toml index 9e781610de1cf..24cce1deb029f 100644 --- a/crates/bevy_animation/Cargo.toml +++ b/crates/bevy_animation/Cargo.toml @@ -14,7 +14,9 @@ bevy_app = { path = "../bevy_app", version = "0.11.0-dev" } bevy_asset = { path = "../bevy_asset", version = "0.11.0-dev" } bevy_core = { path = "../bevy_core", version = "0.11.0-dev" } bevy_math = { path = "../bevy_math", version = "0.11.0-dev" } -bevy_reflect = { path = "../bevy_reflect", version = "0.11.0-dev", features = ["bevy"] } +bevy_reflect = { path = "../bevy_reflect", version = "0.11.0-dev", features = [ + "bevy", +] } bevy_time = { path = "../bevy_time", version = "0.11.0-dev" } bevy_utils = { path = "../bevy_utils", version = "0.11.0-dev" } bevy_ecs = { path = "../bevy_ecs", version = "0.11.0-dev" } diff --git a/crates/bevy_winit/Cargo.toml b/crates/bevy_winit/Cargo.toml index 664c7b05d1d70..f1d7af3705447 100644 --- a/crates/bevy_winit/Cargo.toml +++ b/crates/bevy_winit/Cargo.toml @@ -28,13 +28,15 @@ bevy_utils = { path = "../bevy_utils", version = "0.11.0-dev" } bevy_tasks = { path = "../bevy_tasks", version = "0.11.0-dev" } # other -winit = { version = "0.28", default-features = false } -accesskit_winit = { version = "0.12", default-features = false } +winit = { git = "https://github.com/rust-windowing/winit.git", branch = "master", default-features = false } +accesskit_winit = { git = "https://github.com/Vrixyz/accesskit.git", branch = "winit-main-after-0.28", default-features = false } approx = { version = "0.5", default-features = false } raw-window-handle = "0.5" [target.'cfg(target_os = "android")'.dependencies] -winit = { version = "0.28", default-features = false, features = ["android-native-activity"] } +winit = { git = "https://github.com/rust-windowing/winit.git", branch = "master", default-features = false, features = [ + "android-native-activity", +] } once_cell = "1.11" [target.'cfg(target_arch = "wasm32")'.dependencies] From a93bf05a9d79adb32f90bb7c1766c81dc9684435 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Sat, 3 Jun 2023 05:28:38 +0200 Subject: [PATCH 02/29] compiling ; but using physical key rather than virtual key --- crates/bevy_a11y/Cargo.toml | 3 +- crates/bevy_input/src/keyboard.rs | 765 ++++++++++-------- crates/bevy_window/src/cursor.rs | 152 ++-- crates/bevy_winit/src/converters.rs | 374 +++++---- crates/bevy_winit/src/lib.rs | 10 +- examples/2d/bloom_2d.rs | 28 +- examples/2d/rotation.rs | 6 +- examples/3d/3d_gizmos.rs | 2 +- examples/3d/anti_aliasing.rs | 30 +- examples/3d/atmospheric_fog.rs | 2 +- examples/3d/blend_modes.rs | 12 +- examples/3d/bloom_3d.rs | 28 +- examples/3d/fog.rs | 30 +- examples/3d/lighting.rs | 8 +- examples/3d/parallax_mapping.rs | 8 +- examples/3d/shadow_biases.rs | 32 +- examples/3d/shadow_caster_receiver.rs | 6 +- examples/3d/skybox.rs | 16 +- examples/3d/spotlight.rs | 8 +- examples/3d/tonemapping.rs | 34 +- examples/animation/animated_fox.rs | 10 +- examples/audio/audio_control.rs | 4 +- examples/ecs/run_conditions.rs | 2 +- examples/ecs/state.rs | 8 +- examples/games/alien_cake_addict.rs | 8 +- examples/games/breakout.rs | 4 +- examples/input/keyboard_input.rs | 6 +- examples/input/keyboard_modifiers.rs | 6 +- examples/input/text_input.rs | 4 +- examples/stress_tests/many_foxes.rs | 16 +- examples/stress_tests/many_gizmos.rs | 4 +- .../scene_viewer/camera_controller_plugin.rs | 16 +- .../tools/scene_viewer/scene_viewer_plugin.rs | 10 +- examples/ui/overflow_debug.rs | 4 +- examples/ui/ui_scaling.rs | 4 +- examples/ui/window_fallthrough.rs | 2 +- examples/window/scale_factor_override.rs | 6 +- examples/window/window_resizing.rs | 6 +- examples/window/window_settings.rs | 6 +- 39 files changed, 934 insertions(+), 746 deletions(-) diff --git a/crates/bevy_a11y/Cargo.toml b/crates/bevy_a11y/Cargo.toml index d4957d89c80de..93ed106a769bd 100644 --- a/crates/bevy_a11y/Cargo.toml +++ b/crates/bevy_a11y/Cargo.toml @@ -14,4 +14,5 @@ bevy_app = { path = "../bevy_app", version = "0.11.0-dev" } bevy_derive = { path = "../bevy_derive", version = "0.11.0-dev" } bevy_ecs = { path = "../bevy_ecs", version = "0.11.0-dev" } -accesskit = "0.10" +# accesskit = "0.10" +accesskit = { git = "https://github.com/Vrixyz/accesskit.git", branch = "winit-main-after-0.28" } diff --git a/crates/bevy_input/src/keyboard.rs b/crates/bevy_input/src/keyboard.rs index a792bc0f4b4df..253d658f40372 100644 --- a/crates/bevy_input/src/keyboard.rs +++ b/crates/bevy_input/src/keyboard.rs @@ -23,9 +23,9 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; )] pub struct KeyboardInput { /// The scan code of the key. - pub scan_code: u32, + pub scan_code: Option, /// The key code of the key. - pub key_code: Option, + pub key_code: KeyCode, /// The press state of the key. pub state: ButtonState, } @@ -48,16 +48,16 @@ pub fn keyboard_input_system( let KeyboardInput { scan_code, state, .. } = event; - if let Some(key_code) = event.key_code { + match state { + ButtonState::Pressed => key_input.press(event.key_code), + ButtonState::Released => key_input.release(event.key_code), + } + if let Some(scan_code) = *scan_code { match state { - ButtonState::Pressed => key_input.press(key_code), - ButtonState::Released => key_input.release(key_code), + ButtonState::Pressed => scan_input.press(ScanCode(scan_code)), + ButtonState::Released => scan_input.release(ScanCode(scan_code)), } } - match state { - ButtonState::Pressed => scan_input.press(ScanCode(*scan_code)), - ButtonState::Released => scan_input.release(ScanCode(*scan_code)), - } } } @@ -71,6 +71,10 @@ pub fn keyboard_input_system( /// ## Updating /// /// The resource is updated inside of the [`keyboard_input_system`](crate::keyboard::keyboard_input_system). +/// +/// ## Technical +/// +/// Its values map 1 to 1 to winit's KeyCode. #[derive(Debug, Hash, Ord, PartialOrd, PartialEq, Eq, Clone, Copy, Reflect, FromReflect)] #[reflect(Debug, Hash, PartialEq)] #[cfg_attr( @@ -80,352 +84,453 @@ pub fn keyboard_input_system( )] #[repr(u32)] pub enum KeyCode { - /// The `1` key over the letters. - Key1, - /// The `2` key over the letters. - Key2, - /// The `3` key over the letters. - Key3, - /// The `4` key over the letters. - Key4, - /// The `5` key over the letters. - Key5, - /// The `6` key over the letters. - Key6, - /// The `7` key over the letters. - Key7, - /// The `8` key over the letters. - Key8, - /// The `9` key over the letters. - Key9, - /// The `0` key over the letters. - Key0, - - /// The `A` key. - A, - /// The `B` key. - B, - /// The `C` key. - C, - /// The `D` key. - D, - /// The `E` key. - E, - /// The `F` key. - F, - /// The `G` key. - G, - /// The `H` key. - H, - /// The `I` key. - I, - /// The `J` key. - J, - /// The `K` key. - K, - /// The `L` key. - L, - /// The `M` key. - M, - /// The `N` key. - N, - /// The `O` key. - O, - /// The `P` key. - P, - /// The `Q` key. - Q, - /// The `R` key. - R, - /// The `S` key. - S, - /// The `T` key. - T, - /// The `U` key. - U, - /// The `V` key. - V, - /// The `W` key. - W, - /// The `X` key. - X, - /// The `Y` key. - Y, - /// The `Z` key. - Z, - - /// The `Escape` / `ESC` key, next to the `F1` key. + /// This variant is used when the key cannot be translated to any other variant. + /// + /// The native keycode is provided (if available) so you're able to more reliably match + /// key-press and key-release events by hashing the [`KeyCode`]. It is also possible to use + /// this for keybinds for non-standard keys, but such keybinds are tied to a given platform. + Unidentified, + /// ` on a US keyboard. This is also called a backtick or grave. + /// This is the 半角/全角/漢字 + /// (hankaku/zenkaku/kanji) key on Japanese keyboards + Backquote, + /// Used for both the US \\ (on the 101-key layout) and also for the key + /// located between the " and Enter keys on row C of the 102-, + /// 104- and 106-key layouts. + /// Labeled # on a UK (102) keyboard. + Backslash, + /// [ on a US keyboard. + BracketLeft, + /// ] on a US keyboard. + BracketRight, + /// , on a US keyboard. + Comma, + /// 0 on a US keyboard. + Digit0, + /// 1 on a US keyboard. + Digit1, + /// 2 on a US keyboard. + Digit2, + /// 3 on a US keyboard. + Digit3, + /// 4 on a US keyboard. + Digit4, + /// 5 on a US keyboard. + Digit5, + /// 6 on a US keyboard. + Digit6, + /// 7 on a US keyboard. + Digit7, + /// 8 on a US keyboard. + Digit8, + /// 9 on a US keyboard. + Digit9, + /// = on a US keyboard. + Equal, + /// Located between the left Shift and Z keys. + /// Labeled \\ on a UK keyboard. + IntlBackslash, + /// Located between the / and right Shift keys. + /// Labeled \\ (ro) on a Japanese keyboard. + IntlRo, + /// Located between the = and Backspace keys. + /// Labeled ¥ (yen) on a Japanese keyboard. \\ on a + /// Russian keyboard. + IntlYen, + /// a on a US keyboard. + /// Labeled q on an AZERTY (e.g., French) keyboard. + KeyA, + /// b on a US keyboard. + KeyB, + /// c on a US keyboard. + KeyC, + /// d on a US keyboard. + KeyD, + /// e on a US keyboard. + KeyE, + /// f on a US keyboard. + KeyF, + /// g on a US keyboard. + KeyG, + /// h on a US keyboard. + KeyH, + /// i on a US keyboard. + KeyI, + /// j on a US keyboard. + KeyJ, + /// k on a US keyboard. + KeyK, + /// l on a US keyboard. + KeyL, + /// m on a US keyboard. + KeyM, + /// n on a US keyboard. + KeyN, + /// o on a US keyboard. + KeyO, + /// p on a US keyboard. + KeyP, + /// q on a US keyboard. + /// Labeled a on an AZERTY (e.g., French) keyboard. + KeyQ, + /// r on a US keyboard. + KeyR, + /// s on a US keyboard. + KeyS, + /// t on a US keyboard. + KeyT, + /// u on a US keyboard. + KeyU, + /// v on a US keyboard. + KeyV, + /// w on a US keyboard. + /// Labeled z on an AZERTY (e.g., French) keyboard. + KeyW, + /// x on a US keyboard. + KeyX, + /// y on a US keyboard. + /// Labeled z on a QWERTZ (e.g., German) keyboard. + KeyY, + /// z on a US keyboard. + /// Labeled w on an AZERTY (e.g., French) keyboard, and y on a + /// QWERTZ (e.g., German) keyboard. + KeyZ, + /// - on a US keyboard. + Minus, + /// . on a US keyboard. + Period, + /// ' on a US keyboard. + Quote, + /// ; on a US keyboard. + Semicolon, + /// / on a US keyboard. + Slash, + /// Alt, Option, or . + AltLeft, + /// Alt, Option, or . + /// This is labeled AltGr on many keyboard layouts. + AltRight, + /// Backspace or . + /// Labeled Delete on Apple keyboards. + Backspace, + /// CapsLock or + CapsLock, + /// The application context menu key, which is typically found between the right + /// Super key and the right Control key. + ContextMenu, + /// Control or + ControlLeft, + /// Control or + ControlRight, + /// Enter or . Labeled Return on Apple keyboards. + Enter, + /// The Windows, , Command, or other OS symbol key. + SuperLeft, + /// The Windows, , Command, or other OS symbol key. + SuperRight, + /// Shift or + ShiftLeft, + /// Shift or + ShiftRight, + ///   (space) + Space, + /// Tab or + Tab, + /// Japanese: (henkan) + Convert, + /// Japanese: カタカナ/ひらがな/ローマ字 (katakana/hiragana/romaji) + KanaMode, + /// Korean: HangulMode 한/영 (han/yeong) + /// + /// Japanese (Mac keyboard): (kana) + Lang1, + /// Korean: Hanja (hanja) + /// + /// Japanese (Mac keyboard): (eisu) + Lang2, + /// Japanese (word-processing keyboard): Katakana + Lang3, + /// Japanese (word-processing keyboard): Hiragana + Lang4, + /// Japanese (word-processing keyboard): Zenkaku/Hankaku + Lang5, + /// Japanese: 無変換 (muhenkan) + NonConvert, + /// . The forward delete key. + /// Note that on Apple keyboards, the key labelled Delete on the main part of + /// the keyboard is encoded as [`Backspace`]. + /// + /// [`Backspace`]: Self::Backspace + Delete, + /// Page Down, End, or + End, + /// Help. Not present on standard PC keyboards. + Help, + /// Home or + Home, + /// Insert or Ins. Not present on Apple keyboards. + Insert, + /// Page Down, PgDn, or + PageDown, + /// Page Up, PgUp, or + PageUp, + /// + ArrowDown, + /// + ArrowLeft, + /// + ArrowRight, + /// + ArrowUp, + /// On the Mac, this is used for the numpad Clear key. + NumLock, + /// 0 Ins on a keyboard. 0 on a phone or remote control + Numpad0, + /// 1 End on a keyboard. 1 or 1 QZ on a phone or remote control + Numpad1, + /// 2 ↓ on a keyboard. 2 ABC on a phone or remote control + Numpad2, + /// 3 PgDn on a keyboard. 3 DEF on a phone or remote control + Numpad3, + /// 4 ← on a keyboard. 4 GHI on a phone or remote control + Numpad4, + /// 5 on a keyboard. 5 JKL on a phone or remote control + Numpad5, + /// 6 → on a keyboard. 6 MNO on a phone or remote control + Numpad6, + /// 7 Home on a keyboard. 7 PQRS or 7 PRS on a phone + /// or remote control + Numpad7, + /// 8 ↑ on a keyboard. 8 TUV on a phone or remote control + Numpad8, + /// 9 PgUp on a keyboard. 9 WXYZ or 9 WXY on a phone + /// or remote control + Numpad9, + /// + + NumpadAdd, + /// Found on the Microsoft Natural Keyboard. + NumpadBackspace, + /// C or A (All Clear). Also for use with numpads that have a + /// Clear key that is separate from the NumLock key. On the Mac, the + /// numpad Clear key is encoded as [`NumLock`]. + /// + /// [`NumLock`]: Self::NumLock + NumpadClear, + /// C (Clear Entry) + NumpadClearEntry, + /// , (thousands separator). For locales where the thousands separator + /// is a "." (e.g., Brazil), this key may generate a .. + NumpadComma, + /// . Del. For locales where the decimal separator is "," (e.g., + /// Brazil), this key may generate a ,. + NumpadDecimal, + /// / + NumpadDivide, + NumpadEnter, + /// = + NumpadEqual, + /// # on a phone or remote control device. This key is typically found + /// below the 9 key and to the right of the 0 key. + NumpadHash, + /// M Add current entry to the value stored in memory. + NumpadMemoryAdd, + /// M Clear the value stored in memory. + NumpadMemoryClear, + /// M Replace the current entry with the value stored in memory. + NumpadMemoryRecall, + /// M Replace the value stored in memory with the current entry. + NumpadMemoryStore, + /// M Subtract current entry from the value stored in memory. + NumpadMemorySubtract, + /// * on a keyboard. For use with numpads that provide mathematical + /// operations (+, - * and /). + /// + /// Use `NumpadStar` for the * key on phones and remote controls. + NumpadMultiply, + /// ( Found on the Microsoft Natural Keyboard. + NumpadParenLeft, + /// ) Found on the Microsoft Natural Keyboard. + NumpadParenRight, + /// * on a phone or remote control device. + /// + /// This key is typically found below the 7 key and to the left of + /// the 0 key. + /// + /// Use "NumpadMultiply" for the * key on + /// numeric keypads. + NumpadStar, + /// - + NumpadSubtract, + /// Esc or Escape, - - /// The `F1` key. + /// Fn This is typically a hardware key that does not generate a separate code. + Fn, + /// FLock or FnLock. Function Lock key. Found on the Microsoft + /// Natural Keyboard. + FnLock, + /// PrtScr SysRq or Print Screen + PrintScreen, + /// Scroll Lock + ScrollLock, + /// Pause Break + Pause, + /// Some laptops place this key to the left of the key. + /// + /// This also the "back" button (triangle) on Android. + BrowserBack, + BrowserFavorites, + /// Some laptops place this key to the right of the key. + BrowserForward, + /// The "home" button on Android. + BrowserHome, + BrowserRefresh, + BrowserSearch, + BrowserStop, + /// Eject or . This key is placed in the function section on some Apple + /// keyboards. + Eject, + /// Sometimes labelled My Computer on the keyboard + LaunchApp1, + /// Sometimes labelled Calculator on the keyboard + LaunchApp2, + LaunchMail, + MediaPlayPause, + MediaSelect, + MediaStop, + MediaTrackNext, + MediaTrackPrevious, + /// This key is placed in the function section on some Apple keyboards, replacing the + /// Eject key. + Power, + Sleep, + AudioVolumeDown, + AudioVolumeMute, + AudioVolumeUp, + WakeUp, + // Legacy modifier key. Also called "Super" in certain places. + Meta, + // Legacy modifier key. + Hyper, + Turbo, + Abort, + Resume, + Suspend, + /// Found on Sun’s USB keyboard. + Again, + /// Found on Sun’s USB keyboard. + Copy, + /// Found on Sun’s USB keyboard. + Cut, + /// Found on Sun’s USB keyboard. + Find, + /// Found on Sun’s USB keyboard. + Open, + /// Found on Sun’s USB keyboard. + Paste, + /// Found on Sun’s USB keyboard. + Props, + /// Found on Sun’s USB keyboard. + Select, + /// Found on Sun’s USB keyboard. + Undo, + /// Use for dedicated ひらがな key found on some Japanese word processing keyboards. + Hiragana, + /// Use for dedicated カタカナ key found on some Japanese word processing keyboards. + Katakana, + /// General-purpose function key. + /// Usually found at the top of the keyboard. F1, - /// The `F2` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F2, - /// The `F3` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F3, - /// The `F4` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F4, - /// The `F5` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F5, - /// The `F6` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F6, - /// The `F7` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F7, - /// The `F8` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F8, - /// The `F9` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F9, - /// The `F10` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F10, - /// The `F11` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F11, - /// The `F12` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F12, - /// The `F13` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F13, - /// The `F14` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F14, - /// The `F15` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F15, - /// The `F16` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F16, - /// The `F17` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F17, - /// The `F18` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F18, - /// The `F19` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F19, - /// The `F20` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F20, - /// The `F21` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F21, - /// The `F22` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F22, - /// The `F23` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F23, - /// The `F24` key. + /// General-purpose function key. + /// Usually found at the top of the keyboard. F24, - - /// The `Snapshot` / `Print Screen` key. - Snapshot, - /// The `Scroll` / `Scroll Lock` key. - Scroll, - /// The `Pause` / `Break` key, next to the `Scroll` key. - Pause, - - /// The `Insert` key, next to the `Backspace` key. - Insert, - /// The `Home` key. - Home, - /// The `Delete` key. - Delete, - /// The `End` key. - End, - /// The `PageDown` key. - PageDown, - /// The `PageUp` key. - PageUp, - - /// The `Left` / `Left Arrow` key. - Left, - /// The `Up` / `Up Arrow` key. - Up, - /// The `Right` / `Right Arrow` key. - Right, - /// The `Down` / `Down Arrow` key. - Down, - - /// The `Back` / `Backspace` key. - Back, - /// The `Return` / `Enter` key. - Return, - /// The `Space` / `Spacebar` / ` ` key. - Space, - - /// The `Compose` key on Linux. - Compose, - /// The `Caret` / `^` key. - Caret, - - /// The `Numlock` key. - Numlock, - /// The `Numpad0` / `0` key. - Numpad0, - /// The `Numpad1` / `1` key. - Numpad1, - /// The `Numpad2` / `2` key. - Numpad2, - /// The `Numpad3` / `3` key. - Numpad3, - /// The `Numpad4` / `4` key. - Numpad4, - /// The `Numpad5` / `5` key. - Numpad5, - /// The `Numpad6` / `6` key. - Numpad6, - /// The `Numpad7` / `7` key. - Numpad7, - /// The `Numpad8` / `8` key. - Numpad8, - /// The `Numpad9` / `9` key. - Numpad9, - - /// The `AbntC1` key. - AbntC1, - /// The `AbntC2` key. - AbntC2, - - /// The `NumpadAdd` / `+` key. - NumpadAdd, - /// The `Apostrophe` / `'` key. - Apostrophe, - /// The `Apps` key. - Apps, - /// The `Asterisk` / `*` key. - Asterisk, - /// The `Plus` / `+` key. - Plus, - /// The `At` / `@` key. - At, - /// The `Ax` key. - Ax, - /// The `Backslash` / `\` key. - Backslash, - /// The `Calculator` key. - Calculator, - /// The `Capital` key. - Capital, - /// The `Colon` / `:` key. - Colon, - /// The `Comma` / `,` key. - Comma, - /// The `Convert` key. - Convert, - /// The `NumpadDecimal` / `.` key. - NumpadDecimal, - /// The `NumpadDivide` / `/` key. - NumpadDivide, - /// The `Equals` / `=` key. - Equals, - /// The `Grave` / `Backtick` / `` ` `` key. - Grave, - /// The `Kana` key. - Kana, - /// The `Kanji` key. - Kanji, - - /// The `LAlt` / `Left Alt` key. Maps to `Left Option` on Mac. - LAlt, - /// The `LBracket` / `Left Bracket` key. - LBracket, - /// The `LControl` / `Left Control` key. - LControl, - /// The `LShift` / `Left Shift` key. - LShift, - /// The `LWin` / `Left Windows` key. Maps to `Left Command` on Mac. - LWin, - - /// The `Mail` key. - Mail, - /// The `MediaSelect` key. - MediaSelect, - /// The `MediaStop` key. - MediaStop, - /// The `Minus` / `-` key. - Minus, - /// The `NumpadMultiply` / `*` key. - NumpadMultiply, - /// The `Mute` key. - Mute, - /// The `MyComputer` key. - MyComputer, - /// The `NavigateForward` / `Prior` key. - NavigateForward, - /// The `NavigateBackward` / `Next` key. - NavigateBackward, - /// The `NextTrack` key. - NextTrack, - /// The `NoConvert` key. - NoConvert, - /// The `NumpadComma` / `,` key. - NumpadComma, - /// The `NumpadEnter` key. - NumpadEnter, - /// The `NumpadEquals` / `=` key. - NumpadEquals, - /// The `Oem102` key. - Oem102, - /// The `Period` / `.` key. - Period, - /// The `PlayPause` key. - PlayPause, - /// The `Power` key. - Power, - /// The `PrevTrack` key. - PrevTrack, - - /// The `RAlt` / `Right Alt` key. Maps to `Right Option` on Mac. - RAlt, - /// The `RBracket` / `Right Bracket` key. - RBracket, - /// The `RControl` / `Right Control` key. - RControl, - /// The `RShift` / `Right Shift` key. - RShift, - /// The `RWin` / `Right Windows` key. Maps to `Right Command` on Mac. - RWin, - - /// The `Semicolon` / `;` key. - Semicolon, - /// The `Slash` / `/` key. - Slash, - /// The `Sleep` key. - Sleep, - /// The `Stop` key. - Stop, - /// The `NumpadSubtract` / `-` key. - NumpadSubtract, - /// The `Sysrq` key. - Sysrq, - /// The `Tab` / ` ` key. - Tab, - /// The `Underline` / `_` key. - Underline, - /// The `Unlabeled` key. - Unlabeled, - - /// The `VolumeDown` key. - VolumeDown, - /// The `VolumeUp` key. - VolumeUp, - - /// The `Wake` key. - Wake, - - /// The `WebBack` key. - WebBack, - /// The `WebFavorites` key. - WebFavorites, - /// The `WebForward` key. - WebForward, - /// The `WebHome` key. - WebHome, - /// The `WebRefresh` key. - WebRefresh, - /// The `WebSearch` key. - WebSearch, - /// The `WebStop` key. - WebStop, - - /// The `Yen` key. - Yen, - - /// The `Copy` key. - Copy, - /// The `Paste` key. - Paste, - /// The `Cut` key. - Cut, + /// General-purpose function key. + F25, + /// General-purpose function key. + F26, + /// General-purpose function key. + F27, + /// General-purpose function key. + F28, + /// General-purpose function key. + F29, + /// General-purpose function key. + F30, + /// General-purpose function key. + F31, + /// General-purpose function key. + F32, + /// General-purpose function key. + F33, + /// General-purpose function key. + F34, + /// General-purpose function key. + F35, } /// The scan code of a [`KeyboardInput`](crate::keyboard::KeyboardInput). diff --git a/crates/bevy_window/src/cursor.rs b/crates/bevy_window/src/cursor.rs index 17e4dce56b892..9ed581600a663 100644 --- a/crates/bevy_window/src/cursor.rs +++ b/crates/bevy_window/src/cursor.rs @@ -9,85 +9,137 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; /// This `enum` is simply a copy of a similar `enum` found in [`winit`](https://docs.rs/winit/latest/winit/window/enum.CursorIcon.html). /// `winit`, in turn, mostly copied cursor types available in the browser. #[derive(Default, Debug, Hash, PartialEq, Eq, Clone, Copy, Reflect, FromReflect)] +#[non_exhaustive] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), reflect(Serialize, Deserialize) )] -#[reflect(Debug, PartialEq, Default)] pub enum CursorIcon { - /// The platform-dependent default cursor. + /// The platform-dependent default cursor. Often rendered as arrow. #[default] Default, - /// A simple crosshair. - Crosshair, - /// A hand (often used to indicate links in web browsers). - Hand, - /// An arrow. This is the default cursor on most systems. - Arrow, - /// Indicates something is to be moved. - Move, - /// Indicates text that may be selected or edited. - Text, - /// Program busy indicator. - Wait, - /// Help indicator (often rendered as a "?") + + /// A context menu is available for the object under the cursor. Often + /// rendered as an arrow with a small menu-like graphic next to it. + ContextMenu, + + /// Help is available for the object under the cursor. Often rendered as a + /// question mark or a balloon. Help, - /// Progress indicator. Shows that processing is being done. - /// - /// But in contrast with "Wait" the user may still interact with the program. - /// Often rendered as a spinning beach ball, or an arrow with a watch or hourglass. + + /// The cursor is a pointer that indicates a link. Often rendered as the + /// backside of a hand with the index finger extended. + Pointer, + + /// A progress indicator. The program is performing some processing, but is + /// different from [`CursorIcon::Wait`] in that the user may still interact + /// with the program. Progress, - /// Cursor showing that something cannot be done. - NotAllowed, - /// Indicates that a context menu is available. - ContextMenu, - /// Indicates that a cell (or set of cells) may be selected. + + /// Indicates that the program is busy and the user should wait. Often + /// rendered as a watch or hourglass. + Wait, + + /// Indicates that a cell or set of cells may be selected. Often rendered as + /// a thick plus-sign with a dot in the middle. Cell, - /// Indicates vertical text that may be selected or edited. + + /// A simple crosshair (e.g., short line segments resembling a "+" sign). + /// Often used to indicate a two dimensional bitmap selection mode. + Crosshair, + + /// Indicates text that may be selected. Often rendered as an I-beam. + Text, + + /// Indicates vertical-text that may be selected. Often rendered as a + /// horizontal I-beam. VerticalText, - /// Indicates that an alias of something is to be created. + + /// Indicates an alias of/shortcut to something is to be created. Often + /// rendered as an arrow with a small curved arrow next to it. Alias, - /// Indicates something is to be copied. + + /// Indicates something is to be copied. Often rendered as an arrow with a + /// small plus sign next to it. Copy, - /// Indicates that the dragged item cannot be dropped here. + + /// Indicates something is to be moved. + Move, + + /// Indicates that the dragged item cannot be dropped at the current cursor + /// location. Often rendered as a hand or pointer with a small circle with a + /// line through it. NoDrop, - /// Indicates that something can be grabbed. + + /// Indicates that the requested action will not be carried out. Often + /// rendered as a circle with a line through it. + NotAllowed, + + /// Indicates that something can be grabbed (dragged to be moved). Often + /// rendered as the backside of an open hand. Grab, - /// Indicates that something is grabbed. + + /// Indicates that something is being grabbed (dragged to be moved). Often + /// rendered as the backside of a hand with fingers closed mostly out of + /// view. Grabbing, - /// Indicates that the user can scroll by dragging the mouse. - AllScroll, - /// Indicates that the user can zoom in. - ZoomIn, - /// Indicates that the user can zoom out. - ZoomOut, - /// Indicates that an edge of a box is to be moved right (east). + + /// The east border to be moved. EResize, - /// Indicates that an edge of a box is to be moved up (north). + + /// The north border to be moved. NResize, - /// Indicates that an edge of a box is to be moved up and right (north/east). + + /// The north-east corner to be moved. NeResize, - /// indicates that an edge of a box is to be moved up and left (north/west). + + /// The north-west corner to be moved. NwResize, - /// Indicates that an edge of a box is to be moved down (south). + + /// The south border to be moved. SResize, - /// The cursor indicates that an edge of a box is to be moved down and right (south/east). + + /// The south-east corner to be moved. SeResize, - /// The cursor indicates that an edge of a box is to be moved down and left (south/west). + + /// The south-west corner to be moved. SwResize, - /// Indicates that an edge of a box is to be moved left (west). + + /// The west border to be moved. WResize, - /// Indicates a bidirectional resize cursor. + + /// The east and west borders to be moved. EwResize, - /// Indicates a bidirectional resize cursor. + + /// The south and north borders to be moved. NsResize, - /// Indicates a bidirectional resize cursor. + + /// The north-east and south-west corners to be moved. NeswResize, - /// Indicates a bidirectional resize cursor. + + /// The north-west and south-east corners to be moved. NwseResize, - /// Indicates that a column can be resized horizontally. + + /// Indicates that the item/column can be resized horizontally. Often + /// rendered as arrows pointing left and right with a vertical bar + /// separating them. ColResize, - /// Indicates that the row can be resized vertically. + + /// Indicates that the item/row can be resized vertically. Often rendered as + /// arrows pointing up and down with a horizontal bar separating them. RowResize, + + /// Indicates that the something can be scrolled in any direction. Often + /// rendered as arrows pointing up, down, left, and right with a dot in the + /// middle. + AllScroll, + + /// Indicates that something can be zoomed in. Often rendered as a + /// magnifying glass with a "+" in the center of the glass. + ZoomIn, + + /// Indicates that something can be zoomed in. Often rendered as a + /// magnifying glass with a "-" in the center of the glass. + ZoomOut, } diff --git a/crates/bevy_winit/src/converters.rs b/crates/bevy_winit/src/converters.rs index 6da825eb03ae5..a19fb4fc4e5bf 100644 --- a/crates/bevy_winit/src/converters.rs +++ b/crates/bevy_winit/src/converters.rs @@ -6,12 +6,13 @@ use bevy_input::{ }; use bevy_math::Vec2; use bevy_window::{CursorIcon, WindowLevel}; +use winit::{keyboard::Key, platform::scancode::KeyCodeExtScancode}; -pub fn convert_keyboard_input(keyboard_input: &winit::event::KeyboardInput) -> KeyboardInput { +pub fn convert_keyboard_input(keyboard_input: &winit::event::KeyEvent) -> KeyboardInput { KeyboardInput { - scan_code: keyboard_input.scancode, + scan_code: keyboard_input.physical_key.to_scancode(), state: convert_element_state(keyboard_input.state), - key_code: keyboard_input.virtual_keycode.map(convert_virtual_key_code), + key_code: convert_virtual_key_code(keyboard_input.physical_key), } } @@ -59,171 +60,205 @@ pub fn convert_touch_input( } } -pub fn convert_virtual_key_code(virtual_key_code: winit::event::VirtualKeyCode) -> KeyCode { +pub fn convert_virtual_key_code(virtual_key_code: winit::keyboard::KeyCode) -> KeyCode { match virtual_key_code { - winit::event::VirtualKeyCode::Key1 => KeyCode::Key1, - winit::event::VirtualKeyCode::Key2 => KeyCode::Key2, - winit::event::VirtualKeyCode::Key3 => KeyCode::Key3, - winit::event::VirtualKeyCode::Key4 => KeyCode::Key4, - winit::event::VirtualKeyCode::Key5 => KeyCode::Key5, - winit::event::VirtualKeyCode::Key6 => KeyCode::Key6, - winit::event::VirtualKeyCode::Key7 => KeyCode::Key7, - winit::event::VirtualKeyCode::Key8 => KeyCode::Key8, - winit::event::VirtualKeyCode::Key9 => KeyCode::Key9, - winit::event::VirtualKeyCode::Key0 => KeyCode::Key0, - winit::event::VirtualKeyCode::A => KeyCode::A, - winit::event::VirtualKeyCode::B => KeyCode::B, - winit::event::VirtualKeyCode::C => KeyCode::C, - winit::event::VirtualKeyCode::D => KeyCode::D, - winit::event::VirtualKeyCode::E => KeyCode::E, - winit::event::VirtualKeyCode::F => KeyCode::F, - winit::event::VirtualKeyCode::G => KeyCode::G, - winit::event::VirtualKeyCode::H => KeyCode::H, - winit::event::VirtualKeyCode::I => KeyCode::I, - winit::event::VirtualKeyCode::J => KeyCode::J, - winit::event::VirtualKeyCode::K => KeyCode::K, - winit::event::VirtualKeyCode::L => KeyCode::L, - winit::event::VirtualKeyCode::M => KeyCode::M, - winit::event::VirtualKeyCode::N => KeyCode::N, - winit::event::VirtualKeyCode::O => KeyCode::O, - winit::event::VirtualKeyCode::P => KeyCode::P, - winit::event::VirtualKeyCode::Q => KeyCode::Q, - winit::event::VirtualKeyCode::R => KeyCode::R, - winit::event::VirtualKeyCode::S => KeyCode::S, - winit::event::VirtualKeyCode::T => KeyCode::T, - winit::event::VirtualKeyCode::U => KeyCode::U, - winit::event::VirtualKeyCode::V => KeyCode::V, - winit::event::VirtualKeyCode::W => KeyCode::W, - winit::event::VirtualKeyCode::X => KeyCode::X, - winit::event::VirtualKeyCode::Y => KeyCode::Y, - winit::event::VirtualKeyCode::Z => KeyCode::Z, - winit::event::VirtualKeyCode::Escape => KeyCode::Escape, - winit::event::VirtualKeyCode::F1 => KeyCode::F1, - winit::event::VirtualKeyCode::F2 => KeyCode::F2, - winit::event::VirtualKeyCode::F3 => KeyCode::F3, - winit::event::VirtualKeyCode::F4 => KeyCode::F4, - winit::event::VirtualKeyCode::F5 => KeyCode::F5, - winit::event::VirtualKeyCode::F6 => KeyCode::F6, - winit::event::VirtualKeyCode::F7 => KeyCode::F7, - winit::event::VirtualKeyCode::F8 => KeyCode::F8, - winit::event::VirtualKeyCode::F9 => KeyCode::F9, - winit::event::VirtualKeyCode::F10 => KeyCode::F10, - winit::event::VirtualKeyCode::F11 => KeyCode::F11, - winit::event::VirtualKeyCode::F12 => KeyCode::F12, - winit::event::VirtualKeyCode::F13 => KeyCode::F13, - winit::event::VirtualKeyCode::F14 => KeyCode::F14, - winit::event::VirtualKeyCode::F15 => KeyCode::F15, - winit::event::VirtualKeyCode::F16 => KeyCode::F16, - winit::event::VirtualKeyCode::F17 => KeyCode::F17, - winit::event::VirtualKeyCode::F18 => KeyCode::F18, - winit::event::VirtualKeyCode::F19 => KeyCode::F19, - winit::event::VirtualKeyCode::F20 => KeyCode::F20, - winit::event::VirtualKeyCode::F21 => KeyCode::F21, - winit::event::VirtualKeyCode::F22 => KeyCode::F22, - winit::event::VirtualKeyCode::F23 => KeyCode::F23, - winit::event::VirtualKeyCode::F24 => KeyCode::F24, - winit::event::VirtualKeyCode::Snapshot => KeyCode::Snapshot, - winit::event::VirtualKeyCode::Scroll => KeyCode::Scroll, - winit::event::VirtualKeyCode::Pause => KeyCode::Pause, - winit::event::VirtualKeyCode::Insert => KeyCode::Insert, - winit::event::VirtualKeyCode::Home => KeyCode::Home, - winit::event::VirtualKeyCode::Delete => KeyCode::Delete, - winit::event::VirtualKeyCode::End => KeyCode::End, - winit::event::VirtualKeyCode::PageDown => KeyCode::PageDown, - winit::event::VirtualKeyCode::PageUp => KeyCode::PageUp, - winit::event::VirtualKeyCode::Left => KeyCode::Left, - winit::event::VirtualKeyCode::Up => KeyCode::Up, - winit::event::VirtualKeyCode::Right => KeyCode::Right, - winit::event::VirtualKeyCode::Down => KeyCode::Down, - winit::event::VirtualKeyCode::Back => KeyCode::Back, - winit::event::VirtualKeyCode::Return => KeyCode::Return, - winit::event::VirtualKeyCode::Space => KeyCode::Space, - winit::event::VirtualKeyCode::Compose => KeyCode::Compose, - winit::event::VirtualKeyCode::Caret => KeyCode::Caret, - winit::event::VirtualKeyCode::Numlock => KeyCode::Numlock, - winit::event::VirtualKeyCode::Numpad0 => KeyCode::Numpad0, - winit::event::VirtualKeyCode::Numpad1 => KeyCode::Numpad1, - winit::event::VirtualKeyCode::Numpad2 => KeyCode::Numpad2, - winit::event::VirtualKeyCode::Numpad3 => KeyCode::Numpad3, - winit::event::VirtualKeyCode::Numpad4 => KeyCode::Numpad4, - winit::event::VirtualKeyCode::Numpad5 => KeyCode::Numpad5, - winit::event::VirtualKeyCode::Numpad6 => KeyCode::Numpad6, - winit::event::VirtualKeyCode::Numpad7 => KeyCode::Numpad7, - winit::event::VirtualKeyCode::Numpad8 => KeyCode::Numpad8, - winit::event::VirtualKeyCode::Numpad9 => KeyCode::Numpad9, - winit::event::VirtualKeyCode::AbntC1 => KeyCode::AbntC1, - winit::event::VirtualKeyCode::AbntC2 => KeyCode::AbntC2, - winit::event::VirtualKeyCode::NumpadAdd => KeyCode::NumpadAdd, - winit::event::VirtualKeyCode::Apostrophe => KeyCode::Apostrophe, - winit::event::VirtualKeyCode::Apps => KeyCode::Apps, - winit::event::VirtualKeyCode::Asterisk => KeyCode::Asterisk, - winit::event::VirtualKeyCode::Plus => KeyCode::Plus, - winit::event::VirtualKeyCode::At => KeyCode::At, - winit::event::VirtualKeyCode::Ax => KeyCode::Ax, - winit::event::VirtualKeyCode::Backslash => KeyCode::Backslash, - winit::event::VirtualKeyCode::Calculator => KeyCode::Calculator, - winit::event::VirtualKeyCode::Capital => KeyCode::Capital, - winit::event::VirtualKeyCode::Colon => KeyCode::Colon, - winit::event::VirtualKeyCode::Comma => KeyCode::Comma, - winit::event::VirtualKeyCode::Convert => KeyCode::Convert, - winit::event::VirtualKeyCode::NumpadDecimal => KeyCode::NumpadDecimal, - winit::event::VirtualKeyCode::NumpadDivide => KeyCode::NumpadDivide, - winit::event::VirtualKeyCode::Equals => KeyCode::Equals, - winit::event::VirtualKeyCode::Grave => KeyCode::Grave, - winit::event::VirtualKeyCode::Kana => KeyCode::Kana, - winit::event::VirtualKeyCode::Kanji => KeyCode::Kanji, - winit::event::VirtualKeyCode::LAlt => KeyCode::LAlt, - winit::event::VirtualKeyCode::LBracket => KeyCode::LBracket, - winit::event::VirtualKeyCode::LControl => KeyCode::LControl, - winit::event::VirtualKeyCode::LShift => KeyCode::LShift, - winit::event::VirtualKeyCode::LWin => KeyCode::LWin, - winit::event::VirtualKeyCode::Mail => KeyCode::Mail, - winit::event::VirtualKeyCode::MediaSelect => KeyCode::MediaSelect, - winit::event::VirtualKeyCode::MediaStop => KeyCode::MediaStop, - winit::event::VirtualKeyCode::Minus => KeyCode::Minus, - winit::event::VirtualKeyCode::NumpadMultiply => KeyCode::NumpadMultiply, - winit::event::VirtualKeyCode::Mute => KeyCode::Mute, - winit::event::VirtualKeyCode::MyComputer => KeyCode::MyComputer, - winit::event::VirtualKeyCode::NavigateForward => KeyCode::NavigateForward, - winit::event::VirtualKeyCode::NavigateBackward => KeyCode::NavigateBackward, - winit::event::VirtualKeyCode::NextTrack => KeyCode::NextTrack, - winit::event::VirtualKeyCode::NoConvert => KeyCode::NoConvert, - winit::event::VirtualKeyCode::NumpadComma => KeyCode::NumpadComma, - winit::event::VirtualKeyCode::NumpadEnter => KeyCode::NumpadEnter, - winit::event::VirtualKeyCode::NumpadEquals => KeyCode::NumpadEquals, - winit::event::VirtualKeyCode::OEM102 => KeyCode::Oem102, - winit::event::VirtualKeyCode::Period => KeyCode::Period, - winit::event::VirtualKeyCode::PlayPause => KeyCode::PlayPause, - winit::event::VirtualKeyCode::Power => KeyCode::Power, - winit::event::VirtualKeyCode::PrevTrack => KeyCode::PrevTrack, - winit::event::VirtualKeyCode::RAlt => KeyCode::RAlt, - winit::event::VirtualKeyCode::RBracket => KeyCode::RBracket, - winit::event::VirtualKeyCode::RControl => KeyCode::RControl, - winit::event::VirtualKeyCode::RShift => KeyCode::RShift, - winit::event::VirtualKeyCode::RWin => KeyCode::RWin, - winit::event::VirtualKeyCode::Semicolon => KeyCode::Semicolon, - winit::event::VirtualKeyCode::Slash => KeyCode::Slash, - winit::event::VirtualKeyCode::Sleep => KeyCode::Sleep, - winit::event::VirtualKeyCode::Stop => KeyCode::Stop, - winit::event::VirtualKeyCode::NumpadSubtract => KeyCode::NumpadSubtract, - winit::event::VirtualKeyCode::Sysrq => KeyCode::Sysrq, - winit::event::VirtualKeyCode::Tab => KeyCode::Tab, - winit::event::VirtualKeyCode::Underline => KeyCode::Underline, - winit::event::VirtualKeyCode::Unlabeled => KeyCode::Unlabeled, - winit::event::VirtualKeyCode::VolumeDown => KeyCode::VolumeDown, - winit::event::VirtualKeyCode::VolumeUp => KeyCode::VolumeUp, - winit::event::VirtualKeyCode::Wake => KeyCode::Wake, - winit::event::VirtualKeyCode::WebBack => KeyCode::WebBack, - winit::event::VirtualKeyCode::WebFavorites => KeyCode::WebFavorites, - winit::event::VirtualKeyCode::WebForward => KeyCode::WebForward, - winit::event::VirtualKeyCode::WebHome => KeyCode::WebHome, - winit::event::VirtualKeyCode::WebRefresh => KeyCode::WebRefresh, - winit::event::VirtualKeyCode::WebSearch => KeyCode::WebSearch, - winit::event::VirtualKeyCode::WebStop => KeyCode::WebStop, - winit::event::VirtualKeyCode::Yen => KeyCode::Yen, - winit::event::VirtualKeyCode::Copy => KeyCode::Copy, - winit::event::VirtualKeyCode::Paste => KeyCode::Paste, - winit::event::VirtualKeyCode::Cut => KeyCode::Cut, + // TOCLEAN: Thierry: we probably want to pass this nativeKeyCode, but then interface it by our own type "NativeKeyCode" + winit::keyboard::KeyCode::Unidentified(native_key_code) => KeyCode::Unidentified, + winit::keyboard::KeyCode::Backquote => KeyCode::Backquote, + winit::keyboard::KeyCode::Backslash => KeyCode::Backslash, + winit::keyboard::KeyCode::BracketLeft => KeyCode::BracketLeft, + winit::keyboard::KeyCode::BracketRight => KeyCode::BracketRight, + winit::keyboard::KeyCode::Comma => KeyCode::Comma, + winit::keyboard::KeyCode::Digit0 => KeyCode::Digit0, + winit::keyboard::KeyCode::Digit1 => KeyCode::Digit1, + winit::keyboard::KeyCode::Digit2 => KeyCode::Digit2, + winit::keyboard::KeyCode::Digit3 => KeyCode::Digit3, + winit::keyboard::KeyCode::Digit4 => KeyCode::Digit4, + winit::keyboard::KeyCode::Digit5 => KeyCode::Digit5, + winit::keyboard::KeyCode::Digit6 => KeyCode::Digit6, + winit::keyboard::KeyCode::Digit7 => KeyCode::Digit7, + winit::keyboard::KeyCode::Digit8 => KeyCode::Digit8, + winit::keyboard::KeyCode::Digit9 => KeyCode::Digit9, + winit::keyboard::KeyCode::Equal => KeyCode::Equal, + winit::keyboard::KeyCode::IntlBackslash => KeyCode::IntlBackslash, + winit::keyboard::KeyCode::IntlRo => KeyCode::IntlRo, + winit::keyboard::KeyCode::IntlYen => KeyCode::IntlYen, + winit::keyboard::KeyCode::KeyA => KeyCode::KeyA, + winit::keyboard::KeyCode::KeyB => KeyCode::KeyB, + winit::keyboard::KeyCode::KeyC => KeyCode::KeyC, + winit::keyboard::KeyCode::KeyD => KeyCode::KeyD, + winit::keyboard::KeyCode::KeyE => KeyCode::KeyE, + winit::keyboard::KeyCode::KeyF => KeyCode::KeyF, + winit::keyboard::KeyCode::KeyG => KeyCode::KeyG, + winit::keyboard::KeyCode::KeyH => KeyCode::KeyH, + winit::keyboard::KeyCode::KeyI => KeyCode::KeyI, + winit::keyboard::KeyCode::KeyJ => KeyCode::KeyJ, + winit::keyboard::KeyCode::KeyK => KeyCode::KeyK, + winit::keyboard::KeyCode::KeyL => KeyCode::KeyL, + winit::keyboard::KeyCode::KeyM => KeyCode::KeyM, + winit::keyboard::KeyCode::KeyN => KeyCode::KeyN, + winit::keyboard::KeyCode::KeyO => KeyCode::KeyO, + winit::keyboard::KeyCode::KeyP => KeyCode::KeyP, + winit::keyboard::KeyCode::KeyQ => KeyCode::KeyQ, + winit::keyboard::KeyCode::KeyR => KeyCode::KeyR, + winit::keyboard::KeyCode::KeyS => KeyCode::KeyS, + winit::keyboard::KeyCode::KeyT => KeyCode::KeyT, + winit::keyboard::KeyCode::KeyU => KeyCode::KeyU, + winit::keyboard::KeyCode::KeyV => KeyCode::KeyV, + winit::keyboard::KeyCode::KeyW => KeyCode::KeyW, + winit::keyboard::KeyCode::KeyX => KeyCode::KeyX, + winit::keyboard::KeyCode::KeyY => KeyCode::KeyY, + winit::keyboard::KeyCode::KeyZ => KeyCode::KeyZ, + winit::keyboard::KeyCode::Minus => KeyCode::Minus, + winit::keyboard::KeyCode::Period => KeyCode::Period, + winit::keyboard::KeyCode::Quote => KeyCode::Quote, + winit::keyboard::KeyCode::Semicolon => KeyCode::Semicolon, + winit::keyboard::KeyCode::Slash => KeyCode::Slash, + winit::keyboard::KeyCode::AltLeft => KeyCode::AltLeft, + winit::keyboard::KeyCode::AltRight => KeyCode::AltRight, + winit::keyboard::KeyCode::Enter => KeyCode::Enter, + winit::keyboard::KeyCode::CapsLock => KeyCode::CapsLock, + winit::keyboard::KeyCode::ContextMenu => KeyCode::ContextMenu, + winit::keyboard::KeyCode::ControlLeft => KeyCode::ControlLeft, + winit::keyboard::KeyCode::ControlRight => KeyCode::ControlRight, + winit::keyboard::KeyCode::Enter => KeyCode::Enter, + winit::keyboard::KeyCode::SuperLeft => KeyCode::SuperLeft, + winit::keyboard::KeyCode::SuperRight => KeyCode::SuperRight, + winit::keyboard::KeyCode::ShiftLeft => KeyCode::ShiftLeft, + winit::keyboard::KeyCode::ShiftRight => KeyCode::ShiftRight, + winit::keyboard::KeyCode::Space => KeyCode::Space, + winit::keyboard::KeyCode::Tab => KeyCode::Tab, + winit::keyboard::KeyCode::Convert => KeyCode::Convert, + winit::keyboard::KeyCode::KanaMode => KeyCode::KanaMode, + winit::keyboard::KeyCode::Lang1 => KeyCode::Lang1, + winit::keyboard::KeyCode::Lang2 => KeyCode::Lang2, + winit::keyboard::KeyCode::Lang3 => KeyCode::Lang3, + winit::keyboard::KeyCode::Lang4 => KeyCode::Lang4, + winit::keyboard::KeyCode::Lang5 => KeyCode::Lang5, + winit::keyboard::KeyCode::NonConvert => KeyCode::NonConvert, + winit::keyboard::KeyCode::Delete => KeyCode::Delete, + winit::keyboard::KeyCode::End => KeyCode::End, + winit::keyboard::KeyCode::Help => KeyCode::Help, + winit::keyboard::KeyCode::Home => KeyCode::Home, + winit::keyboard::KeyCode::Insert => KeyCode::Insert, + winit::keyboard::KeyCode::PageDown => KeyCode::PageDown, + winit::keyboard::KeyCode::PageUp => KeyCode::PageUp, + winit::keyboard::KeyCode::ArrowDown => KeyCode::ArrowDown, + winit::keyboard::KeyCode::ArrowLeft => KeyCode::ArrowLeft, + winit::keyboard::KeyCode::ArrowRight => KeyCode::ArrowRight, + winit::keyboard::KeyCode::ArrowUp => KeyCode::ArrowUp, + winit::keyboard::KeyCode::NumLock => KeyCode::NumLock, + winit::keyboard::KeyCode::Numpad0 => KeyCode::Numpad0, + winit::keyboard::KeyCode::Numpad1 => KeyCode::Numpad1, + winit::keyboard::KeyCode::Numpad2 => KeyCode::Numpad2, + winit::keyboard::KeyCode::Numpad3 => KeyCode::Numpad3, + winit::keyboard::KeyCode::Numpad4 => KeyCode::Numpad4, + winit::keyboard::KeyCode::Numpad5 => KeyCode::Numpad5, + winit::keyboard::KeyCode::Numpad6 => KeyCode::Numpad6, + winit::keyboard::KeyCode::Numpad7 => KeyCode::Numpad7, + winit::keyboard::KeyCode::Numpad8 => KeyCode::Numpad8, + winit::keyboard::KeyCode::Numpad9 => KeyCode::Numpad9, + winit::keyboard::KeyCode::NumpadAdd => KeyCode::NumpadAdd, + winit::keyboard::KeyCode::NumpadBackspace => KeyCode::NumpadBackspace, + winit::keyboard::KeyCode::NumpadClear => KeyCode::NumpadClear, + winit::keyboard::KeyCode::NumpadClearEntry => KeyCode::NumpadClearEntry, + winit::keyboard::KeyCode::NumpadComma => KeyCode::NumpadComma, + winit::keyboard::KeyCode::NumpadDecimal => KeyCode::NumpadDecimal, + winit::keyboard::KeyCode::NumpadDivide => KeyCode::NumpadDivide, + winit::keyboard::KeyCode::NumpadEnter => KeyCode::NumpadEnter, + winit::keyboard::KeyCode::NumpadEqual => KeyCode::NumpadEqual, + winit::keyboard::KeyCode::NumpadHash => KeyCode::NumpadHash, + winit::keyboard::KeyCode::NumpadMemoryAdd => KeyCode::NumpadMemoryAdd, + winit::keyboard::KeyCode::NumpadMemoryClear => KeyCode::NumpadMemoryClear, + winit::keyboard::KeyCode::NumpadMemoryRecall => KeyCode::NumpadMemoryRecall, + winit::keyboard::KeyCode::NumpadMemoryStore => KeyCode::NumpadMemoryStore, + winit::keyboard::KeyCode::NumpadMemorySubtract => KeyCode::NumpadMemorySubtract, + winit::keyboard::KeyCode::NumpadMultiply => KeyCode::NumpadMultiply, + winit::keyboard::KeyCode::NumpadParenLeft => KeyCode::NumpadParenLeft, + winit::keyboard::KeyCode::NumpadParenRight => KeyCode::NumpadParenRight, + winit::keyboard::KeyCode::NumpadStar => KeyCode::NumpadStar, + winit::keyboard::KeyCode::NumpadSubtract => KeyCode::NumpadSubtract, + winit::keyboard::KeyCode::Escape => KeyCode::Escape, + winit::keyboard::KeyCode::Fn => KeyCode::Fn, + winit::keyboard::KeyCode::FnLock => KeyCode::FnLock, + winit::keyboard::KeyCode::PrintScreen => KeyCode::PrintScreen, + winit::keyboard::KeyCode::ScrollLock => KeyCode::ScrollLock, + winit::keyboard::KeyCode::Pause => KeyCode::Pause, + winit::keyboard::KeyCode::BrowserBack => KeyCode::BrowserBack, + winit::keyboard::KeyCode::BrowserFavorites => KeyCode::BrowserFavorites, + winit::keyboard::KeyCode::BrowserForward => KeyCode::BrowserForward, + winit::keyboard::KeyCode::BrowserHome => KeyCode::BrowserHome, + winit::keyboard::KeyCode::BrowserRefresh => KeyCode::BrowserRefresh, + winit::keyboard::KeyCode::BrowserSearch => KeyCode::BrowserSearch, + winit::keyboard::KeyCode::BrowserStop => KeyCode::BrowserStop, + winit::keyboard::KeyCode::Eject => KeyCode::Eject, + winit::keyboard::KeyCode::LaunchApp1 => KeyCode::LaunchApp1, + winit::keyboard::KeyCode::LaunchApp2 => KeyCode::LaunchApp2, + winit::keyboard::KeyCode::LaunchMail => KeyCode::LaunchMail, + winit::keyboard::KeyCode::MediaPlayPause => KeyCode::MediaPlayPause, + winit::keyboard::KeyCode::MediaSelect => KeyCode::MediaSelect, + winit::keyboard::KeyCode::MediaStop => KeyCode::MediaStop, + winit::keyboard::KeyCode::MediaTrackNext => KeyCode::MediaTrackNext, + winit::keyboard::KeyCode::MediaTrackPrevious => KeyCode::MediaTrackPrevious, + winit::keyboard::KeyCode::Power => KeyCode::Power, + winit::keyboard::KeyCode::Sleep => KeyCode::Sleep, + winit::keyboard::KeyCode::AudioVolumeDown => KeyCode::AudioVolumeDown, + winit::keyboard::KeyCode::AudioVolumeMute => KeyCode::AudioVolumeMute, + winit::keyboard::KeyCode::AudioVolumeUp => KeyCode::AudioVolumeUp, + winit::keyboard::KeyCode::WakeUp => KeyCode::WakeUp, + winit::keyboard::KeyCode::Meta => KeyCode::Meta, + winit::keyboard::KeyCode::Hyper => KeyCode::Hyper, + winit::keyboard::KeyCode::Turbo => KeyCode::Turbo, + winit::keyboard::KeyCode::Abort => KeyCode::Abort, + winit::keyboard::KeyCode::Resume => KeyCode::Resume, + winit::keyboard::KeyCode::Suspend => KeyCode::Suspend, + winit::keyboard::KeyCode::Again => KeyCode::Again, + winit::keyboard::KeyCode::Copy => KeyCode::Copy, + winit::keyboard::KeyCode::Cut => KeyCode::Cut, + winit::keyboard::KeyCode::Find => KeyCode::Find, + winit::keyboard::KeyCode::Open => KeyCode::Open, + winit::keyboard::KeyCode::Paste => KeyCode::Paste, + winit::keyboard::KeyCode::Props => KeyCode::Props, + winit::keyboard::KeyCode::Select => KeyCode::Select, + winit::keyboard::KeyCode::Undo => KeyCode::Undo, + winit::keyboard::KeyCode::Hiragana => KeyCode::Hiragana, + winit::keyboard::KeyCode::Katakana => KeyCode::Katakana, + winit::keyboard::KeyCode::F1 => KeyCode::F1, + winit::keyboard::KeyCode::F2 => KeyCode::F2, + winit::keyboard::KeyCode::F3 => KeyCode::F3, + winit::keyboard::KeyCode::F4 => KeyCode::F4, + winit::keyboard::KeyCode::F5 => KeyCode::F5, + winit::keyboard::KeyCode::F6 => KeyCode::F6, + winit::keyboard::KeyCode::F7 => KeyCode::F7, + winit::keyboard::KeyCode::F8 => KeyCode::F8, + winit::keyboard::KeyCode::F9 => KeyCode::F9, + winit::keyboard::KeyCode::F10 => KeyCode::F10, + winit::keyboard::KeyCode::F11 => KeyCode::F11, + winit::keyboard::KeyCode::F12 => KeyCode::F12, + winit::keyboard::KeyCode::F13 => KeyCode::F13, + winit::keyboard::KeyCode::F14 => KeyCode::F14, + winit::keyboard::KeyCode::F15 => KeyCode::F15, + winit::keyboard::KeyCode::F16 => KeyCode::F16, + winit::keyboard::KeyCode::F17 => KeyCode::F17, + winit::keyboard::KeyCode::F18 => KeyCode::F18, + winit::keyboard::KeyCode::F19 => KeyCode::F19, + winit::keyboard::KeyCode::F20 => KeyCode::F20, + winit::keyboard::KeyCode::F21 => KeyCode::F21, + winit::keyboard::KeyCode::F22 => KeyCode::F22, + winit::keyboard::KeyCode::F23 => KeyCode::F23, + winit::keyboard::KeyCode::F24 => KeyCode::F24, + winit::keyboard::KeyCode::F25 => KeyCode::F25, + winit::keyboard::KeyCode::F26 => KeyCode::F26, + winit::keyboard::KeyCode::F27 => KeyCode::F27, + winit::keyboard::KeyCode::F28 => KeyCode::F28, + winit::keyboard::KeyCode::F29 => KeyCode::F29, + winit::keyboard::KeyCode::F30 => KeyCode::F30, + winit::keyboard::KeyCode::F31 => KeyCode::F31, + winit::keyboard::KeyCode::F32 => KeyCode::F32, + winit::keyboard::KeyCode::F33 => KeyCode::F33, + winit::keyboard::KeyCode::F34 => KeyCode::F34, + winit::keyboard::KeyCode::F35 => KeyCode::F35, + _ => KeyCode::Unidentified, } } @@ -231,8 +266,8 @@ pub fn convert_cursor_icon(cursor_icon: CursorIcon) -> winit::window::CursorIcon match cursor_icon { CursorIcon::Default => winit::window::CursorIcon::Default, CursorIcon::Crosshair => winit::window::CursorIcon::Crosshair, - CursorIcon::Hand => winit::window::CursorIcon::Hand, - CursorIcon::Arrow => winit::window::CursorIcon::Arrow, + CursorIcon::Pointer => winit::window::CursorIcon::Pointer, + // TOCLEAN: Thierry: removed arrow, see https://github.com/rust-windowing/winit/commit/bd9cc2a9da7de62bf2cdd5d220f8c3635c3d82cc#diff-16d03f80ac1bc39829a757b6ad926ac811321ee124bed73d7bdd5f3ce898075eL57 CursorIcon::Move => winit::window::CursorIcon::Move, CursorIcon::Text => winit::window::CursorIcon::Text, CursorIcon::Wait => winit::window::CursorIcon::Wait, @@ -264,6 +299,7 @@ pub fn convert_cursor_icon(cursor_icon: CursorIcon) -> winit::window::CursorIcon CursorIcon::NwseResize => winit::window::CursorIcon::NwseResize, CursorIcon::ColResize => winit::window::CursorIcon::ColResize, CursorIcon::RowResize => winit::window::CursorIcon::RowResize, + _ => winit::window::CursorIcon::Default, } } diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index 17be50b2904ac..fba423eb889d6 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -445,10 +445,10 @@ pub fn winit_runner(mut app: App) { window: window_entity, }); } - WindowEvent::KeyboardInput { ref input, .. } => { + WindowEvent::KeyboardInput { ref event, .. } => { input_events .keyboard_input - .send(converters::convert_keyboard_input(input)); + .send(converters::convert_keyboard_input(event)); } WindowEvent::CursorMoved { position, .. } => { let physical_position = DVec2::new(position.x, position.y); @@ -503,12 +503,6 @@ pub fn winit_runner(mut app: App) { .touch_input .send(converters::convert_touch_input(touch, location)); } - WindowEvent::ReceivedCharacter(c) => { - input_events.character_input.send(ReceivedCharacter { - window: window_entity, - char: c, - }); - } WindowEvent::ScaleFactorChanged { scale_factor, new_inner_size, diff --git a/examples/2d/bloom_2d.rs b/examples/2d/bloom_2d.rs index 108cc94c571f1..e386611ff226e 100644 --- a/examples/2d/bloom_2d.rs +++ b/examples/2d/bloom_2d.rs @@ -137,59 +137,59 @@ fn update_bloom_settings( let dt = time.delta_seconds(); - if keycode.pressed(KeyCode::A) { + if keycode.pressed(KeyCode::KeyA) { bloom_settings.intensity -= dt / 10.0; } - if keycode.pressed(KeyCode::Q) { + if keycode.pressed(KeyCode::KeyQ) { bloom_settings.intensity += dt / 10.0; } bloom_settings.intensity = bloom_settings.intensity.clamp(0.0, 1.0); - if keycode.pressed(KeyCode::S) { + if keycode.pressed(KeyCode::KeyS) { bloom_settings.low_frequency_boost -= dt / 10.0; } - if keycode.pressed(KeyCode::W) { + if keycode.pressed(KeyCode::KeyW) { bloom_settings.low_frequency_boost += dt / 10.0; } bloom_settings.low_frequency_boost = bloom_settings.low_frequency_boost.clamp(0.0, 1.0); - if keycode.pressed(KeyCode::D) { + if keycode.pressed(KeyCode::KeyD) { bloom_settings.low_frequency_boost_curvature -= dt / 10.0; } - if keycode.pressed(KeyCode::E) { + if keycode.pressed(KeyCode::KeyE) { bloom_settings.low_frequency_boost_curvature += dt / 10.0; } bloom_settings.low_frequency_boost_curvature = bloom_settings.low_frequency_boost_curvature.clamp(0.0, 1.0); - if keycode.pressed(KeyCode::F) { + if keycode.pressed(KeyCode::KeyF) { bloom_settings.high_pass_frequency -= dt / 10.0; } - if keycode.pressed(KeyCode::R) { + if keycode.pressed(KeyCode::KeyR) { bloom_settings.high_pass_frequency += dt / 10.0; } bloom_settings.high_pass_frequency = bloom_settings.high_pass_frequency.clamp(0.0, 1.0); - if keycode.pressed(KeyCode::G) { + if keycode.pressed(KeyCode::KeyG) { bloom_settings.composite_mode = BloomCompositeMode::Additive; } - if keycode.pressed(KeyCode::T) { + if keycode.pressed(KeyCode::KeyT) { bloom_settings.composite_mode = BloomCompositeMode::EnergyConserving; } - if keycode.pressed(KeyCode::H) { + if keycode.pressed(KeyCode::KeyH) { bloom_settings.prefilter_settings.threshold -= dt; } - if keycode.pressed(KeyCode::Y) { + if keycode.pressed(KeyCode::KeyY) { bloom_settings.prefilter_settings.threshold += dt; } bloom_settings.prefilter_settings.threshold = bloom_settings.prefilter_settings.threshold.max(0.0); - if keycode.pressed(KeyCode::J) { + if keycode.pressed(KeyCode::KeyJ) { bloom_settings.prefilter_settings.threshold_softness -= dt / 10.0; } - if keycode.pressed(KeyCode::U) { + if keycode.pressed(KeyCode::KeyU) { bloom_settings.prefilter_settings.threshold_softness += dt / 10.0; } bloom_settings.prefilter_settings.threshold_softness = bloom_settings diff --git a/examples/2d/rotation.rs b/examples/2d/rotation.rs index 3447543b7541a..fb649eb514e81 100644 --- a/examples/2d/rotation.rs +++ b/examples/2d/rotation.rs @@ -125,15 +125,15 @@ fn player_movement_system( let mut rotation_factor = 0.0; let mut movement_factor = 0.0; - if keyboard_input.pressed(KeyCode::Left) { + if keyboard_input.pressed(KeyCode::ArrowLeft) { rotation_factor += 1.0; } - if keyboard_input.pressed(KeyCode::Right) { + if keyboard_input.pressed(KeyCode::ArrowRight) { rotation_factor -= 1.0; } - if keyboard_input.pressed(KeyCode::Up) { + if keyboard_input.pressed(KeyCode::ArrowUp) { movement_factor += 1.0; } diff --git a/examples/3d/3d_gizmos.rs b/examples/3d/3d_gizmos.rs index 585df5718da4f..39dc6c3104702 100644 --- a/examples/3d/3d_gizmos.rs +++ b/examples/3d/3d_gizmos.rs @@ -107,7 +107,7 @@ fn rotate_camera(mut query: Query<&mut Transform, With>, time: Res