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::*;
|
2020-03-28 00:43:03 +00:00
|
|
|
|
2020-04-06 23:15:59 +00:00
|
|
|
use bevy_app::{AppBuilder, AppPlugin, Events};
|
2020-03-28 00:43:03 +00:00
|
|
|
|
2020-04-05 21:12:14 +00:00
|
|
|
pub struct WindowPlugin {
|
|
|
|
pub primary_window: Option<WindowDescriptor>,
|
2020-04-19 19:13:04 +00:00
|
|
|
pub exit_on_close: bool,
|
2020-03-31 05:23:48 +00:00
|
|
|
}
|
|
|
|
|
2020-04-05 21:12:14 +00:00
|
|
|
impl Default for WindowPlugin {
|
|
|
|
fn default() -> Self {
|
|
|
|
WindowPlugin {
|
|
|
|
primary_window: Some(WindowDescriptor::default()),
|
2020-04-19 19:13:04 +00:00
|
|
|
exit_on_close: true,
|
2020-03-30 21:53:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 21:12:14 +00:00
|
|
|
impl AppPlugin 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>()
|
2020-05-13 23:35:38 +00:00
|
|
|
.init_resource::<Windows>();
|
2020-04-05 21:12:14 +00:00
|
|
|
|
|
|
|
if let Some(ref primary_window_descriptor) = self.primary_window {
|
2020-04-06 23:15:59 +00:00
|
|
|
let mut create_window_event =
|
|
|
|
app.resources().get_mut::<Events<CreateWindow>>().unwrap();
|
2020-04-05 21:12:14 +00:00
|
|
|
create_window_event.send(CreateWindow {
|
|
|
|
descriptor: primary_window_descriptor.clone(),
|
|
|
|
});
|
2020-03-28 00:43:03 +00:00
|
|
|
}
|
2020-04-19 19:13:04 +00:00
|
|
|
|
|
|
|
if self.exit_on_close {
|
|
|
|
let exit_on_close_system = exit_on_window_close_system(app.resources_mut(), None);
|
|
|
|
app.add_system(exit_on_close_system);
|
|
|
|
}
|
2020-03-28 00:43:03 +00:00
|
|
|
}
|
2020-04-06 23:15:59 +00:00
|
|
|
}
|