bevy/crates/bevy_window/src/lib.rs

65 lines
1.7 KiB
Rust
Raw Normal View History

2020-04-19 19:13:04 +00:00
mod event;
mod system;
2020-04-05 21:12:14 +00:00
mod window;
2020-04-04 19:43:16 +00:00
mod windows;
2020-03-30 21:53:32 +00:00
2020-04-19 19:13:04 +00:00
pub use event::*;
pub use system::*;
2020-04-05 21:12:14 +00:00
pub use window::*;
2020-04-04 19:43:16 +00:00
pub use windows::*;
pub mod prelude {
pub use crate::{
CursorEntered, CursorLeft, CursorMoved, ReceivedCharacter, Window, WindowDescriptor,
Windows,
};
}
2020-07-17 01:47:51 +00:00
use bevy_app::prelude::*;
2020-04-05 21:12:14 +00:00
pub struct WindowPlugin {
pub add_primary_window: bool,
2020-04-19 19:13:04 +00:00
pub exit_on_close: bool,
}
2020-04-05 21:12:14 +00:00
impl Default for WindowPlugin {
fn default() -> Self {
WindowPlugin {
add_primary_window: true,
2020-04-19 19:13:04 +00:00
exit_on_close: true,
2020-03-30 21:53:32 +00:00
}
}
}
2020-08-08 03:22:17 +00:00
impl Plugin for WindowPlugin {
2020-04-06 03:19:02 +00:00
fn build(&self, app: &mut AppBuilder) {
2020-04-06 23:15:59 +00:00
app.add_event::<WindowResized>()
2020-04-05 21:12:14 +00:00
.add_event::<CreateWindow>()
.add_event::<WindowCreated>()
2020-04-19 19:13:04 +00:00
.add_event::<WindowCloseRequested>()
.add_event::<CloseWindow>()
.add_event::<CursorMoved>()
.add_event::<CursorEntered>()
.add_event::<CursorLeft>()
.add_event::<ReceivedCharacter>()
2020-05-13 23:35:38 +00:00
.init_resource::<Windows>();
2020-04-05 21:12:14 +00:00
if self.add_primary_window {
let resources = app.resources();
let window_descriptor = resources
.get::<WindowDescriptor>()
.map(|descriptor| (*descriptor).clone())
.unwrap_or_else(WindowDescriptor::default);
let mut create_window_event = resources.get_mut::<Events<CreateWindow>>().unwrap();
2020-04-05 21:12:14 +00:00
create_window_event.send(CreateWindow {
2020-07-25 06:04:45 +00:00
id: WindowId::primary(),
descriptor: window_descriptor,
2020-04-05 21:12:14 +00:00
});
}
2020-04-19 19:13:04 +00:00
if self.exit_on_close {
app.add_system(exit_on_window_close_system);
2020-04-19 19:13:04 +00:00
}
}
2020-04-06 23:15:59 +00:00
}