add rectangle and circle shapes
This commit is contained in:
parent
50094c3872
commit
7933057062
4 changed files with 129 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
|||
use alloc::vec::Vec;
|
||||
use tiny_skia::{
|
||||
BlendMode, Color, LineCap, Paint, PathBuilder, Pixmap, Shader, Stroke as SStroke, Transform,
|
||||
BlendMode, Color, LineCap, Paint, PathBuilder, Pixmap, Rect, Shader, Stroke as SStroke,
|
||||
Transform,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
|
@ -132,6 +133,46 @@ impl<'a> Renderer<'a> {
|
|||
None,
|
||||
);
|
||||
}
|
||||
|
||||
Shape::Rect(position, size) => {
|
||||
let mut pb = PathBuilder::new();
|
||||
if let Some(rect) =
|
||||
tiny_skia::Rect::from_xywh(position.x, position.y, size.x, size.y)
|
||||
{
|
||||
pb.push_rect(rect);
|
||||
}
|
||||
let path = pb.finish().unwrap();
|
||||
|
||||
self.pixmap_mut().stroke_path(
|
||||
&path,
|
||||
&paint,
|
||||
&SStroke {
|
||||
width: stroke.thickness,
|
||||
line_cap: LineCap::Square,
|
||||
..Default::default()
|
||||
},
|
||||
transform,
|
||||
None,
|
||||
);
|
||||
}
|
||||
|
||||
Shape::Circle(position, radius) => {
|
||||
let mut pb = PathBuilder::new();
|
||||
pb.push_circle(position.x, position.y, radius);
|
||||
let path = pb.finish().unwrap();
|
||||
|
||||
self.pixmap_mut().stroke_path(
|
||||
&path,
|
||||
&paint,
|
||||
&SStroke {
|
||||
width: stroke.thickness,
|
||||
line_cap: LineCap::Square,
|
||||
..Default::default()
|
||||
},
|
||||
transform,
|
||||
None,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue