pub struct Image {
    pub color: Option<[f32; 4]>,
    pub rectangle: Option<[f64; 4]>,
    pub source_rectangle: Option<[f64; 4]>,
}
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<[f32; 4]>

The color

rectangle: Option<[f64; 4]>

The rectangle to draw image inside

source_rectangle: Option<[f64; 4]>

The image source rectangle

Implementations

Creates a new image

Creates a new colored image

Sets color.

Sets optional color.

Sets rectangle.

Sets optional rectangle.

Sets source rectangle.

Sets optional source rectangle.

Draws image using default method.

Draws image using triangulation.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.