Struct graphics::image::Image [] [src]

pub struct Image {
    pub color: Option<Color>,
    pub rectangle: Option<Rectangle>,
    pub source_rectangle: Option<SourceRectangle>,

An image


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(
                [600, 400]

    //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 {
        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);



The color


The rectangle to draw image inside


The image source rectangle


impl Image

fn new() -> Image

Creates a new image

fn new_color(color: Color) -> Image

Creates a new colored image

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

Sets color.

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

Sets optional color.

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

Sets rectangle.

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

Sets optional rectangle.

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

Sets source rectangle.

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

Sets optional source rectangle.

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

Draws image using default method.

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

Draws image using triangulation.

Trait Implementations

Derived Implementations

impl Clone for Image

fn clone(&self) -> Image

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

impl Copy for Image