mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
add ability to render strings on multiple lines
This commit is contained in:
parent
19a7a9ce98
commit
7ba75b14f9
5 changed files with 57 additions and 12 deletions
|
|
@ -619,7 +619,10 @@ pub enum Opcode<'a> {
|
|||
/// Set the current string glyph set for strings
|
||||
SetGlyph(GlyphSet),
|
||||
|
||||
/// Render the string at the (x,y) coordinates
|
||||
/// Set the clipping region for the string.
|
||||
SetStringClipping(Rect),
|
||||
|
||||
/// Render the string inside the clipping region.
|
||||
String(&'a str),
|
||||
|
||||
/// Retrieve the X and Y dimensions of the screen
|
||||
|
|
@ -651,6 +654,7 @@ impl<'a> core::convert::TryFrom<&'a Message> for Opcode<'a> {
|
|||
m.arg4 as _,
|
||||
))),
|
||||
9 => Ok(Opcode::SetGlyph(arg_to_glyph(m.arg1))),
|
||||
11 => Ok(Opcode::SetStringClipping(Rect::new(m.arg1 as _, m.arg2 as _, m.arg3 as _, m.arg4 as _))),
|
||||
_ => Err("unrecognized opcode"),
|
||||
},
|
||||
Message::BlockingScalar(m) => match m.id {
|
||||
|
|
@ -732,6 +736,10 @@ impl<'a> Into<Message> for Opcode<'a> {
|
|||
Opcode::ScreenSize => Message::BlockingScalar(ScalarMessage {id: 8, arg1: 0, arg2: 0, arg3: 0, arg4: 0}),
|
||||
Opcode::QueryGlyph => Message::BlockingScalar(ScalarMessage {id: 10, arg1: 0, arg2: 0, arg3: 0, arg4: 0}),
|
||||
Opcode::SetGlyph(glyph) => Message::Scalar(ScalarMessage { id:9, arg1: glyph_to_arg(glyph), arg2: 0, arg3: 0, arg4: 0 }),
|
||||
Opcode::SetStringClipping(r) => Message::Scalar(ScalarMessage {
|
||||
id: 11,
|
||||
arg1: r.x0 as _, arg2: r.y0 as _, arg3: r.x1 as _, arg4: r.y1 as _,
|
||||
}),
|
||||
Opcode::String(string) => {
|
||||
let region = xous::carton::Carton::from_bytes(string.as_bytes());
|
||||
Message::Borrow(region.into_message(1))
|
||||
|
|
|
|||
|
|
@ -33,6 +33,14 @@ pub fn clear_region(cid: CID, x0: usize, y0: usize, x1: usize, y1: usize) -> Res
|
|||
send_message(cid, api::Opcode::ClearRegion(Rect::new(x0 as _, y0 as _, x1 as _, y1 as _)).into()).map(|_| ())
|
||||
}
|
||||
|
||||
pub fn clear_rectangle(cid: CID, r: Rect) -> Result<(), xous::Error> {
|
||||
send_message(cid, api::Opcode::ClearRegion(r).into()).map(|_| ())
|
||||
}
|
||||
|
||||
pub fn set_string_clipping(cid: CID, r: Rect) -> Result<(), xous::Error> {
|
||||
send_message(cid, api::Opcode::SetStringClipping(r).into()).map(|_| ())
|
||||
}
|
||||
|
||||
pub fn draw_string(cid: CID, s: &String) -> Result<(), xous::Error> {
|
||||
s.lend(cid, 1).map(|_| ())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ fn xmain() -> ! {
|
|||
|
||||
let mut current_color = api::Color::from(0usize);
|
||||
let mut current_glyph = api::GlyphSet::Regular;
|
||||
let mut current_string_clip = op::ClipRegion::screen();
|
||||
|
||||
display.redraw();
|
||||
|
||||
|
|
@ -94,14 +95,17 @@ fn xmain() -> ! {
|
|||
}
|
||||
Opcode::String(s) => {
|
||||
match current_glyph {
|
||||
api::GlyphSet::Small => op::string_small_left(display.native_buffer(), op::ClipRegion::screen(), s),
|
||||
api::GlyphSet::Regular => op::string_regular_left(display.native_buffer(), op::ClipRegion::screen(), s),
|
||||
api::GlyphSet::Bold => op::string_bold_left(display.native_buffer(), op::ClipRegion::screen(), s),
|
||||
api::GlyphSet::Small => op::string_small_left(display.native_buffer(), current_string_clip, s),
|
||||
api::GlyphSet::Regular => op::string_regular_left(display.native_buffer(), current_string_clip, s),
|
||||
api::GlyphSet::Bold => op::string_bold_left(display.native_buffer(), current_string_clip, s),
|
||||
}
|
||||
}
|
||||
Opcode::SetGlyph(glyph) => {
|
||||
current_glyph = glyph;
|
||||
}
|
||||
Opcode::SetStringClipping(r) => {
|
||||
current_string_clip = op::ClipRegion::from(r);
|
||||
}
|
||||
Opcode::ScreenSize => {
|
||||
xous::return_scalar2(
|
||||
msg.sender,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use super::fonts;
|
||||
use super::fonts::{Font, GlyphHeader};
|
||||
use crate::api::{Point, Style, Pixel, GlyphSet};
|
||||
use crate::api::{Point, Style, Pixel, GlyphSet, Rect};
|
||||
|
||||
/// LCD Frame buffer bounds
|
||||
pub const LCD_WORDS_PER_LINE: usize = 11;
|
||||
|
|
@ -49,6 +49,21 @@ impl ClipRegion {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Rect> for ClipRegion {
|
||||
fn from(r: Rect) -> Self {
|
||||
let mut cr = r.clone();
|
||||
if cr.x0 < 0 { cr.x0 = 0 };
|
||||
if cr.x0 >= WIDTH as _ { cr.x0 = WIDTH as i16 - 1 };
|
||||
if cr.x1 < 0 { cr.x1 = 0 };
|
||||
if cr.x1 >= WIDTH as _ { cr.x1 = WIDTH as i16 - 1 };
|
||||
if cr.y0 < 0 { cr.y0 = 0 };
|
||||
if cr.y0 >= HEIGHT as _ { cr.y0 = HEIGHT as i16 - 1 };
|
||||
if cr.y1 < 0 { cr.y1 = 0 };
|
||||
if cr.y1 >= HEIGHT as _ { cr.y1 = HEIGHT as i16 - 1 };
|
||||
ClipRegion {x0: cr.x0 as usize, y0: cr.y0 as usize, x1: cr.x1 as usize, y1: cr.y1 as usize}
|
||||
}
|
||||
}
|
||||
|
||||
/// Blit string with: XOR, bold font, align xr left yr top
|
||||
pub fn string_bold_left(fb: &mut LcdFB, mut cr: ClipRegion, s: &str) {
|
||||
let f = Font::new(GlyphSet::Bold);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ use log::{error, info};
|
|||
use xous::String;
|
||||
use graphics_server::Point;
|
||||
use graphics_server::GlyphSet;
|
||||
use graphics_server::Rect;
|
||||
use com::api::BattStats;
|
||||
use com::*;
|
||||
|
||||
|
|
@ -77,9 +78,9 @@ impl Bounce {
|
|||
pub fn next_rand(&mut self) -> i16 {
|
||||
let mut ret = move_lfsr(self.lfsr);
|
||||
self.lfsr = ret;
|
||||
ret *= 2; // make the ball move faster
|
||||
ret *= 3; // make the ball move faster
|
||||
|
||||
(ret % 8) as i16
|
||||
(ret % 12) as i16
|
||||
}
|
||||
|
||||
pub fn update(&mut self) -> &mut Self {
|
||||
|
|
@ -221,14 +222,23 @@ fn shell_main() -> ! {
|
|||
let mut last_time: u64 = 0;
|
||||
ticktimer_server::reset(ticktimer_conn).unwrap();
|
||||
let mut string_buffer = String::new(4096);
|
||||
graphics_server::set_glyph(graphics_conn, GlyphSet::Small).expect("unable to set glyph");
|
||||
let (_, font_h) = graphics_server::query_glyph(graphics_conn).expect("unable to query glyph");
|
||||
let status_clipregion = Rect::new(0, 0, screensize.x, font_h as i16);
|
||||
let work_clipregion = Rect::new(0, font_h as i16, screensize.x, font_h as i16 * 2);
|
||||
loop {
|
||||
string_buffer.clear();
|
||||
write!(&mut string_buffer, "{}mV Uptime: {:.2}s", BATT_STATS_VOLTAGE.load(Ordering::Relaxed), last_time as f32 / 1000f32).expect("Can't write");
|
||||
graphics_server::set_glyph(graphics_conn, GlyphSet::Small).expect("unable to set glyph");
|
||||
let (_, h) = graphics_server::query_glyph(graphics_conn).expect("unable to query glyph");
|
||||
graphics_server::clear_region(graphics_conn, 0, 0, screensize.x as usize - 1, h)
|
||||
write!(&mut string_buffer, "{}mV | {}mA", BATT_STATS_VOLTAGE.load(Ordering::Relaxed), BATT_STATS_CURRENT.load(Ordering::Relaxed)).expect("Can't write");
|
||||
graphics_server::clear_rectangle(graphics_conn, status_clipregion)
|
||||
.expect("unable to clear region");
|
||||
info!("drawing string: {}", string_buffer);
|
||||
graphics_server::set_string_clipping(graphics_conn, status_clipregion).expect("unable to set string clip region");
|
||||
graphics_server::draw_string(graphics_conn, &string_buffer).expect("unable to draw string");
|
||||
|
||||
string_buffer.clear();
|
||||
write!(&mut string_buffer, "Uptime: {:.2}s", last_time as f32 / 1000f32).expect("Can't write");
|
||||
graphics_server::clear_rectangle(graphics_conn, work_clipregion)
|
||||
.expect("unable to clear region");
|
||||
graphics_server::set_string_clipping(graphics_conn, work_clipregion).expect("unable to set string clip region");
|
||||
graphics_server::draw_string(graphics_conn, &string_buffer).expect("unable to draw string");
|
||||
|
||||
// ticktimer_server::sleep_ms(ticktimer_conn, 500).expect("couldn't sleep");
|
||||
|
|
|
|||
Loading…
Reference in a new issue