rstubs/
graphics.rs

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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//! Graphics example

use core::hint;

use embedded_graphics::image::Image;
use embedded_graphics::mono_font::ascii::FONT_10X20;
use embedded_graphics::mono_font::MonoTextStyle;
use embedded_graphics::pixelcolor::Rgb888;
use embedded_graphics::prelude::*;
use embedded_graphics::primitives::{
    Circle, PrimitiveStyle, PrimitiveStyleBuilder, StrokeAlignment, Triangle,
};
use embedded_graphics::text::{Alignment, Text};
use tinytga::Tga;

use crate::device::vga;

#[allow(unused)]
pub extern "C" fn app() -> ! {
    let Ok(mut display) = vga::Display::new() else {
        debug!("Could not init display!!!");
        serial!("Could not init display!!!");
        loop {
            hint::spin_loop()
        }
    };

    let sra_logo: Tga<Rgb888> = Tga::from_slice(include_bytes!("../assets/sra.tga")).unwrap();

    // Create styles used by the drawing operations
    let thin_stroke = PrimitiveStyle::with_stroke(RgbColor::GREEN, 1);
    let thick_stroke = PrimitiveStyle::with_stroke(RgbColor::BLUE, 3);
    let border_stroke = PrimitiveStyleBuilder::new()
        .stroke_color(RgbColor::BLUE)
        .stroke_width(3)
        .stroke_alignment(StrokeAlignment::Inside)
        .build();
    let character_style = MonoTextStyle::new(&FONT_10X20, RgbColor::BLUE);

    let mut i = 0usize;
    let rect = display.bounding_box();
    let center = rect.center();
    loop {
        // Draw a 3px wide outline around the display
        rect.into_styled(border_stroke).draw(&mut display).unwrap();

        Image::new(&sra_logo, Point::new(10, 10))
            .draw(&mut display)
            .unwrap();

        // Draw a triangles
        let s = 120;
        Triangle::new(
            center + Point::new(-s * 4 / 5, s / 2),
            center + Point::new(s * 4 / 5, s / 2),
            center + Point::new(0, -s),
        )
        .into_styled(thin_stroke)
        .draw(&mut display)
        .unwrap();
        let s = s / 2;
        Triangle::new(
            center + Point::new(-s * 4 / 5, -s / 2),
            center + Point::new(s * 4 / 5, -s / 2),
            center + Point::new(0, s),
        )
        .into_styled(thin_stroke)
        .draw(&mut display)
        .unwrap();

        // Draw a circles
        let d = 500 + ((i as i32 % 300) - 150).abs();
        Circle::new(center - Point::new(d / 2, d / 2), d as _)
            .into_styled(thick_stroke)
            .draw(&mut display)
            .unwrap();
        let d = 450 + (((i / 2 + 30) as i32 % 200) - 100).abs();
        Circle::new(center - Point::new(d / 2, d / 2), d as _)
            .into_styled(thin_stroke)
            .draw(&mut display)
            .unwrap();

        // Draw centered text
        Text::with_alignment(
            "Woa such graphics!",
            center + Point::new(0, 0),
            character_style,
            Alignment::Center,
        )
        .draw(&mut display)
        .unwrap();

        // Render and swap framebuffers
        display.render();
        display.clear(RgbColor::BLACK).unwrap();
        i = i.wrapping_add(1);
    }
}