bevy/examples/window/window_settings.rs
François 814f8d1635 update wgpu to 0.13 (#5168)
# Objective

- Update wgpu to 0.13
- ~~Wait, is wgpu 0.13 released? No, but I had most of the changes already ready since playing with webgpu~~ well it has been released now
- Also update parking_lot to 0.12 and naga to 0.9

## Solution

- Update syntax for wgsl shaders https://github.com/gfx-rs/wgpu/blob/master/CHANGELOG.md#wgsl-syntax
- Add a few options, remove some references: https://github.com/gfx-rs/wgpu/blob/master/CHANGELOG.md#other-breaking-changes
- fragment inputs should now exactly match vertex outputs for locations, so I added exports for those to be able to reuse them https://github.com/gfx-rs/wgpu/pull/2704
2022-07-14 21:17:16 +00:00

65 lines
2 KiB
Rust

//! Illustrates how to change window settings and shows how to affect
//! the mouse pointer in various ways.
use bevy::{prelude::*, window::PresentMode};
fn main() {
App::new()
.insert_resource(WindowDescriptor {
title: "I am a window!".to_string(),
width: 500.,
height: 300.,
present_mode: PresentMode::AutoVsync,
..default()
})
.add_plugins(DefaultPlugins)
.add_system(change_title)
.add_system(toggle_cursor)
.add_system(cycle_cursor_icon)
.run();
}
/// This system will then change the title during execution
fn change_title(time: Res<Time>, mut windows: ResMut<Windows>) {
let window = windows.primary_mut();
window.set_title(format!(
"Seconds since startup: {}",
time.seconds_since_startup().round()
));
}
/// This system toggles the cursor's visibility when the space bar is pressed
fn toggle_cursor(input: Res<Input<KeyCode>>, mut windows: ResMut<Windows>) {
let window = windows.primary_mut();
if input.just_pressed(KeyCode::Space) {
window.set_cursor_lock_mode(!window.cursor_locked());
window.set_cursor_visibility(!window.cursor_visible());
}
}
/// This system cycles the cursor's icon through a small set of icons when clicking
fn cycle_cursor_icon(
input: Res<Input<MouseButton>>,
mut windows: ResMut<Windows>,
mut index: Local<usize>,
) {
const ICONS: &[CursorIcon] = &[
CursorIcon::Default,
CursorIcon::Hand,
CursorIcon::Wait,
CursorIcon::Text,
CursorIcon::Copy,
];
let window = windows.primary_mut();
if input.just_pressed(MouseButton::Left) {
*index = (*index + 1) % ICONS.len();
window.set_cursor_icon(ICONS[*index]);
} else if input.just_pressed(MouseButton::Right) {
*index = if *index == 0 {
ICONS.len() - 1
} else {
*index - 1
};
window.set_cursor_icon(ICONS[*index]);
}
}