Struct graphics::image::Image

source ·
pub struct Image {
    pub color: Option<Color>,
    pub rectangle: Option<Rectangle>,
    pub source_rectangle: Option<SourceRectangle>,
}
Expand description

An image

Example

extern crate piston;
extern crate graphics;
extern crate glutin_window;
extern crate opengl_graphics;

use piston::window::WindowSettings;
use piston::event::*;
use glutin_window::GlutinWindow as Window;
use opengl_graphics::{GlGraphics, OpenGL, Texture};
use graphics::{Image, clear, default_draw_state};
use graphics::rectangle::square;
use std::path::Path;

fn main() {
    let opengl  = OpenGL::_3_2;
    let mut gl  = GlGraphics::new(opengl);
    let window  = Window::new(
			opengl,
			WindowSettings::new(
				"Example",
				[600, 400]
			).exit_on_esc(true));

    // Create the image object and attach a square Rectangle object inside.
    let image   = Image::new().rect(square(0.0, 0.0, 200.0));
    // A texture to use with the image
    let texture = Texture::from_path(Path::new("Example.png")).unwrap();

    // Main loop
    for e in window.events() {
		if let Some(r) = e.render_args() {
			gl.draw(r.viewport(), |c, gl| {
				//Clear the screen
				clear([0.0, 0.0, 0.0, 1.0], gl);
				//Draw the image with the texture
				image.draw(&texture, default_draw_state(), c.transform, gl);
			});
		}
	}
}

Fields§

§color: Option<Color>

The color

§rectangle: Option<Rectangle>

The rectangle to draw image inside

§source_rectangle: Option<SourceRectangle>

The image source rectangle

Implementations§

source§

impl Image

source

pub fn new() -> Image

Creates a new image

source

pub fn new_color(color: Color) -> Image

Creates a new colored image

source

pub fn color(self, value: Color) -> Self

Sets color.

source

pub fn maybe_color(self, value: Option<Color>) -> Self

Sets optional color.

source

pub fn rect<R: Into<Rectangle>>(self, value: R) -> Self

Sets rectangle.

source

pub fn maybe_rect<R: Into<Rectangle>>(self, value: Option<R>) -> Self

Sets optional rectangle.

source

pub fn src_rect(self, value: SourceRectangle) -> Self

Sets source rectangle.

source

pub fn maybe_src_rect(self, value: Option<SourceRectangle>) -> Self

Sets optional source rectangle.

source

pub fn draw<G>( &self, texture: &<G as Graphics>::Texture, draw_state: &DrawState, transform: Matrix2d, g: &mut G )where G: Graphics,

Draws image using default method.

source

pub fn draw_tri<G>( &self, texture: &<G as Graphics>::Texture, draw_state: &DrawState, transform: Matrix2d, g: &mut G )where G: Graphics,

Draws image using triangulation.

Trait Implementations§

source§

impl Clone for Image

source§

fn clone(&self) -> Image

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 Copy for 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 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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 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.
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.
source§

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

Performs the conversion.