2020-08-29 17:17:56 +00:00
|
|
|
#![cfg_attr(target_os = "none", no_std)]
|
|
|
|
|
|
2020-11-22 16:40:40 +00:00
|
|
|
// pub mod size;
|
2020-08-29 17:17:56 +00:00
|
|
|
pub mod api;
|
2021-02-28 20:01:33 +00:00
|
|
|
pub use api::{Circle, DrawStyle, Line, PixelColor, Point, Rectangle, TextView, TextBounds, Gid, TextOp, RoundedRectangle};
|
2021-01-20 08:22:38 +00:00
|
|
|
use blitstr_ref as blitstr;
|
2021-01-03 10:31:51 +00:00
|
|
|
pub use blitstr::{ClipRect, Cursor, GlyphStyle};
|
2020-10-30 03:19:17 +00:00
|
|
|
use xous::String;
|
2020-11-22 16:40:40 +00:00
|
|
|
pub mod op;
|
2020-08-29 17:17:56 +00:00
|
|
|
|
2020-10-14 03:18:31 +00:00
|
|
|
use xous::{send_message, CID};
|
2021-02-14 20:42:30 +00:00
|
|
|
use core::fmt::Write;
|
2020-08-29 17:17:56 +00:00
|
|
|
|
2020-12-02 17:48:10 +00:00
|
|
|
pub fn draw_line(cid: CID, line: Line) -> Result<(), xous::Error> {
|
2021-02-28 20:01:33 +00:00
|
|
|
let m: xous::Message = api::Opcode::Line(line).into();
|
2021-03-02 11:25:41 +00:00
|
|
|
//log::info!("GFX|LIB: api encoded line as {:?}", m);
|
2021-02-28 20:01:33 +00:00
|
|
|
send_message(cid, m).map(|_| ())
|
2020-08-29 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
2020-12-02 17:48:10 +00:00
|
|
|
pub fn draw_circle(cid: CID, circ: Circle) -> Result<(), xous::Error> {
|
|
|
|
|
send_message(cid, api::Opcode::Circle(circ).into()).map(|_| ())
|
2020-08-29 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
2020-12-02 17:48:10 +00:00
|
|
|
pub fn draw_rectangle(cid: CID, rect: Rectangle) -> Result<(), xous::Error> {
|
|
|
|
|
send_message(cid, api::Opcode::Rectangle(rect).into()).map(|_| ())
|
2021-02-28 20:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn draw_rounded_rectangle(cid: CID, rr: RoundedRectangle) -> Result<(), xous::Error> {
|
|
|
|
|
send_message(cid, api::Opcode::RoundedRectangle(rr).into()).map(|_| ())
|
2020-08-29 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn flush(cid: CID) -> Result<(), xous::Error> {
|
2020-10-14 03:18:31 +00:00
|
|
|
send_message(cid, api::Opcode::Flush.into()).map(|_| ())
|
2020-08-29 17:17:56 +00:00
|
|
|
}
|
2020-10-30 02:22:03 +00:00
|
|
|
|
2021-01-18 20:54:54 +00:00
|
|
|
#[deprecated(
|
|
|
|
|
note = "Please use draw_textview for atomic text updates"
|
|
|
|
|
)]
|
2020-12-02 17:48:10 +00:00
|
|
|
pub fn set_string_clipping(cid: CID, r: ClipRect) -> Result<(), xous::Error> {
|
2020-11-26 19:33:44 +00:00
|
|
|
send_message(cid, api::Opcode::SetStringClipping(r).into()).map(|_| ())
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 20:54:54 +00:00
|
|
|
#[deprecated(
|
|
|
|
|
note = "Please use draw_textview for atomic text updates"
|
|
|
|
|
)]
|
2020-11-27 18:05:55 +00:00
|
|
|
pub fn set_cursor(cid: CID, c: Cursor) -> Result<(), xous::Error> {
|
|
|
|
|
send_message(cid, api::Opcode::SetCursor(c).into()).map(|_| ())
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 20:54:54 +00:00
|
|
|
#[deprecated(
|
|
|
|
|
note = "Please use draw_textview for atomic text updates"
|
|
|
|
|
)]
|
2020-12-02 17:48:10 +00:00
|
|
|
pub fn get_cursor(cid: CID) -> Result<Cursor, xous::Error> {
|
2020-11-27 18:05:55 +00:00
|
|
|
let response = send_message(cid, api::Opcode::GetCursor.into())?;
|
|
|
|
|
if let xous::Result::Scalar2(pt_as_usize, h) = response {
|
|
|
|
|
let p: Point = pt_as_usize.into();
|
2021-01-21 16:27:45 +00:00
|
|
|
Ok(Cursor::new(p.x as u32, p.y as u32, h as _))
|
2020-11-27 18:05:55 +00:00
|
|
|
} else {
|
|
|
|
|
panic!("unexpected return value: {:#?}", response);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 20:54:54 +00:00
|
|
|
#[deprecated(
|
|
|
|
|
note = "Please use draw_textview for atomic text updates"
|
|
|
|
|
)]
|
2021-02-14 20:42:30 +00:00
|
|
|
pub fn draw_string(cid: CID, s: &String<4096>) -> Result<(), xous::Error> {
|
|
|
|
|
let mut clone_s: String<4096> = String::new();
|
2021-02-17 12:50:42 +00:00
|
|
|
write!(clone_s, "{}", s.as_str().unwrap()).map_err(|_| xous::Error::AccessDenied)?;
|
2021-02-14 20:42:30 +00:00
|
|
|
let request = api::Opcode::String(clone_s);
|
|
|
|
|
let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096));
|
|
|
|
|
use rkyv::Write;
|
|
|
|
|
let pos = writer.archive(&request).expect("GFX: couldn't archive String request");
|
|
|
|
|
let xous_buffer = writer.into_inner();
|
|
|
|
|
|
2021-02-15 16:28:44 +00:00
|
|
|
//log::info!("GFX: draw_string message being sent");
|
2021-02-14 20:42:30 +00:00
|
|
|
xous_buffer.lend(cid, pos as u32).expect("GFX: String request failure");
|
2021-02-15 16:28:44 +00:00
|
|
|
//log::info!("GFX: draw_string completed");
|
2021-02-14 20:42:30 +00:00
|
|
|
Ok(())
|
2020-10-30 02:22:03 +00:00
|
|
|
}
|
2020-11-23 06:55:56 +00:00
|
|
|
|
2021-01-18 20:54:54 +00:00
|
|
|
#[deprecated(
|
|
|
|
|
note = "Please use draw_textview for atomic text updates"
|
|
|
|
|
)]
|
2020-12-02 17:48:10 +00:00
|
|
|
pub fn set_glyph_style(cid: CID, glyph: GlyphStyle) -> Result<(), xous::Error> {
|
2021-01-03 10:31:51 +00:00
|
|
|
send_message(cid, api::Opcode::SetGlyphStyle(glyph).into()).map(|_| ())
|
2020-11-23 07:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
2020-11-23 06:55:56 +00:00
|
|
|
pub fn screen_size(cid: CID) -> Result<Point, xous::Error> {
|
|
|
|
|
let response = send_message(cid, api::Opcode::ScreenSize.into())?;
|
|
|
|
|
if let xous::Result::Scalar2(x, y) = response {
|
|
|
|
|
Ok(Point::new(x as _, y as _))
|
|
|
|
|
} else {
|
|
|
|
|
panic!("unexpected return value: {:#?}", response);
|
|
|
|
|
}
|
2020-11-23 07:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
2021-01-18 20:54:54 +00:00
|
|
|
#[deprecated(
|
|
|
|
|
note = "Please use draw_textview for atomic text updates"
|
|
|
|
|
)]
|
2020-12-02 17:48:10 +00:00
|
|
|
pub fn query_glyph(cid: CID) -> Result<(GlyphStyle, usize), xous::Error> {
|
|
|
|
|
let response = send_message(cid, api::Opcode::QueryGlyphStyle.into())?;
|
2020-11-23 07:42:58 +00:00
|
|
|
if let xous::Result::Scalar2(glyph, h) = response {
|
2020-12-02 17:48:10 +00:00
|
|
|
Ok((GlyphStyle::from(glyph), h))
|
2020-11-23 07:42:58 +00:00
|
|
|
} else {
|
|
|
|
|
panic!("unexpected return value: {:#?}", response);
|
|
|
|
|
}
|
2021-01-03 10:31:51 +00:00
|
|
|
}
|
2021-01-17 20:12:40 +00:00
|
|
|
|
|
|
|
|
pub fn glyph_height_hint(cid: CID, glyph: GlyphStyle) -> Result<usize, xous::Error> {
|
|
|
|
|
let response = send_message(cid, api::Opcode::QueryGlyphProps(glyph).into())?;
|
|
|
|
|
if let xous::Result::Scalar2(_, h) = response {
|
|
|
|
|
Ok(h)
|
|
|
|
|
} else {
|
|
|
|
|
panic!("unexpected return value: {:#?}", response);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-18 20:54:54 +00:00
|
|
|
|
2021-02-28 17:49:22 +00:00
|
|
|
pub fn draw_textview(cid: CID, tv: &mut TextView) -> Result<(), xous::Error> {
|
|
|
|
|
use log::info;
|
|
|
|
|
use rkyv::Write;
|
|
|
|
|
use rkyv::Unarchive;
|
|
|
|
|
|
|
|
|
|
let mut rkyv_tv = api::Opcode::DrawTextView(*tv);
|
|
|
|
|
let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096));
|
|
|
|
|
let pos = writer.archive(&rkyv_tv).expect("couldn't archive textview");
|
|
|
|
|
let mut xous_buffer = writer.into_inner();
|
|
|
|
|
|
|
|
|
|
xous_buffer.lend_mut(cid, pos as u32).expect("draw_textview operation failure");
|
|
|
|
|
|
|
|
|
|
let returned = unsafe { rkyv::archived_value::<api::Opcode>(xous_buffer.as_ref(), pos)};
|
|
|
|
|
if let rkyv::Archived::<api::Opcode>::DrawTextView(result) = returned {
|
2021-03-03 06:53:33 +00:00
|
|
|
let tvr: TextView = result.unarchive();
|
|
|
|
|
tv.bounds_computed = tvr.bounds_computed;
|
|
|
|
|
tv.cursor = tvr.cursor;
|
|
|
|
|
Ok(())
|
2021-02-28 17:49:22 +00:00
|
|
|
} else {
|
|
|
|
|
let tvr = returned.unarchive();
|
2021-03-03 06:53:33 +00:00
|
|
|
info!("draw_textview saw an unhandled return type of {:?}", tvr);
|
|
|
|
|
Err(xous::Error::InternalError)
|
2021-02-28 17:49:22 +00:00
|
|
|
}
|
2021-02-17 12:50:42 +00:00
|
|
|
}
|