//! Illustrates how to change window settings and shows how to affect
//! the mouse pointer in various ways.
use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*,
window::{CursorGrabMode, PresentMode},
};
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "I am a window!".into(),
resolution: (500., 300.).into(),
present_mode: PresentMode::AutoVsync,
// Tells wasm to resize the window according to the available canvas
fit_canvas_to_parent: true,
// Tells wasm not to override default event handling, like F5, Ctrl+R etc.
prevent_default_event_handling: false,
..default()
}),
..default()
}))
.add_plugin(LogDiagnosticsPlugin::default())
.add_plugin(FrameTimeDiagnosticsPlugin)
.add_system(change_title)
.add_system(toggle_cursor)
.add_system(toggle_vsync)
.add_system(cycle_cursor_icon)
.add_system(toggle_always_on_top)
.run();
}
/// 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>, mut windows: Query<&mut Window>) {
if input.just_pressed(KeyCode::V) {
let mut window = windows.single_mut();
window.present_mode = if matches!(window.present_mode, PresentMode::AutoVsync) {
PresentMode::AutoNoVsync
} else {
PresentMode::AutoVsync
};
info!("PRESENT_MODE: {:?}", window.present_mode);
}
}
/// This system toggles whether the window is always on top when pressing the T button
/// You'll notice it won't be covered by other windows.
///
/// This feature only works on some platforms. Please check the
/// [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.WindowDescriptor.html#structfield.always_on_top)
/// for more details.
fn toggle_always_on_top(input: Res>, mut windows: Query<&mut Window>) {
if input.just_pressed(KeyCode::T) {
let mut window = windows.single_mut();
window.always_on_top = !window.always_on_top;
if window.always_on_top {
info!("LOCKING WINDOW ON TOP");
} else {
info!("UNLOCKING WINDOW");
}
}
}
/// This system will then change the title during execution
fn change_title(mut windows: Query<&mut Window>, time: Res