#![deny(missing_docs)]
#![deny(missing_copy_implementations)]
extern crate input;
#[macro_use]
extern crate quack;
use input::Input;
use quack::{ ActOn, Action, Associative, Get, GetFrom, Pair };
pub trait Window {
type Event;
fn should_close(&self) -> bool;
fn size(&self) -> [u32; 2];
fn swap_buffers(&mut self);
fn poll_event(&mut self) -> Option<Self::Event>;
}
impl<T> Window for T
where
(PollEvent, T): Pair<Data = PollEvent, Object = T>
+ Associative
+ ActOn<Result = Option<<(PollEvent, T) as quack::Associative>::Type>>,
(ShouldClose, T): Pair<Data = ShouldClose, Object = T>
+ GetFrom,
(SwapBuffers, T): Pair<Data = SwapBuffers, Object = T>
+ ActOn,
(Size, T): Pair<Data = Size, Object = T>
+ GetFrom
{
type Event = <(PollEvent, T) as Associative>::Type;
#[inline(always)]
fn should_close(&self) -> bool {
let ShouldClose(val) = self.get();
val
}
#[inline(always)]
fn size(&self) -> [u32; 2] {
let Size(size) = self.get();
size
}
#[inline(always)]
fn swap_buffers(&mut self) {
self.action(SwapBuffers);
}
#[inline(always)]
fn poll_event(&mut self) -> Option<<Self as Window>::Event> {
self.action(PollEvent)
}
}
#[derive(Copy)]
pub struct ShouldClose(pub bool);
#[derive(Copy)]
pub struct Size(pub [u32; 2]);
#[derive(Copy)]
pub struct SwapBuffers;
#[derive(Copy)]
pub struct PollEvent;
pub struct Title(pub String);
#[derive(Copy)]
pub struct Samples(pub u8);
#[derive(Copy)]
pub struct Fullscreen(pub bool);
#[derive(Copy)]
pub struct ExitOnEsc(pub bool);
#[derive(Copy)]
pub struct CaptureCursor(pub bool);
#[derive(Copy)]
pub struct DrawSize(pub [u32; 2]);
#[derive(Copy)]
pub struct DesktopPosition(pub [u32; 2]);
#[derive(Copy)]
pub struct DesktopSize(pub [u32; 2]);
pub struct WindowSettings {
pub title: String,
pub size: [u32; 2],
pub samples: u8,
pub fullscreen: bool,
pub exit_on_esc: bool,
}
impl WindowSettings {
pub fn default() -> WindowSettings {
WindowSettings {
title: "Piston".to_string(),
size: [640, 480],
samples: 0,
fullscreen: false,
exit_on_esc: true,
}
}
}
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,
}
}
}
quack! {
_window: NoWindow[]
get:
fn () -> ShouldClose [] { ShouldClose(_window.should_close) }
fn () -> Size [] { Size([0, 0]) }
fn () -> DrawSize [] {
let Size(val) = _window.get();
DrawSize(val)
}
fn () -> Title [] { Title(_window.title.clone()) }
fn () -> ExitOnEsc [] { ExitOnEsc(false) }
set:
fn (__: CaptureCursor) [] {}
fn (val: ShouldClose) [] { _window.should_close = val.0 }
fn (val: Title) [] { _window.title = val.0; }
fn (__: ExitOnEsc) [] {}
action:
fn (__: SwapBuffers) -> () [] {}
fn (__: PollEvent) -> Option<Input> [] { None }
}
impl Associative for (PollEvent, NoWindow) {
type Type = Input;
}