Struct mage_core::image::Image

source ·
pub struct Image {
    pub width: u32,
    pub height: u32,
    pub fore_image: Vec<u32>,
    pub back_image: Vec<u32>,
    pub text_image: Vec<u32>,
}
Expand description

Represents a rectangular collection of chars to render as sprites or screens.

Fields§

§width: u32

The width of the image in chars.

§height: u32

The height of the image in chars.

§fore_image: Vec<u32>

The foreground color of each char in the image.

§back_image: Vec<u32>

The background color of each char in the image.

§text_image: Vec<u32>

The char to render at each position in the image.

Implementations§

source§

impl Image

source

pub fn new(width: u32, height: u32) -> Self

Creates a new image with the given dimensions.

Arguments
  • width - The width of the image in chars.
  • height - The height of the image in chars.
Returns

A new image with the given dimensions. The image is filled with character zero.

source

pub fn point_to_index(&self, p: Point) -> Option<usize>

Returns the index of the char at the given coordinates.

Arguments
  • p - The coordinates of the char to get the index of.
Returns

The index of the char at the given coordinates, or None if the coordinates are out of bounds.

source

pub fn coords_to_index(&self, x: i32, y: i32) -> Option<usize>

Returns the index of the char at the given coordinates.

Arguments
  • x - The x coordinate of the char to get the index of.
  • y - The y coordinate of the char to get the index of.
Returns

The index of the char at the given coordinates, or None if the coordinates are out of bounds.

source

pub fn clear(&mut self, ink: u32, paper: u32)

Clears the image with a given ink and paper colour.

Arguments
  • ink - The foreground colour to clear the image with.
  • paper - The background colour to clear the image with.
source

pub fn draw_char(&mut self, p: Point, ch: Char)

Draws a character at the given coordinates.

Arguments
  • p - The coordinates to draw the character at.
  • ch - The character to draw.
Notes

If the coordinates are out of bounds, the character is not drawn.

source

pub fn draw_string(&mut self, p: Point, text: &str, ink: u32, paper: u32)

Draws a string at the given coordinates.

Arguments
  • p - The coordinates to draw the string at.
  • text - The string to draw.
  • ink - The foreground colour of the string.
  • paper - The background colour of the string.
Notes

If the coordinates are out of bounds, the string is clipped.

source

pub fn draw_filled_rect(&mut self, rect: Rect, ch: Char)

Draws a rectangle at the given coordinates and dimensions using the given character.

Arguments
  • p - The coordinates to draw the rectangle at.
  • width - The width of the rectangle.
  • height - The height of the rectangle.
  • ch - The character to draw the rectangle with.
Notes

If the coordinates are out of bounds, the rectangle is clipped.

source

pub fn rect(&self) -> Rect

Returns a rectangle representing the bounds of the image.

Returns

A rectangle representing the bounds of the image.

Notes

The rectangle returned is always at the origin.

The width and height of the rectangle are the same as the width and height of the image.

Auto Trait Implementations§

§

impl RefUnwindSafe for Image

§

impl Send for Image

§

impl Sync for Image

§

impl Unpin for Image

§

impl UnwindSafe for Image

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSync for T
where T: Sync,