add escape and borderless
This commit is contained in:
parent
68763ea15c
commit
b037f9150b
2 changed files with 27 additions and 7 deletions
|
|
@ -5,4 +5,4 @@ edition = "2024"
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = { version = "0.16.1", features = ["shader_format_glsl"] }
|
bevy = "0.16.1"
|
||||||
|
|
|
||||||
32
src/main.rs
32
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::{
|
use bevy::{
|
||||||
|
input::common_conditions::*,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
reflect::TypePath,
|
reflect::TypePath,
|
||||||
render::render_resource::{AsBindGroup, ShaderRef},
|
render::render_resource::{AsBindGroup, ShaderRef},
|
||||||
sprite::{AlphaMode2d, Material2d, Material2dPlugin},
|
sprite::{AlphaMode2d, Material2d, Material2dPlugin},
|
||||||
window::PrimaryWindow,
|
window::{PrimaryWindow, WindowMode},
|
||||||
};
|
};
|
||||||
|
|
||||||
const SHADER_ASSET_PATH: &str = "shaders/default.wgsl";
|
const SHADER_ASSET_PATH: &str = "shaders/default.wgsl";
|
||||||
|
|
@ -17,7 +18,14 @@ fn main() {
|
||||||
Material2dPlugin::<CustomMaterial>::default(),
|
Material2dPlugin::<CustomMaterial>::default(),
|
||||||
))
|
))
|
||||||
.add_systems(Startup, setup)
|
.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();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -26,9 +34,10 @@ fn setup(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<CustomMaterial>>,
|
mut materials: ResMut<Assets<CustomMaterial>>,
|
||||||
primary_window: Single<&Window, With<PrimaryWindow>>,
|
mut primary_window: Single<&mut Window, With<PrimaryWindow>>,
|
||||||
) {
|
) {
|
||||||
// camera
|
primary_window.decorations = false;
|
||||||
|
|
||||||
commands.spawn(Camera2d);
|
commands.spawn(Camera2d);
|
||||||
|
|
||||||
// quad that fills the whole window
|
// quad that fills the whole window
|
||||||
|
|
@ -36,7 +45,6 @@ fn setup(
|
||||||
primary_window.resolution.width(),
|
primary_window.resolution.width(),
|
||||||
primary_window.resolution.height(),
|
primary_window.resolution.height(),
|
||||||
);
|
);
|
||||||
|
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Mesh2d(meshes.add(Rectangle::default())),
|
Mesh2d(meshes.add(Rectangle::default())),
|
||||||
MeshMaterial2d(materials.add(CustomMaterial {})),
|
MeshMaterial2d(materials.add(CustomMaterial {})),
|
||||||
|
|
@ -61,6 +69,18 @@ fn resize_fullscreen_quad(
|
||||||
transform.scale = Vec3::new(size.x, size.y, 1.0);
|
transform.scale = Vec3::new(size.x, size.y, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn exit_app(mut exit: EventWriter<AppExit>) {
|
||||||
|
exit.write(AppExit::Success);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn toggle_fullscreen(mut primary_window: Single<&mut Window, With<PrimaryWindow>>) {
|
||||||
|
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
|
// This is the struct that will be passed to your shader
|
||||||
#[derive(Asset, TypePath, AsBindGroup, Clone)]
|
#[derive(Asset, TypePath, AsBindGroup, Clone)]
|
||||||
struct CustomMaterial {}
|
struct CustomMaterial {}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue