[]Struct piston_window::image::Image

pub struct Image {
    pub color: Option<[f32; 4]>,
    pub rectangle: Option<[f64; 4]>,
    pub source_rectangle: Option<[f64; 4]>,
}

An image

Example

This example is not tested
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

Methods

impl Image

pub fn new() -> Image

Creates a new image

pub fn new_color(color: [f32; 4]) -> Image

Creates a new colored image

pub fn color(self, value: [f32; 4]) -> Image

Sets color.

pub fn maybe_color(self, value: Option<[f32; 4]>) -> Image

Sets optional color.

pub fn rect<R>(self, value: R) -> Image where
    R: Into<[f64; 4]>, 

Sets rectangle.

pub fn maybe_rect<R>(self, value: Option<R>) -> Image where
    R: Into<[f64; 4]>, 

Sets optional rectangle.

pub fn src_rect(self, value: [f64; 4]) -> Image

Sets source rectangle.

pub fn maybe_src_rect(self, value: Option<[f64; 4]>) -> Image

Sets optional source rectangle.

pub fn draw<G>(
    &self,
    texture: &<G as Graphics>::Texture,
    draw_state: &DrawState,
    transform: [[f64; 3]; 2],
    g: &mut G
) where
    G: Graphics

Draws image using default method.

pub fn draw_tri<G>(
    &self,
    texture: &<G as Graphics>::Texture,
    draw_state: &DrawState,
    transform: [[f64; 3]; 2],
    g: &mut G
) where
    G: Graphics

Draws image using triangulation.

Trait Implementations

impl Copy for Image

impl Clone for Image

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl Send for Image

impl Sync for Image

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

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

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

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

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> SetParameter for T

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
    T: Parameter<Self>, 

Sets value as a parameter of self.

impl<T> Erased for T