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-07-20 09:05:56 +00:00
|
|
|
pub mod prelude {
|
2020-12-03 19:30:27 +00:00
|
|
|
pub use crate::{
|
|
|
|
CursorEntered, CursorLeft, CursorMoved, ReceivedCharacter, Window, WindowDescriptor,
|
|
|
|
Windows,
|
|
|
|
};
|
2020-07-20 09:05:56 +00:00
|
|
|
}
|
|
|
|
|
2020-07-17 01:47:51 +00:00
|
|
|
use bevy_app::prelude::*;
|
2020-03-28 00:43:03 +00:00
|
|
|
|
2020-04-05 21:12:14 +00:00
|
|
|
pub struct WindowPlugin {
|
2020-07-20 09:05:56 +00:00
|
|
|
pub add_primary_window: bool,
|
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 {
|
2020-07-20 09:05:56 +00:00
|
|
|
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>()
|
2020-06-04 06:22:32 +00:00
|
|
|
.add_event::<CursorMoved>()
|
2020-12-03 19:30:27 +00:00
|
|
|
.add_event::<CursorEntered>()
|
|
|
|
.add_event::<CursorLeft>()
|
2020-11-07 01:15:56 +00:00
|
|
|
.add_event::<ReceivedCharacter>()
|
2020-05-13 23:35:38 +00:00
|
|
|
.init_resource::<Windows>();
|
2020-04-05 21:12:14 +00:00
|
|
|
|
2020-07-20 09:05:56 +00:00
|
|
|
if self.add_primary_window {
|
|
|
|
let resources = app.resources();
|
|
|
|
let window_descriptor = resources
|
|
|
|
.get::<WindowDescriptor>()
|
|
|
|
.map(|descriptor| (*descriptor).clone())
|
2020-08-16 07:30:04 +00:00
|
|
|
.unwrap_or_else(WindowDescriptor::default);
|
2020-07-20 09:05:56 +00:00
|
|
|
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(),
|
2020-08-16 07:30:04 +00:00
|
|
|
descriptor: window_descriptor,
|
2020-04-05 21:12:14 +00:00
|
|
|
});
|
2020-03-28 00:43:03 +00:00
|
|
|
}
|
2020-04-19 19:13:04 +00:00
|
|
|
|
|
|
|
if self.exit_on_close {
|
2020-11-17 02:18:00 +00:00
|
|
|
app.add_system(exit_on_window_close_system);
|
2020-04-19 19:13:04 +00:00
|
|
|
}
|
2020-03-28 00:43:03 +00:00
|
|
|
}
|
2020-04-06 23:15:59 +00:00
|
|
|
}
|