pub struct ClipMask { /* private fields */ }
Expand description
A clipping mask.
Unlike Skia, we’re using just a simple 8bit alpha mask. It’s way slower, but times easier to implement.
Implementations§
source§impl ClipMask
impl ClipMask
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new, empty mask.
Examples found in repository?
examples/clip_path.rs (line 15)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
fn main() {
let clip_path = {
let mut pb = PathBuilder::new();
pb.push_circle(250.0, 250.0, 200.0);
pb.push_circle(250.0, 250.0, 100.0);
pb.finish().unwrap()
};
let clip_path = clip_path
.transform(Transform::from_row(1.0, -0.3, 0.0, 1.0, 0.0, 75.0))
.unwrap();
let mut clip_mask = ClipMask::new();
clip_mask.set_path(500, 500, &clip_path, FillRule::EvenOdd, true);
let mut paint = Paint::default();
paint.set_color_rgba8(50, 127, 150, 200);
let mut pixmap = Pixmap::new(500, 500).unwrap();
pixmap.fill_rect(
Rect::from_xywh(0.0, 0.0, 500.0, 500.0).unwrap(),
&paint,
Transform::identity(),
Some(&clip_mask),
);
pixmap.save_png("image.png").unwrap();
}
sourcepub fn set_path(
&mut self,
width: u32,
height: u32,
path: &Path,
fill_rule: FillRule,
anti_alias: bool
) -> Option<()>
pub fn set_path(
&mut self,
width: u32,
height: u32,
path: &Path,
fill_rule: FillRule,
anti_alias: bool
) -> Option<()>
Sets the current clipping path.
Not additive. Overwrites the previous data.
Path must be transformed beforehand.
Examples found in repository?
examples/clip_path.rs (line 16)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
fn main() {
let clip_path = {
let mut pb = PathBuilder::new();
pb.push_circle(250.0, 250.0, 200.0);
pb.push_circle(250.0, 250.0, 100.0);
pb.finish().unwrap()
};
let clip_path = clip_path
.transform(Transform::from_row(1.0, -0.3, 0.0, 1.0, 0.0, 75.0))
.unwrap();
let mut clip_mask = ClipMask::new();
clip_mask.set_path(500, 500, &clip_path, FillRule::EvenOdd, true);
let mut paint = Paint::default();
paint.set_color_rgba8(50, 127, 150, 200);
let mut pixmap = Pixmap::new(500, 500).unwrap();
pixmap.fill_rect(
Rect::from_xywh(0.0, 0.0, 500.0, 500.0).unwrap(),
&paint,
Transform::identity(),
Some(&clip_mask),
);
pixmap.save_png("image.png").unwrap();
}