Merge pull request #606 from rowr111/graphics-server-docs
graphics server docs
BIN
docs/images/graphics-server/boot_logo.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
docs/images/graphics-server/circle.png
Normal file
|
After Width: | Height: | Size: 8 KiB |
BIN
docs/images/graphics-server/circle_clipped.png
Normal file
|
After Width: | Height: | Size: 6.6 KiB |
BIN
docs/images/graphics-server/line.png
Normal file
|
After Width: | Height: | Size: 6.7 KiB |
BIN
docs/images/graphics-server/line_clipped.png
Normal file
|
After Width: | Height: | Size: 6.3 KiB |
BIN
docs/images/graphics-server/line_clipped_xor.png
Normal file
|
After Width: | Height: | Size: 6.6 KiB |
BIN
docs/images/graphics-server/object_list_clipped.png
Normal file
|
After Width: | Height: | Size: 7.2 KiB |
BIN
docs/images/graphics-server/rectangle.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
docs/images/graphics-server/rectangle_clipped.png
Normal file
|
After Width: | Height: | Size: 7.3 KiB |
BIN
docs/images/graphics-server/rounded_rectangle.png
Normal file
|
After Width: | Height: | Size: 6 KiB |
BIN
docs/images/graphics-server/rounded_rectangle_clipped.png
Normal file
|
After Width: | Height: | Size: 5.9 KiB |
BIN
docs/images/graphics-server/selftest.png
Normal file
|
After Width: | Height: | Size: 9.1 KiB |
BIN
docs/images/graphics-server/sleepscreen.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
docs/images/graphics-server/textview.png
Normal file
|
After Width: | Height: | Size: 7 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
|
|
@ -31,6 +31,23 @@ impl Gfx {
|
|||
|
||||
pub fn conn(&self) -> xous::CID { self.conn }
|
||||
|
||||
/// Draws a line.
|
||||
///
|
||||
/// <details>
|
||||
/// <summary>Example Image</summary>
|
||||
///
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::{Gfx, Line, Point};
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// let line = Line::new(Point::new(100, 100), Point::new(200, 200)); // if you want to specify a style, use Line::new_with_style
|
||||
/// gfx.draw_line(line).unwrap();
|
||||
/// gfx.flush().unwrap();
|
||||
/// ```
|
||||
pub fn draw_line(&self, line: Line) -> Result<(), xous::Error> {
|
||||
send_message(
|
||||
self.conn,
|
||||
|
|
@ -45,6 +62,23 @@ impl Gfx {
|
|||
.map(|_| ())
|
||||
}
|
||||
|
||||
/// Draws a circle.
|
||||
///
|
||||
/// <details>
|
||||
/// <summary>Example Image</summary>
|
||||
///
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::{Circle, Gfx, Point};
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// let circle = Circle::new(Point::new(150, 150), 25); // if you want to specify a style, use Circle::new_with_style
|
||||
/// gfx.draw_circle(circle).unwrap();
|
||||
/// gfx.flush().unwrap();
|
||||
/// ```
|
||||
pub fn draw_circle(&self, circ: Circle) -> Result<(), xous::Error> {
|
||||
send_message(
|
||||
self.conn,
|
||||
|
|
@ -59,6 +93,23 @@ impl Gfx {
|
|||
.map(|_| ())
|
||||
}
|
||||
|
||||
/// Draws a rectangle.
|
||||
///
|
||||
/// <details>
|
||||
/// <summary>Example Image</summary>
|
||||
///
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::{Gfx, Point, Rectangle};
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// let rect = Rectangle::new(Point::new(100, 100), Point::new(250, 150)); // if you want to specify a style, use Rectangle::new_with_style
|
||||
/// gfx.draw_rectangle(rect).unwrap();
|
||||
/// gfx.flush().unwrap();
|
||||
/// ```
|
||||
pub fn draw_rectangle(&self, rect: Rectangle) -> Result<(), xous::Error> {
|
||||
send_message(
|
||||
self.conn,
|
||||
|
|
@ -73,6 +124,23 @@ impl Gfx {
|
|||
.map(|_| ())
|
||||
}
|
||||
|
||||
/// Draws a rounded rectangle.
|
||||
///
|
||||
/// <details>
|
||||
/// <summary>Example Image</summary>
|
||||
///
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::{Gfx, Point, Rectangle, RoundedRectangle};
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// let rr = RoundedRectangle::new(Rectangle::new(Point::new(100, 100), Point::new(150, 200)), 5);
|
||||
/// gfx.draw_rounded_rectangle(rr).unwrap();
|
||||
/// gfx.flush().unwrap();
|
||||
/// ```
|
||||
pub fn draw_rounded_rectangle(&self, rr: RoundedRectangle) -> Result<(), xous::Error> {
|
||||
send_message(
|
||||
self.conn,
|
||||
|
|
@ -87,21 +155,82 @@ impl Gfx {
|
|||
.map(|_| ())
|
||||
}
|
||||
|
||||
/// Flushes the graphics server, ensuring all previous drawing commands are executed.
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::{Circle, Gfx, Line, Point};
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// let line = Line::new(Point::new(0, 0), Point::new(100, 100));
|
||||
/// let circle = Circle::new(Point::new(150, 150), 25);
|
||||
/// gfx.draw_line(line).unwrap();
|
||||
/// gfx.draw_circle(circle).unwrap();
|
||||
/// gfx.flush().unwrap(); // Both the line and the circle will be drawn
|
||||
/// ```
|
||||
pub fn flush(&self) -> Result<(), xous::Error> {
|
||||
send_message(self.conn, Message::new_scalar(Opcode::Flush.to_usize().unwrap(), 0, 0, 0, 0))
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
/// Draws the sleep screen.
|
||||
///
|
||||
/// This function sends a message to the graphics server to draw the sleep screen.
|
||||
///
|
||||
/// <details>
|
||||
/// <summary>Example Image</summary>
|
||||
///
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::Gfx;
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// gfx.draw_sleepscreen().unwrap();
|
||||
/// gfx.flush().unwrap();
|
||||
/// ```
|
||||
pub fn draw_sleepscreen(&self) -> Result<(), xous::Error> {
|
||||
send_message(self.conn, Message::new_scalar(Opcode::DrawSleepScreen.to_usize().unwrap(), 0, 0, 0, 0))
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
/// Draws the boot logo.
|
||||
///
|
||||
/// This function sends a message to the graphics server to draw the boot logo.
|
||||
/// The boot logo is typically displayed during the device's startup sequence.
|
||||
///
|
||||
/// <details>
|
||||
/// <summary>Example Image</summary>
|
||||
///
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::Gfx;
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// gfx.draw_boot_logo().unwrap();
|
||||
/// gfx.flush().unwrap();
|
||||
/// ```
|
||||
pub fn draw_boot_logo(&self) -> Result<(), xous::Error> {
|
||||
send_message(self.conn, Message::new_scalar(Opcode::DrawBootLogo.to_usize().unwrap(), 0, 0, 0, 0))
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
/// Retrieves the screen size from the graphics server.
|
||||
///
|
||||
/// This function sends a message to the graphics server to query the screen size.
|
||||
/// The screen size is returned as a `Point` representing the width and height.
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::Gfx;
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// let screen_dimensions = gfx.screen_size().expect("Couldn't get screen size");
|
||||
/// println!("Screen size: {}x{}", screen_dimensions.x, screen_dimensions.y);
|
||||
/// ```
|
||||
pub fn screen_size(&self) -> Result<Point, xous::Error> {
|
||||
let response = send_message(
|
||||
self.conn,
|
||||
|
|
@ -115,6 +244,18 @@ impl Gfx {
|
|||
}
|
||||
}
|
||||
|
||||
/// Retrieves the height hint for a specific glyph from the graphics server.
|
||||
///
|
||||
/// This function sends a message to the graphics server to query the height hint of a glyph.
|
||||
/// The height hint is returned as a `usize`.
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::{Gfx, GlyphStyle};
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// let height_hint = gfx.glyph_height_hint(GlyphStyle::Regular).unwrap();
|
||||
/// println!("Glyph height hint: {}", height_hint);
|
||||
/// ```
|
||||
pub fn glyph_height_hint(&self, glyph: GlyphStyle) -> Result<usize, xous::Error> {
|
||||
let response = send_message(
|
||||
self.conn,
|
||||
|
|
@ -134,8 +275,31 @@ impl Gfx {
|
|||
}
|
||||
}
|
||||
|
||||
/// This function will truncate a TextView string if it is too long to transmit in
|
||||
/// a single page of memory.
|
||||
/// Draws a `TextView`.
|
||||
///
|
||||
/// This function sends a message to the graphics server to draw the specified `TextView`.
|
||||
/// If the text in the `TextView` is too long to transmit in a single page of memory, it will be
|
||||
/// truncated.
|
||||
/// Text that overflows the bounds of the `TextView` will be clipped.
|
||||
///
|
||||
/// <details>
|
||||
/// <summary>Example Image</summary>
|
||||
///
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::{Gfx, TextView};
|
||||
/// let clipping_area = Rectangle::new_coords(50, 50, 290, 450);
|
||||
/// let text_bounds = Rectangle::new_coords(10, 10, 240, 400);
|
||||
/// let mut tv = TextView::new(Gid::new([0, 0, 0, 0]), TextBounds::BoundingBox(text_bounds));
|
||||
/// tv.clip_rect = Some(clipping_area);
|
||||
/// write!(tv, "Hello, world!").unwrap();
|
||||
/// gfx.draw_textview(&mut tv).unwrap();
|
||||
/// gfx.flush().unwrap();
|
||||
/// ````
|
||||
pub fn draw_textview(&self, tv: &mut TextView) -> Result<(), xous::Error> {
|
||||
if tv.text.len() > TEXTVIEW_LEN {
|
||||
tv.text.truncate(TEXTVIEW_LEN);
|
||||
|
|
@ -152,31 +316,137 @@ impl Gfx {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Draws a line with clipping.
|
||||
///
|
||||
/// This function sends a message to the graphics server to draw the specified `Line` within the specified
|
||||
/// `Rectangle` clip area.
|
||||
///
|
||||
/// <details>
|
||||
/// <summary>Example Image - clipped line with clipping area represented by light rectangle.</summary>
|
||||
///
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::{Gfx, Line, Point, Rectangle};
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// let line = Line::new(Point::new(100, 100), Point::new(200, 200));
|
||||
/// let clip = Rectangle::new(Point::new(110, 110), Point::new(190, 190));
|
||||
/// gfx.draw_line_clipped(line, clip).unwrap();
|
||||
/// gfx.flush().unwrap();
|
||||
/// ```
|
||||
pub fn draw_line_clipped(&self, line: Line, clip: Rectangle) -> Result<(), xous::Error> {
|
||||
let co = ClipObject { clip, obj: ClipObjectType::Line(line) };
|
||||
let buf = Buffer::into_buf(co).or(Err(xous::Error::InternalError))?;
|
||||
buf.lend(self.conn, Opcode::DrawClipObject.to_u32().unwrap()).map(|_| ())
|
||||
}
|
||||
|
||||
// for use in the deface operation
|
||||
/// Draws a line with XOR clipping.
|
||||
/// For use in the deface operation.
|
||||
///
|
||||
/// This function sends a message to the graphics server to draw the specified `Line` within the specified
|
||||
/// `Rectangle` clip area using XOR mode.
|
||||
///
|
||||
/// <details>
|
||||
/// <summary>Example Image - line clipped by area represented by dark rectangle. Light inner
|
||||
/// rectangle added to show XOR behavior.</summary>
|
||||
///
|
||||
///  ///
|
||||
/// </details>
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::{Gfx, Line, Point, Rectangle};
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// let line = Line::new(Point::new(0, 0), Point::new(100, 100));
|
||||
/// let clip = Rectangle::new(Point::new(10, 10), Point::new(90, 90));
|
||||
/// gfx.draw_line_clipped_xor(line, clip).unwrap();
|
||||
/// gfx.flush().unwrap();
|
||||
/// ```
|
||||
pub fn draw_line_clipped_xor(&self, line: Line, clip: Rectangle) -> Result<(), xous::Error> {
|
||||
let co = ClipObject { clip, obj: ClipObjectType::XorLine(line) };
|
||||
let buf = Buffer::into_buf(co).or(Err(xous::Error::InternalError))?;
|
||||
buf.lend(self.conn, Opcode::DrawClipObject.to_u32().unwrap()).map(|_| ())
|
||||
}
|
||||
|
||||
/// Draws a circle with clipping.
|
||||
///
|
||||
/// This function sends a message to the graphics server to draw the specified `Circle` within the
|
||||
/// specified `Rectangle` clip area.
|
||||
///
|
||||
/// <details>
|
||||
/// <summary>Example Image - circle clipped by area represented by light rectangle.</summary>
|
||||
///
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::{Circle, Gfx, Point, Rectangle};
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// let circ = Circle::new(Point::new(130, 130), 25);
|
||||
/// let clip = Rectangle::new(Point::new(110, 110), Point::new(190, 190));
|
||||
/// gfx.draw_circle_clipped(circ, clip).unwrap();
|
||||
/// gfx.flush().unwrap();
|
||||
/// ```
|
||||
pub fn draw_circle_clipped(&self, circ: Circle, clip: Rectangle) -> Result<(), xous::Error> {
|
||||
let co = ClipObject { clip, obj: ClipObjectType::Circ(circ) };
|
||||
let buf = Buffer::into_buf(co).or(Err(xous::Error::InternalError))?;
|
||||
buf.lend(self.conn, Opcode::DrawClipObject.to_u32().unwrap()).map(|_| ())
|
||||
}
|
||||
|
||||
/// Draws a rectangle with clipping.
|
||||
///
|
||||
/// This function sends a message to the graphics server to draw the specified `Rectangle`
|
||||
/// within the specified `ClipRect` clip area.
|
||||
///
|
||||
/// <details>
|
||||
/// <summary>Example Image - rectangle clipped by area represented by light rectangle.</summary>
|
||||
///
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::{Gfx, Point, Rectangle};
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// let rect = Rectangle::new(Point::new(100, 100), Point::new(160, 160));
|
||||
/// let clip = Rectangle::new(Point::new(110, 110), Point::new(190, 190));
|
||||
/// gfx.draw_rectangle_clipped(rect, clip).unwrap();
|
||||
/// gfx.flush().unwrap();
|
||||
/// ```
|
||||
pub fn draw_rectangle_clipped(&self, rect: Rectangle, clip: Rectangle) -> Result<(), xous::Error> {
|
||||
let co = ClipObject { clip, obj: ClipObjectType::Rect(rect) };
|
||||
let buf = Buffer::into_buf(co).or(Err(xous::Error::InternalError))?;
|
||||
buf.lend(self.conn, Opcode::DrawClipObject.to_u32().unwrap()).map(|_| ())
|
||||
}
|
||||
|
||||
/// Draws a rounded rectangle with clipping.
|
||||
///
|
||||
/// This function sends a message to the graphics server to draw the specified `RoundedRectangle`
|
||||
/// within the specified `ClipRect` clip area.
|
||||
///
|
||||
/// <details>
|
||||
/// <summary>Example Image - rounded rectangle clipped by area represented by light
|
||||
/// rectangle.</summary>
|
||||
///
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::{Gfx, Point, Rectangle, RoundedRectangle};
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// let rr = RoundedRectangle::new(Rectangle::new(Point::new(100, 100), Point::new(160, 160)), 8);
|
||||
/// let clip = Rectangle::new(Point::new(0, 0), Point::new(100, 100));
|
||||
/// gfx.draw_rounded_rectangle_clipped(rr, clip).unwrap();
|
||||
/// gfx.flush().unwrap();
|
||||
/// ```
|
||||
pub fn draw_rounded_rectangle_clipped(
|
||||
&self,
|
||||
rr: RoundedRectangle,
|
||||
|
|
@ -195,25 +465,93 @@ impl Gfx {
|
|||
buf.lend(self.conn, Opcode::DrawClipObject.to_u32().unwrap()).map(|_| ())
|
||||
}
|
||||
|
||||
/// Draws a list of objects with clipping.
|
||||
///
|
||||
/// This function sends a message to the graphics server to draw the specified list of objects
|
||||
/// within the specified `ClipRect` clip area.
|
||||
///
|
||||
/// <details>
|
||||
/// <summary>Example Image - two objects, a line and a circle, each with their own clipping areas
|
||||
/// represented by light rectangles.</summary>
|
||||
///
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::{ClipObjectList, Gfx, Point, Rectangle};
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// let mut object_list = ClipObjectList::default();
|
||||
///
|
||||
/// // Create and add the first object (a line)
|
||||
/// let line = Line::new(Point::new(0, 0), Point::new(100, 100));
|
||||
/// let clip = Rectangle::new(Point::new(10, 10), Point::new(90, 90));
|
||||
/// object_list.push(ClipObjectType::Line(line), clip);
|
||||
///
|
||||
/// // Create and add the second object (a circle)
|
||||
/// let circle = Circle::new(Point::new(150, 150), 25);
|
||||
/// let clip2 = Rectangle::new(Point::new(140, 100), Point::new(190, 190));
|
||||
/// object_list.push(ClipObjectType::Circ(circle), clip2);
|
||||
///
|
||||
/// gfx.draw_object_list_clipped(object_list).unwrap();
|
||||
/// gfx.flush().unwrap();
|
||||
/// ```
|
||||
pub fn draw_object_list_clipped(&self, list: ClipObjectList) -> Result<(), xous::Error> {
|
||||
let buf = Buffer::into_buf(list).or(Err(xous::Error::InternalError))?;
|
||||
buf.lend(self.conn, Opcode::DrawClipObjectList.to_u32().unwrap()).map(|_| ())
|
||||
}
|
||||
|
||||
/// this is a one-way door, once you've set it, you can't unset it.
|
||||
/// Sets the developer boot mode.
|
||||
///
|
||||
/// This function sends a message to the graphics server to enable or disable the developer boot mode.
|
||||
/// The purpose of this call is to let users be aware of who signed their kernel. Kernels signed with the
|
||||
/// developer signature can boot, but this API call ensures that a small dashed line appears through the
|
||||
/// status bar, so there is an obvious indicator that the kernel has yet to be self-signed. Self-signed
|
||||
/// kernels do not have this signature.
|
||||
///
|
||||
/// NOTE: This call is a one-way operation. Once the developer boot mode is enabled, it cannot be
|
||||
/// disabled.
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::Gfx;
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// gfx.set_devboot(true); // Enable developer boot mode
|
||||
/// ```
|
||||
pub fn set_devboot(&self, enable: bool) -> Result<(), xous::Error> {
|
||||
let ena = if enable { 1 } else { 0 };
|
||||
send_message(self.conn, Message::new_scalar(Opcode::Devboot.to_usize().unwrap(), ena, 0, 0, 0))
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
/// instead of implementing the read in the library, we had the raw opcode to the caller
|
||||
/// this allows the caller to re-use the bulk read data structure across multiple reads
|
||||
/// instead of it being re-allocated and re-init'd every single call
|
||||
/// Reads the font map in bulk from the graphics server.
|
||||
///
|
||||
/// Instead of implementing the read in the library, we hand the raw opcode to the caller.
|
||||
/// This allows the caller to re-use the bulk read data structure across multiple reads
|
||||
/// instead of it being re-allocated and re-initialized every single call. This is used by the security
|
||||
/// system to inspect the font maps for integrity.
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::{ArchivedBulkRead, Gfx};
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// let font_map = gfx.bulk_read_fontmap_op();
|
||||
/// // Process the font map as needed
|
||||
/// ```
|
||||
pub fn bulk_read_fontmap_op(&self) -> u32 { Opcode::BulkReadFonts.to_u32().unwrap() }
|
||||
|
||||
/// the bulk read auto-increments a pointer on the gfx server, so this message is necessary
|
||||
/// Resets the bulk read pointer.
|
||||
///
|
||||
/// The bulk read operation auto-increments a pointer on the graphics server, so this message is necessary
|
||||
/// to reset the pointer to 0.
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::Gfx;
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// gfx.bulk_read_restart();
|
||||
/// ```
|
||||
pub fn bulk_read_restart(&self) {
|
||||
send_message(
|
||||
self.conn,
|
||||
|
|
@ -222,6 +560,24 @@ impl Gfx {
|
|||
.expect("couldn't reset bulk read");
|
||||
}
|
||||
|
||||
/// Runs a self-test pattern.
|
||||
///
|
||||
/// This function sends a message to the graphics server to display a test pattern for a specified
|
||||
/// duration. The test pattern is typically used to verify the functionality of the graphics hardware.
|
||||
///
|
||||
/// <details>
|
||||
/// <summary>Example Image - selftest in progress.</summary>
|
||||
///
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::Gfx;
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// gfx.selftest(1000); // Display the test pattern for 1000 milliseconds
|
||||
/// ```
|
||||
pub fn selftest(&self, duration_ms: usize) {
|
||||
send_message(
|
||||
self.conn,
|
||||
|
|
@ -230,6 +586,25 @@ impl Gfx {
|
|||
.expect("couldn't self test");
|
||||
}
|
||||
|
||||
/// Stashes the current graphics state.
|
||||
///
|
||||
/// This function sends a message to the graphics server to stash (save) the current graphics state.
|
||||
/// The stashed state can be restored later using the `pop` function. This is useful for temporarily
|
||||
/// saving the current state before making changes, and then restoring it later.
|
||||
///
|
||||
/// If `blocking` is `true`, the function will wait until the graphics server confirms that the state
|
||||
/// has been stashed, otherwise it will return immediately without waiting for confirmation.
|
||||
///
|
||||
/// NOTE: the top 34 lines will not be stashed, as this is the area where the status bar is drawn.
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::Gfx;
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// let line = Line::new(Point::new(0, 0), Point::new(100, 100));
|
||||
/// gfx.draw_line(line).unwrap(); // Draw a line before stashing
|
||||
/// gfx.stash(false); // Stash the current state in a non-blocking manner
|
||||
/// ```
|
||||
pub fn stash(&self, blocking: bool) {
|
||||
if blocking {
|
||||
send_message(
|
||||
|
|
@ -243,6 +618,47 @@ impl Gfx {
|
|||
}
|
||||
}
|
||||
|
||||
/// Restores the previously stashed graphics state on the graphics server.
|
||||
///
|
||||
/// This function sends a message to the graphics server to restore the previously stashed graphics state.
|
||||
/// The stashed state can be restored using this function after it has been saved using the `stash`
|
||||
/// function. This is useful for reverting to a previous state after making temporary changes.
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use graphics_server::{DrawStyle, Gfx, Line, PixelColor, Point, Rectangle};
|
||||
/// use ticktimer_server::Ticktimer;
|
||||
/// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||
/// let ticktimer = Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||
///
|
||||
/// // Draw a line
|
||||
/// let line = Line::new(Point::new(0, 0), Point::new(100, 100));
|
||||
/// gfx.draw_line(line).unwrap();
|
||||
/// gfx.flush().unwrap();
|
||||
///
|
||||
/// // Wait for a moment
|
||||
/// ticktimer.sleep_ms(1000).unwrap();
|
||||
///
|
||||
/// // Stash the current state
|
||||
/// gfx.stash(true); // Stash the current state in a blocking manner
|
||||
///
|
||||
/// // Clear the screen
|
||||
/// let screensize = gfx.screen_size().expect("Couldn't get screen size");
|
||||
/// let whiteout = Rectangle::new_with_style(
|
||||
/// Point::new(0, 0),
|
||||
/// screensize,
|
||||
/// DrawStyle::new(PixelColor::Light, PixelColor::Light, 1),
|
||||
/// );
|
||||
/// gfx.draw_rectangle(blackout).unwrap();
|
||||
/// gfx.flush().unwrap();
|
||||
///
|
||||
/// // Wait for a moment
|
||||
/// ticktimer.sleep_ms(1000).unwrap();
|
||||
///
|
||||
/// // Restore the previously stashed state
|
||||
/// gfx.pop(true); // Restore the previously stashed state in a blocking manner
|
||||
/// gfx.flush().unwrap();
|
||||
/// ```
|
||||
pub fn pop(&self, blocking: bool) {
|
||||
if blocking {
|
||||
send_message(
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ impl Modals {
|
|||
/// <details>
|
||||
/// <summary>Example Image</summary>
|
||||
///
|
||||
/// 
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
|
|
@ -248,7 +248,7 @@ impl Modals {
|
|||
/// <details>
|
||||
/// <summary>Example Image</summary>
|
||||
///
|
||||
/// 
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
|
|
@ -296,9 +296,9 @@ impl Modals {
|
|||
/// <details>
|
||||
/// <summary>Example Images (from example code below)</summary>
|
||||
///
|
||||
/// 
|
||||
/// 
|
||||
/// 
|
||||
/// 
|
||||
/// 
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
|
|
@ -385,7 +385,7 @@ impl Modals {
|
|||
/// <details>
|
||||
/// <summary>Example Image</summary>
|
||||
///
|
||||
/// 
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
|
|
@ -424,7 +424,7 @@ impl Modals {
|
|||
/// <details>
|
||||
/// <summary>Example Image</summary>
|
||||
///
|
||||
/// 
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
|
|
@ -616,7 +616,7 @@ impl Modals {
|
|||
/// <details>
|
||||
/// <summary>Example Image</summary>
|
||||
///
|
||||
/// 
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
|
|
@ -691,7 +691,7 @@ impl Modals {
|
|||
/// <details>
|
||||
/// <summary>Example Image</summary>
|
||||
///
|
||||
/// 
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
|
|
@ -794,7 +794,7 @@ impl Modals {
|
|||
/// <details>
|
||||
/// <summary>Example Image</summary>
|
||||
///
|
||||
/// 
|
||||
/// 
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
|
|
|
|||