premium_pixel/
lib.rs

1//! Platform independent code for drawing to monochrome surfaces
2
3#![no_std]
4#![warn(missing_docs)]
5
6mod awakening;
7mod digits;
8mod premium;
9mod utils;
10
11pub use awakening::Awakening;
12pub use digits::large::DigitsLarge;
13pub use digits::medium::DigitsMedium;
14pub use premium::Premium;
15pub use utils::*;
16
17/// A drawable surface
18pub trait Surface {
19    /// Clear all pixels
20    fn clear(&mut self);
21    /// Fill a pixel
22    fn pixel(&mut self, x: i32, y: i32);
23    /// Get the width of the surface
24    fn width(&self) -> i32;
25    /// Get the height of the surface
26    fn height(&self) -> i32;
27    /// Draw a line
28    fn line(&mut self, x1: i32, y1: i32, x2: i32, y2: i32) {
29        let dx = (x2 - x1).abs();
30        let sx = (x2 - x1).signum();
31        let dy = (y2 - y1).abs();
32        let sy = (y2 - y1).signum();
33        let mut e = if dx > dy { dx / 2 } else { -dy / 2 };
34        let mut x = x1;
35        let mut y = y1;
36        loop {
37            self.pixel(x, y);
38            if x == x2 && y == y2 {
39                break;
40            }
41            let t = e;
42            if t > -dx {
43                e -= dy;
44                x += sx;
45            }
46            if t < dy {
47                e += dx;
48                y += sy;
49            }
50        }
51    }
52}