From b037f9150b752e47b38c43c48793e98520c8481e Mon Sep 17 00:00:00 2001 From: Matthew Deville Date: Sun, 31 Aug 2025 12:17:57 +0200 Subject: [PATCH] add escape and borderless --- Cargo.toml | 2 +- src/main.rs | 32 ++++++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 598c628..0d59283 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,4 +5,4 @@ edition = "2024" [dependencies] -bevy = { version = "0.16.1", features = ["shader_format_glsl"] } +bevy = "0.16.1" diff --git a/src/main.rs b/src/main.rs index 4b2a756..db2dae4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,12 @@ -//! A shader that uses the GLSL shading language. +//! A shader that uses the WGSL shading language. use bevy::{ + input::common_conditions::*, prelude::*, reflect::TypePath, render::render_resource::{AsBindGroup, ShaderRef}, sprite::{AlphaMode2d, Material2d, Material2dPlugin}, - window::PrimaryWindow, + window::{PrimaryWindow, WindowMode}, }; const SHADER_ASSET_PATH: &str = "shaders/default.wgsl"; @@ -17,7 +18,14 @@ fn main() { Material2dPlugin::::default(), )) .add_systems(Startup, setup) - .add_systems(Update, resize_fullscreen_quad) + .add_systems( + Update, + ( + resize_fullscreen_quad, + exit_app.run_if(input_just_pressed(KeyCode::Escape)), + toggle_fullscreen.run_if(input_just_pressed(KeyCode::F11)), + ), + ) .run(); } @@ -26,9 +34,10 @@ fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, - primary_window: Single<&Window, With>, + mut primary_window: Single<&mut Window, With>, ) { - // camera + primary_window.decorations = false; + commands.spawn(Camera2d); // quad that fills the whole window @@ -36,7 +45,6 @@ fn setup( primary_window.resolution.width(), primary_window.resolution.height(), ); - commands.spawn(( Mesh2d(meshes.add(Rectangle::default())), MeshMaterial2d(materials.add(CustomMaterial {})), @@ -61,6 +69,18 @@ fn resize_fullscreen_quad( transform.scale = Vec3::new(size.x, size.y, 1.0); } +fn exit_app(mut exit: EventWriter) { + exit.write(AppExit::Success); +} + +fn toggle_fullscreen(mut primary_window: Single<&mut Window, With>) { + primary_window.mode = match primary_window.mode { + WindowMode::BorderlessFullscreen(_) => WindowMode::Windowed, + WindowMode::Windowed => WindowMode::BorderlessFullscreen(MonitorSelection::Current), + WindowMode::Fullscreen(_, _) => WindowMode::BorderlessFullscreen(MonitorSelection::Current), + }; +} + // This is the struct that will be passed to your shader #[derive(Asset, TypePath, AsBindGroup, Clone)] struct CustomMaterial {}