2022-06-10 13:43:33 +03:00
|
|
|
#![allow(clippy::single_match)]
|
|
|
|
|
2018-04-24 16:20:40 -04:00
|
|
|
use std::collections::HashMap;
|
2020-09-09 17:58:30 -08:00
|
|
|
|
|
|
|
use simple_logger::SimpleLogger;
|
2019-06-21 11:33:15 -04:00
|
|
|
use winit::{
|
2023-05-28 20:02:59 +02:00
|
|
|
event::{ElementState, Event, KeyEvent, WindowEvent},
|
2022-04-09 18:32:02 -07:00
|
|
|
event_loop::EventLoop,
|
2023-05-28 20:02:59 +02:00
|
|
|
keyboard::Key,
|
2019-06-21 11:33:15 -04:00
|
|
|
window::Window,
|
|
|
|
};
|
2018-04-24 16:20:40 -04:00
|
|
|
|
2023-06-19 11:46:38 -07:00
|
|
|
#[path = "util/fill.rs"]
|
|
|
|
mod fill;
|
|
|
|
|
2014-08-03 17:23:08 +02:00
|
|
|
fn main() {
|
2020-09-09 17:58:30 -08:00
|
|
|
SimpleLogger::new().init().unwrap();
|
2019-02-05 10:30:33 -05:00
|
|
|
let event_loop = EventLoop::new();
|
2014-08-03 17:23:08 +02:00
|
|
|
|
2018-04-24 16:20:40 -04:00
|
|
|
let mut windows = HashMap::new();
|
|
|
|
for _ in 0..3 {
|
2019-02-05 10:30:33 -05:00
|
|
|
let window = Window::new(&event_loop).unwrap();
|
2022-07-03 20:25:08 +01:00
|
|
|
println!("Opened a new window: {:?}", window.id());
|
2018-04-24 16:20:40 -04:00
|
|
|
windows.insert(window.id(), window);
|
|
|
|
}
|
2014-12-23 17:12:29 +01:00
|
|
|
|
2022-07-03 20:25:08 +01:00
|
|
|
println!("Press N to open a new window.");
|
|
|
|
|
2019-02-05 10:30:33 -05:00
|
|
|
event_loop.run(move |event, event_loop, control_flow| {
|
2022-04-09 18:32:02 -07:00
|
|
|
control_flow.set_wait();
|
2020-01-05 02:12:03 -05:00
|
|
|
|
2015-06-16 13:48:08 +02:00
|
|
|
match event {
|
2019-02-05 10:30:33 -05:00
|
|
|
Event::WindowEvent { event, window_id } => {
|
|
|
|
match event {
|
|
|
|
WindowEvent::CloseRequested => {
|
2023-01-27 07:18:58 +03:00
|
|
|
println!("Window {window_id:?} has received the signal to close");
|
2018-04-24 16:20:40 -04:00
|
|
|
|
2019-02-05 10:30:33 -05:00
|
|
|
// This drops the window, causing it to close.
|
|
|
|
windows.remove(&window_id);
|
2017-01-28 15:45:01 +01:00
|
|
|
|
2019-02-05 10:30:33 -05:00
|
|
|
if windows.is_empty() {
|
2022-04-09 18:32:02 -07:00
|
|
|
control_flow.set_exit();
|
2019-02-05 10:30:33 -05:00
|
|
|
}
|
2019-06-24 12:14:55 -04:00
|
|
|
}
|
2019-06-21 11:33:15 -04:00
|
|
|
WindowEvent::KeyboardInput {
|
2023-05-28 20:02:59 +02:00
|
|
|
event:
|
|
|
|
KeyEvent {
|
2019-06-21 11:33:15 -04:00
|
|
|
state: ElementState::Pressed,
|
2023-05-28 20:02:59 +02:00
|
|
|
logical_key: Key::Character(c),
|
2019-06-21 11:33:15 -04:00
|
|
|
..
|
|
|
|
},
|
2022-07-03 20:25:08 +01:00
|
|
|
is_synthetic: false,
|
2019-06-21 11:33:15 -04:00
|
|
|
..
|
2023-05-28 20:02:59 +02:00
|
|
|
} if matches!(c.as_ref(), "n" | "N") => {
|
2022-01-01 13:00:11 +11:00
|
|
|
let window = Window::new(event_loop).unwrap();
|
2022-07-03 20:25:08 +01:00
|
|
|
println!("Opened a new window: {:?}", window.id());
|
2019-02-05 10:30:33 -05:00
|
|
|
windows.insert(window.id(), window);
|
2019-06-24 12:14:55 -04:00
|
|
|
}
|
2019-06-21 11:33:15 -04:00
|
|
|
_ => (),
|
2017-01-28 15:45:01 +01:00
|
|
|
}
|
2019-06-24 12:14:55 -04:00
|
|
|
}
|
2023-06-19 11:46:38 -07:00
|
|
|
Event::RedrawRequested(window_id) => {
|
|
|
|
if let Some(window) = windows.get(&window_id) {
|
|
|
|
fill::fill_window(window);
|
|
|
|
}
|
|
|
|
}
|
2017-01-28 15:45:01 +01:00
|
|
|
_ => (),
|
2015-06-16 13:48:08 +02:00
|
|
|
}
|
2017-01-28 15:45:01 +01:00
|
|
|
})
|
2014-08-03 17:23:08 +02:00
|
|
|
}
|