#![deny(missing_docs)]
#![deny(missing_copy_implementations)]
extern crate shader_version;
extern crate input;
use std::convert::From;
use std::time::Duration;
use shader_version::OpenGL;
use input::Input;
pub use no_window::NoWindow;
mod no_window;
pub type ProcAddress = *const ();
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
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,
}
}
}
impl From<Size> for [u32; 2] {
#[inline(always)]
fn from(value: Size) -> [u32; 2] {
[value.width, value.height]
}
}
impl From<Size> for (u32, u32) {
#[inline(always)]
fn from(value: Size) -> (u32, u32) {
(value.width, value.height)
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct Position {
pub x: i32,
pub y: i32,
}
impl From<[i32; 2]> for Position {
#[inline(always)]
fn from(value: [i32; 2]) -> Position {
Position {
x: value[0],
y: value[1],
}
}
}
impl From<(i32, i32)> for Position {
#[inline(always)]
fn from(value: (i32, i32)) -> Position {
Position {
x: value.0,
y: value.1,
}
}
}
impl From<Position> for [i32; 2] {
#[inline(always)]
fn from(value: Position) -> [i32; 2] {
[value.x, value.y]
}
}
impl From<Position> for (i32, i32) {
#[inline(always)]
fn from(value: Position) -> (i32, i32) {
(value.x, value.y)
}
}
pub trait BuildFromWindowSettings: Sized {
fn build_from_window_settings(settings: &WindowSettings) -> Result<Self, String>;
}
pub trait Window {
fn set_should_close(&mut self, value: bool);
fn should_close(&self) -> bool;
fn size(&self) -> Size;
fn swap_buffers(&mut self);
fn wait_event(&mut self) -> Input;
fn wait_event_timeout(&mut self, timeout: Duration) -> Option<Input>;
fn poll_event(&mut self) -> Option<Input>;
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
}
fn show(&mut self);
fn hide(&mut self);
fn get_position(&self) -> Option<Position>;
fn set_position<P: Into<Position>>(&mut self, val: P);
fn set_size<S: Into<Size>>(&mut self, val: S);
fn position<P: Into<Position>>(mut self, val: P) -> Self {
self.set_position(val);
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);
}
#[derive(Clone)]
pub struct WindowSettings {
title: String,
size: Size,
samples: u8,
fullscreen: bool,
exit_on_esc: bool,
vsync: bool,
opengl: Option<OpenGL>,
srgb: bool,
resizable: bool,
decorated: bool,
controllers: 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,
opengl: None,
srgb: true,
resizable: true,
decorated: true,
controllers: true,
}
}
pub fn build<W: BuildFromWindowSettings>(&self) -> Result<W, String> {
BuildFromWindowSettings::build_from_window_settings(self)
}
pub fn get_title(&self) -> String {
self.title.clone()
}
pub fn set_title(&mut self, value: String) {
self.title = value;
}
pub fn title(mut self, value: String) -> Self {
self.set_title(value);
self
}
pub fn get_size(&self) -> Size {
self.size
}
pub fn set_size(&mut self, value: Size) {
self.size = value;
}
pub fn size(mut self, value: Size) -> Self {
self.set_size(value);
self
}
pub fn get_fullscreen(&self) -> bool {
self.fullscreen
}
pub fn set_fullscreen(&mut self, value: bool) {
self.fullscreen = value;
}
pub fn fullscreen(mut self, value: bool) -> Self {
self.set_fullscreen(value);
self
}
pub fn get_exit_on_esc(&self) -> bool {
self.exit_on_esc
}
pub fn set_exit_on_esc(&mut self, value: bool) {
self.exit_on_esc = value;
}
pub fn exit_on_esc(mut self, value: bool) -> Self {
self.set_exit_on_esc(value);
self
}
pub fn get_samples(&self) -> u8 {
self.samples
}
pub fn set_samples(&mut self, value: u8) {
self.samples = value;
}
pub fn samples(mut self, value: u8) -> Self {
self.set_samples(value);
self
}
pub fn get_vsync(&self) -> bool {
self.vsync
}
pub fn set_vsync(&mut self, value: bool) {
self.vsync = value;
}
pub fn vsync(mut self, value: bool) -> Self {
self.set_vsync(value);
self
}
pub fn get_maybe_opengl(&self) -> Option<OpenGL> {
self.opengl
}
pub fn set_maybe_opengl(&mut self, value: Option<OpenGL>) {
self.opengl = value;
}
pub fn maybe_opengl(mut self, value: Option<OpenGL>) -> Self {
self.set_maybe_opengl(value);
self
}
pub fn set_opengl(&mut self, value: OpenGL) {
self.opengl = Some(value);
}
pub fn opengl(mut self, value: OpenGL) -> Self {
self.set_opengl(value);
self
}
pub fn get_srgb(&self) -> bool {
self.srgb
}
pub fn set_srgb(&mut self, value: bool) {
self.srgb = value;
}
pub fn srgb(mut self, value: bool) -> Self {
self.set_srgb(value);
self
}
pub fn get_resizable(&self) -> bool {
self.resizable
}
pub fn set_resizable(&mut self, value: bool) {
self.resizable = value;
}
pub fn resizable(mut self, value: bool) -> Self {
self.set_resizable(value);
self
}
pub fn get_decorated(&self) -> bool {
self.decorated
}
pub fn set_decorated(&mut self, value: bool) {
self.decorated = value;
}
pub fn decorated(mut self, value: bool) -> Self {
self.set_decorated(value);
self
}
pub fn get_controllers(&self) -> bool {
self.controllers
}
pub fn set_controllers(&mut self, value: bool) {
self.controllers = value;
}
pub fn controllers(mut self, value: bool) -> Self {
self.set_controllers(value);
self
}
}