pub struct Canvas2D { /* private fields */ }

Implementations§

source§

impl Canvas2D

source

pub fn new(width: f32, height: f32) -> Self

Create a new canvas with the given width and height.

source

pub fn width(&self) -> f32

Get width.

source

pub fn height(&self) -> f32

Get height.

source

pub fn width_height(&self) -> (f32, f32)

Get width and height.

source

pub fn get_texture(&self) -> &Texture2D

Get a reference of the canvas texture.

source

pub fn get_texture_mut(&mut self) -> &mut Texture2D

Get a mutable reference of the canvas texture.

source

pub fn set_camera(&self)

Set the canvas as te default camera to draw if you want to draw to the screen you should call macroquad::camera::set_default_camera()

source

pub fn calculate_size_and_padding( &self, target_width: f32, target_height: f32 ) -> (f32, f32, Vec2)

Calculate size and padding of the canvas so it can fit inside of the target and its position is in the center.

source

pub fn calculate_size(&self, target_width: f32, target_height: f32) -> Vec2

Calculate size of the canvas so it can fit inside of the target respecting the aspect ratio.

source

pub fn calculate_min_scale_factor( &self, target_width: f32, target_height: f32 ) -> f32

Calculate the minimum scale factor.

source

pub fn calculate_scale_factor( &self, target_width: f32, target_height: f32 ) -> (f32, f32)

Calculate scale factor.

source

pub fn parent_coordinates_to_canvas_coordinates( &self, parent_width: f32, parent_height: f32, screen_x: f32, screen_y: f32, offset_x: f32, offset_y: f32 ) -> (f32, f32)

Convert from the parent coordinates to canvas coordinates.

Warning it can return negative numbers or values grater than the canvas when the mouse is outside of the canvas.

source

pub fn canvas_coordinates_to_parent_coordinates( &self, parent_width: f32, parent_height: f32, canvas_x: f32, canvas_y: f32, offset_x: f32, offset_y: f32 ) -> (f32, f32)

Convert from the canvas coordinates to parent coordinates.

Warning do to float division it can be a small margin of error.

source

pub fn screen_coordinates_to_canvas_coordinates( &self, screen_x: f32, screen_y: f32, offset_x: f32, offset_y: f32 ) -> (f32, f32)

A wrapper around the parent_to_canvas for better ergonomic. Convert from the screen coordinates to canvas coordinates.

Warning it can return negative numbers or values grater than the canvas when the mouse is outside of the canvas.

source

pub fn canvas_coordinates_to_screen_coordinates( &self, canvas_x: f32, canvas_y: f32, offset_x: f32, offset_y: f32 ) -> (f32, f32)

A wrapper around the canvas_to_parent for better ergonomic. Convert from the canvas coordinates to screen coordinates.

Warning do to float division it can be a small margin of error.

source

pub fn screen_mouse_position_to_canvas( &self, offset_x: f32, offset_y: f32 ) -> (f32, f32)

Get the mouse position in canvas coordinates.

Warning it can return negative numbers or values grater than the canvas

source

pub fn draw_to_screen(&self)

Draws the canvas to the middle of the screen, keeping the aspect ratio. It calls set_default_camera before drawing.

source

pub fn zoom_add(&mut self, zoom: f32)

Zoom the camera by a factor.

source

pub fn zoom_to(&mut self, zoom: f32)

Zoom the camera to a factor.

source

pub fn rotate_add(&mut self, rotation: f32)

Rotate the camera by a factor. The factor is in degrees.

source

pub fn rotate_to(&mut self, rotation: f32)

Rotate the camera to a factor. The factor is in degrees.

source

pub fn move_camera(&mut self, offset_x: f32, offset_y: f32)

Move the camera by a factor in pixels.

source

pub fn move_camera_to(&mut self, offset_x: f32, offset_y: f32)

Set the camera offset to a factor in pixels.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where 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 T
where 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.