| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
use bevy::{prelude::*, window::CursorOptions}; |
| 6 |
|
| 7 |
fn main() { |
| 8 |
App::new() |
| 9 |
.insert_resource(ClearColor(Color::NONE)) |
| 10 |
.add_plugins(DefaultPlugins.set(WindowPlugin { |
| 11 |
primary_window: Some(Window { |
| 12 |
|
| 13 |
transparent: true, |
| 14 |
decorations: true, |
| 15 |
window_level: bevy::window::WindowLevel::AlwaysOnTop, |
| 16 |
..default() |
| 17 |
}), |
| 18 |
..default() |
| 19 |
})) |
| 20 |
.add_systems(Startup, setup) |
| 21 |
.add_systems(Update, toggle_mouse_passthrough) |
| 22 |
.run(); |
| 23 |
} |
| 24 |
|
| 25 |
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { |
| 26 |
|
| 27 |
commands.spawn(Camera2d); |
| 28 |
|
| 29 |
commands.spawn(( |
| 30 |
|
| 31 |
Text::new("Hit 'P' then scroll/click around!"), |
| 32 |
TextFont { |
| 33 |
font: asset_server.load("fonts/FiraSans-Bold.ttf").into(), |
| 34 |
font_size: FontSize::Px(83.0), |
| 35 |
..default() |
| 36 |
}, |
| 37 |
|
| 38 |
Node { |
| 39 |
position_type: PositionType::Absolute, |
| 40 |
bottom: px(5), |
| 41 |
right: px(10), |
| 42 |
..default() |
| 43 |
}, |
| 44 |
)); |
| 45 |
} |
| 46 |
|
| 47 |
fn toggle_mouse_passthrough( |
| 48 |
keyboard_input: Res<ButtonInput<KeyCode>>, |
| 49 |
mut cursor_options: Single<&mut CursorOptions>, |
| 50 |
) { |
| 51 |
if keyboard_input.just_pressed(KeyCode::KeyP) { |
| 52 |
cursor_options.hit_test = !cursor_options.hit_test; |
| 53 |
} |
| 54 |
} |