Struct speedy2d::Graphics2D[][src]

pub struct Graphics2D { /* fields omitted */ }

A Graphics2D object allows you to draw shapes, images, and text to the screen.

An instance is provided in the window::WindowHandler::on_draw callback.

If you are managing the GL context yourself, you must invoke GLRenderer::draw_frame to obtain an instance.

Implementations

impl Graphics2D[src]

pub fn create_image_from_raw_pixels<S: Into<Vector2<u32>>>(
    &mut self,
    data_type: ImageDataType,
    smoothing_mode: ImageSmoothingMode,
    size: S,
    data: &[u8]
) -> Result<ImageHandle, BacktraceError<ErrorMessage>>
[src]

Creates a new ImageHandle from the specified raw pixel data.

The data provided in the data parameter must be in the format specified by data_type.

The returned ImageHandle is valid only for the current graphics context.

pub fn clear_screen(&mut self, color: Color)[src]

Fills the screen with the specified color.

pub fn draw_text<V: Into<Vector2<f32>>>(
    &mut self,
    position: V,
    color: Color,
    text: &Rc<FormattedTextBlock>
)
[src]

Draws the provided line of text at the specified position.

Lines of text can be prepared by loading a font (using crate::font::Font::new), and calling layout_text_line() on that font with your desired text.

To fall back to another font if a glyph isn’t found, see crate::font::FontFamily.

To achieve good performance, it’s possible to layout a line of text once, and then re-use the same crate::font::FormattedTextLine object whenever you need to draw that text to the screen.

Note: Text will be rendered with subpixel precision. If the subpixel position changes between frames, performance may be degraded, as the text will need to be re-rendered and re-uploaded. To avoid this, call round() on the position coordinates, to ensure that the text is always located at an integer pixel position.

pub fn draw_triangle_three_color(
    &mut self,
    vertex_positions_clockwise: [Vector2<f32>; 3],
    vertex_colors_clockwise: [Color; 3]
)
[src]

Draws a triangle with the specified colors (one color for each corner).

The vertex positions (and associated colors) must be provided in clockwise order.

pub fn draw_triangle_image_tinted_three_color(
    &mut self,
    vertex_positions_clockwise: [Vector2<f32>; 3],
    vertex_colors: [Color; 3],
    image_coords_normalized: [Vector2<f32>; 3],
    image: &ImageHandle
)
[src]

Draws part of an image, tinted with the provided colors, at the specified location. The sub-image will be scaled to fill the triangle described by the vertices in vertex_positions_clockwise.

The coordinates in image_coords_normalized should be in the range 0.0 to 1.0, and define the portion of the source image which should be drawn.

The tinting is performed by for each pixel by multiplying each color component in the image pixel by the corresponding color component in the color parameter.

The vertex positions (and associated colors and image coordinates) must be provided in clockwise order.

pub fn draw_triangle(
    &mut self,
    vertex_positions_clockwise: [Vector2<f32>; 3],
    color: Color
)
[src]

Draws a triangle with the specified color.

The vertex positions must be provided in clockwise order.

pub fn draw_quad_four_color(
    &mut self,
    vertex_positions_clockwise: [Vector2<f32>; 4],
    vertex_colors: [Color; 4]
)
[src]

Draws a quadrilateral with the specified colors (one color for each corner).

The vertex positions (and associated colors) must be provided in clockwise order.

pub fn draw_quad(
    &mut self,
    vertex_positions_clockwise: [Vector2<f32>; 4],
    color: Color
)
[src]

Draws a quadrilateral with the specified color.

The vertex positions must be provided in clockwise order.

pub fn draw_quad_image_tinted_four_color(
    &mut self,
    vertex_positions_clockwise: [Vector2<f32>; 4],
    vertex_colors: [Color; 4],
    image_coords_normalized: [Vector2<f32>; 4],
    image: &ImageHandle
)
[src]

Draws part of an image, tinted with the provided colors, at the specified location. The sub-image will be scaled to fill the quadrilateral described by the vertices in vertex_positions_clockwise.

The coordinates in image_coords_normalized should be in the range 0.0 to 1.0, and define the portion of the source image which should be drawn.

The tinting is performed by for each pixel by multiplying each color component in the image pixel by the corresponding color component in the color parameter.

The vertex positions (and associated colors and image coordinates) must be provided in clockwise order.

pub fn draw_rectangle_image_subset_tinted(
    &mut self,
    rect: Rectangle,
    color: Color,
    image_coords_normalized: Rectangle,
    image: &ImageHandle
)
[src]

Draws part of an image, tinted with the provided color, at the specified location. The sub-image will be scaled to fill the pixel coordinates in the provided rectangle.

The coordinates in image_coords_normalized should be in the range 0.0 to 1.0, and define the portion of the source image which should be drawn.

The tinting is performed by for each pixel by multiplying each color component in the image pixel by the corresponding color component in the color parameter.

pub fn draw_rectangle_image_tinted(
    &mut self,
    rect: Rectangle,
    color: Color,
    image: &ImageHandle
)
[src]

Draws an image, tinted with the provided color, at the specified location. The image will be scaled to fill the pixel coordinates in the provided rectangle.

The tinting is performed by for each pixel by multiplying each color component in the image pixel by the corresponding color component in the color parameter.

pub fn draw_rectangle_image(&mut self, rect: Rectangle, image: &ImageHandle)[src]

Draws an image at the specified location. The image will be scaled to fill the pixel coordinates in the provided rectangle.

pub fn draw_image(&mut self, position: Vector2<f32>, image: &ImageHandle)[src]

Draws an image at the specified pixel location. The image will be drawn at its original size with no scaling.

pub fn draw_rectangle(&mut self, rect: Rectangle, color: Color)[src]

Draws a single-color rectangle at the specified location. The coordinates of the rectangle are specified in pixels.

pub fn draw_line<VStart: Into<Vector2<f32>>, VEnd: Into<Vector2<f32>>>(
    &mut self,
    start_position: VStart,
    end_position: VEnd,
    thickness: f32,
    color: Color
)
[src]

Draws a single-color line between the given points, specified in pixels.

Pixel alignment

On a display with square pixels, an integer-valued coordinate is located at the boundary between two pixels, rather than the center of the pixel. For example:

  • (0.0, 0.0) = Top left of pixel
  • (0.5, 0.5) = Center of pixel
  • (1.0, 1.0) = Bottom right of pixel

If drawing a line of odd-numbered thickness, it is advisable to locate the start and end of the line at the centers of pixels, rather than the edges.

For example, a one-pixel-thick line between (0.0, 10.0) and (100.0, 10.0) will be drawn as a rectangle with corners (0.0, 9.5) and (100.0, 10.5), meaning that the line’s thickness will actually span two half-pixels. Drawing the same line between (0.0, 10.5) and (100.0, 10.5) will result in a pixel-aligned rectangle between (0.0, 10.0) and (100.0, 11.0).

pub fn draw_circle<V: Into<Vector2<f32>>>(
    &mut self,
    center_position: V,
    radius: f32,
    color: Color
)
[src]

Draws a circle, filled with a single color, at the specified pixel location.

pub fn draw_circle_section_triangular_three_color(
    &mut self,
    vertex_positions_clockwise: [Vector2<f32>; 3],
    vertex_colors: [Color; 3],
    vertex_circle_coords_normalized: [Vector2<f32>; 3]
)
[src]

Draws a triangular subset of a circle.

Put simply, this function will draw a triangle on the screen, textured with a region of a circle.

The circle region is specified using vertex_circle_coords_normalized, which denotes UV coordinates relative to an infinitely-detailed circle of radius 1.0, and center (0.0, 0.0).

For example, to draw the top-right half of a circle with radius 100px:

graphics.draw_circle_section_triangular_three_color(
        [
                Vector2::new(200.0, 200.0),
                Vector2::new(300.0, 200.0),
                Vector2::new(300.0, 300.0)],
        [Color::MAGENTA; 3],
        [
                Vector2::new(-1.0, -1.0),
                Vector2::new(1.0, -1.0),
                Vector2::new(1.0, 1.0)]);

Auto Trait Implementations

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.