1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#[macro_use(lift)]
extern crate carboxyl;
extern crate clock_ticks;
extern crate input;
extern crate window;
use carboxyl::{Stream, Signal};
pub use source_win::SourceWindow;
mod source_win;
mod borrowing;
pub trait StreamingWindow {
fn context(&self) -> Signal<Context>;
fn events(&self) -> Stream<Event>;
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct WindowProperties {
pub position: (i32, i32),
pub size: (u32, u32),
pub focus: bool
}
impl WindowProperties {
pub fn new(position: (i32, i32), size: (u32, u32), focus: bool)
-> WindowProperties
{
WindowProperties {
position: position,
size: size,
focus: focus
}
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Cursor {
pub position: (f64, f64),
pub wheel: (f64, f64)
}
impl Cursor {
pub fn new(position: (f64, f64), wheel: (f64, f64)) -> Cursor {
Cursor { position: position, wheel: wheel }
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Context {
pub window: WindowProperties,
pub cursor: Cursor
}
impl Context {
pub fn new(window: WindowProperties, cursor: Cursor) -> Context {
Context { window: window, cursor: cursor }
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Event {
Press(input::Button),
Release(input::Button),
Text(String)
}
pub trait RunnableWindow {
fn run_with<F: FnMut()>(&mut self, fps: f64, render: F);
fn run(&mut self, fps: f64) {
self.run_with(fps, || ());
}
}