2021-01-04 20:45:23 +00:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
|
2021-01-16 20:02:08 +00:00
|
|
|
/*
|
|
|
|
|
Primitives needed:
|
|
|
|
|
|
|
|
|
|
- clipping rectangles (for drawing)
|
|
|
|
|
- rounded rectangles
|
|
|
|
|
- inverse text
|
|
|
|
|
- icons/sprites
|
|
|
|
|
- width of a text string with a given font (to compute alignments)
|
|
|
|
|
- untrusted backgrounds
|
|
|
|
|
- bitmaps
|
|
|
|
|
|
|
|
|
|
*/
|
2020-12-02 17:48:10 +00:00
|
|
|
|
2021-01-19 09:10:31 +00:00
|
|
|
//////////////// primitives
|
|
|
|
|
pub mod points;
|
|
|
|
|
pub use points::Point;
|
|
|
|
|
pub mod styles;
|
|
|
|
|
pub use styles::*;
|
|
|
|
|
pub mod shapes;
|
|
|
|
|
pub use shapes::*;
|
|
|
|
|
pub mod text;
|
|
|
|
|
pub use text::*;
|
2020-12-02 17:48:10 +00:00
|
|
|
|
2021-01-20 08:22:38 +00:00
|
|
|
use blitstr_ref as blitstr;
|
2021-01-19 09:10:31 +00:00
|
|
|
use blitstr::{ClipRect, Cursor, GlyphStyle};
|
2020-08-29 17:17:56 +00:00
|
|
|
|
2021-01-19 09:10:31 +00:00
|
|
|
use xous::{Message, ScalarMessage};
|
|
|
|
|
use hash32::{Hash, Hasher};
|
2020-12-02 17:48:10 +00:00
|
|
|
|
2021-01-19 09:10:31 +00:00
|
|
|
//////////////// OS APIs
|
2020-08-29 17:17:56 +00:00
|
|
|
|
2021-02-18 20:02:29 +00:00
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Unarchive)]
|
2021-01-19 09:10:31 +00:00
|
|
|
pub struct Gid {
|
|
|
|
|
/// a 128-bit random identifier for graphical objects
|
|
|
|
|
gid: [u32; 4],
|
2020-08-29 17:17:56 +00:00
|
|
|
}
|
2021-01-19 09:10:31 +00:00
|
|
|
impl Gid {
|
|
|
|
|
pub fn new(id: [u32; 4]) -> Self { Gid{gid: id} }
|
|
|
|
|
pub fn gid(&self) -> [u32; 4] { self.gid }
|
2020-12-02 17:48:10 +00:00
|
|
|
}
|
2021-01-19 09:10:31 +00:00
|
|
|
impl hash32::Hash for Gid {
|
|
|
|
|
fn hash<H>(&self, state: &mut H)
|
|
|
|
|
where
|
|
|
|
|
H: Hasher,
|
|
|
|
|
{
|
|
|
|
|
Hash::hash(&self.gid[..], state);
|
2020-12-02 17:48:10 +00:00
|
|
|
}
|
2020-11-22 16:40:40 +00:00
|
|
|
}
|
|
|
|
|
|
2021-02-28 17:49:22 +00:00
|
|
|
#[derive(Debug, rkyv::Archive, rkyv::Unarchive)]
|
2021-02-14 20:42:30 +00:00
|
|
|
pub enum Opcode {
|
2020-08-29 17:17:56 +00:00
|
|
|
/// Flush the buffer to the screen
|
|
|
|
|
Flush,
|
|
|
|
|
|
2020-12-02 17:48:10 +00:00
|
|
|
/// Clear the buffer to "light" colored pixels
|
|
|
|
|
Clear,
|
2020-08-29 17:17:56 +00:00
|
|
|
|
|
|
|
|
/// Draw a line at the specified area
|
2020-12-02 17:48:10 +00:00
|
|
|
Line(Line),
|
2020-08-29 17:17:56 +00:00
|
|
|
|
|
|
|
|
/// Draw a rectangle or square at the specified coordinates
|
2020-12-02 17:48:10 +00:00
|
|
|
Rectangle(Rectangle),
|
2020-08-29 17:17:56 +00:00
|
|
|
|
2021-02-28 20:01:33 +00:00
|
|
|
/// Draw a rounded rectangle
|
|
|
|
|
RoundedRectangle(RoundedRectangle),
|
|
|
|
|
|
2020-08-29 17:17:56 +00:00
|
|
|
/// Draw a circle with a specified radius
|
2020-12-02 17:48:10 +00:00
|
|
|
Circle(Circle),
|
2020-10-30 02:22:03 +00:00
|
|
|
|
2020-11-23 07:42:58 +00:00
|
|
|
/// Set the current string glyph set for strings
|
2020-12-02 17:48:10 +00:00
|
|
|
SetGlyphStyle(GlyphStyle),
|
2020-11-23 07:42:58 +00:00
|
|
|
|
2020-11-27 18:05:55 +00:00
|
|
|
/// Set the cursor point for the current string clipping region
|
|
|
|
|
SetCursor(Cursor),
|
|
|
|
|
|
|
|
|
|
/// Retrieve the current cursor porint for the current string clipping region
|
|
|
|
|
GetCursor,
|
|
|
|
|
|
2020-11-26 19:33:44 +00:00
|
|
|
/// Set the clipping region for the string.
|
2020-12-02 17:48:10 +00:00
|
|
|
SetStringClipping(ClipRect),
|
2020-11-26 19:33:44 +00:00
|
|
|
|
2021-01-12 20:39:04 +00:00
|
|
|
/// Overwrite the string inside the clipping region.
|
2021-02-14 20:42:30 +00:00
|
|
|
String(xous::String<4096>),
|
2020-11-23 06:55:56 +00:00
|
|
|
|
2021-01-12 20:39:04 +00:00
|
|
|
/// Xor the string inside the clipping region.
|
2021-02-14 20:42:30 +00:00
|
|
|
StringXor(xous::String<4096>),
|
2021-01-12 20:39:04 +00:00
|
|
|
|
2021-01-18 16:05:33 +00:00
|
|
|
/// Simulate the string on the clipping region (for computing text widths)
|
2021-02-14 20:42:30 +00:00
|
|
|
SimulateString(xous::String<4096>),
|
2021-01-18 16:05:33 +00:00
|
|
|
|
2020-11-23 06:55:56 +00:00
|
|
|
/// Retrieve the X and Y dimensions of the screen
|
|
|
|
|
ScreenSize,
|
2020-11-23 07:42:58 +00:00
|
|
|
|
2020-12-02 17:48:10 +00:00
|
|
|
/// Retrieve the current Glyph style
|
|
|
|
|
QueryGlyphStyle,
|
2021-01-17 20:12:40 +00:00
|
|
|
|
|
|
|
|
/// gets info about the current glyph to assist with layout
|
|
|
|
|
QueryGlyphProps(GlyphStyle),
|
2021-01-18 20:54:54 +00:00
|
|
|
|
2021-03-05 17:10:18 +00:00
|
|
|
/// draws a textview
|
2021-02-28 17:49:22 +00:00
|
|
|
DrawTextView(TextView),
|
2021-03-05 17:10:18 +00:00
|
|
|
|
|
|
|
|
/// draws an object that requires clipping
|
|
|
|
|
DrawClipObject(ClipObject),
|
2021-03-10 17:45:54 +00:00
|
|
|
|
|
|
|
|
/// draws the sleep screen; assumes requests are vetted by GAM/xous-names
|
|
|
|
|
DrawSleepScreen
|
2020-08-29 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
2021-02-14 20:42:30 +00:00
|
|
|
impl core::convert::TryFrom<& Message> for Opcode {
|
2020-08-29 17:17:56 +00:00
|
|
|
type Error = &'static str;
|
2021-02-14 20:42:30 +00:00
|
|
|
fn try_from(message: & Message) -> Result<Self, Self::Error> {
|
2020-08-29 17:17:56 +00:00
|
|
|
match message {
|
|
|
|
|
Message::Scalar(m) => match m.id {
|
|
|
|
|
1 => Ok(Opcode::Flush),
|
2020-12-02 17:48:10 +00:00
|
|
|
2 => Ok(Opcode::Clear),
|
|
|
|
|
3 => Ok(Opcode::Line(Line::new_with_style(
|
2021-01-03 10:31:51 +00:00
|
|
|
Point::from(m.arg1),
|
|
|
|
|
Point::from(m.arg2),
|
|
|
|
|
DrawStyle::from(m.arg3),
|
|
|
|
|
))),
|
2020-12-02 17:48:10 +00:00
|
|
|
4 => Ok(Opcode::Rectangle(Rectangle::new_with_style(
|
2021-01-03 10:31:51 +00:00
|
|
|
Point::from(m.arg1),
|
|
|
|
|
Point::from(m.arg2),
|
|
|
|
|
DrawStyle::from(m.arg3),
|
|
|
|
|
))),
|
2020-12-02 17:48:10 +00:00
|
|
|
5 => Ok(Opcode::Circle(Circle::new_with_style(
|
2021-01-03 10:31:51 +00:00
|
|
|
Point::from(m.arg1),
|
|
|
|
|
m.arg2 as _,
|
|
|
|
|
DrawStyle::from(m.arg3),
|
|
|
|
|
))),
|
2020-12-02 17:48:10 +00:00
|
|
|
9 => Ok(Opcode::SetGlyphStyle(GlyphStyle::from(m.arg1))),
|
2021-01-03 10:31:51 +00:00
|
|
|
11 => Ok(Opcode::SetStringClipping(ClipRect::new(
|
|
|
|
|
m.arg1 as _,
|
|
|
|
|
m.arg2 as _,
|
|
|
|
|
m.arg3 as _,
|
|
|
|
|
m.arg4 as _,
|
|
|
|
|
))),
|
|
|
|
|
12 => Ok(Opcode::SetCursor(Cursor::new(
|
|
|
|
|
m.arg1 as _,
|
|
|
|
|
m.arg2 as _,
|
|
|
|
|
m.arg3 as _,
|
|
|
|
|
))),
|
2021-02-28 20:01:33 +00:00
|
|
|
15 => Ok(Opcode::RoundedRectangle(RoundedRectangle::new(Rectangle::new_with_style(
|
|
|
|
|
Point::from(m.arg1),
|
|
|
|
|
Point::from(m.arg2),
|
|
|
|
|
DrawStyle::from(m.arg3)),
|
|
|
|
|
m.arg4 as _
|
|
|
|
|
))),
|
2021-03-10 17:45:54 +00:00
|
|
|
16 => Ok(Opcode::DrawSleepScreen),
|
2020-10-30 02:22:03 +00:00
|
|
|
_ => Err("unrecognized opcode"),
|
|
|
|
|
},
|
2020-11-23 06:55:56 +00:00
|
|
|
Message::BlockingScalar(m) => match m.id {
|
|
|
|
|
8 => Ok(Opcode::ScreenSize),
|
2020-12-02 17:48:10 +00:00
|
|
|
10 => Ok(Opcode::QueryGlyphStyle),
|
2020-11-27 18:05:55 +00:00
|
|
|
13 => Ok(Opcode::GetCursor),
|
2021-01-19 10:58:57 +00:00
|
|
|
14 => Ok(Opcode::QueryGlyphProps(GlyphStyle::from(m.arg1))),
|
2020-11-23 06:55:56 +00:00
|
|
|
_ => Err("unrecognized opcode"),
|
|
|
|
|
},
|
2021-02-14 20:42:30 +00:00
|
|
|
/*Message::MutableBorrow(m) => match m.id {
|
2021-01-18 20:54:54 +00:00
|
|
|
0x100 => {
|
|
|
|
|
let tv: &mut TextView = unsafe {
|
|
|
|
|
&mut *(m.buf.as_mut_ptr() as *mut TextView)
|
|
|
|
|
};
|
|
|
|
|
Ok(Opcode::TextView(tv))
|
|
|
|
|
},
|
|
|
|
|
_ => Err("unrecognized opcode"),
|
2021-02-14 20:42:30 +00:00
|
|
|
}*/
|
2020-08-29 17:17:56 +00:00
|
|
|
_ => Err("unhandled message type"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-14 20:42:30 +00:00
|
|
|
impl Into<Message> for Opcode {
|
2020-08-29 17:17:56 +00:00
|
|
|
fn into(self) -> Message {
|
|
|
|
|
match self {
|
|
|
|
|
Opcode::Flush => Message::Scalar(ScalarMessage {
|
|
|
|
|
id: 1,
|
2021-01-03 10:31:51 +00:00
|
|
|
arg1: 0,
|
|
|
|
|
arg2: 0,
|
|
|
|
|
arg3: 0,
|
|
|
|
|
arg4: 0,
|
2020-08-29 17:17:56 +00:00
|
|
|
}),
|
2020-12-02 17:48:10 +00:00
|
|
|
Opcode::Clear => Message::Scalar(ScalarMessage {
|
2020-08-29 17:17:56 +00:00
|
|
|
id: 2,
|
2021-01-03 10:31:51 +00:00
|
|
|
arg1: 0,
|
|
|
|
|
arg2: 0,
|
|
|
|
|
arg3: 0,
|
|
|
|
|
arg4: 0,
|
2020-08-29 17:17:56 +00:00
|
|
|
}),
|
2020-12-02 17:48:10 +00:00
|
|
|
Opcode::Line(line) => Message::Scalar(ScalarMessage {
|
2020-08-29 17:17:56 +00:00
|
|
|
id: 3,
|
2020-12-02 17:48:10 +00:00
|
|
|
arg1: line.start.into(),
|
|
|
|
|
arg2: line.end.into(),
|
|
|
|
|
arg3: line.style.into(),
|
2020-08-29 17:17:56 +00:00
|
|
|
arg4: 0,
|
|
|
|
|
}),
|
2020-12-02 17:48:10 +00:00
|
|
|
Opcode::Rectangle(r) => Message::Scalar(ScalarMessage {
|
2020-08-29 17:17:56 +00:00
|
|
|
id: 4,
|
2020-12-02 17:48:10 +00:00
|
|
|
arg1: r.tl.into(),
|
|
|
|
|
arg2: r.br.into(),
|
|
|
|
|
arg3: r.style.into(),
|
2020-08-29 17:17:56 +00:00
|
|
|
arg4: 0,
|
|
|
|
|
}),
|
2020-12-02 17:48:10 +00:00
|
|
|
Opcode::Circle(c) => Message::Scalar(ScalarMessage {
|
2020-08-29 17:17:56 +00:00
|
|
|
id: 5,
|
2020-12-02 17:48:10 +00:00
|
|
|
arg1: c.center.into(),
|
|
|
|
|
arg2: c.radius as usize,
|
|
|
|
|
arg3: c.style.into(),
|
2020-08-29 17:17:56 +00:00
|
|
|
arg4: 0,
|
|
|
|
|
}),
|
2021-01-03 10:31:51 +00:00
|
|
|
Opcode::ScreenSize => Message::BlockingScalar(ScalarMessage {
|
|
|
|
|
id: 8,
|
|
|
|
|
arg1: 0,
|
|
|
|
|
arg2: 0,
|
|
|
|
|
arg3: 0,
|
|
|
|
|
arg4: 0,
|
|
|
|
|
}),
|
|
|
|
|
Opcode::QueryGlyphStyle => Message::BlockingScalar(ScalarMessage {
|
|
|
|
|
id: 10,
|
|
|
|
|
arg1: 0,
|
|
|
|
|
arg2: 0,
|
|
|
|
|
arg3: 0,
|
|
|
|
|
arg4: 0,
|
|
|
|
|
}),
|
|
|
|
|
Opcode::SetGlyphStyle(glyph) => Message::Scalar(ScalarMessage {
|
|
|
|
|
id: 9,
|
|
|
|
|
arg1: glyph as usize,
|
|
|
|
|
arg2: 0,
|
|
|
|
|
arg3: 0,
|
|
|
|
|
arg4: 0,
|
|
|
|
|
}),
|
2020-11-26 19:33:44 +00:00
|
|
|
Opcode::SetStringClipping(r) => Message::Scalar(ScalarMessage {
|
|
|
|
|
id: 11,
|
2021-01-03 10:31:51 +00:00
|
|
|
arg1: r.min.x as _,
|
|
|
|
|
arg2: r.min.y as _,
|
|
|
|
|
arg3: r.max.x as _,
|
|
|
|
|
arg4: r.max.y as _,
|
2020-11-26 19:33:44 +00:00
|
|
|
}),
|
2021-01-03 10:31:51 +00:00
|
|
|
Opcode::SetCursor(c) => Message::Scalar(ScalarMessage {
|
|
|
|
|
id: 12,
|
2021-01-21 16:27:45 +00:00
|
|
|
arg1: c.pt.x as usize,
|
|
|
|
|
arg2: c.pt.y as usize,
|
|
|
|
|
arg3: c.line_height as usize,
|
2021-01-03 10:31:51 +00:00
|
|
|
arg4: 0,
|
|
|
|
|
}),
|
|
|
|
|
Opcode::GetCursor => Message::BlockingScalar(ScalarMessage {
|
|
|
|
|
id: 13,
|
|
|
|
|
arg1: 0,
|
|
|
|
|
arg2: 0,
|
|
|
|
|
arg3: 0,
|
|
|
|
|
arg4: 0,
|
|
|
|
|
}),
|
2021-01-19 10:58:57 +00:00
|
|
|
Opcode::QueryGlyphProps(glyph) => Message::BlockingScalar(ScalarMessage {
|
2021-01-17 20:12:40 +00:00
|
|
|
id: 14,
|
|
|
|
|
arg1: glyph as usize,
|
|
|
|
|
arg2: 0,
|
|
|
|
|
arg3: 0,
|
|
|
|
|
arg4: 0,
|
|
|
|
|
}),
|
2021-02-28 20:01:33 +00:00
|
|
|
Opcode::RoundedRectangle(rr) => Message::Scalar(ScalarMessage {
|
|
|
|
|
id: 15,
|
|
|
|
|
arg1: rr.border.tl.into(),
|
|
|
|
|
arg2: rr.border.br.into(),
|
|
|
|
|
arg3: rr.border.style.into(),
|
|
|
|
|
arg4: rr.radius as _,
|
|
|
|
|
}),
|
2021-03-10 17:45:54 +00:00
|
|
|
Opcode::DrawSleepScreen => Message::Scalar(ScalarMessage {
|
|
|
|
|
id: 16, arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
|
|
|
|
}),
|
2021-01-18 20:54:54 +00:00
|
|
|
_ => panic!("GFX api: Opcode type not handled by Into(), maybe you meant to use a helper method?"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-05 17:10:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, rkyv::Archive, rkyv::Unarchive, Copy, Clone)]
|
|
|
|
|
pub enum ClipObjectType {
|
|
|
|
|
Line(Line),
|
|
|
|
|
Circ(Circle),
|
|
|
|
|
Rect(Rectangle),
|
|
|
|
|
RoundRect(RoundedRectangle),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, rkyv::Archive, rkyv::Unarchive, Copy, Clone)]
|
|
|
|
|
pub struct ClipObject {
|
|
|
|
|
pub clip: Rectangle,
|
|
|
|
|
pub obj: ClipObjectType,
|
|
|
|
|
}
|