Struct tiny_skia::ClipMask

source ·
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

source

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();
}
source

pub fn is_empty(&self) -> bool

Checks that mask is empty.

source

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();
}
source

pub fn intersect_path(
&mut self,
path: &Path,
fill_rule: FillRule,
anti_alias: bool
) -> Option<()>

Intersects the provided path with the current clipping path.

Path must be transformed beforehand.

source

pub fn clear(&mut self)

Clears the mask.

Internal memory buffer is not deallocated.

Trait Implementations§

source§

impl Clone for ClipMask

source§

fn clone(&self) -> ClipMask

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ClipMask

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for ClipMask

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere
T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere
T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere
U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.