use std::sync::Arc;
use log::warn;
use winit::window::{CursorGrabMode, Fullscreen, Window};
pub struct WindowContext {
pub window: Arc<Window>,
}
impl WindowContext {
pub(crate) fn from_window(window: Window) -> Self {
let window = Arc::new(window);
Self { window }
}
pub fn set_title(&self, title: &str) {
self.window.set_title(title);
}
pub fn lock_cursor(&self) {
self.window.set_cursor_visible(false);
self.window
.set_cursor_grab(CursorGrabMode::Locked)
.unwrap_or_else(|_| warn!("Failed to grab the cursor!"));
}
pub fn is_fullscreen(&self) -> bool {
self.window
.fullscreen()
.is_some()
}
pub fn borderless_fullscreen(&self) {
let mode = Fullscreen::Borderless(None);
self.window.set_fullscreen(Some(mode));
}
pub fn exit_fullscreen(&self) {
self.window.set_fullscreen(None);
}
pub(crate) fn redraw(&self) {
self.window.request_redraw();
}
}