OXYGENHUB
# 317d776c725b oxygenhub / crates / backdrop / src / scene.rs
2.2 KiB · Rust · last changed Live arrivals on the sky 22 days ago source blame history raw
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, Kind};
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
    /// New activity in repository `repo` (§5, "Live"); only the sky shows it.
21
    fn arrive(&mut self, _repo: &str, _kind: Kind, _n: u32) {}
22
    /// Whether a frame would show anything new besides the drift, which
23
    /// the engine stops drawing a while after the last input (§6).
24
    fn busy(&self) -> bool;
25
    fn still(&self) -> bool;
26
    fn size(&self) -> (f32, f32);
27
}
28
29
impl Scene for crate::sky::Sky {
30
    fn resize(&mut self, w: f32, h: f32, avoid: Option<(f32, f32)>) {
31
        crate::sky::Sky::resize(self, w, h, avoid)
32
    }
33
    fn point(&mut self, at: Option<(f32, f32)>) {
34
        crate::sky::Sky::point(self, at)
35
    }
36
    fn step(&mut self, dt: f32) {
37
        crate::sky::Sky::step(self, dt)
38
    }
39
    fn instances(&self, c: &Colours, out: &mut Vec<f32>) {
40
        crate::sky::Sky::instances(self, c, out)
41
    }
42
    fn links(&self, c: &Colours, out: &mut Vec<f32>) {
43
        crate::sky::Sky::links(self, c, out)
44
    }
45
    fn label(&self) -> Option<(&str, f32, f32)> {
46
        crate::sky::Sky::label(self)
47
    }
48
    fn arrive(&mut self, repo: &str, kind: Kind, n: u32) {
49
        crate::sky::Sky::arrive(self, repo, kind, n)
50
    }
51
    fn busy(&self) -> bool {
52
        crate::sky::Sky::busy(self)
53
    }
54
    fn still(&self) -> bool {
55
        self.still
56
    }
57
    fn size(&self) -> (f32, f32) {
58
        (self.w, self.h)
59
    }
60
}