mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +00:00
Update winit dependency to 0.29 (#10702)
# Objective - Update winit dependency to 0.29 ## Changelog ### KeyCode changes - Removed `ScanCode`, as it was [replaced by KeyCode](https://github.com/rust-windowing/winit/blob/master/CHANGELOG.md#0292). - `ReceivedCharacter.char` is now a `SmolStr`, [relevant doc](https://docs.rs/winit/latest/winit/event/struct.KeyEvent.html#structfield.text). - Changed most `KeyCode` values, and added more. KeyCode has changed meaning. With this PR, it refers to physical position on keyboard rather than the printed letter on keyboard keys. In practice this means: - On QWERTY keyboard layouts, nothing changes - On any other keyboard layout, `KeyCode` no longer reflects the label on key. - This is "good". In bevy 0.12, when you used WASD for movement, users with non-QWERTY keyboards couldn't play your game! This was especially bad for non-latin keyboards. Now, WASD represents the physical keys. A French player will press the ZQSD keys, which are near each other, Kyrgyz players will use "Цфыв". - This is "bad" as well. You can't know in advance what the label of the key for input is. Your UI says "press WASD to move", even if in reality, they should be pressing "ZQSD" or "Цфыв". You also no longer can use `KeyCode` for text inputs. In any case, it was a pretty bad API for text input. You should use `ReceivedCharacter` now instead. ### Other changes - Use `web-time` rather than `instant` crate. (https://github.com/rust-windowing/winit/pull/2836) - winit did split `run_return` in `run_onDemand` and `pump_events`, I did the same change in bevy_winit and used `pump_events`. - Removed `return_from_run` from `WinitSettings` as `winit::run` now returns on supported platforms. - I left the example "return_after_run" as I think it's still useful. - This winit change is done partly to allow to create a new window after quitting all windows: https://github.com/emilk/egui/issues/1918 ; this PR doesn't address. - added `width` and `height` properties in the `canvas` from wasm example (https://github.com/bevyengine/bevy/pull/10702#discussion_r1420567168) ## Known regressions (important follow ups?) - Provide an API for reacting when a specific key from current layout was released. - possible solutions: use winit::Key from winit::KeyEvent ; mapping between KeyCode and Key ; or . - We don't receive characters through alt+numpad (e.g. alt + 151 = "ù") anymore ; reproduced on winit example "ime". maybe related to https://github.com/rust-windowing/winit/issues/2945 - (windows) Window content doesn't refresh at all when resizing. By reading https://github.com/rust-windowing/winit/issues/2900 ; I suspect we should just fire a `window.request_redraw();` from `AboutToWait`, and handle actual redrawing within `RedrawRequested`. I'm not sure how to move all that code so I'd appreciate it to be a follow up. - (windows) unreleased winit fix for using set_control_flow in AboutToWait https://github.com/rust-windowing/winit/issues/3215 ; ⚠️ I'm not sure what the implications are, but that feels bad 🤔 ## Follow up I'd like to avoid bloating this PR, here are a few follow up tasks worthy of a separate PR, or new issue to track them once this PR is closed, as they would either complicate reviews, or at risk of being controversial: - remove CanvasParentResizePlugin (https://github.com/bevyengine/bevy/pull/10702#discussion_r1417068856) - avoid mentionning explicitly winit in docs from bevy_window ? - NamedKey integration on bevy_input: https://github.com/rust-windowing/winit/pull/3143 introduced a new NamedKey variant. I implemented it only on the converters but we'd benefit making the same changes to bevy_input. - Add more info in KeyboardInput https://github.com/bevyengine/bevy/pull/10702#pullrequestreview-1748336313 - https://github.com/bevyengine/bevy/pull/9905 added a workaround on a bug allegedly fixed by winit 0.29. We should check if it's still necessary. - update to raw_window_handle 0.6 - blocked by wgpu - Rename `KeyCode` to `PhysicalKeyCode` https://github.com/bevyengine/bevy/pull/10702#discussion_r1404595015 - remove `instant` dependency, [replaced by](https://github.com/rust-windowing/winit/pull/2836) `web_time`), we'd need to update to : - fastrand >= 2.0 - [`async-executor`](https://github.com/smol-rs/async-executor) >= 1.7 - [`futures-lite`](https://github.com/smol-rs/futures-lite) >= 2.0 - Verify license, see [discussion](https://github.com/bevyengine/bevy/pull/8745#discussion_r1402439800) - we might be missing a short notice or description of changes made - Consider using https://github.com/rust-windowing/cursor-icon directly rather than vendoring it in bevy. - investigate [this unwrap](https://github.com/bevyengine/bevy/pull/8745#discussion_r1387044986) (`winit_window.canvas().unwrap();`) - Use more good things about winit's update - https://github.com/bevyengine/bevy/pull/10689#issuecomment-1823560428 ## Migration Guide This PR should have one.
This commit is contained in:
parent
3b59dbd772
commit
ced216f59a
70 changed files with 1396 additions and 1089 deletions
|
@ -278,7 +278,7 @@ impl App {
|
|||
///
|
||||
/// # `run()` might not return
|
||||
///
|
||||
/// Calls to [`App::run()`] might never return.
|
||||
/// Calls to [`App::run()`] will never return on iOS and Web.
|
||||
///
|
||||
/// In simple and *headless* applications, one can expect that execution will
|
||||
/// proceed, normally, after calling [`run()`](App::run()) but this is not the case for
|
||||
|
@ -289,10 +289,7 @@ impl App {
|
|||
/// window is closed and that event loop terminates – behavior of processes that
|
||||
/// do not is often platform dependent or undocumented.
|
||||
///
|
||||
/// By default, *Bevy* uses the `winit` crate for window creation. See
|
||||
/// [`WinitSettings::return_from_run`](https://docs.rs/bevy/latest/bevy/winit/struct.WinitSettings.html#structfield.return_from_run)
|
||||
/// for further discussion of this topic and for a mechanism to require that [`App::run()`]
|
||||
/// *does* return – albeit one that carries its own caveats and disclaimers.
|
||||
/// By default, *Bevy* uses the `winit` crate for window creation.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
|
|
|
@ -29,7 +29,7 @@ impl AssetReader for AndroidAssetReader {
|
|||
let mut opened_asset = asset_manager
|
||||
.open(&CString::new(path.to_str().unwrap()).unwrap())
|
||||
.ok_or(AssetReaderError::NotFound(path.to_path_buf()))?;
|
||||
let bytes = opened_asset.get_buffer()?;
|
||||
let bytes = opened_asset.buffer()?;
|
||||
let reader: Box<Reader> = Box::new(VecReader::new(bytes.to_vec()));
|
||||
Ok(reader)
|
||||
})
|
||||
|
@ -48,7 +48,7 @@ impl AssetReader for AndroidAssetReader {
|
|||
let mut opened_asset = asset_manager
|
||||
.open(&CString::new(meta_path.to_str().unwrap()).unwrap())
|
||||
.ok_or(AssetReaderError::NotFound(meta_path))?;
|
||||
let bytes = opened_asset.get_buffer()?;
|
||||
let bytes = opened_asset.buffer()?;
|
||||
let reader: Box<Reader> = Box::new(VecReader::new(bytes.to_vec()));
|
||||
Ok(reader)
|
||||
})
|
||||
|
|
|
@ -1,5 +1,70 @@
|
|||
//! The keyboard input functionality.
|
||||
|
||||
// This file contains a substantial portion of the UI Events Specification by the W3C. In
|
||||
// particular, the variant names within `KeyCode` and their documentation are modified
|
||||
// versions of contents of the aforementioned specification.
|
||||
//
|
||||
// The original documents are:
|
||||
//
|
||||
//
|
||||
// ### For `KeyCode`
|
||||
// UI Events KeyboardEvent code Values
|
||||
// https://www.w3.org/TR/2017/CR-uievents-code-20170601/
|
||||
// Copyright © 2017 W3C® (MIT, ERCIM, Keio, Beihang).
|
||||
//
|
||||
// These documents were used under the terms of the following license. This W3C license as well as
|
||||
// the W3C short notice apply to the `KeyCode` enums and their variants and the
|
||||
// documentation attached to their variants.
|
||||
|
||||
// --------- BEGGINING OF W3C LICENSE --------------------------------------------------------------
|
||||
//
|
||||
// License
|
||||
//
|
||||
// By obtaining and/or copying this work, you (the licensee) agree that you have read, understood,
|
||||
// and will comply with the following terms and conditions.
|
||||
//
|
||||
// Permission to copy, modify, and distribute this work, with or without modification, for any
|
||||
// purpose and without fee or royalty is hereby granted, provided that you include the following on
|
||||
// ALL copies of the work or portions thereof, including modifications:
|
||||
//
|
||||
// - The full text of this NOTICE in a location viewable to users of the redistributed or derivative
|
||||
// work.
|
||||
// - Any pre-existing intellectual property disclaimers, notices, or terms and conditions. If none
|
||||
// exist, the W3C Software and Document Short Notice should be included.
|
||||
// - Notice of any changes or modifications, through a copyright statement on the new code or
|
||||
// document such as "This software or document includes material copied from or derived from
|
||||
// [title and URI of the W3C document]. Copyright © [YEAR] W3C® (MIT, ERCIM, Keio, Beihang)."
|
||||
//
|
||||
// Disclaimers
|
||||
//
|
||||
// THIS WORK IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR
|
||||
// ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE OR DOCUMENT WILL NOT INFRINGE ANY THIRD
|
||||
// PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
||||
//
|
||||
// COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES
|
||||
// ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENT.
|
||||
//
|
||||
// The name and trademarks of copyright holders may NOT be used in advertising or publicity
|
||||
// pertaining to the work without specific, written prior permission. Title to copyright in this
|
||||
// work will at all times remain with copyright holders.
|
||||
//
|
||||
// --------- END OF W3C LICENSE --------------------------------------------------------------------
|
||||
|
||||
// --------- BEGGINING OF W3C SHORT NOTICE ---------------------------------------------------------
|
||||
//
|
||||
// winit: https://github.com/rust-windowing/winit
|
||||
//
|
||||
// Copyright © 2021 World Wide Web Consortium, (Massachusetts Institute of Technology, European
|
||||
// Research Consortium for Informatics and Mathematics, Keio University, Beihang). All Rights
|
||||
// Reserved. This work is distributed under the W3C® Software License [1] in the hope that it will
|
||||
// be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// [1] http://www.w3.org/Consortium/Legal/copyright-software
|
||||
//
|
||||
// --------- END OF W3C SHORT NOTICE ---------------------------------------------------------------
|
||||
|
||||
use crate::{ButtonInput, ButtonState};
|
||||
use bevy_ecs::entity::Entity;
|
||||
use bevy_ecs::{
|
||||
|
@ -29,10 +94,8 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
|
|||
reflect(Serialize, Deserialize)
|
||||
)]
|
||||
pub struct KeyboardInput {
|
||||
/// The scan code of the key.
|
||||
pub scan_code: u32,
|
||||
/// The key code of the key.
|
||||
pub key_code: Option<KeyCode>,
|
||||
pub key_code: KeyCode,
|
||||
/// The press state of the key.
|
||||
pub state: ButtonState,
|
||||
/// Window that received the input.
|
||||
|
@ -43,39 +106,69 @@ pub struct KeyboardInput {
|
|||
///
|
||||
/// ## Differences
|
||||
///
|
||||
/// The main difference between the [`KeyboardInput`] event and the [`ButtonInput<KeyCode>`] or [`ButtonInput<ScanCode>`] resources is that
|
||||
/// The main difference between the [`KeyboardInput`] event and the [`ButtonInput<KeyCode>`] resources is that
|
||||
/// the latter have convenient functions such as [`ButtonInput::pressed`], [`ButtonInput::just_pressed`] and [`ButtonInput::just_released`].
|
||||
pub fn keyboard_input_system(
|
||||
mut scan_input: ResMut<ButtonInput<ScanCode>>,
|
||||
mut key_input: ResMut<ButtonInput<KeyCode>>,
|
||||
mut keyboard_input_events: EventReader<KeyboardInput>,
|
||||
) {
|
||||
// Avoid clearing if it's not empty to ensure change detection is not triggered.
|
||||
scan_input.bypass_change_detection().clear();
|
||||
key_input.bypass_change_detection().clear();
|
||||
for event in keyboard_input_events.read() {
|
||||
let KeyboardInput {
|
||||
scan_code, state, ..
|
||||
key_code, state, ..
|
||||
} = event;
|
||||
if let Some(key_code) = event.key_code {
|
||||
match state {
|
||||
ButtonState::Pressed => key_input.press(key_code),
|
||||
ButtonState::Released => key_input.release(key_code),
|
||||
}
|
||||
}
|
||||
match state {
|
||||
ButtonState::Pressed => scan_input.press(ScanCode(*scan_code)),
|
||||
ButtonState::Released => scan_input.release(ScanCode(*scan_code)),
|
||||
ButtonState::Pressed => key_input.press(*key_code),
|
||||
ButtonState::Released => key_input.release(*key_code),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Contains the platform-native physical key identifier
|
||||
///
|
||||
/// The exact values vary from platform to platform (which is part of why this is a per-platform
|
||||
/// enum), but the values are primarily tied to the key's physical location on the keyboard.
|
||||
///
|
||||
/// This enum is primarily used to store raw keycodes when Winit doesn't map a given native
|
||||
/// physical key identifier to a meaningful [`KeyCode`] variant. In the presence of identifiers we
|
||||
/// haven't mapped for you yet, this lets you use use [`KeyCode`] to:
|
||||
///
|
||||
/// - Correctly match key press and release events.
|
||||
/// - On non-web platforms, support assigning keybinds to virtually any key through a UI.
|
||||
#[derive(Debug, Clone, Ord, PartialOrd, Copy, PartialEq, Eq, Hash, Reflect)]
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(serde::Serialize, serde::Deserialize),
|
||||
reflect(Serialize, Deserialize)
|
||||
)]
|
||||
pub enum NativeKeyCode {
|
||||
/// Unidentified
|
||||
Unidentified,
|
||||
/// An Android "scancode".
|
||||
Android(u32),
|
||||
/// A macOS "scancode".
|
||||
MacOS(u16),
|
||||
/// A Windows "scancode".
|
||||
Windows(u16),
|
||||
/// An XKB "keycode".
|
||||
Xkb(u32),
|
||||
}
|
||||
|
||||
/// The key code of a [`KeyboardInput`].
|
||||
///
|
||||
/// ## Usage
|
||||
///
|
||||
/// It is used as the generic `T` value of an [`ButtonInput`] to create a `Res<Input<KeyCode>>`.
|
||||
/// The resource values are mapped to the current layout of the keyboard and correlate to an [`ScanCode`].
|
||||
///
|
||||
/// Code representing the location of a physical key
|
||||
/// This mostly conforms to the UI Events Specification's [`KeyboardEvent.code`] with a few
|
||||
/// exceptions:
|
||||
/// - The keys that the specification calls `MetaLeft` and `MetaRight` are named `SuperLeft` and
|
||||
/// `SuperRight` here.
|
||||
/// - The key that the specification calls "Super" is reported as `Unidentified` here.
|
||||
///
|
||||
/// [`KeyboardEvent.code`]: https://w3c.github.io/uievents-code/#code-value-tables
|
||||
///
|
||||
/// ## Updating
|
||||
///
|
||||
|
@ -89,375 +182,471 @@ 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.
|
||||
Escape,
|
||||
|
||||
/// The `F1` key.
|
||||
F1,
|
||||
/// The `F2` key.
|
||||
F2,
|
||||
/// The `F3` key.
|
||||
F3,
|
||||
/// The `F4` key.
|
||||
F4,
|
||||
/// The `F5` key.
|
||||
F5,
|
||||
/// The `F6` key.
|
||||
F6,
|
||||
/// The `F7` key.
|
||||
F7,
|
||||
/// The `F8` key.
|
||||
F8,
|
||||
/// The `F9` key.
|
||||
F9,
|
||||
/// The `F10` key.
|
||||
F10,
|
||||
/// The `F11` key.
|
||||
F11,
|
||||
/// The `F12` key.
|
||||
F12,
|
||||
/// The `F13` key.
|
||||
F13,
|
||||
/// The `F14` key.
|
||||
F14,
|
||||
/// The `F15` key.
|
||||
F15,
|
||||
/// The `F16` key.
|
||||
F16,
|
||||
/// The `F17` key.
|
||||
F17,
|
||||
/// The `F18` key.
|
||||
F18,
|
||||
/// The `F19` key.
|
||||
F19,
|
||||
/// The `F20` key.
|
||||
F20,
|
||||
/// The `F21` key.
|
||||
F21,
|
||||
/// The `F22` key.
|
||||
F22,
|
||||
/// The `F23` key.
|
||||
F23,
|
||||
/// The `F24` key.
|
||||
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.
|
||||
/// 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(NativeKeyCode),
|
||||
/// <kbd>`</kbd> on a US keyboard. This is also called a backtick or grave.
|
||||
/// This is the <kbd>半角</kbd>/<kbd>全角</kbd>/<kbd>漢字</kbd>
|
||||
/// (hankaku/zenkaku/kanji) key on Japanese keyboards
|
||||
Backquote,
|
||||
/// Used for both the US <kbd>\\</kbd> (on the 101-key layout) and also for the key
|
||||
/// located between the <kbd>"</kbd> and <kbd>Enter</kbd> keys on row C of the 102-,
|
||||
/// 104- and 106-key layouts.
|
||||
/// Labeled <kbd>#</kbd> on a UK (102) keyboard.
|
||||
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 `Left Alt` key. Maps to `Left Option` on Mac.
|
||||
AltLeft,
|
||||
/// The `Left Bracket` / `[` key.
|
||||
/// <kbd>[</kbd> on a US keyboard.
|
||||
BracketLeft,
|
||||
/// The `Left Control` key.
|
||||
ControlLeft,
|
||||
/// The `Left Shift` key.
|
||||
ShiftLeft,
|
||||
/// The `Left Super` key.
|
||||
/// Generic keyboards usually display this key with the *Microsoft Windows* logo.
|
||||
/// Apple keyboards call this key the *Command Key* and display it using the ⌘ character.
|
||||
#[doc(alias("LWin", "LMeta", "LLogo"))]
|
||||
SuperLeft,
|
||||
|
||||
/// 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 `Right Alt` key. Maps to `Right Option` on Mac.
|
||||
AltRight,
|
||||
/// The `Right Bracket` / `]` key.
|
||||
/// <kbd>]</kbd> on a US keyboard.
|
||||
BracketRight,
|
||||
/// The `Right Control` key.
|
||||
ControlRight,
|
||||
/// The `Right Shift` key.
|
||||
ShiftRight,
|
||||
/// The `Right Super` key.
|
||||
/// Generic keyboards usually display this key with the *Microsoft Windows* logo.
|
||||
/// Apple keyboards call this key the *Command Key* and display it using the ⌘ character.
|
||||
#[doc(alias("RWin", "RMeta", "RLogo"))]
|
||||
SuperRight,
|
||||
|
||||
/// The `Semicolon` / `;` key.
|
||||
/// <kbd>,</kbd> on a US keyboard.
|
||||
Comma,
|
||||
/// <kbd>0</kbd> on a US keyboard.
|
||||
Digit0,
|
||||
/// <kbd>1</kbd> on a US keyboard.
|
||||
Digit1,
|
||||
/// <kbd>2</kbd> on a US keyboard.
|
||||
Digit2,
|
||||
/// <kbd>3</kbd> on a US keyboard.
|
||||
Digit3,
|
||||
/// <kbd>4</kbd> on a US keyboard.
|
||||
Digit4,
|
||||
/// <kbd>5</kbd> on a US keyboard.
|
||||
Digit5,
|
||||
/// <kbd>6</kbd> on a US keyboard.
|
||||
Digit6,
|
||||
/// <kbd>7</kbd> on a US keyboard.
|
||||
Digit7,
|
||||
/// <kbd>8</kbd> on a US keyboard.
|
||||
Digit8,
|
||||
/// <kbd>9</kbd> on a US keyboard.
|
||||
Digit9,
|
||||
/// <kbd>=</kbd> on a US keyboard.
|
||||
Equal,
|
||||
/// Located between the left <kbd>Shift</kbd> and <kbd>Z</kbd> keys.
|
||||
/// Labeled <kbd>\\</kbd> on a UK keyboard.
|
||||
IntlBackslash,
|
||||
/// Located between the <kbd>/</kbd> and right <kbd>Shift</kbd> keys.
|
||||
/// Labeled <kbd>\\</kbd> (ro) on a Japanese keyboard.
|
||||
IntlRo,
|
||||
/// Located between the <kbd>=</kbd> and <kbd>Backspace</kbd> keys.
|
||||
/// Labeled <kbd>¥</kbd> (yen) on a Japanese keyboard. <kbd>\\</kbd> on a
|
||||
/// Russian keyboard.
|
||||
IntlYen,
|
||||
/// <kbd>a</kbd> on a US keyboard.
|
||||
/// Labeled <kbd>q</kbd> on an AZERTY (e.g., French) keyboard.
|
||||
KeyA,
|
||||
/// <kbd>b</kbd> on a US keyboard.
|
||||
KeyB,
|
||||
/// <kbd>c</kbd> on a US keyboard.
|
||||
KeyC,
|
||||
/// <kbd>d</kbd> on a US keyboard.
|
||||
KeyD,
|
||||
/// <kbd>e</kbd> on a US keyboard.
|
||||
KeyE,
|
||||
/// <kbd>f</kbd> on a US keyboard.
|
||||
KeyF,
|
||||
/// <kbd>g</kbd> on a US keyboard.
|
||||
KeyG,
|
||||
/// <kbd>h</kbd> on a US keyboard.
|
||||
KeyH,
|
||||
/// <kbd>i</kbd> on a US keyboard.
|
||||
KeyI,
|
||||
/// <kbd>j</kbd> on a US keyboard.
|
||||
KeyJ,
|
||||
/// <kbd>k</kbd> on a US keyboard.
|
||||
KeyK,
|
||||
/// <kbd>l</kbd> on a US keyboard.
|
||||
KeyL,
|
||||
/// <kbd>m</kbd> on a US keyboard.
|
||||
KeyM,
|
||||
/// <kbd>n</kbd> on a US keyboard.
|
||||
KeyN,
|
||||
/// <kbd>o</kbd> on a US keyboard.
|
||||
KeyO,
|
||||
/// <kbd>p</kbd> on a US keyboard.
|
||||
KeyP,
|
||||
/// <kbd>q</kbd> on a US keyboard.
|
||||
/// Labeled <kbd>a</kbd> on an AZERTY (e.g., French) keyboard.
|
||||
KeyQ,
|
||||
/// <kbd>r</kbd> on a US keyboard.
|
||||
KeyR,
|
||||
/// <kbd>s</kbd> on a US keyboard.
|
||||
KeyS,
|
||||
/// <kbd>t</kbd> on a US keyboard.
|
||||
KeyT,
|
||||
/// <kbd>u</kbd> on a US keyboard.
|
||||
KeyU,
|
||||
/// <kbd>v</kbd> on a US keyboard.
|
||||
KeyV,
|
||||
/// <kbd>w</kbd> on a US keyboard.
|
||||
/// Labeled <kbd>z</kbd> on an AZERTY (e.g., French) keyboard.
|
||||
KeyW,
|
||||
/// <kbd>x</kbd> on a US keyboard.
|
||||
KeyX,
|
||||
/// <kbd>y</kbd> on a US keyboard.
|
||||
/// Labeled <kbd>z</kbd> on a QWERTZ (e.g., German) keyboard.
|
||||
KeyY,
|
||||
/// <kbd>z</kbd> on a US keyboard.
|
||||
/// Labeled <kbd>w</kbd> on an AZERTY (e.g., French) keyboard, and <kbd>y</kbd> on a
|
||||
/// QWERTZ (e.g., German) keyboard.
|
||||
KeyZ,
|
||||
/// <kbd>-</kbd> on a US keyboard.
|
||||
Minus,
|
||||
/// <kbd>.</kbd> on a US keyboard.
|
||||
Period,
|
||||
/// <kbd>'</kbd> on a US keyboard.
|
||||
Quote,
|
||||
/// <kbd>;</kbd> on a US keyboard.
|
||||
Semicolon,
|
||||
/// The `Slash` / `/` key.
|
||||
/// <kbd>/</kbd> on a US keyboard.
|
||||
Slash,
|
||||
/// The `Sleep` key.
|
||||
Sleep,
|
||||
/// The `Stop` key.
|
||||
Stop,
|
||||
/// The `NumpadSubtract` / `-` key.
|
||||
NumpadSubtract,
|
||||
/// The `Sysrq` key.
|
||||
Sysrq,
|
||||
/// The `Tab` / ` ` key.
|
||||
/// <kbd>Alt</kbd>, <kbd>Option</kbd>, or <kbd>⌥</kbd>.
|
||||
AltLeft,
|
||||
/// <kbd>Alt</kbd>, <kbd>Option</kbd>, or <kbd>⌥</kbd>.
|
||||
/// This is labeled <kbd>AltGr</kbd> on many keyboard layouts.
|
||||
AltRight,
|
||||
/// <kbd>Backspace</kbd> or <kbd>⌫</kbd>.
|
||||
/// Labeled <kbd>Delete</kbd> on Apple keyboards.
|
||||
Backspace,
|
||||
/// <kbd>CapsLock</kbd> or <kbd>⇪</kbd>
|
||||
CapsLock,
|
||||
/// The application context menu key, which is typically found between the right
|
||||
/// <kbd>Super</kbd> key and the right <kbd>Control</kbd> key.
|
||||
ContextMenu,
|
||||
/// <kbd>Control</kbd> or <kbd>⌃</kbd>
|
||||
ControlLeft,
|
||||
/// <kbd>Control</kbd> or <kbd>⌃</kbd>
|
||||
ControlRight,
|
||||
/// <kbd>Enter</kbd> or <kbd>↵</kbd>. Labeled <kbd>Return</kbd> on Apple keyboards.
|
||||
Enter,
|
||||
/// The Windows, <kbd>⌘</kbd>, <kbd>Command</kbd>, or other OS symbol key.
|
||||
SuperLeft,
|
||||
/// The Windows, <kbd>⌘</kbd>, <kbd>Command</kbd>, or other OS symbol key.
|
||||
SuperRight,
|
||||
/// <kbd>Shift</kbd> or <kbd>⇧</kbd>
|
||||
ShiftLeft,
|
||||
/// <kbd>Shift</kbd> or <kbd>⇧</kbd>
|
||||
ShiftRight,
|
||||
/// <kbd> </kbd> (space)
|
||||
Space,
|
||||
/// <kbd>Tab</kbd> or <kbd>⇥</kbd>
|
||||
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.
|
||||
/// Japanese: <kbd>変</kbd> (henkan)
|
||||
Convert,
|
||||
/// Japanese: <kbd>カタカナ</kbd>/<kbd>ひらがな</kbd>/<kbd>ローマ字</kbd> (katakana/hiragana/romaji)
|
||||
KanaMode,
|
||||
/// Korean: HangulMode <kbd>한/영</kbd> (han/yeong)
|
||||
///
|
||||
/// Japanese (Mac keyboard): <kbd>か</kbd> (kana)
|
||||
Lang1,
|
||||
/// Korean: Hanja <kbd>한</kbd> (hanja)
|
||||
///
|
||||
/// Japanese (Mac keyboard): <kbd>英</kbd> (eisu)
|
||||
Lang2,
|
||||
/// Japanese (word-processing keyboard): Katakana
|
||||
Lang3,
|
||||
/// Japanese (word-processing keyboard): Hiragana
|
||||
Lang4,
|
||||
/// Japanese (word-processing keyboard): Zenkaku/Hankaku
|
||||
Lang5,
|
||||
/// Japanese: <kbd>無変換</kbd> (muhenkan)
|
||||
NonConvert,
|
||||
/// <kbd>⌦</kbd>. The forward delete key.
|
||||
/// Note that on Apple keyboards, the key labelled <kbd>Delete</kbd> on the main part of
|
||||
/// the keyboard is encoded as [`Backspace`].
|
||||
///
|
||||
/// [`Backspace`]: Self::Backspace
|
||||
Delete,
|
||||
/// <kbd>Page Down</kbd>, <kbd>End</kbd>, or <kbd>↘</kbd>
|
||||
End,
|
||||
/// <kbd>Help</kbd>. Not present on standard PC keyboards.
|
||||
Help,
|
||||
/// <kbd>Home</kbd> or <kbd>↖</kbd>
|
||||
Home,
|
||||
/// <kbd>Insert</kbd> or <kbd>Ins</kbd>. Not present on Apple keyboards.
|
||||
Insert,
|
||||
/// <kbd>Page Down</kbd>, <kbd>PgDn</kbd>, or <kbd>⇟</kbd>
|
||||
PageDown,
|
||||
/// <kbd>Page Up</kbd>, <kbd>PgUp</kbd>, or <kbd>⇞</kbd>
|
||||
PageUp,
|
||||
/// <kbd>↓</kbd>
|
||||
ArrowDown,
|
||||
/// <kbd>←</kbd>
|
||||
ArrowLeft,
|
||||
/// <kbd>→</kbd>
|
||||
ArrowRight,
|
||||
/// <kbd>↑</kbd>
|
||||
ArrowUp,
|
||||
/// On the Mac, this is used for the numpad <kbd>Clear</kbd> key.
|
||||
NumLock,
|
||||
/// <kbd>0 Ins</kbd> on a keyboard. <kbd>0</kbd> on a phone or remote control
|
||||
Numpad0,
|
||||
/// <kbd>1 End</kbd> on a keyboard. <kbd>1</kbd> or <kbd>1 QZ</kbd> on a phone or remote control
|
||||
Numpad1,
|
||||
/// <kbd>2 ↓</kbd> on a keyboard. <kbd>2 ABC</kbd> on a phone or remote control
|
||||
Numpad2,
|
||||
/// <kbd>3 PgDn</kbd> on a keyboard. <kbd>3 DEF</kbd> on a phone or remote control
|
||||
Numpad3,
|
||||
/// <kbd>4 ←</kbd> on a keyboard. <kbd>4 GHI</kbd> on a phone or remote control
|
||||
Numpad4,
|
||||
/// <kbd>5</kbd> on a keyboard. <kbd>5 JKL</kbd> on a phone or remote control
|
||||
Numpad5,
|
||||
/// <kbd>6 →</kbd> on a keyboard. <kbd>6 MNO</kbd> on a phone or remote control
|
||||
Numpad6,
|
||||
/// <kbd>7 Home</kbd> on a keyboard. <kbd>7 PQRS</kbd> or <kbd>7 PRS</kbd> on a phone
|
||||
/// or remote control
|
||||
Numpad7,
|
||||
/// <kbd>8 ↑</kbd> on a keyboard. <kbd>8 TUV</kbd> on a phone or remote control
|
||||
Numpad8,
|
||||
/// <kbd>9 PgUp</kbd> on a keyboard. <kbd>9 WXYZ</kbd> or <kbd>9 WXY</kbd> on a phone
|
||||
/// or remote control
|
||||
Numpad9,
|
||||
/// <kbd>+</kbd>
|
||||
NumpadAdd,
|
||||
/// Found on the Microsoft Natural Keyboard.
|
||||
NumpadBackspace,
|
||||
/// <kbd>C</kbd> or <kbd>A</kbd> (All Clear). Also for use with numpads that have a
|
||||
/// <kbd>Clear</kbd> key that is separate from the <kbd>NumLock</kbd> key. On the Mac, the
|
||||
/// numpad <kbd>Clear</kbd> key is encoded as [`NumLock`].
|
||||
///
|
||||
/// [`NumLock`]: Self::NumLock
|
||||
NumpadClear,
|
||||
/// <kbd>C</kbd> (Clear Entry)
|
||||
NumpadClearEntry,
|
||||
/// <kbd>,</kbd> (thousands separator). For locales where the thousands separator
|
||||
/// is a "." (e.g., Brazil), this key may generate a <kbd>.</kbd>.
|
||||
NumpadComma,
|
||||
/// <kbd>. Del</kbd>. For locales where the decimal separator is "," (e.g.,
|
||||
/// Brazil), this key may generate a <kbd>,</kbd>.
|
||||
NumpadDecimal,
|
||||
/// <kbd>/</kbd>
|
||||
NumpadDivide,
|
||||
/// The Enter key on the numpad.
|
||||
NumpadEnter,
|
||||
/// <kbd>=</kbd>
|
||||
NumpadEqual,
|
||||
/// <kbd>#</kbd> on a phone or remote control device. This key is typically found
|
||||
/// below the <kbd>9</kbd> key and to the right of the <kbd>0</kbd> key.
|
||||
NumpadHash,
|
||||
/// <kbd>M</kbd> Add current entry to the value stored in memory.
|
||||
NumpadMemoryAdd,
|
||||
/// <kbd>M</kbd> Clear the value stored in memory.
|
||||
NumpadMemoryClear,
|
||||
/// <kbd>M</kbd> Replace the current entry with the value stored in memory.
|
||||
NumpadMemoryRecall,
|
||||
/// <kbd>M</kbd> Replace the value stored in memory with the current entry.
|
||||
NumpadMemoryStore,
|
||||
/// <kbd>M</kbd> Subtract current entry from the value stored in memory.
|
||||
NumpadMemorySubtract,
|
||||
/// <kbd>*</kbd> on a keyboard. For use with numpads that provide mathematical
|
||||
/// operations (<kbd>+</kbd>, <kbd>-</kbd> <kbd>*</kbd> and <kbd>/</kbd>).
|
||||
///
|
||||
/// Use `NumpadStar` for the <kbd>*</kbd> key on phones and remote controls.
|
||||
NumpadMultiply,
|
||||
/// <kbd>(</kbd> Found on the Microsoft Natural Keyboard.
|
||||
NumpadParenLeft,
|
||||
/// <kbd>)</kbd> Found on the Microsoft Natural Keyboard.
|
||||
NumpadParenRight,
|
||||
/// <kbd>*</kbd> on a phone or remote control device.
|
||||
///
|
||||
/// This key is typically found below the <kbd>7</kbd> key and to the left of
|
||||
/// the <kbd>0</kbd> key.
|
||||
///
|
||||
/// Use <kbd>"NumpadMultiply"</kbd> for the <kbd>*</kbd> key on
|
||||
/// numeric keypads.
|
||||
NumpadStar,
|
||||
/// <kbd>-</kbd>
|
||||
NumpadSubtract,
|
||||
/// <kbd>Esc</kbd> or <kbd>⎋</kbd>
|
||||
Escape,
|
||||
/// <kbd>Fn</kbd> This is typically a hardware key that does not generate a separate code.
|
||||
Fn,
|
||||
/// <kbd>FLock</kbd> or <kbd>FnLock</kbd>. Function Lock key. Found on the Microsoft
|
||||
/// Natural Keyboard.
|
||||
FnLock,
|
||||
/// <kbd>PrtScr SysRq</kbd> or <kbd>Print Screen</kbd>
|
||||
PrintScreen,
|
||||
/// <kbd>Scroll Lock</kbd>
|
||||
ScrollLock,
|
||||
/// <kbd>Pause Break</kbd>
|
||||
Pause,
|
||||
/// Some laptops place this key to the left of the <kbd>↑</kbd> key.
|
||||
///
|
||||
/// This also the "back" button (triangle) on Android.
|
||||
BrowserBack,
|
||||
/// BrowserFavorites
|
||||
BrowserFavorites,
|
||||
/// Some laptops place this key to the right of the <kbd>↑</kbd> key.
|
||||
BrowserForward,
|
||||
/// The "home" button on Android.
|
||||
BrowserHome,
|
||||
/// BrowserRefresh
|
||||
BrowserRefresh,
|
||||
/// BrowserSearch
|
||||
BrowserSearch,
|
||||
/// BrowserStop
|
||||
BrowserStop,
|
||||
/// <kbd>Eject</kbd> or <kbd>⏏</kbd>. This key is placed in the function section on some Apple
|
||||
/// keyboards.
|
||||
Eject,
|
||||
/// Sometimes labelled <kbd>My Computer</kbd> on the keyboard
|
||||
LaunchApp1,
|
||||
/// Sometimes labelled <kbd>Calculator</kbd> on the keyboard
|
||||
LaunchApp2,
|
||||
/// LaunchMail
|
||||
LaunchMail,
|
||||
/// MediaPlayPause
|
||||
MediaPlayPause,
|
||||
/// MediaSelect
|
||||
MediaSelect,
|
||||
/// MediaStop
|
||||
MediaStop,
|
||||
/// MediaTrackNext
|
||||
MediaTrackNext,
|
||||
/// MediaTrackPrevious
|
||||
MediaTrackPrevious,
|
||||
/// This key is placed in the function section on some Apple keyboards, replacing the
|
||||
/// <kbd>Eject</kbd> key.
|
||||
Power,
|
||||
/// Sleep
|
||||
Sleep,
|
||||
/// AudioVolumeDown
|
||||
AudioVolumeDown,
|
||||
/// AudioVolumeMute
|
||||
AudioVolumeMute,
|
||||
/// AudioVolumeUp
|
||||
AudioVolumeUp,
|
||||
/// WakeUp
|
||||
WakeUp,
|
||||
/// Legacy modifier key. Also called "Super" in certain places.
|
||||
Meta,
|
||||
/// Legacy modifier key.
|
||||
Hyper,
|
||||
/// Turbo
|
||||
Turbo,
|
||||
/// Abort
|
||||
Abort,
|
||||
/// Resume
|
||||
Resume,
|
||||
/// Suspend
|
||||
Suspend,
|
||||
/// Found on Sun’s USB keyboard.
|
||||
Again,
|
||||
/// Found on Sun’s USB keyboard.
|
||||
Copy,
|
||||
/// The `Paste` key.
|
||||
Paste,
|
||||
/// The `Cut` key.
|
||||
/// 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 <kbd>ひらがな</kbd> key found on some Japanese word processing keyboards.
|
||||
Hiragana,
|
||||
/// Use for dedicated <kbd>カタカナ</kbd> key found on some Japanese word processing keyboards.
|
||||
Katakana,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F1,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F2,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F3,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F4,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F5,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F6,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F7,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F8,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F9,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F10,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F11,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F12,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F13,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F14,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F15,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F16,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F17,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F18,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F19,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F20,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F21,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F22,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F23,
|
||||
/// General-purpose function key.
|
||||
/// Usually found at the top of the keyboard.
|
||||
F24,
|
||||
/// 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`].
|
||||
///
|
||||
/// ## Usage
|
||||
///
|
||||
/// It is used as the generic `<T>` value of an [`ButtonInput`] to create a `Res<Input<ScanCode>>`.
|
||||
/// The resource values are mapped to the physical location of a key on the keyboard and correlate to an [`KeyCode`]
|
||||
///
|
||||
/// ## Updating
|
||||
///
|
||||
/// The resource is updated inside of the [`keyboard_input_system`].
|
||||
#[derive(Debug, Hash, Ord, PartialOrd, PartialEq, Eq, Clone, Copy, Reflect)]
|
||||
#[reflect(Debug, Hash, PartialEq)]
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(serde::Serialize, serde::Deserialize),
|
||||
reflect(Serialize, Deserialize)
|
||||
)]
|
||||
pub struct ScanCode(pub u32);
|
||||
|
|
|
@ -26,7 +26,7 @@ pub mod prelude {
|
|||
gamepad::{
|
||||
Gamepad, GamepadAxis, GamepadAxisType, GamepadButton, GamepadButtonType, Gamepads,
|
||||
},
|
||||
keyboard::{KeyCode, ScanCode},
|
||||
keyboard::KeyCode,
|
||||
mouse::MouseButton,
|
||||
touch::{TouchInput, Touches},
|
||||
Axis, ButtonInput,
|
||||
|
@ -36,7 +36,7 @@ pub mod prelude {
|
|||
use bevy_app::prelude::*;
|
||||
use bevy_ecs::prelude::*;
|
||||
use bevy_reflect::Reflect;
|
||||
use keyboard::{keyboard_input_system, KeyCode, KeyboardInput, ScanCode};
|
||||
use keyboard::{keyboard_input_system, KeyCode, KeyboardInput};
|
||||
use mouse::{
|
||||
mouse_button_input_system, MouseButton, MouseButtonInput, MouseMotion, MouseScrollUnit,
|
||||
MouseWheel,
|
||||
|
@ -69,7 +69,6 @@ impl Plugin for InputPlugin {
|
|||
// keyboard
|
||||
.add_event::<KeyboardInput>()
|
||||
.init_resource::<ButtonInput<KeyCode>>()
|
||||
.init_resource::<ButtonInput<ScanCode>>()
|
||||
.add_systems(PreUpdate, keyboard_input_system.in_set(InputSystem))
|
||||
// mouse
|
||||
.add_event::<MouseButtonInput>()
|
||||
|
@ -115,8 +114,7 @@ impl Plugin for InputPlugin {
|
|||
|
||||
// Register keyboard types
|
||||
app.register_type::<KeyboardInput>()
|
||||
.register_type::<KeyCode>()
|
||||
.register_type::<ScanCode>();
|
||||
.register_type::<KeyCode>();
|
||||
|
||||
// Register mouse types
|
||||
app.register_type::<MouseButtonInput>()
|
||||
|
|
|
@ -61,6 +61,10 @@ pub enum MouseButton {
|
|||
Right,
|
||||
/// The middle mouse button.
|
||||
Middle,
|
||||
/// The back mouse button.
|
||||
Back,
|
||||
/// The forward mouse button.
|
||||
Forward,
|
||||
/// Another mouse button with the associated number.
|
||||
Other(u16),
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ concurrent-queue = "2.0.0"
|
|||
wasm-bindgen-futures = "0.4"
|
||||
|
||||
[dev-dependencies]
|
||||
instant = { version = "0.1", features = ["wasm-bindgen"] }
|
||||
web-time = { version = "0.2" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use bevy_tasks::TaskPoolBuilder;
|
||||
use web_time::{Duration, Instant};
|
||||
|
||||
// This sample demonstrates creating a thread pool with 4 tasks and spawning 40 tasks that spin
|
||||
// for 100ms. It's expected to take about a second to run (assuming the machine has >= 4 logical
|
||||
|
@ -10,12 +11,12 @@ fn main() {
|
|||
.num_threads(4)
|
||||
.build();
|
||||
|
||||
let t0 = instant::Instant::now();
|
||||
let t0 = Instant::now();
|
||||
pool.scope(|s| {
|
||||
for i in 0..40 {
|
||||
s.spawn(async move {
|
||||
let now = instant::Instant::now();
|
||||
while instant::Instant::now() - now < instant::Duration::from_millis(100) {
|
||||
let now = Instant::now();
|
||||
while Instant::now() - now < Duration::from_millis(100) {
|
||||
// spin, simulating work being done
|
||||
}
|
||||
|
||||
|
@ -28,6 +29,6 @@ fn main() {
|
|||
}
|
||||
});
|
||||
|
||||
let t1 = instant::Instant::now();
|
||||
let t1 = Instant::now();
|
||||
println!("all tasks finished in {} secs", (t1 - t0).as_secs_f32());
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use bevy_tasks::TaskPoolBuilder;
|
||||
use web_time::{Duration, Instant};
|
||||
|
||||
// This sample demonstrates a thread pool with one thread per logical core and only one task
|
||||
// spinning. Other than the one thread, the system should remain idle, demonstrating good behavior
|
||||
|
@ -13,8 +14,8 @@ fn main() {
|
|||
for i in 0..1 {
|
||||
s.spawn(async move {
|
||||
println!("Blocking for 10 seconds");
|
||||
let now = instant::Instant::now();
|
||||
while instant::Instant::now() - now < instant::Duration::from_millis(10000) {
|
||||
let now = Instant::now();
|
||||
while Instant::now() - now < Duration::from_millis(10000) {
|
||||
// spin, simulating work being done
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ use crate::time::Time;
|
|||
/// zero must be handled without errors in application logic, as it may
|
||||
/// theoretically also happen at other times.
|
||||
///
|
||||
/// [`Instant`](std::time::Instant)s for [`startup()`](Time::startup),
|
||||
/// [`Instant`]s for [`startup()`](Time::startup),
|
||||
/// [`first_update()`](Time::first_update) and
|
||||
/// [`last_update()`](Time::last_update) are recorded and accessible.
|
||||
#[derive(Debug, Copy, Clone, Reflect)]
|
||||
|
@ -47,7 +47,7 @@ impl Default for Real {
|
|||
|
||||
impl Time<Real> {
|
||||
/// Constructs a new `Time<Real>` instance with a specific startup
|
||||
/// [`Instant`](std::time::Instant).
|
||||
/// [`Instant`].
|
||||
pub fn new(startup: Instant) -> Self {
|
||||
Self::new_with(Real {
|
||||
startup,
|
||||
|
@ -77,7 +77,7 @@ impl Time<Real> {
|
|||
self.update_with_instant(last_update + duration);
|
||||
}
|
||||
|
||||
/// Updates time with a specified [`Instant`](std::time::Instant).
|
||||
/// Updates time with a specified [`Instant`].
|
||||
///
|
||||
/// This method is provided for use in tests.
|
||||
///
|
||||
|
@ -95,7 +95,7 @@ impl Time<Real> {
|
|||
self.context_mut().last_update = Some(instant);
|
||||
}
|
||||
|
||||
/// Returns the [`Instant`](std::time::Instant) the clock was created.
|
||||
/// Returns the [`Instant`] the clock was created.
|
||||
///
|
||||
/// This usually represents when the app was started.
|
||||
#[inline]
|
||||
|
@ -103,7 +103,7 @@ impl Time<Real> {
|
|||
self.context().startup
|
||||
}
|
||||
|
||||
/// Returns the [`Instant`](std::time::Instant) when [`Self::update`] was first called, if it
|
||||
/// Returns the [`Instant`] when [`Self::update`] was first called, if it
|
||||
/// exists.
|
||||
///
|
||||
/// This usually represents when the first app update started.
|
||||
|
@ -112,7 +112,7 @@ impl Time<Real> {
|
|||
self.context().first_update
|
||||
}
|
||||
|
||||
/// Returns the [`Instant`](std::time::Instant) when [`Self::update`] was last called, if it
|
||||
/// Returns the [`Instant`] when [`Self::update`] was last called, if it
|
||||
/// exists.
|
||||
///
|
||||
/// This usually represents when the current app update started.
|
||||
|
|
|
@ -14,7 +14,7 @@ detailed_trace = []
|
|||
[dependencies]
|
||||
ahash = "0.8.3"
|
||||
tracing = { version = "0.1", default-features = false, features = ["std"] }
|
||||
instant = { version = "0.1", features = ["wasm-bindgen"] }
|
||||
web-time = { version = "0.2" }
|
||||
uuid = { version = "1.1", features = ["v4", "serde"] }
|
||||
hashbrown = { version = "0.14", features = ["serde"] }
|
||||
bevy_utils_proc_macros = { version = "0.12.0", path = "macros" }
|
||||
|
|
|
@ -31,10 +31,10 @@ pub use cow_arc::*;
|
|||
pub use default::default;
|
||||
pub use float_ord::*;
|
||||
pub use hashbrown;
|
||||
pub use instant::{Duration, Instant, SystemTime};
|
||||
pub use petgraph;
|
||||
pub use thiserror;
|
||||
pub use tracing;
|
||||
pub use web_time::{Duration, Instant};
|
||||
|
||||
#[allow(missing_docs)]
|
||||
pub mod nonmax {
|
||||
|
|
|
@ -10,7 +10,7 @@ keywords = ["bevy"]
|
|||
|
||||
[features]
|
||||
default = []
|
||||
serialize = ["serde"]
|
||||
serialize = ["serde", "smol_str/serde"]
|
||||
|
||||
[dependencies]
|
||||
# bevy
|
||||
|
@ -24,10 +24,11 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.12.0", features = [
|
|||
bevy_utils = { path = "../bevy_utils", version = "0.12.0" }
|
||||
# Used for close_on_esc
|
||||
bevy_input = { path = "../bevy_input", version = "0.12.0" }
|
||||
raw-window-handle = "0.5"
|
||||
|
||||
# other
|
||||
serde = { version = "1.0", features = ["derive"], optional = true }
|
||||
raw-window-handle = "0.5"
|
||||
smol_str = "0.2"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
|
@ -1,3 +1,73 @@
|
|||
// This file contains a portion of the CSS Basic User Interface Module Level 3
|
||||
// specification. In particular, the names for the cursor from the #cursor
|
||||
// section and documentation for some of the variants were taken.
|
||||
//
|
||||
// The original document is https://www.w3.org/TR/css-ui-3/#cursor.
|
||||
// Copyright © 2018 W3C® (MIT, ERCIM, Keio, Beihang)
|
||||
//
|
||||
// These documents were used under the terms of the following license. This W3C
|
||||
// license as well as the W3C short notice apply to the `CursorIcon` enum's
|
||||
// variants and documentation attached to them.
|
||||
|
||||
// --------- BEGGINING OF W3C LICENSE
|
||||
// --------------------------------------------------------------
|
||||
//
|
||||
// License
|
||||
//
|
||||
// By obtaining and/or copying this work, you (the licensee) agree that you have
|
||||
// read, understood, and will comply with the following terms and conditions.
|
||||
//
|
||||
// Permission to copy, modify, and distribute this work, with or without
|
||||
// modification, for any purpose and without fee or royalty is hereby granted,
|
||||
// provided that you include the following on ALL copies of the work or portions
|
||||
// thereof, including modifications:
|
||||
//
|
||||
// - The full text of this NOTICE in a location viewable to users of the
|
||||
// redistributed or derivative work.
|
||||
// - Any pre-existing intellectual property disclaimers, notices, or terms and
|
||||
// conditions. If none exist, the W3C Software and Document Short Notice
|
||||
// should be included.
|
||||
// - Notice of any changes or modifications, through a copyright statement on
|
||||
// the new code or document such as "This software or document includes
|
||||
// material copied from or derived from [title and URI of the W3C document].
|
||||
// Copyright © [YEAR] W3C® (MIT, ERCIM, Keio, Beihang)."
|
||||
//
|
||||
// Disclaimers
|
||||
//
|
||||
// THIS WORK IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS
|
||||
// OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES
|
||||
// OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF
|
||||
// THE SOFTWARE OR DOCUMENT WILL NOT INFRINGE ANY THIRD PARTY PATENTS,
|
||||
// COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
||||
//
|
||||
// COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR
|
||||
// CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENT.
|
||||
//
|
||||
// The name and trademarks of copyright holders may NOT be used in advertising
|
||||
// or publicity pertaining to the work without specific, written prior
|
||||
// permission. Title to copyright in this work will at all times remain with
|
||||
// copyright holders.
|
||||
//
|
||||
// --------- END OF W3C LICENSE
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// --------- BEGGINING OF W3C SHORT NOTICE
|
||||
// ---------------------------------------------------------
|
||||
//
|
||||
// winit: https://github.com/rust-windowing/cursor-icon
|
||||
//
|
||||
// Copyright © 2023 World Wide Web Consortium, (Massachusetts Institute of
|
||||
// Technology, European Research Consortium for Informatics and Mathematics,
|
||||
// Keio University, Beihang). All Rights Reserved. This work is distributed
|
||||
// under the W3C® Software License [1] in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// [1] http://www.w3.org/Consortium/Legal/copyright-software
|
||||
//
|
||||
// --------- END OF W3C SHORT NOTICE
|
||||
// --------------------------------------------------------------
|
||||
|
||||
use bevy_reflect::{prelude::ReflectDefault, Reflect};
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
|
@ -20,78 +90,130 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
|
|||
)]
|
||||
#[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 "?")
|
||||
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.
|
||||
Progress,
|
||||
/// Cursor showing that something cannot be done.
|
||||
NotAllowed,
|
||||
/// Indicates that a context menu is available.
|
||||
|
||||
/// 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,
|
||||
/// Indicates that a cell (or set of cells) may be selected.
|
||||
|
||||
/// Help is available for the object under the cursor. Often rendered as a
|
||||
/// question mark or a balloon.
|
||||
Help,
|
||||
|
||||
/// 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,
|
||||
|
||||
/// 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,
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ use bevy_ecs::entity::Entity;
|
|||
use bevy_ecs::event::Event;
|
||||
use bevy_math::{IVec2, Vec2};
|
||||
use bevy_reflect::Reflect;
|
||||
use smol_str::SmolStr;
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
|
||||
|
@ -172,7 +173,7 @@ pub struct ReceivedCharacter {
|
|||
/// Window that received the character.
|
||||
pub window: Entity,
|
||||
/// Received character.
|
||||
pub char: char,
|
||||
pub char: SmolStr,
|
||||
}
|
||||
|
||||
/// A Input Method Editor event.
|
||||
|
|
|
@ -28,19 +28,25 @@ bevy_utils = { path = "../bevy_utils", version = "0.12.0" }
|
|||
bevy_tasks = { path = "../bevy_tasks", version = "0.12.0" }
|
||||
|
||||
# other
|
||||
winit = { version = "0.28.7", default-features = false }
|
||||
accesskit_winit = { version = "0.15", default-features = false }
|
||||
# feature rwh_05 refers to window_raw_handle@v0.5,
|
||||
# updating to rwh_06 is blocked until wgpu 0.19 release lands.
|
||||
winit = { version = "0.29", default-features = false, features = ["rwh_05"] }
|
||||
accesskit_winit = { version = "0.17", default-features = false, features = [
|
||||
"rwh_05",
|
||||
] }
|
||||
approx = { version = "0.5", default-features = false }
|
||||
raw-window-handle = "0.5"
|
||||
|
||||
[target.'cfg(target_os = "android")'.dependencies]
|
||||
winit = { version = "0.28.7", default-features = false, features = [
|
||||
winit = { version = "0.29", default-features = false, features = [
|
||||
"android-native-activity",
|
||||
"rwh_05",
|
||||
] }
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
wasm-bindgen = { version = "0.2" }
|
||||
web-sys = "0.3"
|
||||
|
||||
crossbeam-channel = "0.5"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use bevy_ecs::entity::Entity;
|
||||
use bevy_input::{
|
||||
keyboard::{KeyCode, KeyboardInput},
|
||||
keyboard::{KeyCode, KeyboardInput, NativeKeyCode},
|
||||
mouse::MouseButton,
|
||||
touch::{ForceTouch, TouchInput, TouchPhase},
|
||||
ButtonState,
|
||||
|
@ -9,13 +9,12 @@ use bevy_math::Vec2;
|
|||
use bevy_window::{CursorIcon, EnabledButtons, WindowLevel, WindowTheme};
|
||||
|
||||
pub fn convert_keyboard_input(
|
||||
keyboard_input: &winit::event::KeyboardInput,
|
||||
keyboard_input: &winit::event::KeyEvent,
|
||||
window: Entity,
|
||||
) -> KeyboardInput {
|
||||
KeyboardInput {
|
||||
scan_code: keyboard_input.scancode,
|
||||
state: convert_element_state(keyboard_input.state),
|
||||
key_code: keyboard_input.virtual_keycode.map(convert_virtual_key_code),
|
||||
key_code: convert_physical_key_code(keyboard_input.physical_key),
|
||||
window,
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +31,8 @@ pub fn convert_mouse_button(mouse_button: winit::event::MouseButton) -> MouseBut
|
|||
winit::event::MouseButton::Left => MouseButton::Left,
|
||||
winit::event::MouseButton::Right => MouseButton::Right,
|
||||
winit::event::MouseButton::Middle => MouseButton::Middle,
|
||||
winit::event::MouseButton::Back => MouseButton::Back,
|
||||
winit::event::MouseButton::Forward => MouseButton::Forward,
|
||||
winit::event::MouseButton::Other(val) => MouseButton::Other(val),
|
||||
}
|
||||
}
|
||||
|
@ -64,180 +65,226 @@ pub fn convert_touch_input(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn convert_virtual_key_code(virtual_key_code: winit::event::VirtualKeyCode) -> KeyCode {
|
||||
pub fn convert_physical_native_key_code(
|
||||
native_key_code: winit::keyboard::NativeKeyCode,
|
||||
) -> NativeKeyCode {
|
||||
match native_key_code {
|
||||
winit::keyboard::NativeKeyCode::Unidentified => NativeKeyCode::Unidentified,
|
||||
winit::keyboard::NativeKeyCode::Android(scan_code) => NativeKeyCode::Android(scan_code),
|
||||
winit::keyboard::NativeKeyCode::MacOS(scan_code) => NativeKeyCode::MacOS(scan_code),
|
||||
winit::keyboard::NativeKeyCode::Windows(scan_code) => NativeKeyCode::Windows(scan_code),
|
||||
winit::keyboard::NativeKeyCode::Xkb(key_code) => NativeKeyCode::Xkb(key_code),
|
||||
}
|
||||
}
|
||||
pub fn convert_physical_key_code(virtual_key_code: winit::keyboard::PhysicalKey) -> 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::AltLeft,
|
||||
winit::event::VirtualKeyCode::LBracket => KeyCode::BracketLeft,
|
||||
winit::event::VirtualKeyCode::LControl => KeyCode::ControlLeft,
|
||||
winit::event::VirtualKeyCode::LShift => KeyCode::ShiftLeft,
|
||||
winit::event::VirtualKeyCode::LWin => KeyCode::SuperLeft,
|
||||
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::AltRight,
|
||||
winit::event::VirtualKeyCode::RBracket => KeyCode::BracketRight,
|
||||
winit::event::VirtualKeyCode::RControl => KeyCode::ControlRight,
|
||||
winit::event::VirtualKeyCode::RShift => KeyCode::ShiftRight,
|
||||
winit::event::VirtualKeyCode::RWin => KeyCode::SuperRight,
|
||||
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,
|
||||
winit::keyboard::PhysicalKey::Unidentified(native_key_code) => {
|
||||
KeyCode::Unidentified(convert_physical_native_key_code(native_key_code))
|
||||
}
|
||||
winit::keyboard::PhysicalKey::Code(code) => match code {
|
||||
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::Backspace => KeyCode::Backspace,
|
||||
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(NativeKeyCode::Unidentified),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
CursorIcon::Move => winit::window::CursorIcon::Move,
|
||||
CursorIcon::Text => winit::window::CursorIcon::Text,
|
||||
CursorIcon::Wait => winit::window::CursorIcon::Wait,
|
||||
|
@ -269,6 +316,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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ mod winit_config;
|
|||
mod winit_windows;
|
||||
|
||||
use bevy_a11y::AccessibilityRequested;
|
||||
use bevy_utils::{Duration, Instant};
|
||||
use system::{changed_windows, create_windows, despawn_windows, CachedWindow};
|
||||
pub use winit_config::*;
|
||||
pub use winit_windows::*;
|
||||
|
@ -32,10 +33,7 @@ use bevy_input::{
|
|||
use bevy_math::{ivec2, DVec2, Vec2};
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use bevy_tasks::tick_global_task_pools_on_main_thread;
|
||||
use bevy_utils::{
|
||||
tracing::{trace, warn},
|
||||
Duration, Instant,
|
||||
};
|
||||
use bevy_utils::tracing::{error, trace, warn};
|
||||
use bevy_window::{
|
||||
exit_on_all_closed, ApplicationLifetime, CursorEntered, CursorLeft, CursorMoved,
|
||||
FileDragAndDrop, Ime, ReceivedCharacter, RequestRedraw, Window,
|
||||
|
@ -148,7 +146,9 @@ impl Plugin for WinitPlugin {
|
|||
#[cfg(target_arch = "wasm32")]
|
||||
app.add_plugins(CanvasParentResizePlugin);
|
||||
|
||||
let event_loop = event_loop_builder.build();
|
||||
let event_loop = event_loop_builder
|
||||
.build()
|
||||
.expect("Failed to build event loop");
|
||||
|
||||
// iOS, macOS, and Android don't like it if you create windows before the event loop is
|
||||
// initialized.
|
||||
|
@ -229,46 +229,6 @@ impl Plugin for WinitPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
fn run<F, T>(event_loop: EventLoop<T>, event_handler: F) -> !
|
||||
where
|
||||
F: 'static + FnMut(Event<'_, T>, &EventLoopWindowTarget<T>, &mut ControlFlow),
|
||||
{
|
||||
event_loop.run(event_handler)
|
||||
}
|
||||
|
||||
#[cfg(any(
|
||||
target_os = "windows",
|
||||
target_os = "macos",
|
||||
target_os = "linux",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
fn run_return<F, T>(event_loop: &mut EventLoop<T>, event_handler: F)
|
||||
where
|
||||
F: FnMut(Event<'_, T>, &EventLoopWindowTarget<T>, &mut ControlFlow),
|
||||
{
|
||||
use winit::platform::run_return::EventLoopExtRunReturn;
|
||||
event_loop.run_return(event_handler);
|
||||
}
|
||||
|
||||
#[cfg(not(any(
|
||||
target_os = "windows",
|
||||
target_os = "macos",
|
||||
target_os = "linux",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
)))]
|
||||
fn run_return<F, T>(_event_loop: &mut EventLoop<T>, _event_handler: F)
|
||||
where
|
||||
F: FnMut(Event<'_, T>, &EventLoopWindowTarget<T>, &mut ControlFlow),
|
||||
{
|
||||
panic!("Run return is not supported on this platform!")
|
||||
}
|
||||
|
||||
#[derive(SystemParam)]
|
||||
struct WindowAndInputEventWriters<'w> {
|
||||
// `winit` `WindowEvent`s
|
||||
|
@ -356,13 +316,11 @@ pub fn winit_runner(mut app: App) {
|
|||
app.cleanup();
|
||||
}
|
||||
|
||||
let mut event_loop = app
|
||||
let event_loop = app
|
||||
.world
|
||||
.remove_non_send_resource::<EventLoop<()>>()
|
||||
.unwrap();
|
||||
|
||||
let return_from_run = app.world.resource::<WinitSettings>().return_from_run;
|
||||
|
||||
app.world
|
||||
.insert_non_send_resource(event_loop.create_proxy());
|
||||
|
||||
|
@ -406,9 +364,7 @@ pub fn winit_runner(mut app: App) {
|
|||
)> = SystemState::from_world(&mut app.world);
|
||||
|
||||
// setup up the event loop
|
||||
let event_handler = move |event: Event<()>,
|
||||
event_loop: &EventLoopWindowTarget<()>,
|
||||
control_flow: &mut ControlFlow| {
|
||||
let event_handler = move |event: Event<()>, event_loop: &EventLoopWindowTarget<()>| {
|
||||
#[cfg(feature = "trace")]
|
||||
let _span = bevy_utils::tracing::info_span!("winit event_handler").entered();
|
||||
|
||||
|
@ -423,7 +379,7 @@ pub fn winit_runner(mut app: App) {
|
|||
|
||||
if let Some(app_exit_events) = app.world.get_resource::<Events<AppExit>>() {
|
||||
if app_exit_event_reader.read(app_exit_events).last().is_some() {
|
||||
*control_flow = ControlFlow::Exit;
|
||||
event_loop.exit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -507,11 +463,7 @@ pub fn winit_runner(mut app: App) {
|
|||
// the engine.
|
||||
if let Some(adapter) = access_kit_adapters.get(&window_entity) {
|
||||
if let Some(window) = winit_windows.get_window(window_entity) {
|
||||
// Somewhat surprisingly, this call has meaningful side effects
|
||||
// See https://github.com/AccessKit/accesskit/issues/300
|
||||
// AccessKit might later need to filter events based on this, but we currently do not.
|
||||
// See https://github.com/bevyengine/bevy/pull/10239#issuecomment-1775572176
|
||||
let _ = adapter.on_event(window, &event);
|
||||
adapter.process_event(window, &event);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -519,15 +471,7 @@ pub fn winit_runner(mut app: App) {
|
|||
|
||||
match event {
|
||||
WindowEvent::Resized(size) => {
|
||||
window
|
||||
.resolution
|
||||
.set_physical_resolution(size.width, size.height);
|
||||
|
||||
event_writers.window_resized.send(WindowResized {
|
||||
window: window_entity,
|
||||
width: window.width(),
|
||||
height: window.height(),
|
||||
});
|
||||
react_to_resize(&mut window, size, &mut event_writers, window_entity);
|
||||
}
|
||||
WindowEvent::CloseRequested => {
|
||||
event_writers
|
||||
|
@ -536,10 +480,18 @@ pub fn winit_runner(mut app: App) {
|
|||
window: window_entity,
|
||||
});
|
||||
}
|
||||
WindowEvent::KeyboardInput { ref input, .. } => {
|
||||
event_writers
|
||||
.keyboard_input
|
||||
.send(converters::convert_keyboard_input(input, window_entity));
|
||||
WindowEvent::KeyboardInput { ref event, .. } => {
|
||||
if event.state.is_pressed() {
|
||||
if let Some(char) = &event.text {
|
||||
event_writers.character_input.send(ReceivedCharacter {
|
||||
window: window_entity,
|
||||
char: char.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
let keyboard_event =
|
||||
converters::convert_keyboard_input(event, window_entity);
|
||||
event_writers.keyboard_input.send(keyboard_event);
|
||||
}
|
||||
WindowEvent::CursorMoved { position, .. } => {
|
||||
let physical_position = DVec2::new(position.x, position.y);
|
||||
|
@ -604,15 +556,9 @@ pub fn winit_runner(mut app: App) {
|
|||
.touch_input
|
||||
.send(converters::convert_touch_input(touch, location));
|
||||
}
|
||||
WindowEvent::ReceivedCharacter(char) => {
|
||||
event_writers.character_input.send(ReceivedCharacter {
|
||||
window: window_entity,
|
||||
char,
|
||||
});
|
||||
}
|
||||
WindowEvent::ScaleFactorChanged {
|
||||
scale_factor,
|
||||
new_inner_size,
|
||||
mut inner_size_writer,
|
||||
} => {
|
||||
event_writers.window_backend_scale_factor_changed.send(
|
||||
WindowBackendScaleFactorChanged {
|
||||
|
@ -625,13 +571,22 @@ pub fn winit_runner(mut app: App) {
|
|||
window.resolution.set_scale_factor(scale_factor as f32);
|
||||
let new_factor = window.resolution.scale_factor();
|
||||
|
||||
let mut new_inner_size = winit::dpi::PhysicalSize::new(
|
||||
window.physical_width(),
|
||||
window.physical_height(),
|
||||
);
|
||||
if let Some(forced_factor) = window.resolution.scale_factor_override() {
|
||||
// This window is overriding the OS-suggested DPI, so its physical size
|
||||
// should be set based on the overriding value. Its logical size already
|
||||
// incorporates any resize constraints.
|
||||
*new_inner_size =
|
||||
let maybe_new_inner_size =
|
||||
winit::dpi::LogicalSize::new(window.width(), window.height())
|
||||
.to_physical::<u32>(forced_factor as f64);
|
||||
if let Err(err) = inner_size_writer.request_inner_size(new_inner_size) {
|
||||
warn!("Winit Failed to resize the window: {err}");
|
||||
} else {
|
||||
new_inner_size = maybe_new_inner_size;
|
||||
}
|
||||
} else if approx::relative_ne!(new_factor, prior_factor) {
|
||||
event_writers.window_scale_factor_changed.send(
|
||||
WindowScaleFactorChanged {
|
||||
|
@ -640,7 +595,6 @@ pub fn winit_runner(mut app: App) {
|
|||
},
|
||||
);
|
||||
}
|
||||
|
||||
let new_logical_width = new_inner_size.width as f32 / new_factor;
|
||||
let new_logical_height = new_inner_size.height as f32 / new_factor;
|
||||
if approx::relative_ne!(window.width(), new_logical_width)
|
||||
|
@ -807,10 +761,10 @@ pub fn winit_runner(mut app: App) {
|
|||
|
||||
app.world.entity_mut(entity).insert(wrapper);
|
||||
}
|
||||
*control_flow = ControlFlow::Poll;
|
||||
event_loop.set_control_flow(ControlFlow::Poll);
|
||||
}
|
||||
}
|
||||
Event::MainEventsCleared => {
|
||||
Event::AboutToWait => {
|
||||
if runner_state.active.should_run() {
|
||||
if runner_state.active == ActiveState::WillSuspend {
|
||||
runner_state.active = ActiveState::Suspended;
|
||||
|
@ -822,7 +776,7 @@ pub fn winit_runner(mut app: App) {
|
|||
app.world.query_filtered::<Entity, With<PrimaryWindow>>();
|
||||
let entity = query.single(&app.world);
|
||||
app.world.entity_mut(entity).remove::<RawHandleWrapper>();
|
||||
*control_flow = ControlFlow::Wait;
|
||||
event_loop.set_control_flow(ControlFlow::Wait);
|
||||
}
|
||||
}
|
||||
let (config, windows) = focused_windows_state.get(&app.world);
|
||||
|
@ -855,15 +809,17 @@ pub fn winit_runner(mut app: App) {
|
|||
let (config, windows) = focused_windows_state.get(&app.world);
|
||||
let focused = windows.iter().any(|window| window.focused);
|
||||
match config.update_mode(focused) {
|
||||
UpdateMode::Continuous => *control_flow = ControlFlow::Poll,
|
||||
UpdateMode::Continuous => {
|
||||
event_loop.set_control_flow(ControlFlow::Poll);
|
||||
}
|
||||
UpdateMode::Reactive { wait }
|
||||
| UpdateMode::ReactiveLowPower { wait } => {
|
||||
if let Some(next) = runner_state.last_update.checked_add(*wait) {
|
||||
runner_state.scheduled_update = Some(next);
|
||||
*control_flow = ControlFlow::WaitUntil(next);
|
||||
event_loop.set_control_flow(ControlFlow::WaitUntil(next));
|
||||
} else {
|
||||
runner_state.scheduled_update = None;
|
||||
*control_flow = ControlFlow::Wait;
|
||||
event_loop.set_control_flow(ControlFlow::Wait);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -873,13 +829,13 @@ pub fn winit_runner(mut app: App) {
|
|||
{
|
||||
if redraw_event_reader.read(app_redraw_events).last().is_some() {
|
||||
runner_state.redraw_requested = true;
|
||||
*control_flow = ControlFlow::Poll;
|
||||
event_loop.set_control_flow(ControlFlow::Poll);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(app_exit_events) = app.world.get_resource::<Events<AppExit>>() {
|
||||
if app_exit_event_reader.read(app_exit_events).last().is_some() {
|
||||
*control_flow = ControlFlow::Exit;
|
||||
event_loop.exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -930,9 +886,24 @@ pub fn winit_runner(mut app: App) {
|
|||
};
|
||||
|
||||
trace!("starting winit event loop");
|
||||
if return_from_run {
|
||||
run_return(&mut event_loop, event_handler);
|
||||
} else {
|
||||
run(event_loop, event_handler);
|
||||
if let Err(err) = event_loop.run(event_handler) {
|
||||
error!("winit event loop returned an error: {err}");
|
||||
}
|
||||
}
|
||||
|
||||
fn react_to_resize(
|
||||
window: &mut Mut<'_, Window>,
|
||||
size: winit::dpi::PhysicalSize<u32>,
|
||||
event_writers: &mut WindowAndInputEventWriters<'_>,
|
||||
window_entity: Entity,
|
||||
) {
|
||||
window
|
||||
.resolution
|
||||
.set_physical_resolution(size.width, size.height);
|
||||
|
||||
event_writers.window_resized.send(WindowResized {
|
||||
window: window_entity,
|
||||
width: window.width(),
|
||||
height: window.height(),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ use crate::{
|
|||
self, convert_enabled_buttons, convert_window_level, convert_window_theme,
|
||||
convert_winit_theme,
|
||||
},
|
||||
get_best_videomode, get_fitting_videomode, WinitWindows,
|
||||
get_best_videomode, get_fitting_videomode, WindowAndInputEventWriters, WinitWindows,
|
||||
};
|
||||
|
||||
/// Creates new windows on the [`winit`] backend for each entity with a newly-added
|
||||
|
@ -138,6 +138,7 @@ pub struct CachedWindow {
|
|||
pub(crate) fn changed_windows(
|
||||
mut changed_windows: Query<(Entity, &mut Window, &mut CachedWindow), Changed<Window>>,
|
||||
winit_windows: NonSendMut<WinitWindows>,
|
||||
mut event_writers: WindowAndInputEventWriters<'_>,
|
||||
) {
|
||||
for (entity, mut window, mut cache) in &mut changed_windows {
|
||||
if let Some(winit_window) = winit_windows.get_window(entity) {
|
||||
|
@ -174,7 +175,9 @@ pub(crate) fn changed_windows(
|
|||
window.resolution.physical_width(),
|
||||
window.resolution.physical_height(),
|
||||
);
|
||||
winit_window.set_inner_size(physical_size);
|
||||
if let Some(size_now) = winit_window.request_inner_size(physical_size) {
|
||||
crate::react_to_resize(&mut window, size_now, &mut event_writers, entity);
|
||||
}
|
||||
}
|
||||
|
||||
if window.physical_cursor_position() != cache.window.physical_cursor_position() {
|
||||
|
@ -298,10 +301,10 @@ pub(crate) fn changed_windows(
|
|||
}
|
||||
|
||||
if window.ime_position != cache.window.ime_position {
|
||||
winit_window.set_ime_position(LogicalPosition::new(
|
||||
window.ime_position.x,
|
||||
window.ime_position.y,
|
||||
));
|
||||
winit_window.set_ime_cursor_area(
|
||||
LogicalPosition::new(window.ime_position.x, window.ime_position.y),
|
||||
PhysicalSize::new(10, 10),
|
||||
);
|
||||
}
|
||||
|
||||
if window.window_theme != cache.window.window_theme {
|
||||
|
|
|
@ -31,7 +31,7 @@ fn canvas_parent_resize_event_handler(
|
|||
) {
|
||||
for event in resize_events.receiver.try_iter() {
|
||||
if let Some(window) = winit_windows.get_window(event.window) {
|
||||
window.set_inner_size(event.size);
|
||||
let _ = window.request_inner_size(event.size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,32 +4,6 @@ use bevy_utils::Duration;
|
|||
/// Settings for the [`WinitPlugin`](super::WinitPlugin).
|
||||
#[derive(Debug, Resource)]
|
||||
pub struct WinitSettings {
|
||||
/// Controls how the [`EventLoop`](winit::event_loop::EventLoop) is deployed.
|
||||
///
|
||||
/// - If this value is set to `false` (default), [`run`] is called, and exiting the loop will
|
||||
/// terminate the program.
|
||||
/// - If this value is set to `true`, [`run_return`] is called, and exiting the loop will
|
||||
/// return control to the caller.
|
||||
///
|
||||
/// **Note:** This cannot be changed while the loop is running. `winit` also discourages use of
|
||||
/// `run_return`.
|
||||
///
|
||||
/// # Supported platforms
|
||||
///
|
||||
/// `run_return` is only available on the following `target_os` environments:
|
||||
/// - `windows`
|
||||
/// - `macos`
|
||||
/// - `linux`
|
||||
/// - `freebsd`
|
||||
/// - `openbsd`
|
||||
/// - `netbsd`
|
||||
/// - `dragonfly`
|
||||
///
|
||||
/// The runner will panic if this is set to `true` on other platforms.
|
||||
///
|
||||
/// [`run`]: https://docs.rs/winit/latest/winit/event_loop/struct.EventLoop.html#method.run
|
||||
/// [`run_return`]: https://docs.rs/winit/latest/winit/platform/run_return/trait.EventLoopExtRunReturn.html#tymethod.run_return
|
||||
pub return_from_run: bool,
|
||||
/// Determines how frequently the application can update when it has focus.
|
||||
pub focused_mode: UpdateMode,
|
||||
/// Determines how frequently the application can update when it's out of focus.
|
||||
|
@ -47,7 +21,6 @@ impl WinitSettings {
|
|||
unfocused_mode: UpdateMode::ReactiveLowPower {
|
||||
wait: Duration::from_secs_f64(1.0 / 60.0), // 60Hz
|
||||
},
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,7 +36,6 @@ impl WinitSettings {
|
|||
unfocused_mode: UpdateMode::ReactiveLowPower {
|
||||
wait: Duration::from_secs(60),
|
||||
},
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,7 +53,6 @@ impl WinitSettings {
|
|||
impl Default for WinitSettings {
|
||||
fn default() -> Self {
|
||||
WinitSettings {
|
||||
return_from_run: false,
|
||||
focused_mode: UpdateMode::Continuous,
|
||||
unfocused_mode: UpdateMode::Continuous,
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ impl WinitWindows {
|
|||
use winit::platform::web::WindowExtWebSys;
|
||||
|
||||
if window.canvas.is_none() {
|
||||
let canvas = winit_window.canvas();
|
||||
let canvas = winit_window.canvas().expect("Failed to retrieve canvas.");
|
||||
|
||||
let window = web_sys::window().unwrap();
|
||||
let document = window.document().unwrap();
|
||||
|
|
|
@ -66,10 +66,10 @@ fn update_config(
|
|||
keyboard: Res<ButtonInput<KeyCode>>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
if keyboard.pressed(KeyCode::Right) {
|
||||
if keyboard.pressed(KeyCode::ArrowRight) {
|
||||
config.line_width += 5. * time.delta_seconds();
|
||||
}
|
||||
if keyboard.pressed(KeyCode::Left) {
|
||||
if keyboard.pressed(KeyCode::ArrowLeft) {
|
||||
config.line_width -= 5. * time.delta_seconds();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,59 +136,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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -111,20 +111,20 @@ fn update_config(
|
|||
keyboard: Res<ButtonInput<KeyCode>>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
if keyboard.just_pressed(KeyCode::D) {
|
||||
if keyboard.just_pressed(KeyCode::KeyD) {
|
||||
config.depth_bias = if config.depth_bias == 0. { -1. } else { 0. };
|
||||
}
|
||||
if keyboard.just_pressed(KeyCode::P) {
|
||||
if keyboard.just_pressed(KeyCode::KeyP) {
|
||||
// Toggle line_perspective
|
||||
config.line_perspective ^= true;
|
||||
// Increase the line width when line_perspective is on
|
||||
config.line_width *= if config.line_perspective { 5. } else { 1. / 5. };
|
||||
}
|
||||
|
||||
if keyboard.pressed(KeyCode::Right) {
|
||||
if keyboard.pressed(KeyCode::ArrowRight) {
|
||||
config.line_width += 5. * time.delta_seconds();
|
||||
}
|
||||
if keyboard.pressed(KeyCode::Left) {
|
||||
if keyboard.pressed(KeyCode::ArrowLeft) {
|
||||
config.line_width -= 5. * time.delta_seconds();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,14 +44,14 @@ fn modify_aa(
|
|||
let mut camera = commands.entity(camera_entity);
|
||||
|
||||
// No AA
|
||||
if keys.just_pressed(KeyCode::Key1) {
|
||||
if keys.just_pressed(KeyCode::Digit1) {
|
||||
*msaa = Msaa::Off;
|
||||
camera.remove::<Fxaa>();
|
||||
camera.remove::<TemporalAntiAliasBundle>();
|
||||
}
|
||||
|
||||
// MSAA
|
||||
if keys.just_pressed(KeyCode::Key2) && *msaa == Msaa::Off {
|
||||
if keys.just_pressed(KeyCode::Digit2) && *msaa == Msaa::Off {
|
||||
camera.remove::<Fxaa>();
|
||||
camera.remove::<TemporalAntiAliasBundle>();
|
||||
|
||||
|
@ -60,19 +60,19 @@ fn modify_aa(
|
|||
|
||||
// MSAA Sample Count
|
||||
if *msaa != Msaa::Off {
|
||||
if keys.just_pressed(KeyCode::Q) {
|
||||
if keys.just_pressed(KeyCode::KeyQ) {
|
||||
*msaa = Msaa::Sample2;
|
||||
}
|
||||
if keys.just_pressed(KeyCode::W) {
|
||||
if keys.just_pressed(KeyCode::KeyW) {
|
||||
*msaa = Msaa::Sample4;
|
||||
}
|
||||
if keys.just_pressed(KeyCode::E) {
|
||||
if keys.just_pressed(KeyCode::KeyE) {
|
||||
*msaa = Msaa::Sample8;
|
||||
}
|
||||
}
|
||||
|
||||
// FXAA
|
||||
if keys.just_pressed(KeyCode::Key3) && fxaa.is_none() {
|
||||
if keys.just_pressed(KeyCode::Digit3) && fxaa.is_none() {
|
||||
*msaa = Msaa::Off;
|
||||
camera.remove::<TemporalAntiAliasBundle>();
|
||||
|
||||
|
@ -81,30 +81,30 @@ fn modify_aa(
|
|||
|
||||
// FXAA Settings
|
||||
if let Some(mut fxaa) = fxaa {
|
||||
if keys.just_pressed(KeyCode::Q) {
|
||||
if keys.just_pressed(KeyCode::KeyQ) {
|
||||
fxaa.edge_threshold = Sensitivity::Low;
|
||||
fxaa.edge_threshold_min = Sensitivity::Low;
|
||||
}
|
||||
if keys.just_pressed(KeyCode::W) {
|
||||
if keys.just_pressed(KeyCode::KeyW) {
|
||||
fxaa.edge_threshold = Sensitivity::Medium;
|
||||
fxaa.edge_threshold_min = Sensitivity::Medium;
|
||||
}
|
||||
if keys.just_pressed(KeyCode::E) {
|
||||
if keys.just_pressed(KeyCode::KeyE) {
|
||||
fxaa.edge_threshold = Sensitivity::High;
|
||||
fxaa.edge_threshold_min = Sensitivity::High;
|
||||
}
|
||||
if keys.just_pressed(KeyCode::R) {
|
||||
if keys.just_pressed(KeyCode::KeyR) {
|
||||
fxaa.edge_threshold = Sensitivity::Ultra;
|
||||
fxaa.edge_threshold_min = Sensitivity::Ultra;
|
||||
}
|
||||
if keys.just_pressed(KeyCode::T) {
|
||||
if keys.just_pressed(KeyCode::KeyT) {
|
||||
fxaa.edge_threshold = Sensitivity::Extreme;
|
||||
fxaa.edge_threshold_min = Sensitivity::Extreme;
|
||||
}
|
||||
}
|
||||
|
||||
// TAA
|
||||
if keys.just_pressed(KeyCode::Key4) && taa.is_none() {
|
||||
if keys.just_pressed(KeyCode::Digit4) && taa.is_none() {
|
||||
*msaa = Msaa::Off;
|
||||
camera.remove::<Fxaa>();
|
||||
|
||||
|
@ -117,7 +117,7 @@ fn modify_sharpening(
|
|||
mut query: Query<&mut ContrastAdaptiveSharpeningSettings>,
|
||||
) {
|
||||
for mut cas in &mut query {
|
||||
if keys.just_pressed(KeyCode::Key0) {
|
||||
if keys.just_pressed(KeyCode::Digit0) {
|
||||
cas.enabled = !cas.enabled;
|
||||
}
|
||||
if cas.enabled {
|
||||
|
@ -125,11 +125,11 @@ fn modify_sharpening(
|
|||
cas.sharpening_strength -= 0.1;
|
||||
cas.sharpening_strength = cas.sharpening_strength.clamp(0.0, 1.0);
|
||||
}
|
||||
if keys.just_pressed(KeyCode::Equals) {
|
||||
if keys.just_pressed(KeyCode::Equal) {
|
||||
cas.sharpening_strength += 0.1;
|
||||
cas.sharpening_strength = cas.sharpening_strength.clamp(0.0, 1.0);
|
||||
}
|
||||
if keys.just_pressed(KeyCode::D) {
|
||||
if keys.just_pressed(KeyCode::KeyD) {
|
||||
cas.denoise = !cas.denoise;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ fn toggle_system(keycode: Res<ButtonInput<KeyCode>>, mut fog: Query<&mut FogSett
|
|||
fog_settings.color.set_a(1.0 - a);
|
||||
}
|
||||
|
||||
if keycode.just_pressed(KeyCode::S) {
|
||||
if keycode.just_pressed(KeyCode::KeyS) {
|
||||
let a = fog_settings.directional_light_color.a();
|
||||
fog_settings.directional_light_color.set_a(0.5 - a);
|
||||
}
|
||||
|
|
|
@ -292,9 +292,9 @@ fn example_control_system(
|
|||
time: Res<Time>,
|
||||
input: Res<ButtonInput<KeyCode>>,
|
||||
) {
|
||||
if input.pressed(KeyCode::Up) {
|
||||
if input.pressed(KeyCode::ArrowUp) {
|
||||
state.alpha = (state.alpha + time.delta_seconds()).min(1.0);
|
||||
} else if input.pressed(KeyCode::Down) {
|
||||
} else if input.pressed(KeyCode::ArrowDown) {
|
||||
state.alpha = (state.alpha - time.delta_seconds()).max(0.0);
|
||||
}
|
||||
|
||||
|
@ -302,7 +302,7 @@ fn example_control_system(
|
|||
state.unlit = !state.unlit;
|
||||
}
|
||||
|
||||
let randomize_colors = input.just_pressed(KeyCode::C);
|
||||
let randomize_colors = input.just_pressed(KeyCode::KeyC);
|
||||
|
||||
for (material_handle, controls) in &controllable {
|
||||
let material = materials.get_mut(material_handle).unwrap();
|
||||
|
@ -320,13 +320,13 @@ fn example_control_system(
|
|||
|
||||
let (mut camera, mut camera_transform, camera_global_transform) = camera.single_mut();
|
||||
|
||||
if input.just_pressed(KeyCode::H) {
|
||||
if input.just_pressed(KeyCode::KeyH) {
|
||||
camera.hdr = !camera.hdr;
|
||||
}
|
||||
|
||||
let rotation = if input.pressed(KeyCode::Left) {
|
||||
let rotation = if input.pressed(KeyCode::ArrowLeft) {
|
||||
time.delta_seconds()
|
||||
} else if input.pressed(KeyCode::Right) {
|
||||
} else if input.pressed(KeyCode::ArrowRight) {
|
||||
-time.delta_seconds()
|
||||
} else {
|
||||
0.0
|
||||
|
|
|
@ -160,59 +160,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
|
||||
|
|
|
@ -352,7 +352,7 @@ fn switch_mode(
|
|||
pause.0 = !pause.0;
|
||||
}
|
||||
|
||||
if keys.just_pressed(KeyCode::Key1) {
|
||||
if keys.just_pressed(KeyCode::Digit1) {
|
||||
*mode = DefaultRenderMode::Deferred;
|
||||
default_opaque_renderer_method.set_to_deferred();
|
||||
println!("DefaultOpaqueRendererMethod: Deferred");
|
||||
|
@ -364,7 +364,7 @@ fn switch_mode(
|
|||
commands.entity(camera).insert(DeferredPrepass);
|
||||
}
|
||||
}
|
||||
if keys.just_pressed(KeyCode::Key2) {
|
||||
if keys.just_pressed(KeyCode::Digit2) {
|
||||
*mode = DefaultRenderMode::Forward;
|
||||
default_opaque_renderer_method.set_to_forward();
|
||||
println!("DefaultOpaqueRendererMethod: Forward");
|
||||
|
@ -376,7 +376,7 @@ fn switch_mode(
|
|||
commands.entity(camera).remove::<DeferredPrepass>();
|
||||
}
|
||||
}
|
||||
if keys.just_pressed(KeyCode::Key3) {
|
||||
if keys.just_pressed(KeyCode::Digit3) {
|
||||
*mode = DefaultRenderMode::ForwardPrepass;
|
||||
default_opaque_renderer_method.set_to_forward();
|
||||
println!("DefaultOpaqueRendererMethod: Forward + Prepass");
|
||||
|
@ -389,7 +389,7 @@ fn switch_mode(
|
|||
}
|
||||
}
|
||||
|
||||
if keys.just_pressed(KeyCode::H) {
|
||||
if keys.just_pressed(KeyCode::KeyH) {
|
||||
*hide_ui = !*hide_ui;
|
||||
}
|
||||
|
||||
|
|
|
@ -184,7 +184,7 @@ fn update_system(
|
|||
.value
|
||||
.push_str("\n\n1 / 2 / 3 - Fog Falloff Mode");
|
||||
|
||||
if keycode.pressed(KeyCode::Key1) {
|
||||
if keycode.pressed(KeyCode::Digit1) {
|
||||
if let FogFalloff::Linear { .. } = fog.falloff {
|
||||
// No change
|
||||
} else {
|
||||
|
@ -195,7 +195,7 @@ fn update_system(
|
|||
};
|
||||
}
|
||||
|
||||
if keycode.pressed(KeyCode::Key2) {
|
||||
if keycode.pressed(KeyCode::Digit2) {
|
||||
if let FogFalloff::Exponential { .. } = fog.falloff {
|
||||
// No change
|
||||
} else if let FogFalloff::ExponentialSquared { density } = fog.falloff {
|
||||
|
@ -205,7 +205,7 @@ fn update_system(
|
|||
};
|
||||
}
|
||||
|
||||
if keycode.pressed(KeyCode::Key3) {
|
||||
if keycode.pressed(KeyCode::Digit3) {
|
||||
if let FogFalloff::Exponential { density } = fog.falloff {
|
||||
fog.falloff = FogFalloff::ExponentialSquared { density };
|
||||
} else if let FogFalloff::ExponentialSquared { .. } = fog.falloff {
|
||||
|
@ -225,16 +225,16 @@ fn update_system(
|
|||
.value
|
||||
.push_str("\nA / S - Move Start Distance\nZ / X - Move End Distance");
|
||||
|
||||
if keycode.pressed(KeyCode::A) {
|
||||
if keycode.pressed(KeyCode::KeyA) {
|
||||
*start -= delta * 3.0;
|
||||
}
|
||||
if keycode.pressed(KeyCode::S) {
|
||||
if keycode.pressed(KeyCode::KeyS) {
|
||||
*start += delta * 3.0;
|
||||
}
|
||||
if keycode.pressed(KeyCode::Z) {
|
||||
if keycode.pressed(KeyCode::KeyZ) {
|
||||
*end -= delta * 3.0;
|
||||
}
|
||||
if keycode.pressed(KeyCode::X) {
|
||||
if keycode.pressed(KeyCode::KeyX) {
|
||||
*end += delta * 3.0;
|
||||
}
|
||||
}
|
||||
|
@ -243,13 +243,13 @@ fn update_system(
|
|||
if let FogFalloff::Exponential { ref mut density } = &mut fog.falloff {
|
||||
text.sections[0].value.push_str("\nA / S - Change Density");
|
||||
|
||||
if keycode.pressed(KeyCode::A) {
|
||||
if keycode.pressed(KeyCode::KeyA) {
|
||||
*density -= delta * 0.5 * *density;
|
||||
if *density < 0.0 {
|
||||
*density = 0.0;
|
||||
}
|
||||
}
|
||||
if keycode.pressed(KeyCode::S) {
|
||||
if keycode.pressed(KeyCode::KeyS) {
|
||||
*density += delta * 0.5 * *density;
|
||||
}
|
||||
}
|
||||
|
@ -258,13 +258,13 @@ fn update_system(
|
|||
if let FogFalloff::ExponentialSquared { ref mut density } = &mut fog.falloff {
|
||||
text.sections[0].value.push_str("\nA / S - Change Density");
|
||||
|
||||
if keycode.pressed(KeyCode::A) {
|
||||
if keycode.pressed(KeyCode::KeyA) {
|
||||
*density -= delta * 0.5 * *density;
|
||||
if *density < 0.0 {
|
||||
*density = 0.0;
|
||||
}
|
||||
}
|
||||
if keycode.pressed(KeyCode::S) {
|
||||
if keycode.pressed(KeyCode::KeyS) {
|
||||
*density += delta * 0.5 * *density;
|
||||
}
|
||||
}
|
||||
|
@ -279,7 +279,7 @@ fn update_system(
|
|||
fog.color.set_r(r);
|
||||
}
|
||||
|
||||
if keycode.pressed(KeyCode::Equals) {
|
||||
if keycode.any_pressed([KeyCode::Equal, KeyCode::NumpadEqual]) {
|
||||
let r = (fog.color.r() + 0.1 * delta).min(1.0);
|
||||
fog.color.set_r(r);
|
||||
}
|
||||
|
@ -299,7 +299,7 @@ fn update_system(
|
|||
fog.color.set_b(b);
|
||||
}
|
||||
|
||||
if keycode.pressed(KeyCode::Apostrophe) {
|
||||
if keycode.pressed(KeyCode::Quote) {
|
||||
let b = (fog.color.b() + 0.1 * delta).min(1.0);
|
||||
fog.color.set_b(b);
|
||||
}
|
||||
|
|
|
@ -96,22 +96,22 @@ fn input_handler(
|
|||
let mesh = meshes.get_mut(mesh_handle).unwrap();
|
||||
toggle_texture(mesh);
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::X) {
|
||||
if keyboard_input.pressed(KeyCode::KeyX) {
|
||||
for mut transform in &mut query {
|
||||
transform.rotate_x(time.delta_seconds() / 1.2);
|
||||
}
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::Y) {
|
||||
if keyboard_input.pressed(KeyCode::KeyY) {
|
||||
for mut transform in &mut query {
|
||||
transform.rotate_y(time.delta_seconds() / 1.2);
|
||||
}
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::Z) {
|
||||
if keyboard_input.pressed(KeyCode::KeyZ) {
|
||||
for mut transform in &mut query {
|
||||
transform.rotate_z(time.delta_seconds() / 1.2);
|
||||
}
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::R) {
|
||||
if keyboard_input.pressed(KeyCode::KeyR) {
|
||||
for mut transform in &mut query {
|
||||
transform.look_to(Vec3::NEG_Z, Vec3::Y);
|
||||
}
|
||||
|
|
|
@ -267,16 +267,16 @@ fn movement(
|
|||
) {
|
||||
for mut transform in &mut query {
|
||||
let mut direction = Vec3::ZERO;
|
||||
if input.pressed(KeyCode::Up) {
|
||||
if input.pressed(KeyCode::ArrowUp) {
|
||||
direction.y += 1.0;
|
||||
}
|
||||
if input.pressed(KeyCode::Down) {
|
||||
if input.pressed(KeyCode::ArrowDown) {
|
||||
direction.y -= 1.0;
|
||||
}
|
||||
if input.pressed(KeyCode::Left) {
|
||||
if input.pressed(KeyCode::ArrowLeft) {
|
||||
direction.x -= 1.0;
|
||||
}
|
||||
if input.pressed(KeyCode::Right) {
|
||||
if input.pressed(KeyCode::ArrowRight) {
|
||||
direction.x += 1.0;
|
||||
}
|
||||
|
||||
|
|
|
@ -85,12 +85,12 @@ fn update_parallax_depth_scale(
|
|||
mut depth_update: Local<bool>,
|
||||
mut text: Query<&mut Text>,
|
||||
) {
|
||||
if input.just_pressed(KeyCode::Key1) {
|
||||
if input.just_pressed(KeyCode::Digit1) {
|
||||
target_depth.0 -= DEPTH_UPDATE_STEP;
|
||||
target_depth.0 = target_depth.0.max(0.0);
|
||||
*depth_update = true;
|
||||
}
|
||||
if input.just_pressed(KeyCode::Key2) {
|
||||
if input.just_pressed(KeyCode::Digit2) {
|
||||
target_depth.0 += DEPTH_UPDATE_STEP;
|
||||
target_depth.0 = target_depth.0.min(MAX_DEPTH);
|
||||
*depth_update = true;
|
||||
|
@ -135,10 +135,10 @@ fn update_parallax_layers(
|
|||
mut target_layers: Local<TargetLayers>,
|
||||
mut text: Query<&mut Text>,
|
||||
) {
|
||||
if input.just_pressed(KeyCode::Key3) {
|
||||
if input.just_pressed(KeyCode::Digit3) {
|
||||
target_layers.0 -= 1.0;
|
||||
target_layers.0 = target_layers.0.max(0.0);
|
||||
} else if input.just_pressed(KeyCode::Key4) {
|
||||
} else if input.just_pressed(KeyCode::Digit4) {
|
||||
target_layers.0 += 1.0;
|
||||
} else {
|
||||
return;
|
||||
|
|
|
@ -192,7 +192,7 @@ fn toggle_light(
|
|||
mut directional_lights: Query<&mut DirectionalLight>,
|
||||
mut example_text: Query<&mut Text>,
|
||||
) {
|
||||
if input.just_pressed(KeyCode::L) {
|
||||
if input.just_pressed(KeyCode::KeyL) {
|
||||
for mut light in &mut point_lights {
|
||||
light.intensity = if light.intensity == 0.0 {
|
||||
example_text.single_mut().sections[5].value = "PointLight".to_string();
|
||||
|
@ -218,16 +218,16 @@ fn adjust_light_position(
|
|||
mut example_text: Query<&mut Text>,
|
||||
) {
|
||||
let mut offset = Vec3::ZERO;
|
||||
if input.just_pressed(KeyCode::Left) {
|
||||
if input.just_pressed(KeyCode::ArrowLeft) {
|
||||
offset.x -= 1.0;
|
||||
}
|
||||
if input.just_pressed(KeyCode::Right) {
|
||||
if input.just_pressed(KeyCode::ArrowRight) {
|
||||
offset.x += 1.0;
|
||||
}
|
||||
if input.just_pressed(KeyCode::Up) {
|
||||
if input.just_pressed(KeyCode::ArrowUp) {
|
||||
offset.z -= 1.0;
|
||||
}
|
||||
if input.just_pressed(KeyCode::Down) {
|
||||
if input.just_pressed(KeyCode::ArrowDown) {
|
||||
offset.z += 1.0;
|
||||
}
|
||||
if input.just_pressed(KeyCode::PageDown) {
|
||||
|
@ -253,7 +253,7 @@ fn cycle_filter_methods(
|
|||
mut filter_methods: Query<&mut ShadowFilteringMethod>,
|
||||
mut example_text: Query<&mut Text>,
|
||||
) {
|
||||
if input.just_pressed(KeyCode::F) {
|
||||
if input.just_pressed(KeyCode::KeyF) {
|
||||
for mut filter_method in &mut filter_methods {
|
||||
let filter_method_string;
|
||||
*filter_method = match *filter_method {
|
||||
|
@ -283,23 +283,23 @@ fn adjust_point_light_biases(
|
|||
let depth_bias_step_size = 0.01;
|
||||
let normal_bias_step_size = 0.1;
|
||||
for mut light in &mut query {
|
||||
if input.just_pressed(KeyCode::Key1) {
|
||||
if input.just_pressed(KeyCode::Digit1) {
|
||||
light.shadow_depth_bias -= depth_bias_step_size;
|
||||
}
|
||||
if input.just_pressed(KeyCode::Key2) {
|
||||
if input.just_pressed(KeyCode::Digit2) {
|
||||
light.shadow_depth_bias += depth_bias_step_size;
|
||||
}
|
||||
if input.just_pressed(KeyCode::Key3) {
|
||||
if input.just_pressed(KeyCode::Digit3) {
|
||||
light.shadow_normal_bias -= normal_bias_step_size;
|
||||
}
|
||||
if input.just_pressed(KeyCode::Key4) {
|
||||
if input.just_pressed(KeyCode::Digit4) {
|
||||
light.shadow_normal_bias += normal_bias_step_size;
|
||||
}
|
||||
if input.just_pressed(KeyCode::R) {
|
||||
if input.just_pressed(KeyCode::KeyR) {
|
||||
light.shadow_depth_bias = PointLight::DEFAULT_SHADOW_DEPTH_BIAS;
|
||||
light.shadow_normal_bias = PointLight::DEFAULT_SHADOW_NORMAL_BIAS;
|
||||
}
|
||||
if input.just_pressed(KeyCode::Z) {
|
||||
if input.just_pressed(KeyCode::KeyZ) {
|
||||
light.shadow_depth_bias = 0.0;
|
||||
light.shadow_normal_bias = 0.0;
|
||||
}
|
||||
|
@ -317,23 +317,23 @@ fn adjust_directional_light_biases(
|
|||
let depth_bias_step_size = 0.01;
|
||||
let normal_bias_step_size = 0.1;
|
||||
for mut light in &mut query {
|
||||
if input.just_pressed(KeyCode::Key5) {
|
||||
if input.just_pressed(KeyCode::Digit5) {
|
||||
light.shadow_depth_bias -= depth_bias_step_size;
|
||||
}
|
||||
if input.just_pressed(KeyCode::Key6) {
|
||||
if input.just_pressed(KeyCode::Digit6) {
|
||||
light.shadow_depth_bias += depth_bias_step_size;
|
||||
}
|
||||
if input.just_pressed(KeyCode::Key7) {
|
||||
if input.just_pressed(KeyCode::Digit7) {
|
||||
light.shadow_normal_bias -= normal_bias_step_size;
|
||||
}
|
||||
if input.just_pressed(KeyCode::Key8) {
|
||||
if input.just_pressed(KeyCode::Digit8) {
|
||||
light.shadow_normal_bias += normal_bias_step_size;
|
||||
}
|
||||
if input.just_pressed(KeyCode::R) {
|
||||
if input.just_pressed(KeyCode::KeyR) {
|
||||
light.shadow_depth_bias = DirectionalLight::DEFAULT_SHADOW_DEPTH_BIAS;
|
||||
light.shadow_normal_bias = DirectionalLight::DEFAULT_SHADOW_NORMAL_BIAS;
|
||||
}
|
||||
if input.just_pressed(KeyCode::Z) {
|
||||
if input.just_pressed(KeyCode::KeyZ) {
|
||||
light.shadow_depth_bias = 0.0;
|
||||
light.shadow_normal_bias = 0.0;
|
||||
}
|
||||
|
@ -367,12 +367,12 @@ impl Default for CameraController {
|
|||
Self {
|
||||
enabled: true,
|
||||
sensitivity: 0.5,
|
||||
key_forward: KeyCode::W,
|
||||
key_back: KeyCode::S,
|
||||
key_left: KeyCode::A,
|
||||
key_right: KeyCode::D,
|
||||
key_up: KeyCode::E,
|
||||
key_down: KeyCode::Q,
|
||||
key_forward: KeyCode::KeyW,
|
||||
key_back: KeyCode::KeyS,
|
||||
key_left: KeyCode::KeyA,
|
||||
key_right: KeyCode::KeyD,
|
||||
key_up: KeyCode::KeyE,
|
||||
key_down: KeyCode::KeyQ,
|
||||
key_run: KeyCode::ShiftLeft,
|
||||
walk_speed: 10.0,
|
||||
run_speed: 30.0,
|
||||
|
|
|
@ -130,7 +130,7 @@ fn toggle_light(
|
|||
mut point_lights: Query<&mut PointLight>,
|
||||
mut directional_lights: Query<&mut DirectionalLight>,
|
||||
) {
|
||||
if input.just_pressed(KeyCode::L) {
|
||||
if input.just_pressed(KeyCode::KeyL) {
|
||||
for mut light in &mut point_lights {
|
||||
light.intensity = if light.intensity == 0.0 {
|
||||
println!("Using PointLight");
|
||||
|
@ -160,7 +160,7 @@ fn toggle_shadows(
|
|||
Query<Entity, (With<Handle<Mesh>>, Without<NotShadowReceiver>)>,
|
||||
)>,
|
||||
) {
|
||||
if input.just_pressed(KeyCode::C) {
|
||||
if input.just_pressed(KeyCode::KeyC) {
|
||||
println!("Toggling casters");
|
||||
for entity in queries.p0().iter() {
|
||||
commands.entity(entity).remove::<NotShadowCaster>();
|
||||
|
@ -169,7 +169,7 @@ fn toggle_shadows(
|
|||
commands.entity(entity).insert(NotShadowCaster);
|
||||
}
|
||||
}
|
||||
if input.just_pressed(KeyCode::R) {
|
||||
if input.just_pressed(KeyCode::KeyR) {
|
||||
println!("Toggling receivers");
|
||||
for entity in queries.p1().iter() {
|
||||
commands.entity(entity).remove::<NotShadowReceiver>();
|
||||
|
|
|
@ -198,15 +198,15 @@ impl Default for CameraController {
|
|||
enabled: true,
|
||||
initialized: false,
|
||||
sensitivity: 0.5,
|
||||
key_forward: KeyCode::W,
|
||||
key_back: KeyCode::S,
|
||||
key_left: KeyCode::A,
|
||||
key_right: KeyCode::D,
|
||||
key_up: KeyCode::E,
|
||||
key_down: KeyCode::Q,
|
||||
key_forward: KeyCode::KeyW,
|
||||
key_back: KeyCode::KeyS,
|
||||
key_left: KeyCode::KeyA,
|
||||
key_right: KeyCode::KeyD,
|
||||
key_up: KeyCode::KeyE,
|
||||
key_down: KeyCode::KeyQ,
|
||||
key_run: KeyCode::ShiftLeft,
|
||||
mouse_key_enable_mouse: MouseButton::Left,
|
||||
keyboard_key_enable_mouse: KeyCode::M,
|
||||
keyboard_key_enable_mouse: KeyCode::KeyM,
|
||||
walk_speed: 2.0,
|
||||
run_speed: 6.0,
|
||||
friction: 0.5,
|
||||
|
|
|
@ -147,16 +147,16 @@ fn movement(
|
|||
) {
|
||||
for mut transform in &mut query {
|
||||
let mut direction = Vec3::ZERO;
|
||||
if input.pressed(KeyCode::Up) {
|
||||
if input.pressed(KeyCode::ArrowUp) {
|
||||
direction.z -= 1.0;
|
||||
}
|
||||
if input.pressed(KeyCode::Down) {
|
||||
if input.pressed(KeyCode::ArrowDown) {
|
||||
direction.z += 1.0;
|
||||
}
|
||||
if input.pressed(KeyCode::Left) {
|
||||
if input.pressed(KeyCode::ArrowLeft) {
|
||||
direction.x -= 1.0;
|
||||
}
|
||||
if input.pressed(KeyCode::Right) {
|
||||
if input.pressed(KeyCode::ArrowRight) {
|
||||
direction.x += 1.0;
|
||||
}
|
||||
if input.pressed(KeyCode::PageUp) {
|
||||
|
|
|
@ -136,25 +136,25 @@ fn update(
|
|||
let (camera_entity, ssao_settings, temporal_jitter) = camera.single();
|
||||
|
||||
let mut commands = commands.entity(camera_entity);
|
||||
if keycode.just_pressed(KeyCode::Key1) {
|
||||
if keycode.just_pressed(KeyCode::Digit1) {
|
||||
commands.remove::<ScreenSpaceAmbientOcclusionSettings>();
|
||||
}
|
||||
if keycode.just_pressed(KeyCode::Key2) {
|
||||
if keycode.just_pressed(KeyCode::Digit2) {
|
||||
commands.insert(ScreenSpaceAmbientOcclusionSettings {
|
||||
quality_level: ScreenSpaceAmbientOcclusionQualityLevel::Low,
|
||||
});
|
||||
}
|
||||
if keycode.just_pressed(KeyCode::Key3) {
|
||||
if keycode.just_pressed(KeyCode::Digit3) {
|
||||
commands.insert(ScreenSpaceAmbientOcclusionSettings {
|
||||
quality_level: ScreenSpaceAmbientOcclusionQualityLevel::Medium,
|
||||
});
|
||||
}
|
||||
if keycode.just_pressed(KeyCode::Key4) {
|
||||
if keycode.just_pressed(KeyCode::Digit4) {
|
||||
commands.insert(ScreenSpaceAmbientOcclusionSettings {
|
||||
quality_level: ScreenSpaceAmbientOcclusionQualityLevel::High,
|
||||
});
|
||||
}
|
||||
if keycode.just_pressed(KeyCode::Key5) {
|
||||
if keycode.just_pressed(KeyCode::Digit5) {
|
||||
commands.insert(ScreenSpaceAmbientOcclusionSettings {
|
||||
quality_level: ScreenSpaceAmbientOcclusionQualityLevel::Ultra,
|
||||
});
|
||||
|
|
|
@ -352,11 +352,11 @@ fn toggle_scene(
|
|||
mut current_scene: ResMut<CurrentScene>,
|
||||
) {
|
||||
let mut pressed = None;
|
||||
if keys.just_pressed(KeyCode::Q) {
|
||||
if keys.just_pressed(KeyCode::KeyQ) {
|
||||
pressed = Some(1);
|
||||
} else if keys.just_pressed(KeyCode::W) {
|
||||
} else if keys.just_pressed(KeyCode::KeyW) {
|
||||
pressed = Some(2);
|
||||
} else if keys.just_pressed(KeyCode::E) {
|
||||
} else if keys.just_pressed(KeyCode::KeyE) {
|
||||
pressed = Some(3);
|
||||
}
|
||||
|
||||
|
@ -382,21 +382,21 @@ fn toggle_tonemapping_method(
|
|||
let mut method = tonemapping.single_mut();
|
||||
let mut color_grading = color_grading.single_mut();
|
||||
|
||||
if keys.just_pressed(KeyCode::Key1) {
|
||||
if keys.just_pressed(KeyCode::Digit1) {
|
||||
*method = Tonemapping::None;
|
||||
} else if keys.just_pressed(KeyCode::Key2) {
|
||||
} else if keys.just_pressed(KeyCode::Digit2) {
|
||||
*method = Tonemapping::Reinhard;
|
||||
} else if keys.just_pressed(KeyCode::Key3) {
|
||||
} else if keys.just_pressed(KeyCode::Digit3) {
|
||||
*method = Tonemapping::ReinhardLuminance;
|
||||
} else if keys.just_pressed(KeyCode::Key4) {
|
||||
} else if keys.just_pressed(KeyCode::Digit4) {
|
||||
*method = Tonemapping::AcesFitted;
|
||||
} else if keys.just_pressed(KeyCode::Key5) {
|
||||
} else if keys.just_pressed(KeyCode::Digit5) {
|
||||
*method = Tonemapping::AgX;
|
||||
} else if keys.just_pressed(KeyCode::Key6) {
|
||||
} else if keys.just_pressed(KeyCode::Digit6) {
|
||||
*method = Tonemapping::SomewhatBoringDisplayTransform;
|
||||
} else if keys.just_pressed(KeyCode::Key7) {
|
||||
} else if keys.just_pressed(KeyCode::Digit7) {
|
||||
*method = Tonemapping::TonyMcMapface;
|
||||
} else if keys.just_pressed(KeyCode::Key8) {
|
||||
} else if keys.just_pressed(KeyCode::Digit8) {
|
||||
*method = Tonemapping::BlenderFilmic;
|
||||
}
|
||||
|
||||
|
@ -432,17 +432,17 @@ fn update_color_grading_settings(
|
|||
let method = tonemapping.single();
|
||||
let color_grading = per_method_settings.settings.get_mut(method).unwrap();
|
||||
let mut dt = time.delta_seconds() * 0.25;
|
||||
if keys.pressed(KeyCode::Left) {
|
||||
if keys.pressed(KeyCode::ArrowLeft) {
|
||||
dt = -dt;
|
||||
}
|
||||
|
||||
if keys.just_pressed(KeyCode::Down) {
|
||||
if keys.just_pressed(KeyCode::ArrowDown) {
|
||||
selected_parameter.next();
|
||||
}
|
||||
if keys.just_pressed(KeyCode::Up) {
|
||||
if keys.just_pressed(KeyCode::ArrowUp) {
|
||||
selected_parameter.prev();
|
||||
}
|
||||
if keys.pressed(KeyCode::Left) || keys.pressed(KeyCode::Right) {
|
||||
if keys.pressed(KeyCode::ArrowLeft) || keys.pressed(KeyCode::ArrowRight) {
|
||||
match selected_parameter.value {
|
||||
0 => {
|
||||
color_grading.exposure += dt;
|
||||
|
@ -466,7 +466,7 @@ fn update_color_grading_settings(
|
|||
}
|
||||
}
|
||||
|
||||
if keys.just_pressed(KeyCode::Return) && current_scene.0 == 1 {
|
||||
if keys.just_pressed(KeyCode::Enter) && current_scene.0 == 1 {
|
||||
for (mapper, grading) in per_method_settings.settings.iter_mut() {
|
||||
*grading = PerMethodSettings::basic_scene_recommendation(*mapper);
|
||||
}
|
||||
|
@ -487,7 +487,7 @@ fn update_ui(
|
|||
let mut text = text.single_mut();
|
||||
let text = &mut text.sections[0].value;
|
||||
|
||||
if keys.just_pressed(KeyCode::H) {
|
||||
if keys.just_pressed(KeyCode::KeyH) {
|
||||
*hide_ui = !*hide_ui;
|
||||
}
|
||||
text.clear();
|
||||
|
|
|
@ -440,43 +440,43 @@ fn example_control_system(
|
|||
time: Res<Time>,
|
||||
input: Res<ButtonInput<KeyCode>>,
|
||||
) {
|
||||
if input.pressed(KeyCode::Key2) {
|
||||
if input.pressed(KeyCode::Digit2) {
|
||||
state.diffuse_transmission = (state.diffuse_transmission + time.delta_seconds()).min(1.0);
|
||||
} else if input.pressed(KeyCode::Key1) {
|
||||
} else if input.pressed(KeyCode::Digit1) {
|
||||
state.diffuse_transmission = (state.diffuse_transmission - time.delta_seconds()).max(0.0);
|
||||
}
|
||||
|
||||
if input.pressed(KeyCode::W) {
|
||||
if input.pressed(KeyCode::KeyW) {
|
||||
state.specular_transmission = (state.specular_transmission + time.delta_seconds()).min(1.0);
|
||||
} else if input.pressed(KeyCode::Q) {
|
||||
} else if input.pressed(KeyCode::KeyQ) {
|
||||
state.specular_transmission = (state.specular_transmission - time.delta_seconds()).max(0.0);
|
||||
}
|
||||
|
||||
if input.pressed(KeyCode::S) {
|
||||
if input.pressed(KeyCode::KeyS) {
|
||||
state.thickness = (state.thickness + time.delta_seconds()).min(5.0);
|
||||
} else if input.pressed(KeyCode::A) {
|
||||
} else if input.pressed(KeyCode::KeyA) {
|
||||
state.thickness = (state.thickness - time.delta_seconds()).max(0.0);
|
||||
}
|
||||
|
||||
if input.pressed(KeyCode::X) {
|
||||
if input.pressed(KeyCode::KeyX) {
|
||||
state.ior = (state.ior + time.delta_seconds()).min(3.0);
|
||||
} else if input.pressed(KeyCode::Z) {
|
||||
} else if input.pressed(KeyCode::KeyZ) {
|
||||
state.ior = (state.ior - time.delta_seconds()).max(1.0);
|
||||
}
|
||||
|
||||
if input.pressed(KeyCode::I) {
|
||||
if input.pressed(KeyCode::KeyI) {
|
||||
state.reflectance = (state.reflectance + time.delta_seconds()).min(1.0);
|
||||
} else if input.pressed(KeyCode::U) {
|
||||
} else if input.pressed(KeyCode::KeyU) {
|
||||
state.reflectance = (state.reflectance - time.delta_seconds()).max(0.0);
|
||||
}
|
||||
|
||||
if input.pressed(KeyCode::R) {
|
||||
if input.pressed(KeyCode::KeyR) {
|
||||
state.perceptual_roughness = (state.perceptual_roughness + time.delta_seconds()).min(1.0);
|
||||
} else if input.pressed(KeyCode::E) {
|
||||
} else if input.pressed(KeyCode::KeyE) {
|
||||
state.perceptual_roughness = (state.perceptual_roughness - time.delta_seconds()).max(0.0);
|
||||
}
|
||||
|
||||
let randomize_colors = input.just_pressed(KeyCode::C);
|
||||
let randomize_colors = input.just_pressed(KeyCode::KeyC);
|
||||
|
||||
for (material_handle, controls) in &controllable {
|
||||
let material = materials.get_mut(material_handle).unwrap();
|
||||
|
@ -508,12 +508,12 @@ fn example_control_system(
|
|||
temporal_jitter,
|
||||
) = camera.single_mut();
|
||||
|
||||
if input.just_pressed(KeyCode::H) {
|
||||
if input.just_pressed(KeyCode::KeyH) {
|
||||
camera.hdr = !camera.hdr;
|
||||
}
|
||||
|
||||
#[cfg(not(all(feature = "webgl2", target_arch = "wasm32")))]
|
||||
if input.just_pressed(KeyCode::D) {
|
||||
if input.just_pressed(KeyCode::KeyD) {
|
||||
if depth_prepass.is_none() {
|
||||
commands.entity(camera_entity).insert(DepthPrepass);
|
||||
} else {
|
||||
|
@ -522,7 +522,7 @@ fn example_control_system(
|
|||
}
|
||||
|
||||
#[cfg(not(all(feature = "webgl2", target_arch = "wasm32")))]
|
||||
if input.just_pressed(KeyCode::T) {
|
||||
if input.just_pressed(KeyCode::KeyT) {
|
||||
if temporal_jitter.is_none() {
|
||||
commands.entity(camera_entity).insert((
|
||||
TemporalJitter::default(),
|
||||
|
@ -535,24 +535,24 @@ fn example_control_system(
|
|||
}
|
||||
}
|
||||
|
||||
if input.just_pressed(KeyCode::O) && camera_3d.screen_space_specular_transmission_steps > 0 {
|
||||
if input.just_pressed(KeyCode::KeyO) && camera_3d.screen_space_specular_transmission_steps > 0 {
|
||||
camera_3d.screen_space_specular_transmission_steps -= 1;
|
||||
}
|
||||
|
||||
if input.just_pressed(KeyCode::P) && camera_3d.screen_space_specular_transmission_steps < 4 {
|
||||
if input.just_pressed(KeyCode::KeyP) && camera_3d.screen_space_specular_transmission_steps < 4 {
|
||||
camera_3d.screen_space_specular_transmission_steps += 1;
|
||||
}
|
||||
|
||||
if input.just_pressed(KeyCode::J) {
|
||||
if input.just_pressed(KeyCode::KeyJ) {
|
||||
camera_3d.screen_space_specular_transmission_quality = ScreenSpaceTransmissionQuality::Low;
|
||||
}
|
||||
|
||||
if input.just_pressed(KeyCode::K) {
|
||||
if input.just_pressed(KeyCode::KeyK) {
|
||||
camera_3d.screen_space_specular_transmission_quality =
|
||||
ScreenSpaceTransmissionQuality::Medium;
|
||||
}
|
||||
|
||||
if input.just_pressed(KeyCode::L) {
|
||||
if input.just_pressed(KeyCode::KeyL) {
|
||||
camera_3d.screen_space_specular_transmission_quality = ScreenSpaceTransmissionQuality::High;
|
||||
}
|
||||
|
||||
|
@ -561,10 +561,10 @@ fn example_control_system(
|
|||
ScreenSpaceTransmissionQuality::Ultra;
|
||||
}
|
||||
|
||||
let rotation = if input.pressed(KeyCode::Right) {
|
||||
let rotation = if input.pressed(KeyCode::ArrowRight) {
|
||||
state.auto_camera = false;
|
||||
time.delta_seconds()
|
||||
} else if input.pressed(KeyCode::Left) {
|
||||
} else if input.pressed(KeyCode::ArrowLeft) {
|
||||
state.auto_camera = false;
|
||||
-time.delta_seconds()
|
||||
} else if state.auto_camera {
|
||||
|
@ -574,9 +574,9 @@ fn example_control_system(
|
|||
};
|
||||
|
||||
let distance_change =
|
||||
if input.pressed(KeyCode::Down) && camera_transform.translation.length() < 25.0 {
|
||||
if input.pressed(KeyCode::ArrowDown) && camera_transform.translation.length() < 25.0 {
|
||||
time.delta_seconds()
|
||||
} else if input.pressed(KeyCode::Up) && camera_transform.translation.length() > 2.0 {
|
||||
} else if input.pressed(KeyCode::ArrowUp) && camera_transform.translation.length() > 2.0 {
|
||||
-time.delta_seconds()
|
||||
} else {
|
||||
0.0
|
||||
|
|
|
@ -139,12 +139,12 @@ Color: {:?}
|
|||
);
|
||||
|
||||
// Toggle showing a wireframe on all meshes
|
||||
if keyboard_input.just_pressed(KeyCode::Z) {
|
||||
if keyboard_input.just_pressed(KeyCode::KeyZ) {
|
||||
config.global = !config.global;
|
||||
}
|
||||
|
||||
// Toggle the global wireframe color
|
||||
if keyboard_input.just_pressed(KeyCode::X) {
|
||||
if keyboard_input.just_pressed(KeyCode::KeyX) {
|
||||
config.default_color = if config.default_color == Color::WHITE {
|
||||
Color::PINK
|
||||
} else {
|
||||
|
@ -153,7 +153,7 @@ Color: {:?}
|
|||
}
|
||||
|
||||
// Toggle the color of a wireframe using WireframeColor and not the global color
|
||||
if keyboard_input.just_pressed(KeyCode::C) {
|
||||
if keyboard_input.just_pressed(KeyCode::KeyC) {
|
||||
for mut color in &mut wireframe_colors {
|
||||
color.color = if color.color == Color::GREEN {
|
||||
Color::RED
|
||||
|
|
|
@ -106,27 +106,27 @@ fn keyboard_animation_control(
|
|||
}
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::Up) {
|
||||
if keyboard_input.just_pressed(KeyCode::ArrowUp) {
|
||||
let speed = player.speed();
|
||||
player.set_speed(speed * 1.2);
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::Down) {
|
||||
if keyboard_input.just_pressed(KeyCode::ArrowDown) {
|
||||
let speed = player.speed();
|
||||
player.set_speed(speed * 0.8);
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::Left) {
|
||||
if keyboard_input.just_pressed(KeyCode::ArrowLeft) {
|
||||
let elapsed = player.seek_time();
|
||||
player.seek_to(elapsed - 0.1);
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::Right) {
|
||||
if keyboard_input.just_pressed(KeyCode::ArrowRight) {
|
||||
let elapsed = player.seek_time();
|
||||
player.seek_to(elapsed + 0.1);
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::Return) {
|
||||
if keyboard_input.just_pressed(KeyCode::Enter) {
|
||||
*current_animation = (*current_animation + 1) % animations.0.len();
|
||||
player
|
||||
.play_with_transition(
|
||||
|
@ -136,22 +136,22 @@ fn keyboard_animation_control(
|
|||
.repeat();
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::Key1) {
|
||||
if keyboard_input.just_pressed(KeyCode::Digit1) {
|
||||
player.set_repeat(RepeatAnimation::Count(1));
|
||||
player.replay();
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::Key3) {
|
||||
if keyboard_input.just_pressed(KeyCode::Digit3) {
|
||||
player.set_repeat(RepeatAnimation::Count(3));
|
||||
player.replay();
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::Key5) {
|
||||
if keyboard_input.just_pressed(KeyCode::Digit5) {
|
||||
player.set_repeat(RepeatAnimation::Count(5));
|
||||
player.replay();
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::L) {
|
||||
if keyboard_input.just_pressed(KeyCode::KeyL) {
|
||||
player.set_repeat(RepeatAnimation::Forever);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +1,15 @@
|
|||
//! Shows how to return to the calling function after a windowed Bevy app has exited.
|
||||
//!
|
||||
//! In windowed *Bevy* applications, executing code below a call to `App::run()` is
|
||||
//! not recommended because `App::run()` might never return.
|
||||
//!
|
||||
//! This example demonstrates the use of `WinitSettings::return_from_run` to
|
||||
//! require that `App::run()` *does* return but this is not recommended. Be sure
|
||||
//! to read the documentation on both `App::run()` and `WinitSettings::return_from_run`
|
||||
//! for caveats and further details:
|
||||
//!
|
||||
//! - <https://docs.rs/bevy/latest/bevy/app/struct.App.html#method.run>
|
||||
//! - <https://docs.rs/bevy/latest/bevy/winit/struct.WinitSettings.html#structfield.return_from_run>
|
||||
//! not recommended because:
|
||||
//! - `App::run()` will never return on iOS and Web.
|
||||
//! - It is not possible to recreate a window afer the event loop has been terminated.
|
||||
|
||||
use bevy::{prelude::*, window::WindowPlugin, winit::WinitSettings};
|
||||
use bevy::{prelude::*, window::WindowPlugin};
|
||||
|
||||
fn main() {
|
||||
println!("Running Bevy App");
|
||||
App::new()
|
||||
.insert_resource(WinitSettings {
|
||||
return_from_run: true,
|
||||
..default()
|
||||
})
|
||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
title: "Close the window to return to the main function".into(),
|
||||
|
|
|
@ -45,7 +45,7 @@ fn volume(
|
|||
music_controller: Query<&AudioSink, With<MyMusic>>,
|
||||
) {
|
||||
if let Ok(sink) = music_controller.get_single() {
|
||||
if keyboard_input.just_pressed(KeyCode::Plus) {
|
||||
if keyboard_input.just_pressed(KeyCode::Equal) {
|
||||
sink.set_volume(sink.volume() + 0.1);
|
||||
} else if keyboard_input.just_pressed(KeyCode::Minus) {
|
||||
sink.set_volume(sink.volume() - 0.1);
|
||||
|
|
|
@ -43,10 +43,10 @@ fn keyboard_input_system(
|
|||
mut frequency: ResMut<PitchFrequency>,
|
||||
mut events: EventWriter<PlayPitch>,
|
||||
) {
|
||||
if keyboard_input.just_pressed(KeyCode::Up) {
|
||||
if keyboard_input.just_pressed(KeyCode::ArrowUp) {
|
||||
frequency.0 *= 2.0f32.powf(1.0 / 12.0);
|
||||
}
|
||||
if keyboard_input.just_pressed(KeyCode::Down) {
|
||||
if keyboard_input.just_pressed(KeyCode::ArrowDown) {
|
||||
frequency.0 /= 2.0f32.powf(1.0 / 12.0);
|
||||
}
|
||||
if keyboard_input.just_pressed(KeyCode::Space) {
|
||||
|
|
|
@ -124,16 +124,16 @@ fn update_listener(
|
|||
|
||||
let speed = 200.;
|
||||
|
||||
if keyboard.pressed(KeyCode::Right) {
|
||||
if keyboard.pressed(KeyCode::ArrowRight) {
|
||||
transform.translation.x += speed * time.delta_seconds();
|
||||
}
|
||||
if keyboard.pressed(KeyCode::Left) {
|
||||
if keyboard.pressed(KeyCode::ArrowLeft) {
|
||||
transform.translation.x -= speed * time.delta_seconds();
|
||||
}
|
||||
if keyboard.pressed(KeyCode::Up) {
|
||||
if keyboard.pressed(KeyCode::ArrowUp) {
|
||||
transform.translation.y += speed * time.delta_seconds();
|
||||
}
|
||||
if keyboard.pressed(KeyCode::Down) {
|
||||
if keyboard.pressed(KeyCode::ArrowDown) {
|
||||
transform.translation.y -= speed * time.delta_seconds();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,16 +124,16 @@ fn update_listener(
|
|||
|
||||
let speed = 2.;
|
||||
|
||||
if keyboard.pressed(KeyCode::Right) {
|
||||
if keyboard.pressed(KeyCode::ArrowRight) {
|
||||
transform.translation.x += speed * time.delta_seconds();
|
||||
}
|
||||
if keyboard.pressed(KeyCode::Left) {
|
||||
if keyboard.pressed(KeyCode::ArrowLeft) {
|
||||
transform.translation.x -= speed * time.delta_seconds();
|
||||
}
|
||||
if keyboard.pressed(KeyCode::Down) {
|
||||
if keyboard.pressed(KeyCode::ArrowDown) {
|
||||
transform.translation.z += speed * time.delta_seconds();
|
||||
}
|
||||
if keyboard.pressed(KeyCode::Up) {
|
||||
if keyboard.pressed(KeyCode::ArrowUp) {
|
||||
transform.translation.z -= speed * time.delta_seconds();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ fn has_user_input(
|
|||
touch_input: Res<Touches>,
|
||||
) -> bool {
|
||||
keyboard_input.just_pressed(KeyCode::Space)
|
||||
|| keyboard_input.just_pressed(KeyCode::Return)
|
||||
|| keyboard_input.just_pressed(KeyCode::Enter)
|
||||
|| mouse_button_input.just_pressed(MouseButton::Left)
|
||||
|| mouse_button_input.just_pressed(MouseButton::Right)
|
||||
|| touch_input.any_just_pressed()
|
||||
|
|
|
@ -133,16 +133,16 @@ fn movement(
|
|||
) {
|
||||
for mut transform in &mut query {
|
||||
let mut direction = Vec3::ZERO;
|
||||
if input.pressed(KeyCode::Left) {
|
||||
if input.pressed(KeyCode::ArrowLeft) {
|
||||
direction.x -= 1.0;
|
||||
}
|
||||
if input.pressed(KeyCode::Right) {
|
||||
if input.pressed(KeyCode::ArrowRight) {
|
||||
direction.x += 1.0;
|
||||
}
|
||||
if input.pressed(KeyCode::Up) {
|
||||
if input.pressed(KeyCode::ArrowUp) {
|
||||
direction.y += 1.0;
|
||||
}
|
||||
if input.pressed(KeyCode::Down) {
|
||||
if input.pressed(KeyCode::ArrowDown) {
|
||||
direction.y -= 1.0;
|
||||
}
|
||||
|
||||
|
|
|
@ -201,28 +201,28 @@ fn move_player(
|
|||
let mut moved = false;
|
||||
let mut rotation = 0.0;
|
||||
|
||||
if keyboard_input.pressed(KeyCode::Up) {
|
||||
if keyboard_input.pressed(KeyCode::ArrowUp) {
|
||||
if game.player.i < BOARD_SIZE_I - 1 {
|
||||
game.player.i += 1;
|
||||
}
|
||||
rotation = -PI / 2.;
|
||||
moved = true;
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::Down) {
|
||||
if keyboard_input.pressed(KeyCode::ArrowDown) {
|
||||
if game.player.i > 0 {
|
||||
game.player.i -= 1;
|
||||
}
|
||||
rotation = PI / 2.;
|
||||
moved = true;
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::Right) {
|
||||
if keyboard_input.pressed(KeyCode::ArrowRight) {
|
||||
if game.player.j < BOARD_SIZE_J - 1 {
|
||||
game.player.j += 1;
|
||||
}
|
||||
rotation = PI;
|
||||
moved = true;
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::Left) {
|
||||
if keyboard_input.pressed(KeyCode::ArrowLeft) {
|
||||
if game.player.j > 0 {
|
||||
game.player.j -= 1;
|
||||
}
|
||||
|
|
|
@ -310,11 +310,11 @@ fn move_paddle(
|
|||
let mut paddle_transform = query.single_mut();
|
||||
let mut direction = 0.0;
|
||||
|
||||
if keyboard_input.pressed(KeyCode::Left) {
|
||||
if keyboard_input.pressed(KeyCode::ArrowLeft) {
|
||||
direction -= 1.0;
|
||||
}
|
||||
|
||||
if keyboard_input.pressed(KeyCode::Right) {
|
||||
if keyboard_input.pressed(KeyCode::ArrowRight) {
|
||||
direction += 1.0;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,15 +11,14 @@ fn main() {
|
|||
|
||||
/// This system prints 'A' key state
|
||||
fn keyboard_input_system(keyboard_input: Res<ButtonInput<KeyCode>>) {
|
||||
if keyboard_input.pressed(KeyCode::A) {
|
||||
if keyboard_input.pressed(KeyCode::KeyA) {
|
||||
info!("'A' currently pressed");
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::A) {
|
||||
if keyboard_input.just_pressed(KeyCode::KeyA) {
|
||||
info!("'A' just pressed");
|
||||
}
|
||||
|
||||
if keyboard_input.just_released(KeyCode::A) {
|
||||
if keyboard_input.just_released(KeyCode::KeyA) {
|
||||
info!("'A' just released");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ fn keyboard_input_system(input: Res<ButtonInput<KeyCode>>) {
|
|||
let shift = input.any_pressed([KeyCode::ShiftLeft, KeyCode::ShiftRight]);
|
||||
let ctrl = input.any_pressed([KeyCode::ControlLeft, KeyCode::ControlRight]);
|
||||
|
||||
if ctrl && shift && input.just_pressed(KeyCode::A) {
|
||||
if ctrl && shift && input.just_pressed(KeyCode::KeyA) {
|
||||
info!("Just pressed Ctrl + Shift + A!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -169,7 +169,9 @@ fn listen_received_character_events(
|
|||
mut edit_text: Query<&mut Text, (Without<Node>, Without<Bubble>)>,
|
||||
) {
|
||||
for event in events.read() {
|
||||
edit_text.single_mut().sections[0].value.push(event.char);
|
||||
edit_text.single_mut().sections[0]
|
||||
.value
|
||||
.push_str(&event.char);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,7 +182,7 @@ fn listen_keyboard_input_events(
|
|||
) {
|
||||
for event in events.read() {
|
||||
match event.key_code {
|
||||
Some(KeyCode::Return) => {
|
||||
KeyCode::Enter => {
|
||||
let (entity, text) = edit_text.single();
|
||||
commands.entity(entity).insert(Bubble {
|
||||
timer: Timer::from_seconds(5.0, TimerMode::Once),
|
||||
|
@ -191,7 +193,7 @@ fn listen_keyboard_input_events(
|
|||
..default()
|
||||
});
|
||||
}
|
||||
Some(KeyCode::Back) => {
|
||||
KeyCode::Backspace => {
|
||||
edit_text.single_mut().1.sections[0].value.pop();
|
||||
}
|
||||
_ => continue,
|
||||
|
|
|
@ -258,15 +258,15 @@ fn keyboard_animation_control(
|
|||
foxes.moving = !foxes.moving;
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::Up) {
|
||||
if keyboard_input.just_pressed(KeyCode::ArrowUp) {
|
||||
foxes.speed *= 1.25;
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::Down) {
|
||||
if keyboard_input.just_pressed(KeyCode::ArrowDown) {
|
||||
foxes.speed *= 0.8;
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::Return) {
|
||||
if keyboard_input.just_pressed(KeyCode::Enter) {
|
||||
*current_animation = (*current_animation + 1) % animations.0.len();
|
||||
}
|
||||
|
||||
|
@ -279,27 +279,27 @@ fn keyboard_animation_control(
|
|||
}
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::Up) {
|
||||
if keyboard_input.just_pressed(KeyCode::ArrowUp) {
|
||||
let speed = player.speed();
|
||||
player.set_speed(speed * 1.25);
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::Down) {
|
||||
if keyboard_input.just_pressed(KeyCode::ArrowDown) {
|
||||
let speed = player.speed();
|
||||
player.set_speed(speed * 0.8);
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::Left) {
|
||||
if keyboard_input.just_pressed(KeyCode::ArrowLeft) {
|
||||
let elapsed = player.seek_time();
|
||||
player.seek_to(elapsed - 0.1);
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::Right) {
|
||||
if keyboard_input.just_pressed(KeyCode::ArrowRight) {
|
||||
let elapsed = player.seek_time();
|
||||
player.seek_to(elapsed + 0.1);
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::Return) {
|
||||
if keyboard_input.just_pressed(KeyCode::Enter) {
|
||||
player
|
||||
.play_with_transition(
|
||||
animations.0[*current_animation].clone_weak(),
|
||||
|
|
|
@ -43,10 +43,10 @@ struct Config {
|
|||
}
|
||||
|
||||
fn input(mut config: ResMut<Config>, input: Res<ButtonInput<KeyCode>>) {
|
||||
if input.just_pressed(KeyCode::Up) {
|
||||
if input.just_pressed(KeyCode::ArrowUp) {
|
||||
config.line_count += 10_000;
|
||||
}
|
||||
if input.just_pressed(KeyCode::Down) {
|
||||
if input.just_pressed(KeyCode::ArrowDown) {
|
||||
config.line_count = config.line_count.saturating_sub(10_000);
|
||||
}
|
||||
if input.just_pressed(KeyCode::Space) {
|
||||
|
|
|
@ -18,8 +18,8 @@ fn main() {
|
|||
move_virtual_time_sprites,
|
||||
move_real_time_sprites,
|
||||
toggle_pause.run_if(input_just_pressed(KeyCode::Space)),
|
||||
change_time_speed::<1>.run_if(input_just_pressed(KeyCode::Up)),
|
||||
change_time_speed::<-1>.run_if(input_just_pressed(KeyCode::Down)),
|
||||
change_time_speed::<1>.run_if(input_just_pressed(KeyCode::ArrowUp)),
|
||||
change_time_speed::<-1>.run_if(input_just_pressed(KeyCode::ArrowDown)),
|
||||
(update_virtual_time_info_text, update_real_time_info_text)
|
||||
// update the texts on a timer to make them more readable
|
||||
// `on_timer` run condition uses `Virtual` time meaning it's scaled
|
||||
|
|
|
@ -87,7 +87,7 @@ fn handle_inputs(
|
|||
continue;
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::Return) {
|
||||
if keyboard_input.just_pressed(KeyCode::Enter) {
|
||||
info!("switching to new animation for {display_entity_name}");
|
||||
|
||||
let resume = !player.is_paused();
|
||||
|
|
|
@ -42,15 +42,15 @@ impl Default for CameraController {
|
|||
enabled: true,
|
||||
initialized: false,
|
||||
sensitivity: 1.0,
|
||||
key_forward: KeyCode::W,
|
||||
key_back: KeyCode::S,
|
||||
key_left: KeyCode::A,
|
||||
key_right: KeyCode::D,
|
||||
key_up: KeyCode::E,
|
||||
key_down: KeyCode::Q,
|
||||
key_forward: KeyCode::KeyW,
|
||||
key_back: KeyCode::KeyS,
|
||||
key_left: KeyCode::KeyA,
|
||||
key_right: KeyCode::KeyD,
|
||||
key_up: KeyCode::KeyE,
|
||||
key_down: KeyCode::KeyQ,
|
||||
key_run: KeyCode::ShiftLeft,
|
||||
mouse_key_enable_mouse: MouseButton::Left,
|
||||
keyboard_key_enable_mouse: KeyCode::M,
|
||||
keyboard_key_enable_mouse: KeyCode::KeyM,
|
||||
walk_speed: 5.0,
|
||||
run_speed: 15.0,
|
||||
friction: 0.5,
|
||||
|
|
|
@ -15,62 +15,62 @@ use std::fmt;
|
|||
const WEIGHT_PER_SECOND: f32 = 0.8;
|
||||
const ALL_MODIFIERS: &[KeyCode] = &[KeyCode::ShiftLeft, KeyCode::ControlLeft, KeyCode::AltLeft];
|
||||
const AVAILABLE_KEYS: [MorphKey; 56] = [
|
||||
MorphKey::new("r", &[], KeyCode::R),
|
||||
MorphKey::new("t", &[], KeyCode::T),
|
||||
MorphKey::new("z", &[], KeyCode::Z),
|
||||
MorphKey::new("i", &[], KeyCode::I),
|
||||
MorphKey::new("o", &[], KeyCode::O),
|
||||
MorphKey::new("p", &[], KeyCode::P),
|
||||
MorphKey::new("f", &[], KeyCode::F),
|
||||
MorphKey::new("g", &[], KeyCode::G),
|
||||
MorphKey::new("h", &[], KeyCode::H),
|
||||
MorphKey::new("j", &[], KeyCode::J),
|
||||
MorphKey::new("k", &[], KeyCode::K),
|
||||
MorphKey::new("y", &[], KeyCode::Y),
|
||||
MorphKey::new("x", &[], KeyCode::X),
|
||||
MorphKey::new("c", &[], KeyCode::C),
|
||||
MorphKey::new("v", &[], KeyCode::V),
|
||||
MorphKey::new("b", &[], KeyCode::B),
|
||||
MorphKey::new("n", &[], KeyCode::N),
|
||||
MorphKey::new("m", &[], KeyCode::M),
|
||||
MorphKey::new("0", &[], KeyCode::Key0),
|
||||
MorphKey::new("1", &[], KeyCode::Key1),
|
||||
MorphKey::new("2", &[], KeyCode::Key2),
|
||||
MorphKey::new("3", &[], KeyCode::Key3),
|
||||
MorphKey::new("4", &[], KeyCode::Key4),
|
||||
MorphKey::new("5", &[], KeyCode::Key5),
|
||||
MorphKey::new("6", &[], KeyCode::Key6),
|
||||
MorphKey::new("7", &[], KeyCode::Key7),
|
||||
MorphKey::new("8", &[], KeyCode::Key8),
|
||||
MorphKey::new("9", &[], KeyCode::Key9),
|
||||
MorphKey::new("lshift-R", &[KeyCode::ShiftLeft], KeyCode::R),
|
||||
MorphKey::new("lshift-T", &[KeyCode::ShiftLeft], KeyCode::T),
|
||||
MorphKey::new("lshift-Z", &[KeyCode::ShiftLeft], KeyCode::Z),
|
||||
MorphKey::new("lshift-I", &[KeyCode::ShiftLeft], KeyCode::I),
|
||||
MorphKey::new("lshift-O", &[KeyCode::ShiftLeft], KeyCode::O),
|
||||
MorphKey::new("lshift-P", &[KeyCode::ShiftLeft], KeyCode::P),
|
||||
MorphKey::new("lshift-F", &[KeyCode::ShiftLeft], KeyCode::F),
|
||||
MorphKey::new("lshift-G", &[KeyCode::ShiftLeft], KeyCode::G),
|
||||
MorphKey::new("lshift-H", &[KeyCode::ShiftLeft], KeyCode::H),
|
||||
MorphKey::new("lshift-J", &[KeyCode::ShiftLeft], KeyCode::J),
|
||||
MorphKey::new("lshift-K", &[KeyCode::ShiftLeft], KeyCode::K),
|
||||
MorphKey::new("lshift-Y", &[KeyCode::ShiftLeft], KeyCode::Y),
|
||||
MorphKey::new("lshift-X", &[KeyCode::ShiftLeft], KeyCode::X),
|
||||
MorphKey::new("lshift-C", &[KeyCode::ShiftLeft], KeyCode::C),
|
||||
MorphKey::new("lshift-V", &[KeyCode::ShiftLeft], KeyCode::V),
|
||||
MorphKey::new("lshift-B", &[KeyCode::ShiftLeft], KeyCode::B),
|
||||
MorphKey::new("lshift-N", &[KeyCode::ShiftLeft], KeyCode::N),
|
||||
MorphKey::new("lshift-M", &[KeyCode::ShiftLeft], KeyCode::M),
|
||||
MorphKey::new("lshift-0", &[KeyCode::ShiftLeft], KeyCode::Key0),
|
||||
MorphKey::new("lshift-1", &[KeyCode::ShiftLeft], KeyCode::Key1),
|
||||
MorphKey::new("lshift-2", &[KeyCode::ShiftLeft], KeyCode::Key2),
|
||||
MorphKey::new("lshift-3", &[KeyCode::ShiftLeft], KeyCode::Key3),
|
||||
MorphKey::new("lshift-4", &[KeyCode::ShiftLeft], KeyCode::Key4),
|
||||
MorphKey::new("lshift-5", &[KeyCode::ShiftLeft], KeyCode::Key5),
|
||||
MorphKey::new("lshift-6", &[KeyCode::ShiftLeft], KeyCode::Key6),
|
||||
MorphKey::new("lshift-7", &[KeyCode::ShiftLeft], KeyCode::Key7),
|
||||
MorphKey::new("lshift-8", &[KeyCode::ShiftLeft], KeyCode::Key8),
|
||||
MorphKey::new("lshift-9", &[KeyCode::ShiftLeft], KeyCode::Key9),
|
||||
MorphKey::new("r", &[], KeyCode::KeyR),
|
||||
MorphKey::new("t", &[], KeyCode::KeyT),
|
||||
MorphKey::new("z", &[], KeyCode::KeyZ),
|
||||
MorphKey::new("i", &[], KeyCode::KeyI),
|
||||
MorphKey::new("o", &[], KeyCode::KeyO),
|
||||
MorphKey::new("p", &[], KeyCode::KeyP),
|
||||
MorphKey::new("f", &[], KeyCode::KeyF),
|
||||
MorphKey::new("g", &[], KeyCode::KeyG),
|
||||
MorphKey::new("h", &[], KeyCode::KeyH),
|
||||
MorphKey::new("j", &[], KeyCode::KeyJ),
|
||||
MorphKey::new("k", &[], KeyCode::KeyK),
|
||||
MorphKey::new("y", &[], KeyCode::KeyY),
|
||||
MorphKey::new("x", &[], KeyCode::KeyX),
|
||||
MorphKey::new("c", &[], KeyCode::KeyC),
|
||||
MorphKey::new("v", &[], KeyCode::KeyV),
|
||||
MorphKey::new("b", &[], KeyCode::KeyB),
|
||||
MorphKey::new("n", &[], KeyCode::KeyN),
|
||||
MorphKey::new("m", &[], KeyCode::KeyM),
|
||||
MorphKey::new("0", &[], KeyCode::Digit0),
|
||||
MorphKey::new("1", &[], KeyCode::Digit1),
|
||||
MorphKey::new("2", &[], KeyCode::Digit2),
|
||||
MorphKey::new("3", &[], KeyCode::Digit3),
|
||||
MorphKey::new("4", &[], KeyCode::Digit4),
|
||||
MorphKey::new("5", &[], KeyCode::Digit5),
|
||||
MorphKey::new("6", &[], KeyCode::Digit6),
|
||||
MorphKey::new("7", &[], KeyCode::Digit7),
|
||||
MorphKey::new("8", &[], KeyCode::Digit8),
|
||||
MorphKey::new("9", &[], KeyCode::Digit9),
|
||||
MorphKey::new("lshift-R", &[KeyCode::ShiftLeft], KeyCode::KeyR),
|
||||
MorphKey::new("lshift-T", &[KeyCode::ShiftLeft], KeyCode::KeyT),
|
||||
MorphKey::new("lshift-Z", &[KeyCode::ShiftLeft], KeyCode::KeyZ),
|
||||
MorphKey::new("lshift-I", &[KeyCode::ShiftLeft], KeyCode::KeyI),
|
||||
MorphKey::new("lshift-O", &[KeyCode::ShiftLeft], KeyCode::KeyO),
|
||||
MorphKey::new("lshift-P", &[KeyCode::ShiftLeft], KeyCode::KeyP),
|
||||
MorphKey::new("lshift-F", &[KeyCode::ShiftLeft], KeyCode::KeyF),
|
||||
MorphKey::new("lshift-G", &[KeyCode::ShiftLeft], KeyCode::KeyG),
|
||||
MorphKey::new("lshift-H", &[KeyCode::ShiftLeft], KeyCode::KeyH),
|
||||
MorphKey::new("lshift-J", &[KeyCode::ShiftLeft], KeyCode::KeyJ),
|
||||
MorphKey::new("lshift-K", &[KeyCode::ShiftLeft], KeyCode::KeyK),
|
||||
MorphKey::new("lshift-Y", &[KeyCode::ShiftLeft], KeyCode::KeyY),
|
||||
MorphKey::new("lshift-X", &[KeyCode::ShiftLeft], KeyCode::KeyX),
|
||||
MorphKey::new("lshift-C", &[KeyCode::ShiftLeft], KeyCode::KeyC),
|
||||
MorphKey::new("lshift-V", &[KeyCode::ShiftLeft], KeyCode::KeyV),
|
||||
MorphKey::new("lshift-B", &[KeyCode::ShiftLeft], KeyCode::KeyB),
|
||||
MorphKey::new("lshift-N", &[KeyCode::ShiftLeft], KeyCode::KeyN),
|
||||
MorphKey::new("lshift-M", &[KeyCode::ShiftLeft], KeyCode::KeyM),
|
||||
MorphKey::new("lshift-0", &[KeyCode::ShiftLeft], KeyCode::Digit0),
|
||||
MorphKey::new("lshift-1", &[KeyCode::ShiftLeft], KeyCode::Digit1),
|
||||
MorphKey::new("lshift-2", &[KeyCode::ShiftLeft], KeyCode::Digit2),
|
||||
MorphKey::new("lshift-3", &[KeyCode::ShiftLeft], KeyCode::Digit3),
|
||||
MorphKey::new("lshift-4", &[KeyCode::ShiftLeft], KeyCode::Digit4),
|
||||
MorphKey::new("lshift-5", &[KeyCode::ShiftLeft], KeyCode::Digit5),
|
||||
MorphKey::new("lshift-6", &[KeyCode::ShiftLeft], KeyCode::Digit6),
|
||||
MorphKey::new("lshift-7", &[KeyCode::ShiftLeft], KeyCode::Digit7),
|
||||
MorphKey::new("lshift-8", &[KeyCode::ShiftLeft], KeyCode::Digit8),
|
||||
MorphKey::new("lshift-9", &[KeyCode::ShiftLeft], KeyCode::Digit9),
|
||||
];
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
|
|
|
@ -73,7 +73,7 @@ impl Plugin for SceneViewerPlugin {
|
|||
(
|
||||
update_lights,
|
||||
camera_tracker,
|
||||
toggle_bounding_boxes.run_if(input_just_pressed(KeyCode::B)),
|
||||
toggle_bounding_boxes.run_if(input_just_pressed(KeyCode::KeyB)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -139,6 +139,7 @@ fn scene_load_check(
|
|||
Some(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn update_lights(
|
||||
key_input: Res<ButtonInput<KeyCode>>,
|
||||
time: Res<Time>,
|
||||
|
@ -146,12 +147,12 @@ fn update_lights(
|
|||
mut animate_directional_light: Local<bool>,
|
||||
) {
|
||||
for (_, mut light) in &mut query {
|
||||
if key_input.just_pressed(KeyCode::U) {
|
||||
if key_input.just_pressed(KeyCode::KeyU) {
|
||||
light.shadows_enabled = !light.shadows_enabled;
|
||||
}
|
||||
}
|
||||
|
||||
if key_input.just_pressed(KeyCode::L) {
|
||||
if key_input.just_pressed(KeyCode::KeyL) {
|
||||
*animate_directional_light = !*animate_directional_light;
|
||||
}
|
||||
if *animate_directional_light {
|
||||
|
@ -215,7 +216,7 @@ fn camera_tracker(
|
|||
camera.is_active = camera_tracker.track_camera(entity);
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::C) {
|
||||
if keyboard_input.just_pressed(KeyCode::KeyC) {
|
||||
// disable currently active camera
|
||||
if let Some(e) = camera_tracker.active_camera() {
|
||||
if let Ok(mut camera) = queries.p2().get_mut(e) {
|
||||
|
|
|
@ -274,7 +274,7 @@ fn toggle_overflow(
|
|||
keys: Res<ButtonInput<KeyCode>>,
|
||||
mut containers: Query<&mut Style, With<Container>>,
|
||||
) {
|
||||
if keys.just_pressed(KeyCode::O) {
|
||||
if keys.just_pressed(KeyCode::KeyO) {
|
||||
for mut style in &mut containers {
|
||||
style.overflow = match style.overflow {
|
||||
Overflow {
|
||||
|
@ -299,7 +299,7 @@ fn next_container_size(
|
|||
keys: Res<ButtonInput<KeyCode>>,
|
||||
mut containers: Query<(&mut Style, &mut Container)>,
|
||||
) {
|
||||
if keys.just_pressed(KeyCode::S) {
|
||||
if keys.just_pressed(KeyCode::KeyS) {
|
||||
for (mut style, mut container) in &mut containers {
|
||||
container.0 = (container.0 + 1) % 3;
|
||||
|
||||
|
|
|
@ -85,12 +85,12 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
|
||||
/// System that changes the scale of the ui when pressing up or down on the keyboard.
|
||||
fn change_scaling(input: Res<ButtonInput<KeyCode>>, mut ui_scale: ResMut<TargetScale>) {
|
||||
if input.just_pressed(KeyCode::Up) {
|
||||
if input.just_pressed(KeyCode::ArrowUp) {
|
||||
let scale = (ui_scale.target_scale * 2.0).min(8.);
|
||||
ui_scale.set_scale(scale);
|
||||
info!("Scaling up! Scale: {}", ui_scale.target_scale);
|
||||
}
|
||||
if input.just_pressed(KeyCode::Down) {
|
||||
if input.just_pressed(KeyCode::ArrowDown) {
|
||||
let scale = (ui_scale.target_scale / 2.0).max(1. / 8.);
|
||||
ui_scale.set_scale(scale);
|
||||
info!("Scaling down! Scale: {}", ui_scale.target_scale);
|
||||
|
|
|
@ -51,7 +51,7 @@ fn toggle_mouse_passthrough(
|
|||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||
mut windows: Query<&mut Window>,
|
||||
) {
|
||||
if keyboard_input.just_pressed(KeyCode::P) {
|
||||
if keyboard_input.just_pressed(KeyCode::KeyP) {
|
||||
let mut window = windows.single_mut();
|
||||
window.cursor.hit_test = !window.cursor.hit_test;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
background-size: 20px 20px;
|
||||
}
|
||||
canvas {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: white;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -22,7 +22,6 @@ fn main() {
|
|||
unfocused_mode: bevy::winit::UpdateMode::ReactiveLowPower {
|
||||
wait: Duration::from_millis(10),
|
||||
},
|
||||
..default()
|
||||
})
|
||||
.insert_resource(ExampleMode::Game)
|
||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
|
|
|
@ -79,7 +79,7 @@ fn display_override(mut windows: Query<&mut Window>) {
|
|||
fn toggle_override(input: Res<ButtonInput<KeyCode>>, mut windows: Query<&mut Window>) {
|
||||
let mut window = windows.single_mut();
|
||||
|
||||
if input.just_pressed(KeyCode::Return) {
|
||||
if input.just_pressed(KeyCode::Enter) {
|
||||
let scale_factor_override = window.resolution.scale_factor_override();
|
||||
window
|
||||
.resolution
|
||||
|
@ -91,11 +91,11 @@ fn toggle_override(input: Res<ButtonInput<KeyCode>>, mut windows: Query<&mut Win
|
|||
fn change_scale_factor(input: Res<ButtonInput<KeyCode>>, mut windows: Query<&mut Window>) {
|
||||
let mut window = windows.single_mut();
|
||||
let scale_factor_override = window.resolution.scale_factor_override();
|
||||
if input.just_pressed(KeyCode::Up) {
|
||||
if input.just_pressed(KeyCode::ArrowUp) {
|
||||
window
|
||||
.resolution
|
||||
.set_scale_factor_override(scale_factor_override.map(|n| n + 1.0));
|
||||
} else if input.just_pressed(KeyCode::Down) {
|
||||
} else if input.just_pressed(KeyCode::ArrowDown) {
|
||||
window
|
||||
.resolution
|
||||
.set_scale_factor_override(scale_factor_override.map(|n| (n - 1.0).max(1.0)));
|
||||
|
|
|
@ -64,15 +64,15 @@ fn toggle_resolution(
|
|||
) {
|
||||
let mut window = windows.single_mut();
|
||||
|
||||
if keys.just_pressed(KeyCode::Key1) {
|
||||
if keys.just_pressed(KeyCode::Digit1) {
|
||||
let res = resolution.small;
|
||||
window.resolution.set(res.x, res.y);
|
||||
}
|
||||
if keys.just_pressed(KeyCode::Key2) {
|
||||
if keys.just_pressed(KeyCode::Digit2) {
|
||||
let res = resolution.medium;
|
||||
window.resolution.set(res.x, res.y);
|
||||
}
|
||||
if keys.just_pressed(KeyCode::Key3) {
|
||||
if keys.just_pressed(KeyCode::Digit3) {
|
||||
let res = resolution.large;
|
||||
window.resolution.set(res.x, res.y);
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ fn make_visible(mut window: Query<&mut Window>, frames: Res<FrameCount>) {
|
|||
/// This system toggles the vsync mode when pressing the button V.
|
||||
/// You'll see fps increase displayed in the console.
|
||||
fn toggle_vsync(input: Res<ButtonInput<KeyCode>>, mut windows: Query<&mut Window>) {
|
||||
if input.just_pressed(KeyCode::V) {
|
||||
if input.just_pressed(KeyCode::KeyV) {
|
||||
let mut window = windows.single_mut();
|
||||
|
||||
window.present_mode = if matches!(window.present_mode, PresentMode::AutoVsync) {
|
||||
|
@ -84,8 +84,9 @@ fn toggle_vsync(input: Res<ButtonInput<KeyCode>>, mut windows: Query<&mut Window
|
|||
/// This feature only works on some platforms. Please check the
|
||||
/// [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.Window.html#structfield.window_level)
|
||||
/// for more details.
|
||||
|
||||
fn switch_level(input: Res<ButtonInput<KeyCode>>, mut windows: Query<&mut Window>) {
|
||||
if input.just_pressed(KeyCode::T) {
|
||||
if input.just_pressed(KeyCode::KeyT) {
|
||||
let mut window = windows.single_mut();
|
||||
|
||||
window.window_level = match window.window_level {
|
||||
|
@ -103,9 +104,9 @@ fn switch_level(input: Res<ButtonInput<KeyCode>>, mut windows: Query<&mut Window
|
|||
/// [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.Window.html#structfield.enabled_buttons)
|
||||
/// for more details.
|
||||
fn toggle_window_controls(input: Res<ButtonInput<KeyCode>>, mut windows: Query<&mut Window>) {
|
||||
let toggle_minimize = input.just_pressed(KeyCode::Key1);
|
||||
let toggle_maximize = input.just_pressed(KeyCode::Key2);
|
||||
let toggle_close = input.just_pressed(KeyCode::Key3);
|
||||
let toggle_minimize = input.just_pressed(KeyCode::Digit1);
|
||||
let toggle_maximize = input.just_pressed(KeyCode::Digit2);
|
||||
let toggle_close = input.just_pressed(KeyCode::Digit3);
|
||||
|
||||
if toggle_minimize || toggle_maximize || toggle_close {
|
||||
let mut window = windows.single_mut();
|
||||
|
@ -145,7 +146,7 @@ fn toggle_cursor(mut windows: Query<&mut Window>, input: Res<ButtonInput<KeyCode
|
|||
|
||||
// This system will toggle the color theme used by the window
|
||||
fn toggle_theme(mut windows: Query<&mut Window>, input: Res<ButtonInput<KeyCode>>) {
|
||||
if input.just_pressed(KeyCode::F) {
|
||||
if input.just_pressed(KeyCode::KeyF) {
|
||||
let mut window = windows.single_mut();
|
||||
|
||||
if let Some(current_theme) = window.window_theme {
|
||||
|
@ -167,7 +168,7 @@ fn cycle_cursor_icon(
|
|||
|
||||
const ICONS: &[CursorIcon] = &[
|
||||
CursorIcon::Default,
|
||||
CursorIcon::Hand,
|
||||
CursorIcon::Pointer,
|
||||
CursorIcon::Wait,
|
||||
CursorIcon::Text,
|
||||
CursorIcon::Copy,
|
||||
|
|
Loading…
Reference in a new issue