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;
|
2020-10-30 02:22:03 +00:00
|
|
|
pub use api::{Point, Color, Rect};
|
2020-10-30 03:19:17 +00:00
|
|
|
use xous::String;
|
2020-11-22 16:40:40 +00:00
|
|
|
pub mod op;
|
|
|
|
|
pub mod fonts;
|
2020-08-29 17:17:56 +00:00
|
|
|
|
2020-10-14 03:18:31 +00:00
|
|
|
use xous::{send_message, CID};
|
2020-08-29 17:17:56 +00:00
|
|
|
|
|
|
|
|
pub fn draw_line(cid: CID, start: Point, end: Point) -> Result<(), xous::Error> {
|
2020-10-14 03:18:31 +00:00
|
|
|
send_message(cid, api::Opcode::Line(start, end).into()).map(|_| ())
|
2020-08-29 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
2020-11-22 16:40:40 +00:00
|
|
|
pub fn draw_circle(cid: CID, center: Point, radius: u16) -> Result<(), xous::Error> {
|
2020-10-14 03:18:31 +00:00
|
|
|
send_message(cid, api::Opcode::Circle(center, radius).into()).map(|_| ())
|
2020-08-29 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn draw_rectangle(cid: CID, start: Point, end: Point) -> Result<(), xous::Error> {
|
2020-10-14 03:18:31 +00:00
|
|
|
send_message(cid, api::Opcode::Rectangle(start, end).into()).map(|_| ())
|
2020-08-29 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
2020-11-22 16:40:40 +00:00
|
|
|
pub fn set_style(cid: CID, width: u16, stroke: Color, fill: Color) -> Result<(), xous::Error> {
|
2020-10-14 03:18:31 +00:00
|
|
|
send_message(cid, api::Opcode::Style(width, stroke, fill).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
|
|
|
|
|
|
|
|
pub fn clear_region(cid: CID, x0: usize, y0: usize, x1: usize, y1: usize) -> Result<(), xous::Error> {
|
|
|
|
|
send_message(cid, api::Opcode::ClearRegion(Rect::new(x0 as _, y0 as _, x1 as _, y1 as _)).into()).map(|_| ())
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-30 03:19:17 +00:00
|
|
|
pub fn draw_string(cid: CID, s: &String) -> Result<(), xous::Error> {
|
|
|
|
|
s.lend(cid, 1).map(|_| ())
|
2020-10-30 02:22:03 +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);
|
|
|
|
|
}
|
|
|
|
|
}
|