use crate::{
cpp::{CppVector, CppVectorItem},
ffi::window as ffi,
window::thread_safety,
};
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
pub struct VideoMode {
pub width: std::ffi::c_uint,
pub height: std::ffi::c_uint,
pub bits_per_pixel: std::ffi::c_uint,
}
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) }
}
#[must_use]
pub fn desktop_mode() -> Self {
thread_safety::set_window_thread();
unsafe { ffi::sfVideoMode_getDesktopMode() }
}
#[must_use]
pub fn fullscreen_modes() -> &'static CppVector<Self> {
unsafe { &*ffi::sfVideoMode_getFullscreenModes() }
}
}
impl From<(u32, u32)> for VideoMode {
fn from((w, h): (u32, u32)) -> Self {
Self::new(w, h, 32)
}
}
impl From<[u32; 2]> for VideoMode {
fn from([w, h]: [u32; 2]) -> Self {
Self::new(w, h, 32)
}
}
impl Default for VideoMode {
fn default() -> Self {
Self::new(0, 0, 0)
}
}
unsafe impl CppVectorItem for VideoMode {
fn get_data(vec: &crate::cpp::CppVector<Self>) -> *const Self {
unsafe { ffi::sfVideoModeVector_getData(vec) }
}
fn get_len(vec: &crate::cpp::CppVector<Self>) -> usize {
unsafe { ffi::sfVideoModeVector_getLength(vec) }
}
fn del(_vec: &mut CppVector<Self>) {}
}