2020-04-04 21:59:49 +00:00
|
|
|
mod converters;
|
2020-08-21 05:37:19 +00:00
|
|
|
mod winit_config;
|
2020-03-30 21:53:32 +00:00
|
|
|
mod winit_windows;
|
2020-04-06 03:19:02 +00:00
|
|
|
use bevy_input::{
|
|
|
|
keyboard::KeyboardInput,
|
2020-08-21 00:04:01 +00:00
|
|
|
mouse::{MouseButtonInput, MouseMotion, MouseScrollUnit, MouseWheel},
|
2020-10-18 19:24:01 +00:00
|
|
|
touch::TouchInput,
|
2020-04-05 06:42:39 +00:00
|
|
|
};
|
2020-08-21 05:37:19 +00:00
|
|
|
pub use winit_config::*;
|
|
|
|
pub use winit_windows::*;
|
2020-03-28 00:43:03 +00:00
|
|
|
|
2020-07-17 01:47:51 +00:00
|
|
|
use bevy_app::{prelude::*, AppExit};
|
2020-12-16 05:57:16 +00:00
|
|
|
use bevy_ecs::{IntoSystem, Resources, World};
|
2020-07-17 00:23:50 +00:00
|
|
|
use bevy_math::Vec2;
|
2020-11-26 01:31:10 +00:00
|
|
|
use bevy_utils::tracing::{error, trace};
|
2020-04-19 19:13:04 +00:00
|
|
|
use bevy_window::{
|
2020-12-13 23:05:56 +00:00
|
|
|
CreateWindow, CursorEntered, CursorLeft, CursorMoved, ReceivedCharacter, WindowCloseRequested,
|
|
|
|
WindowCreated, WindowFocused, WindowResized, Windows,
|
2020-04-19 19:13:04 +00:00
|
|
|
};
|
2020-03-28 00:43:03 +00:00
|
|
|
use winit::{
|
2020-09-21 20:54:47 +00:00
|
|
|
event::{self, DeviceEvent, Event, WindowEvent},
|
2020-03-30 21:53:32 +00:00
|
|
|
event_loop::{ControlFlow, EventLoop, EventLoopWindowTarget},
|
2020-03-28 00:43:03 +00:00
|
|
|
};
|
|
|
|
|
2020-03-29 07:53:47 +00:00
|
|
|
#[derive(Default)]
|
|
|
|
pub struct WinitPlugin;
|
|
|
|
|
2020-08-08 03:22:17 +00:00
|
|
|
impl Plugin for WinitPlugin {
|
2020-04-06 03:19:02 +00:00
|
|
|
fn build(&self, app: &mut AppBuilder) {
|
2020-12-07 21:24:25 +00:00
|
|
|
app.init_resource::<WinitWindows>()
|
2020-10-15 18:42:19 +00:00
|
|
|
.set_runner(winit_runner)
|
2020-12-16 05:57:16 +00:00
|
|
|
.add_system(change_window.system());
|
2020-10-15 18:42:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn change_window(_: &mut World, resources: &mut Resources) {
|
|
|
|
let winit_windows = resources.get::<WinitWindows>().unwrap();
|
|
|
|
let mut windows = resources.get_mut::<Windows>().unwrap();
|
|
|
|
|
|
|
|
for bevy_window in windows.iter_mut() {
|
|
|
|
let id = bevy_window.id();
|
|
|
|
for command in bevy_window.drain_commands() {
|
|
|
|
match command {
|
|
|
|
bevy_window::WindowCommand::SetWindowMode {
|
|
|
|
mode,
|
|
|
|
resolution: (width, height),
|
|
|
|
} => {
|
|
|
|
let window = winit_windows.get_window(id).unwrap();
|
|
|
|
match mode {
|
|
|
|
bevy_window::WindowMode::BorderlessFullscreen => {
|
|
|
|
window.set_fullscreen(Some(winit::window::Fullscreen::Borderless(None)))
|
|
|
|
}
|
|
|
|
bevy_window::WindowMode::Fullscreen { use_size } => window.set_fullscreen(
|
|
|
|
Some(winit::window::Fullscreen::Exclusive(match use_size {
|
|
|
|
true => get_fitting_videomode(
|
|
|
|
&window.current_monitor().unwrap(),
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
),
|
|
|
|
false => get_best_videomode(&window.current_monitor().unwrap()),
|
|
|
|
})),
|
|
|
|
),
|
|
|
|
bevy_window::WindowMode::Windowed => window.set_fullscreen(None),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bevy_window::WindowCommand::SetTitle { title } => {
|
|
|
|
let window = winit_windows.get_window(id).unwrap();
|
|
|
|
window.set_title(&title);
|
|
|
|
}
|
2020-12-07 21:32:57 +00:00
|
|
|
bevy_window::WindowCommand::SetResolution {
|
2020-12-13 23:05:56 +00:00
|
|
|
resolution: (logical_width, logical_height),
|
2020-12-07 21:32:57 +00:00
|
|
|
} => {
|
2020-10-15 18:42:19 +00:00
|
|
|
let window = winit_windows.get_window(id).unwrap();
|
2020-12-13 23:05:56 +00:00
|
|
|
window.set_inner_size(winit::dpi::LogicalSize::new(
|
|
|
|
logical_width,
|
|
|
|
logical_height,
|
2020-12-07 21:32:57 +00:00
|
|
|
));
|
2020-10-15 18:42:19 +00:00
|
|
|
}
|
|
|
|
bevy_window::WindowCommand::SetVsync { .. } => (),
|
|
|
|
bevy_window::WindowCommand::SetResizable { resizable } => {
|
|
|
|
let window = winit_windows.get_window(id).unwrap();
|
|
|
|
window.set_resizable(resizable);
|
|
|
|
}
|
|
|
|
bevy_window::WindowCommand::SetDecorations { decorations } => {
|
|
|
|
let window = winit_windows.get_window(id).unwrap();
|
|
|
|
window.set_decorations(decorations);
|
|
|
|
}
|
2020-10-16 21:07:01 +00:00
|
|
|
bevy_window::WindowCommand::SetCursorLockMode { locked } => {
|
|
|
|
let window = winit_windows.get_window(id).unwrap();
|
2020-11-26 01:31:10 +00:00
|
|
|
window
|
|
|
|
.set_cursor_grab(locked)
|
|
|
|
.unwrap_or_else(|e| error!("Unable to un/grab cursor: {}", e));
|
2020-10-16 21:07:01 +00:00
|
|
|
}
|
|
|
|
bevy_window::WindowCommand::SetCursorVisibility { visible } => {
|
|
|
|
let window = winit_windows.get_window(id).unwrap();
|
|
|
|
window.set_cursor_visible(visible);
|
|
|
|
}
|
2020-12-03 20:39:03 +00:00
|
|
|
bevy_window::WindowCommand::SetCursorPosition { position } => {
|
2020-11-26 01:31:10 +00:00
|
|
|
let window = winit_windows.get_window(id).unwrap();
|
2020-12-03 20:39:03 +00:00
|
|
|
let inner_size = window.inner_size().to_logical::<f32>(window.scale_factor());
|
2020-11-26 01:31:10 +00:00
|
|
|
window
|
2020-12-03 20:39:03 +00:00
|
|
|
.set_cursor_position(winit::dpi::LogicalPosition::new(
|
|
|
|
position.x,
|
|
|
|
inner_size.height - position.y,
|
|
|
|
))
|
2020-11-26 01:31:10 +00:00
|
|
|
.unwrap_or_else(|e| error!("Unable to set cursor position: {}", e));
|
|
|
|
}
|
2020-12-04 22:31:17 +00:00
|
|
|
bevy_window::WindowCommand::SetMaximized { maximized } => {
|
|
|
|
let window = winit_windows.get_window(id).unwrap();
|
|
|
|
window.set_maximized(maximized)
|
|
|
|
}
|
2020-10-15 18:42:19 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-29 07:53:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-21 05:37:19 +00:00
|
|
|
fn run<F>(event_loop: EventLoop<()>, event_handler: F) -> !
|
|
|
|
where
|
|
|
|
F: 'static + FnMut(Event<'_, ()>, &EventLoopWindowTarget<()>, &mut ControlFlow),
|
|
|
|
{
|
|
|
|
event_loop.run(event_handler)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: It may be worth moving this cfg into a procedural macro so that it can be referenced by
|
|
|
|
// a single name instead of being copied around.
|
|
|
|
// https://gist.github.com/jakerr/231dee4a138f7a5f25148ea8f39b382e seems to work.
|
|
|
|
#[cfg(any(
|
|
|
|
target_os = "windows",
|
|
|
|
target_os = "macos",
|
|
|
|
target_os = "linux",
|
|
|
|
target_os = "dragonfly",
|
|
|
|
target_os = "freebsd",
|
|
|
|
target_os = "netbsd",
|
|
|
|
target_os = "openbsd"
|
|
|
|
))]
|
|
|
|
fn run_return<F>(event_loop: &mut EventLoop<()>, event_handler: F)
|
|
|
|
where
|
|
|
|
F: FnMut(Event<'_, ()>, &EventLoopWindowTarget<()>, &mut ControlFlow),
|
|
|
|
{
|
2020-12-13 19:27:54 +00:00
|
|
|
use winit::platform::run_return::EventLoopExtRunReturn;
|
2020-08-21 05:37:19 +00:00
|
|
|
event_loop.run_return(event_handler)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(any(
|
|
|
|
target_os = "windows",
|
|
|
|
target_os = "macos",
|
|
|
|
target_os = "linux",
|
|
|
|
target_os = "dragonfly",
|
|
|
|
target_os = "freebsd",
|
|
|
|
target_os = "netbsd",
|
|
|
|
target_os = "openbsd"
|
|
|
|
)))]
|
2020-09-16 20:40:32 +00:00
|
|
|
fn run_return<F>(_event_loop: &mut EventLoop<()>, _event_handler: F)
|
2020-08-21 05:37:19 +00:00
|
|
|
where
|
|
|
|
F: FnMut(Event<'_, ()>, &EventLoopWindowTarget<()>, &mut ControlFlow),
|
|
|
|
{
|
|
|
|
panic!("Run return is not supported on this platform!")
|
|
|
|
}
|
|
|
|
|
2020-03-30 18:52:33 +00:00
|
|
|
pub fn winit_runner(mut app: App) {
|
2020-08-21 05:37:19 +00:00
|
|
|
let mut event_loop = EventLoop::new();
|
2020-06-04 06:53:00 +00:00
|
|
|
let mut create_window_event_reader = EventReader::<CreateWindow>::default();
|
|
|
|
let mut app_exit_event_reader = EventReader::<AppExit>::default();
|
2020-03-28 00:43:03 +00:00
|
|
|
|
2020-11-17 21:40:18 +00:00
|
|
|
app.resources.insert_thread_local(event_loop.create_proxy());
|
2020-03-28 00:43:03 +00:00
|
|
|
|
2020-11-13 01:23:57 +00:00
|
|
|
trace!("Entering winit event loop");
|
2020-08-21 05:37:19 +00:00
|
|
|
|
|
|
|
let should_return_from_run = app
|
|
|
|
.resources
|
|
|
|
.get::<WinitConfig>()
|
|
|
|
.map_or(false, |config| config.return_from_run);
|
|
|
|
|
|
|
|
let event_handler = move |event: Event<()>,
|
|
|
|
event_loop: &EventLoopWindowTarget<()>,
|
|
|
|
control_flow: &mut ControlFlow| {
|
2020-11-17 21:40:18 +00:00
|
|
|
*control_flow = ControlFlow::Poll;
|
2020-04-19 19:13:04 +00:00
|
|
|
|
2020-07-19 21:23:06 +00:00
|
|
|
if let Some(app_exit_events) = app.resources.get_mut::<Events<AppExit>>() {
|
2020-04-28 17:59:42 +00:00
|
|
|
if app_exit_event_reader.latest(&app_exit_events).is_some() {
|
2020-04-19 19:13:04 +00:00
|
|
|
*control_flow = ControlFlow::Exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-30 18:52:33 +00:00
|
|
|
match event {
|
2020-04-19 19:13:04 +00:00
|
|
|
event::Event::WindowEvent {
|
|
|
|
event,
|
|
|
|
window_id: winit_window_id,
|
|
|
|
..
|
|
|
|
} => match event {
|
2020-12-01 02:24:49 +00:00
|
|
|
WindowEvent::Resized(size) => {
|
|
|
|
let winit_windows = app.resources.get_mut::<WinitWindows>().unwrap();
|
|
|
|
let mut windows = app.resources.get_mut::<Windows>().unwrap();
|
|
|
|
let window_id = winit_windows.get_window_id(winit_window_id).unwrap();
|
|
|
|
let window = windows.get_mut(window_id).unwrap();
|
2020-12-13 23:05:56 +00:00
|
|
|
window.update_actual_size_from_backend(size.width, size.height);
|
2020-12-01 02:24:49 +00:00
|
|
|
let mut resize_events =
|
|
|
|
app.resources.get_mut::<Events<WindowResized>>().unwrap();
|
|
|
|
resize_events.send(WindowResized {
|
|
|
|
id: window_id,
|
2020-12-13 23:05:56 +00:00
|
|
|
width: window.width(),
|
|
|
|
height: window.height(),
|
2020-12-01 02:24:49 +00:00
|
|
|
});
|
|
|
|
}
|
2020-04-04 21:59:49 +00:00
|
|
|
WindowEvent::CloseRequested => {
|
2020-04-19 19:13:04 +00:00
|
|
|
let mut window_close_requested_events = app
|
|
|
|
.resources
|
|
|
|
.get_mut::<Events<WindowCloseRequested>>()
|
|
|
|
.unwrap();
|
|
|
|
let winit_windows = app.resources.get_mut::<WinitWindows>().unwrap();
|
|
|
|
let window_id = winit_windows.get_window_id(winit_window_id).unwrap();
|
2020-07-26 19:10:18 +00:00
|
|
|
window_close_requested_events.send(WindowCloseRequested { id: window_id });
|
2020-03-28 00:43:03 +00:00
|
|
|
}
|
2020-04-04 21:59:49 +00:00
|
|
|
WindowEvent::KeyboardInput { ref input, .. } => {
|
|
|
|
let mut keyboard_input_events =
|
|
|
|
app.resources.get_mut::<Events<KeyboardInput>>().unwrap();
|
2020-04-06 03:19:02 +00:00
|
|
|
keyboard_input_events.send(converters::convert_keyboard_input(input));
|
2020-04-04 21:59:49 +00:00
|
|
|
}
|
2020-06-04 06:22:32 +00:00
|
|
|
WindowEvent::CursorMoved { position, .. } => {
|
|
|
|
let mut cursor_moved_events =
|
|
|
|
app.resources.get_mut::<Events<CursorMoved>>().unwrap();
|
|
|
|
let winit_windows = app.resources.get_mut::<WinitWindows>().unwrap();
|
2020-12-03 19:30:27 +00:00
|
|
|
let mut windows = app.resources.get_mut::<Windows>().unwrap();
|
2020-06-04 06:22:32 +00:00
|
|
|
let window_id = winit_windows.get_window_id(winit_window_id).unwrap();
|
2020-12-03 19:30:27 +00:00
|
|
|
let winit_window = winit_windows.get_window(window_id).unwrap();
|
|
|
|
let window = windows.get_mut(window_id).unwrap();
|
|
|
|
let position = position.to_logical(winit_window.scale_factor());
|
|
|
|
let inner_size = winit_window
|
|
|
|
.inner_size()
|
|
|
|
.to_logical::<f32>(winit_window.scale_factor());
|
|
|
|
|
2020-07-18 21:08:46 +00:00
|
|
|
// move origin to bottom left
|
2020-12-01 02:24:49 +00:00
|
|
|
let y_position = inner_size.height - position.y;
|
2020-12-03 19:30:27 +00:00
|
|
|
|
|
|
|
let position = Vec2::new(position.x, y_position);
|
|
|
|
window.update_cursor_position_from_backend(Some(position));
|
|
|
|
|
2020-06-04 06:22:32 +00:00
|
|
|
cursor_moved_events.send(CursorMoved {
|
|
|
|
id: window_id,
|
2020-12-03 19:30:27 +00:00
|
|
|
position,
|
2020-06-04 06:22:32 +00:00
|
|
|
});
|
|
|
|
}
|
2020-12-03 19:30:27 +00:00
|
|
|
WindowEvent::CursorEntered { .. } => {
|
|
|
|
let mut cursor_entered_events =
|
|
|
|
app.resources.get_mut::<Events<CursorEntered>>().unwrap();
|
|
|
|
let winit_windows = app.resources.get_mut::<WinitWindows>().unwrap();
|
|
|
|
let window_id = winit_windows.get_window_id(winit_window_id).unwrap();
|
|
|
|
cursor_entered_events.send(CursorEntered { id: window_id });
|
|
|
|
}
|
|
|
|
WindowEvent::CursorLeft { .. } => {
|
|
|
|
let mut cursor_left_events =
|
|
|
|
app.resources.get_mut::<Events<CursorLeft>>().unwrap();
|
|
|
|
let winit_windows = app.resources.get_mut::<WinitWindows>().unwrap();
|
|
|
|
let mut windows = app.resources.get_mut::<Windows>().unwrap();
|
|
|
|
let window_id = winit_windows.get_window_id(winit_window_id).unwrap();
|
|
|
|
let window = windows.get_mut(window_id).unwrap();
|
|
|
|
window.update_cursor_position_from_backend(None);
|
|
|
|
cursor_left_events.send(CursorLeft { id: window_id });
|
|
|
|
}
|
2020-04-05 06:42:39 +00:00
|
|
|
WindowEvent::MouseInput { state, button, .. } => {
|
2020-04-05 07:32:53 +00:00
|
|
|
let mut mouse_button_input_events =
|
|
|
|
app.resources.get_mut::<Events<MouseButtonInput>>().unwrap();
|
|
|
|
mouse_button_input_events.send(MouseButtonInput {
|
2020-08-16 07:30:04 +00:00
|
|
|
button: converters::convert_mouse_button(button),
|
2020-04-06 03:19:02 +00:00
|
|
|
state: converters::convert_element_state(state),
|
2020-04-05 06:42:39 +00:00
|
|
|
});
|
|
|
|
}
|
2020-08-21 00:04:01 +00:00
|
|
|
WindowEvent::MouseWheel { delta, .. } => match delta {
|
|
|
|
event::MouseScrollDelta::LineDelta(x, y) => {
|
|
|
|
let mut mouse_wheel_input_events =
|
|
|
|
app.resources.get_mut::<Events<MouseWheel>>().unwrap();
|
|
|
|
mouse_wheel_input_events.send(MouseWheel {
|
|
|
|
unit: MouseScrollUnit::Line,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
event::MouseScrollDelta::PixelDelta(p) => {
|
|
|
|
let mut mouse_wheel_input_events =
|
|
|
|
app.resources.get_mut::<Events<MouseWheel>>().unwrap();
|
|
|
|
mouse_wheel_input_events.send(MouseWheel {
|
|
|
|
unit: MouseScrollUnit::Pixel,
|
|
|
|
x: p.x as f32,
|
|
|
|
y: p.y as f32,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2020-12-01 02:24:49 +00:00
|
|
|
WindowEvent::Touch(touch) => {
|
2020-10-18 19:24:01 +00:00
|
|
|
let mut touch_input_events =
|
|
|
|
app.resources.get_mut::<Events<TouchInput>>().unwrap();
|
2020-12-01 02:24:49 +00:00
|
|
|
|
|
|
|
let winit_windows = app.resources.get_mut::<WinitWindows>().unwrap();
|
2020-11-03 19:32:48 +00:00
|
|
|
let windows = app.resources.get_mut::<Windows>().unwrap();
|
2020-12-01 02:24:49 +00:00
|
|
|
let window_id = winit_windows.get_window_id(winit_window_id).unwrap();
|
|
|
|
let winit_window = winit_windows.get_window(window_id).unwrap();
|
|
|
|
let mut location = touch.location.to_logical(winit_window.scale_factor());
|
|
|
|
|
2020-11-03 19:32:48 +00:00
|
|
|
// FIXME?: On Android window start is top while on PC/Linux/OSX on bottom
|
|
|
|
if cfg!(target_os = "android") {
|
2020-12-13 23:05:56 +00:00
|
|
|
let window_height = windows.get_primary().unwrap().height();
|
2020-12-07 21:32:57 +00:00
|
|
|
location.y = window_height - location.y;
|
2020-11-03 19:32:48 +00:00
|
|
|
}
|
2020-12-01 02:24:49 +00:00
|
|
|
touch_input_events.send(converters::convert_touch_input(touch, location));
|
2020-10-18 19:24:01 +00:00
|
|
|
}
|
2020-11-07 01:15:56 +00:00
|
|
|
WindowEvent::ReceivedCharacter(c) => {
|
|
|
|
let mut char_input_events = app
|
|
|
|
.resources
|
|
|
|
.get_mut::<Events<ReceivedCharacter>>()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let winit_windows = app.resources.get_mut::<WinitWindows>().unwrap();
|
|
|
|
let window_id = winit_windows.get_window_id(winit_window_id).unwrap();
|
|
|
|
|
|
|
|
char_input_events.send(ReceivedCharacter {
|
|
|
|
id: window_id,
|
|
|
|
char: c,
|
|
|
|
})
|
|
|
|
}
|
2020-12-01 02:24:49 +00:00
|
|
|
WindowEvent::ScaleFactorChanged {
|
|
|
|
scale_factor,
|
|
|
|
new_inner_size,
|
|
|
|
} => {
|
|
|
|
let winit_windows = app.resources.get_mut::<WinitWindows>().unwrap();
|
|
|
|
let mut windows = app.resources.get_mut::<Windows>().unwrap();
|
|
|
|
let window_id = winit_windows.get_window_id(winit_window_id).unwrap();
|
|
|
|
let window = windows.get_mut(window_id).unwrap();
|
2020-12-13 23:05:56 +00:00
|
|
|
window.update_actual_size_from_backend(
|
2020-12-07 21:32:57 +00:00
|
|
|
new_inner_size.width,
|
|
|
|
new_inner_size.height,
|
|
|
|
);
|
2020-12-01 02:24:49 +00:00
|
|
|
window.update_scale_factor_from_backend(scale_factor);
|
2020-12-13 23:05:56 +00:00
|
|
|
// should we send a resize event to indicate the change in
|
|
|
|
// logical size?
|
2020-12-01 02:24:49 +00:00
|
|
|
}
|
2020-12-07 21:24:25 +00:00
|
|
|
WindowEvent::Focused(focused) => {
|
|
|
|
let mut focused_events =
|
|
|
|
app.resources.get_mut::<Events<WindowFocused>>().unwrap();
|
|
|
|
let winit_windows = app.resources.get_mut::<WinitWindows>().unwrap();
|
2020-12-18 21:08:26 +00:00
|
|
|
match (winit_windows.get_window_id(winit_window_id), focused) {
|
|
|
|
(Some(window_id), _) => focused_events.send(WindowFocused {
|
|
|
|
id: window_id,
|
|
|
|
focused,
|
|
|
|
}),
|
|
|
|
// unfocus event for an unknown window, ignore it
|
|
|
|
(None, false) => (),
|
|
|
|
// focus event on an unknown window, this is an error
|
|
|
|
_ => panic!(
|
|
|
|
"Focused(true) event on unknown window {:?}",
|
|
|
|
winit_window_id
|
|
|
|
),
|
|
|
|
}
|
2020-12-07 21:24:25 +00:00
|
|
|
}
|
2020-03-30 18:52:33 +00:00
|
|
|
_ => {}
|
|
|
|
},
|
2020-12-07 19:57:15 +00:00
|
|
|
event::Event::DeviceEvent {
|
|
|
|
event: DeviceEvent::MouseMotion { delta },
|
|
|
|
..
|
|
|
|
} => {
|
|
|
|
let mut mouse_motion_events =
|
|
|
|
app.resources.get_mut::<Events<MouseMotion>>().unwrap();
|
|
|
|
mouse_motion_events.send(MouseMotion {
|
|
|
|
delta: Vec2::new(delta.0 as f32, delta.1 as f32),
|
|
|
|
});
|
2020-08-16 07:30:04 +00:00
|
|
|
}
|
2020-03-30 18:52:33 +00:00
|
|
|
event::Event::MainEventsCleared => {
|
2020-03-30 21:53:32 +00:00
|
|
|
handle_create_window_events(
|
|
|
|
&mut app.resources,
|
|
|
|
event_loop,
|
2020-04-01 01:04:54 +00:00
|
|
|
&mut create_window_event_reader,
|
2020-03-30 21:53:32 +00:00
|
|
|
);
|
2020-03-30 18:52:33 +00:00
|
|
|
app.update();
|
2020-03-28 00:43:03 +00:00
|
|
|
}
|
2020-03-30 18:52:33 +00:00
|
|
|
_ => (),
|
|
|
|
}
|
2020-08-21 05:37:19 +00:00
|
|
|
};
|
|
|
|
if should_return_from_run {
|
|
|
|
run_return(&mut event_loop, event_handler);
|
|
|
|
} else {
|
|
|
|
run(event_loop, event_handler);
|
|
|
|
}
|
2020-03-29 07:53:47 +00:00
|
|
|
}
|
2020-03-30 21:53:32 +00:00
|
|
|
|
|
|
|
fn handle_create_window_events(
|
|
|
|
resources: &mut Resources,
|
|
|
|
event_loop: &EventLoopWindowTarget<()>,
|
2020-04-01 01:04:54 +00:00
|
|
|
create_window_event_reader: &mut EventReader<CreateWindow>,
|
2020-03-30 21:53:32 +00:00
|
|
|
) {
|
|
|
|
let mut winit_windows = resources.get_mut::<WinitWindows>().unwrap();
|
|
|
|
let mut windows = resources.get_mut::<Windows>().unwrap();
|
2020-04-01 01:04:54 +00:00
|
|
|
let create_window_events = resources.get::<Events<CreateWindow>>().unwrap();
|
|
|
|
let mut window_created_events = resources.get_mut::<Events<WindowCreated>>().unwrap();
|
2020-04-28 17:59:42 +00:00
|
|
|
for create_window_event in create_window_event_reader.iter(&create_window_events) {
|
2020-12-13 23:05:56 +00:00
|
|
|
let window = winit_windows.create_window(
|
|
|
|
event_loop,
|
|
|
|
create_window_event.id,
|
|
|
|
&create_window_event.descriptor,
|
|
|
|
);
|
2020-03-30 21:53:32 +00:00
|
|
|
windows.add(window);
|
2020-12-13 23:05:56 +00:00
|
|
|
window_created_events.send(WindowCreated {
|
|
|
|
id: create_window_event.id,
|
|
|
|
});
|
2020-03-30 21:53:32 +00:00
|
|
|
}
|
|
|
|
}
|