#![deny(missing_docs)]
#![deny(missing_copy_implementations)]
extern crate libc;
extern crate input;
use input::Input;
pub type ProcAddress = *const libc::c_void;
#[derive(Copy, Clone)]
pub struct Size {
pub width: u32,
pub height: u32,
}
impl From<[u32; 2]> for Size {
#[inline(always)]
fn from(value: [u32; 2]) -> Size {
Size { width: value[0], height: value[1] }
}
}
impl From<(u32, u32)> for Size {
#[inline(always)]
fn from(value: (u32, u32)) -> Size {
Size { width: value.0, height: value.1 }
}
}
pub trait Window {
type Event;
fn should_close(&self) -> bool;
fn size(&self) -> Size;
fn swap_buffers(&mut self);
fn poll_event(&mut self) -> Option<Self::Event>;
fn draw_size(&self) -> Size;
}
pub trait AdvancedWindow: Window + Sized {
fn get_title(&self) -> String;
fn set_title(&mut self, value: String);
fn title(mut self, value: String) -> Self {
self.set_title(value);
self
}
fn get_exit_on_esc(&self) -> bool;
fn set_exit_on_esc(&mut self, value: bool);
fn exit_on_esc(mut self, value: bool) -> Self {
self.set_exit_on_esc(value);
self
}
fn set_capture_cursor(&mut self, value: bool);
fn capture_cursor(mut self, value: bool) -> Self {
self.set_capture_cursor(value);
self
}
}
pub trait OpenGLWindow: Window {
fn get_proc_address(&mut self, proc_name: &str) -> ProcAddress;
fn is_current(&self) -> bool;
fn make_current(&mut self);
}
pub struct WindowSettings {
title: String,
size: Size,
samples: u8,
fullscreen: bool,
exit_on_esc: bool,
vsync: bool,
}
impl WindowSettings {
pub fn new<T: Into<String>, S: Into<Size>>(
title: T, size: S) -> WindowSettings
{
WindowSettings {
title: title.into(),
size: size.into(),
samples: 0,
fullscreen: false,
exit_on_esc: false,
vsync: false,
}
}
pub fn get_title(&self) -> String { self.title.clone() }
pub fn title(mut self, value: String) -> Self {
self.title = value;
self
}
pub fn get_size(&self) -> Size { self.size }
pub fn size(mut self, value: Size) -> Self {
self.size = value;
self
}
pub fn get_fullscreen(&self) -> bool { self.fullscreen }
pub fn fullscreen(mut self, value: bool) -> Self {
self.fullscreen = value;
self
}
pub fn get_exit_on_esc(&self) -> bool { self.exit_on_esc }
pub fn exit_on_esc(mut self, value: bool) -> Self {
self.exit_on_esc = value;
self
}
pub fn get_samples(&self) -> u8 { self.samples }
pub fn samples(mut self, value: u8) -> Self {
self.samples = value;
self
}
pub fn get_vsync(&self) -> bool { self.vsync }
pub fn vsync(mut self, value: bool) -> Self {
self.vsync = value;
self
}
}
pub struct NoWindow {
should_close: bool,
title: String,
}
impl NoWindow {
pub fn new(settings: WindowSettings) -> NoWindow {
let title = settings.title.clone();
NoWindow {
should_close: false,
title: title,
}
}
}
impl Window for NoWindow {
type Event = Input;
fn should_close(&self) -> bool { self.should_close }
fn size(&self) -> Size { Size { width: 0, height: 0 } }
fn swap_buffers(&mut self) {}
fn poll_event(&mut self) -> Option<Input> { None }
fn draw_size(&self) -> Size { self.size() }
}
impl AdvancedWindow for NoWindow {
fn get_title(&self) -> String { self.title.clone() }
fn set_title(&mut self, value: String) { self.title = value; }
fn get_exit_on_esc(&self) -> bool { false }
fn set_exit_on_esc(&mut self, _value: bool) {}
fn set_capture_cursor(&mut self, _value: bool) {}
}