Enum raqote::Source

source ·
pub enum Source<'a> {
    Solid(SolidSource),
    Image(Image<'a>, ExtendMode, FilterMode, Transform),
    RadialGradient(Gradient, Spread, Transform),
    TwoCircleRadialGradient(Gradient, Spread, Point, f32, Point, f32, Transform),
    LinearGradient(Gradient, Spread, Transform),
    SweepGradient(Gradient, Spread, f32, f32, Transform),
}
Expand description

LinearGradients have an implicit start point at 0,0 and an end point at 256,0. The transform parameter can be used to adjust them to the desired location. RadialGradients have an implicit center at 0,0 and a radius of 128. The helper functions: new_linear_gradient, new_radial_gradient and new_two_circle_radial_gradient allow the gradients to be constructed with easier to understand inputs. The transform parameter maps user space to source space. This means that setting the same transform on the draw target as the source will have the effect of canceling out.

These locations are an artifact of the blitter implementation and will probably change in the future to become more ergonomic.

Variants§

§

Solid(SolidSource)

§

Image(Image<'a>, ExtendMode, FilterMode, Transform)

§

RadialGradient(Gradient, Spread, Transform)

§

TwoCircleRadialGradient(Gradient, Spread, Point, f32, Point, f32, Transform)

§

LinearGradient(Gradient, Spread, Transform)

§

SweepGradient(Gradient, Spread, f32, f32, Transform)

Implementations§

source§

impl<'a> Source<'a>

source

pub fn new_linear_gradient( gradient: Gradient, start: Point, end: Point, spread: Spread ) -> Source<'a>

Creates a new linear gradient source where the start point corresponds to the gradient stop at position = 0 and the end point corresponds to the gradient stop at position = 1.

Examples found in repository?
examples/pad.rs (lines 13-33)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
fn main() {
    let mut dt = DrawTarget::new(200, 200);
    
    let gradient = Source::new_linear_gradient(
        Gradient {
            stops: vec![
                GradientStop {
                    position: 0.0,
                    color: Color::new(0xff, 0xff, 0xff, 0xff),
                },
                GradientStop {
                    position: 0.9999,
                    color: Color::new(0xff, 0x0, 0x0, 0x0),
                },
                GradientStop {
                    position: 1.0,
                    color: Color::new(0xff, 0x0, 0x0, 0x0),
                },
            ],
        },
        Point::new(40., 0.),
        Point::new(100., 0.),
        Spread::Pad,
    );

    let mut pb = PathBuilder::new();
    pb.rect(0., 0., 80., 80.);
    let path = pb.finish();
    dt.fill(&path, &gradient, &DrawOptions::default());

    dt.write_png("out.png").unwrap();
}
source

pub fn new_radial_gradient( gradient: Gradient, center: Point, radius: f32, spread: Spread ) -> Source<'a>

Creates a new radial gradient that is centered at the given point and has the given radius.

source

pub fn new_two_circle_radial_gradient( gradient: Gradient, center1: Point, radius1: f32, center2: Point, radius2: f32, spread: Spread ) -> Source<'a>

Creates a new radial gradient that is centered at the given point and has the given radius.

source

pub fn new_sweep_gradient( gradient: Gradient, center: Point, start_angle: f32, end_angle: f32, spread: Spread ) -> Source<'a>

Creates a new sweep gradient that is centered at the given point with start_angle and end_angle.

Examples found in repository?
examples/sweep-gradient.rs (lines 10-31)
1
2
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
30
31
32
33
34
35
36
37
fn main() {
    use raqote::*;

let mut dt = DrawTarget::new(400, 400);

let mut pb = PathBuilder::new();
pb.rect(0., 0., 400., 400.);
let path = pb.finish();

let gradient = Source::new_sweep_gradient(
    Gradient {
        stops: vec![
            GradientStop {
                position: 0.,
                color: Color::new(0xff, 0, 0, 0),
            },
            GradientStop {
                position: 0.5,
                color: Color::new(0xff, 0xff, 0xff, 0x0),
            },
            GradientStop {
                position: 1.,
                color: Color::new(0xff, 0, 0, 0x0),
            },
        ],
    },
    Point::new(150., 200.),
    45.,
    180.+45.,
    Spread::Repeat,
);
dt.fill(&path, &gradient, &DrawOptions::new());



dt.write_png("example.png");
}

Trait Implementations§

source§

impl<'a> Clone for Source<'a>

source§

fn clone(&self) -> Source<'a>

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 From<Color> for Source<'_>

source§

fn from(color: Color) -> Self

Converts to this type from the input type.
source§

impl From<SolidSource> for Source<'_>

source§

fn from(other: SolidSource) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> Freeze for Source<'a>

§

impl<'a> RefUnwindSafe for Source<'a>

§

impl<'a> Send for Source<'a>

§

impl<'a> Sync for Source<'a>

§

impl<'a> Unpin for Source<'a>

§

impl<'a> UnwindSafe for Source<'a>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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 T
where 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 T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.