OXYGENHUB
# 5501b1c657b2 oxygenhub / crates / backdrop / src / scene.rs
1.8 KiB · Rust · last changed feat(web): the mark, ripples, the swarm and adrift (closes #167) 23 days ago source blame history raw
6246d1e5 Andy McCall ↶ 1
//! A backdrop's scene (docs/backgrounds.md §2): what it draws and how it
2
//! moves. The engine (lib.rs) drives any of them the same way.
3
4
use crate::sky::Colours;
5
6
pub trait Scene {
7
    /// The view is now `w` by `h` CSS pixels, the page's content column
8
    /// between `avoid`'s left and right.
9
    fn resize(&mut self, w: f32, h: f32, avoid: Option<(f32, f32)>);
10
    /// The cursor moved to `(x, y)`, or left the page.
11
    fn point(&mut self, at: Option<(f32, f32)>);
12
    /// Move on by `dt` seconds.
13
    fn step(&mut self, dt: f32);
14
    /// The marks, 8 floats each (sky::Sky::instances).
15
    fn instances(&self, c: &Colours, out: &mut Vec<f32>);
16
    /// The links, 12 floats each (sky::Sky::links).
17
    fn links(&self, c: &Colours, out: &mut Vec<f32>);
18
    /// The name a resting cursor shows, and where.
19
    fn label(&self) -> Option<(&str, f32, f32)>;
20
    /// Whether a frame would show anything new.
21
    fn busy(&self) -> bool;
22
    fn still(&self) -> bool;
23
    fn size(&self) -> (f32, f32);
24
}
25
26
impl Scene for crate::sky::Sky {
27
    fn resize(&mut self, w: f32, h: f32, avoid: Option<(f32, f32)>) {
28
        crate::sky::Sky::resize(self, w, h, avoid)
29
    }
30
    fn point(&mut self, at: Option<(f32, f32)>) {
31
        crate::sky::Sky::point(self, at)
32
    }
33
    fn step(&mut self, dt: f32) {
34
        crate::sky::Sky::step(self, dt)
35
    }
36
    fn instances(&self, c: &Colours, out: &mut Vec<f32>) {
37
        crate::sky::Sky::instances(self, c, out)
38
    }
39
    fn links(&self, c: &Colours, out: &mut Vec<f32>) {
40
        crate::sky::Sky::links(self, c, out)
41
    }
42
    fn label(&self) -> Option<(&str, f32, f32)> {
43
        crate::sky::Sky::label(self)
44
    }
45
    fn busy(&self) -> bool {
46
        crate::sky::Sky::busy(self)
47
    }
48
    fn still(&self) -> bool {
49
        self.still
50
    }
51
    fn size(&self) -> (f32, f32) {
52
        (self.w, self.h)
53
    }
54
}