xous-core/services/graphics-server/src/api.rs

104 lines
2.4 KiB
Rust
Raw Normal View History

2021-01-04 20:45:23 +00:00
#![allow(dead_code)]
/*
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
*/
//////////////// 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::*;
use hash32::{Hash, Hasher};
2021-04-02 16:53:30 +00:00
//////////////// IPC APIs
#[derive(Debug, Copy, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
pub struct Gid {
/// a 128-bit random identifier for graphical objects
gid: [u32; 4],
}
impl Gid {
pub fn new(id: [u32; 4]) -> Self { Gid{gid: id} }
pub fn gid(&self) -> [u32; 4] { self.gid }
}
impl hash32::Hash for Gid {
fn hash<H>(&self, state: &mut H)
where
H: Hasher,
{
Hash::hash(&self.gid[..], state);
}
2020-11-22 16:40:40 +00:00
}
2021-04-02 16:53:30 +00:00
pub const SERVER_NAME_GFX: &str = "_Graphics_";
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
2021-04-02 16:57:30 +00:00
pub(crate) enum Opcode {
/// Flush the buffer to the screen
Flush,
/// Clear the buffer to "light" colored pixels
Clear,
/// Draw a line at the specified area
2021-04-02 16:53:30 +00:00
Line, //(Line),
/// Draw a rectangle or square at the specified coordinates
2021-04-02 16:53:30 +00:00
Rectangle, //(Rectangle),
/// Draw a rounded rectangle
2021-04-02 16:53:30 +00:00
RoundedRectangle, //(RoundedRectangle),
/// Draw a circle with a specified radius
2021-04-02 16:53:30 +00:00
Circle, //(Circle),
2021-01-18 16:05:33 +00:00
/// Retrieve the X and Y dimensions of the screen
ScreenSize,
/// gets info about the current glyph to assist with layout
2021-04-02 16:53:30 +00:00
QueryGlyphProps, //(GlyphStyle),
2021-01-18 20:54:54 +00:00
/// draws a textview
2021-04-02 16:53:30 +00:00
DrawTextView, //(TextView),
/// draws an object that requires clipping
2021-04-02 16:53:30 +00:00
DrawClipObject, //(ClipObject),
/// draws the sleep screen; assumes requests are vetted by GAM/xous-names
DrawSleepScreen,
/// sets whether a sleep note should be rendered or not on suspend
SetSleepNote,
/// SuspendResume callback
SuspendResume,
}
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)]
pub enum ClipObjectType {
Line(Line),
Circ(Circle),
Rect(Rectangle),
RoundRect(RoundedRectangle),
}
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)]
pub struct ClipObject {
pub clip: Rectangle,
pub obj: ClipObjectType,
}