pub enum DrawItem {
Stroke {
start: (f32, f32),
end: (f32, f32),
color: Rgb888,
pixel_width: f32,
},
Ellipse {
center: (f32, f32),
axis_a: (f32, f32),
axis_b: (f32, f32),
color: Rgb888,
},
Circle {
center: (f32, f32),
pixel_radius: f32,
color: Rgb888,
},
Bitmap {
view: Image565View,
top_left: Point,
},
}Expand description
A 2D drawing command that can be rendered onto a PixelTarget.
DrawItem is a compact, Copy representation for a heterogeneous scene.
Its floating-point geometry is convenient for calculated or projected
coordinates, but projection is not required. The same items can be passed to
CydDisplay::draw_items, which
composites and streams them without a pixel frame buffer, or rendered
directly with DrawItem::draw when a frame is available.
For ordinary imperative drawing into a
CydFrame, embedded-graphics primitives are
also appropriate, particularly when their integer-coordinate geometry and
styling API fit the scene. DrawItem::draw uses embedded-graphics internally
for strokes and circles as an implementation detail; DrawItem does not
replace the broader embedded-graphics API.
Coordinates and sizes are measured in display pixels. Colors are specified
as Rgb888, and the target converts them to its native pixel format when
needed.
§Example
This example loads a TGA bitmap at compile time and draws one of each item variant onto a full-screen frame.
use device_envoy_core::cyd::{
Cyd, CydDisplay,
display::{CydFrame, DrawItem, Image565Fixed, tga},
};
use embedded_graphics::{
pixelcolor::Rgb888,
prelude::{Point, RgbColor},
};
const BITMAP: Image565Fixed<45, 73, { 45 * 73 }> = tga!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/docs/assets/cyd_fill_contiguous.tga"
))
.to_565();
async fn draw<C: Cyd>(cyd: &mut C) -> Result<(), C::Error> {
let display = cyd.display();
let mut frame = display.full_frame_mut();
let draw_items = [
DrawItem::Bitmap {
view: BITMAP.view(),
top_left: Point::new(35, 84),
},
DrawItem::Circle {
center: (125.0, 120.0),
pixel_radius: 32.0,
color: Rgb888::CYAN,
},
DrawItem::Ellipse {
center: (215.0, 120.0),
axis_a: (38.0, 0.0),
axis_b: (12.0, 24.0),
color: Rgb888::GREEN,
},
DrawItem::Stroke {
start: (280.0, 80.0),
end: (300.0, 160.0),
color: Rgb888::YELLOW,
pixel_width: 8.0,
},
];
for draw_item in draw_items {
draw_item.draw(&mut frame);
}
frame.flush().await
}
Variants§
Stroke
A line stroke from start to end with the given pixel width.
Fields
Ellipse
A filled ellipse. It can also represent a projected disk.
The ellipse is the locus of center + s·axis_a + t·axis_b with s²+t² ≤ 1.
Fields
Circle
A filled circle. It can also represent a projected sphere.
Fields
Bitmap
A statically stored RGB565 bitmap placed at a display position.
Fields
view: Image565ViewBitmap pixels and dimensions.
Implementations§
Source§impl DrawItem
impl DrawItem
Sourcepub fn draw<T: PixelTarget>(&self, target: &mut T)
pub fn draw<T: PixelTarget>(&self, target: &mut T)
Draw this item onto a PixelTarget.
Strokes use the embedded-graphics
Line
primitive and circles use
Circle;
the general ellipse is rasterized with
fill_ellipse_pixels.
See the DrawItem example.