Struct blit::BlitOptions

source ·
pub struct BlitOptions {
    pub x: i32,
    pub y: i32,
    pub area: Option<Size>,
    pub sub_rect: Option<SubRect>,
    pub mask: Option<SubRect>,
    pub vertical_slice: Option<Slice>,
    pub horizontal_slice: Option<Slice>,
}
Expand description

How, where and which part of the image to render.

Slices can be used to control which part gets scaled using tiling scaling.

Fields§

§x: i32

Horizontal position on the destination buffer.

§y: i32

Vertical position on the destination buffer.

§area: Option<Size>

Size of the area (width, height) on the destination buffer.

  • When None is used, the size of the source buffer or of the subrectangle if set will be used.
  • When the area is smaller than the source buffer it effectively functions as the width and height parameters of BlitOptions::sub_rect.
  • When the area is bigger than the source buffer the default behaviour will be tiling.
assert_eq!(
    BlitOptions::default().with_area((10, 10)).sub_rect((100, 100)),
    BlitOptions::default().with_sub_rect((0, 0, 10, 10)).sub_rect((100, 100))
);
§sub_rect: Option<SubRect>

Which part of the source buffer to render.

  • When None is used, (0, 0, source_width, source_height) is set instead.
  • With Some(..), the values in the tuple are (x, y, width, height).

This is similar to UV coordinates but instead of relative positions in the range of 0..1 this takes absolute positions in the range 0..width for horizontal positions and 0..height for vertical positions.

§mask: Option<SubRect>

Which part of the target buffer to render.

  • When None is used, (0, 0, target_width, target_height) is set instead.
  • With Some(..), the values in the tuple are (x, y, width, height).
§vertical_slice: Option<Slice>

Divide the source buffer into multiple vertical sections and repeat the chosen section to fill the area.

This is only used when BlitOptions::area is set.

§horizontal_slice: Option<Slice>

Divide the source buffer into multiple horizontal sections and repeat the chosen section to fill the area.

This is only used when BlitOptions::area is set.

Implementations§

source§

impl BlitOptions

source

pub fn new() -> Self

Setup options for blitting at position (0, 0).

When no other fields are changed or methods are called this will render the full source.

source

pub fn new_position<X, Y>(x: X, y: Y) -> Self
where X: ToPrimitive, Y: ToPrimitive,

Setup options for blitting at position (x, y).

When no other fields are changed or methods are called this will render the full source.

§Sets field(s)
source

pub fn new_position_tuple<X, Y>((x, y): (X, Y)) -> Self
where X: ToPrimitive, Y: ToPrimitive,

Setup options for blitting at position (x, y).

When no other fields are changed or methods are called this will render the full source.

§Sets field(s)
source

pub fn with_area<S>(self, area: S) -> Self
where S: Into<Size>,

Set the size of the area (width, height) on the destination buffer.

  • When the area is smaller than the source buffer it effectively functions as the width and height parameters of BlitOptions::sub_rect.
  • When the area is bigger than the source buffer the default behaviour will be tiling.
§Sets field(s)
source

pub fn with_mask<R>(self, mask: R) -> Self
where R: Into<SubRect>,

Set the size of the area (width, height) to only show on the destination buffer.

§Sets field(s)
source

pub fn with_sub_rect<R>(self, sub_rect: R) -> Self
where R: Into<SubRect>,

Set which part of the source buffer to render.

  • When None is used, (0, 0, source_width, source_height) is set instead.
  • With Some(..), the values in the tuple are (x, y, width, height).

This is similar to UV coordinates but instead of relative positions in the range of 0..1 this takes absolute positions in the range 0..width for horizontal positions and 0..height for vertical positions.

§Sets field(s)
source

pub fn with_slice9<R>(self, center: R) -> Self
where R: Into<SubRect>,

Draw as a scalable 9-slice graphic.

The sub-rectangle of the center piece that will be scaled needs to be passed. Note that the rectangle has a width and a height instead of the absolute coordinates the other slice functions accept.

§Sets field(s)
source

pub fn with_horizontal_slice(self, slice: Slice) -> Self

Scale a single horizontal piece of the buffer while keeping the other parts the same height.

See crate::slice::Slice for more information.

§Sets field(s)
source

pub fn with_vertical_slice(self, slice: Slice) -> Self

Scale a single vertical piece of the buffer while keeping the other parts the same height.

§Sets field(s)
source

pub fn with_position<X, Y>(self, x: X, y: Y) -> Self
where X: ToPrimitive, Y: ToPrimitive,

Set the render position on the target (x, y).

§Sets field(s)
source

pub fn set_position<P>(&mut self, position: P)
where P: Into<(i32, i32)>,

Set the position (x, y).

§Sets field(s)
source

pub fn position(&self) -> (i32, i32)

Get the position (x, y).

source

pub fn area<S>(&self, source_size: S) -> Size
where S: Into<Size>,

Get the destination area (width, height).

If BlitOptions::area is None the size of the source will be returned.

source

pub fn set_sub_rect<R>(&mut self, sub_rect: R)
where R: Into<SubRect>,

Set which part of the source buffer to render.

  • When None is used, (0, 0, source_width, source_height) is set instead.
  • With Some(..), the values in the tuple are (x, y, width, height).

This is similar to UV coordinates but instead of relative positions in the range of 0..1 this takes absolute positions in the range 0..width for horizontal positions and 0..height for vertical positions.

§Sets field(s)
source

pub fn sub_rect<S>(&self, source_size: S) -> SubRect
where S: Into<Size>,

Get the source area sub rectangle (x, y, width, height).

source

pub fn set_area<S>(&mut self, area: S)
where S: Into<Size>,

Set the size of the area (width, height) on the destination buffer.

  • When the area is smaller than the source buffer it effectively functions as the width and height parameters of BlitOptions::sub_rect.
  • When the area is bigger than the source buffer the default behaviour will be tiling.
§Sets field(s)
source

pub fn set_slice9<R>(&mut self, center: R)
where R: Into<SubRect>,

Draw as a scalable 9-slice graphic.

The sub-rectangle of the center piece that will be scaled needs to be passed. Note that the rectangle has a width and a height instead of the absolute coordinates the other slice functions accept.

§Sets field(s)
source

pub fn set_mask<R>(&mut self, mask: R)
where R: Into<SubRect>,

Set the size of the area (width, height) to only show on the destination buffer.

§Sets field(s)
source

pub fn set_horizontal_slice(&mut self, slice: Slice)

Scale a single horizontal piece of the buffer while keeping the other parts the same height.

See crate::slice::Slice for more information.

§Sets field(s)
source

pub fn set_vertical_slice(&mut self, slice: Slice)

Scale a single vertical piece of the buffer while keeping the other parts the same height.

§Sets field(s)

Trait Implementations§

source§

impl Clone for BlitOptions

source§

fn clone(&self) -> BlitOptions

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 BlitOptions

source§

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

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

impl Default for BlitOptions

source§

fn default() -> BlitOptions

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

impl PartialEq for BlitOptions

source§

fn eq(&self, other: &BlitOptions) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for BlitOptions

Auto Trait Implementations§

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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
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.