use libc::{c_uint, size_t};
use std::vec::Vec;
use traits::Wrappable;
use csfml_window_sys as ffi;
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Copy)]
pub struct VideoMode {
pub width: u32,
pub height: u32,
pub bits_per_pixel: u32
}
impl VideoMode {
pub fn new() -> VideoMode {
VideoMode{
width: 0,
height: 0,
bits_per_pixel: 0
}
}
pub fn new_init(width: u32,
height: u32,
bits_per_pixel: u32) -> VideoMode {
VideoMode{
width: width,
height: height,
bits_per_pixel: bits_per_pixel
}
}
pub fn is_valid(&self) -> bool {
unsafe { ffi::sfVideoMode_isValid(ffi::sfVideoMode {
width: self.width as c_uint,
height: self.height as c_uint,
bits_per_pixel: self.bits_per_pixel as c_uint
}) }.to_bool()
}
pub fn get_desktop_mode() -> VideoMode {
let mode = unsafe { ffi::sfVideoMode_getDesktopMode() };
VideoMode{
width: mode.width as u32,
height: mode.height as u32,
bits_per_pixel: mode.bits_per_pixel as u32
}
}
pub fn get_fullscreen_modes() -> Option<Vec<VideoMode>> {
let mut size: size_t = 0;
let tab = unsafe {
ffi::sfVideoMode_getFullscreenModes(&mut size)
};
if size == 0 {
return None;
}
let size = size as u32;
let tab_slice: &[ffi::sfVideoMode] = unsafe {
::std::slice::from_raw_parts(tab, size as usize)
};
let mut ret_tab = Vec::with_capacity(size as usize);
for sf_video_mode in tab_slice.iter() {
ret_tab.push(Wrappable::wrap(sf_video_mode.clone()));
}
Some(ret_tab)
}
}
impl Wrappable<ffi::sfVideoMode> for VideoMode {
fn wrap(mode: ffi::sfVideoMode) -> VideoMode {
VideoMode{
width: mode.width as u32,
height: mode.height as u32,
bits_per_pixel: mode.bits_per_pixel as u32
}
}
fn unwrap(&self) -> ffi::sfVideoMode {
ffi::sfVideoMode{
width: self.width as c_uint,
height: self.height as c_uint,
bits_per_pixel: self.bits_per_pixel as c_uint
}
}
}