Skip to content
Snippets Groups Projects
Commit a0d9692d authored by Astro's avatar Astro :gear:
Browse files

add support for selecting fonts

parent f6a86600
No related branches found
No related tags found
No related merge requests found
...@@ -75,6 +75,15 @@ pub enum FillStyle { ...@@ -75,6 +75,15 @@ pub enum FillStyle {
pub struct Display; pub struct Display;
#[repr(u8)]
pub enum Font {
Font8 = disp_font_name_DISP_FONT8 as u8,
Font12 = disp_font_name_DISP_FONT12 as u8,
Font16 = disp_font_name_DISP_FONT16 as u8,
Font20 = disp_font_name_DISP_FONT20 as u8,
Font24 = disp_font_name_DISP_FONT24 as u8,
}
impl Display { impl Display {
pub const W: u16 = 160; pub const W: u16 = 160;
pub const H: u16 = 80; pub const H: u16 = 80;
...@@ -107,6 +116,13 @@ impl Display { ...@@ -107,6 +116,13 @@ impl Display {
} }
} }
/// s must be 0-terminated
pub fn print_adv(&self, font: Font, x: u16, y: u16, s: &[u8], fg: Color, bg: Color) {
unsafe {
epic_disp_print_adv(font as u8, x, y, s.as_ptr(), fg.0, bg.0);
}
}
pub fn pixel(&self, x: u16, y: u16, color: Color) { pub fn pixel(&self, x: u16, y: u16, color: Color) {
unsafe { unsafe {
epic_disp_pixel(x, y, color.0); epic_disp_pixel(x, y, color.0);
...@@ -186,3 +202,21 @@ macro_rules! display { ...@@ -186,3 +202,21 @@ macro_rules! display {
$disp.print($x, $y, s.as_bytes(), $fg, $bg); $disp.print($x, $y, s.as_bytes(), $fg, $bg);
}); });
} }
/// Requires `card10_alloc::init()` and `extern crate alloc;`
#[macro_export]
macro_rules! display_adv {
($disp: expr, $font: tt, $x: expr, $y: expr, $fg: expr, $bg: expr,
$fmt: expr) => ({
use alloc::format;
use card10_l0dable::Font;
let s = format!(concat!($fmt, "\0"));
$disp.print_adv(Font::$font, $x, $y, s.as_bytes(), $fg, $bg);
});
($disp: expr, $font: tt, $x: expr, $y: expr, $fg: expr, $bg: expr,
$fmt: expr, $($arg: tt)*) => ({
use alloc::format;
let s = format!(concat!($fmt, "\0"), $($arg)*);
$disp.print_adv(Font::$font, $x, $y, s.as_bytes(), $fg, $bg);
});
}
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
mod os; mod os;
pub use os::*; pub use os::*;
mod display; mod display;
pub use display::{Color, Display, FillStyle, LineStyle}; pub use display::{Color, Display, Font, FillStyle, LineStyle};
mod buttons; mod buttons;
pub mod framebuffer; pub mod framebuffer;
pub use buttons::Buttons; pub use buttons::Buttons;
......
...@@ -292,10 +292,10 @@ fn game(level: u16, mut score: u32) -> GameResult { ...@@ -292,10 +292,10 @@ fn game(level: u16, mut score: u32) -> GameResult {
fn title_screen() { fn title_screen() {
let display = Display::open(); let display = Display::open();
display.clear(Color::red()); display.clear(Color::red());
display!(display, 30, 15, Color::white(), Color::red(), "Rkanoid"); display_adv!(display, Font24, Display::W / 2 - 60, 14, Color::white(), Color::red(), "Rkanoid");
display!(display, 30, 30, Color::white(), Color::red(), "in Rust"); display_adv!(display, Font20, Display::W / 2 - 49, 40, Color::white(), Color::red(), "in Rust");
display!(display, 20, 45, Color::white(), Color::red(), "by Astro"); display_adv!(display, Font16, Display::W / 2 - 44, 64, Color::white(), Color::red(), "by Astro");
display!(display, Display::W - 2 * Display::FONT_W, Display::H - Display::FONT_H, Color::yellow(), Color::blue(), "Go"); display!(display, Display::W - 2 * Display::FONT_W, Display::H - Display::FONT_H + 3, Color::yellow(), Color::blue(), "Go");
display.update(); display.update();
while !Buttons::read().right_bottom() {} while !Buttons::read().right_bottom() {}
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment