use crate::{ffi::window as ffi, window::thread_safety};
#[cfg_attr(feature = "ci-headless", doc = "```no_run")]
#[cfg_attr(not(feature = "ci-headless"), doc = "```")]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Copy)]
pub struct VideoMode {
pub width: u32,
pub height: u32,
pub bits_per_pixel: u32,
}
impl VideoMode {
#[must_use]
pub const fn new(width: u32, height: u32, bits_per_pixel: u32) -> Self {
Self {
width,
height,
bits_per_pixel,
}
}
#[must_use]
pub fn is_valid(&self) -> bool {
unsafe { ffi::sfVideoMode_isValid(self.raw()) }
}
#[must_use]
pub fn desktop_mode() -> Self {
thread_safety::set_window_thread();
unsafe { Self::from_raw(ffi::sfVideoMode_getDesktopMode()) }
}
#[must_use]
pub fn fullscreen_modes() -> &'static ffi::sfVideoModeVector {
unsafe { &*ffi::sfVideoMode_getFullscreenModes() }
}
pub(crate) fn raw(&self) -> ffi::sfVideoMode {
ffi::sfVideoMode {
width: self.width,
height: self.height,
bits_per_pixel: self.bits_per_pixel,
}
}
fn from_raw(raw: ffi::sfVideoMode) -> Self {
Self::new(raw.width, raw.height, raw.bits_per_pixel)
}
}
impl From<(u32, u32)> for VideoMode {
fn from(src: (u32, u32)) -> Self {
Self::new(src.0, src.1, 32)
}
}
impl Default for VideoMode {
fn default() -> Self {
Self::new(0, 0, 0)
}
}