Struct macroquad_canvas_2d::Canvas2D
source · pub struct Canvas2D { /* private fields */ }
Implementations§
source§impl Canvas2D
impl Canvas2D
sourcepub fn new(width: f32, height: f32) -> Self
pub fn new(width: f32, height: f32) -> Self
Create a new canvas with the given width and height.
sourcepub fn width_height(&self) -> (f32, f32)
pub fn width_height(&self) -> (f32, f32)
Get width and height.
sourcepub fn get_texture(&self) -> &Texture2D
pub fn get_texture(&self) -> &Texture2D
Get a reference of the canvas texture.
sourcepub fn get_texture_mut(&mut self) -> &mut Texture2D
pub fn get_texture_mut(&mut self) -> &mut Texture2D
Get a mutable reference of the canvas texture.
sourcepub fn set_camera(&self)
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()
sourcepub fn calculate_size_and_padding(
&self,
target_width: f32,
target_height: f32
) -> (f32, f32, Vec2)
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.
sourcepub fn calculate_size(&self, target_width: f32, target_height: f32) -> Vec2
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.
sourcepub fn calculate_min_scale_factor(
&self,
target_width: f32,
target_height: f32
) -> f32
pub fn calculate_min_scale_factor( &self, target_width: f32, target_height: f32 ) -> f32
Calculate the minimum scale factor.
sourcepub fn calculate_scale_factor(
&self,
target_width: f32,
target_height: f32
) -> (f32, f32)
pub fn calculate_scale_factor( &self, target_width: f32, target_height: f32 ) -> (f32, f32)
Calculate scale factor.
sourcepub 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)
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.
sourcepub 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)
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.
sourcepub fn screen_coordinates_to_canvas_coordinates(
&self,
screen_x: f32,
screen_y: f32,
offset_x: f32,
offset_y: f32
) -> (f32, f32)
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.
sourcepub fn canvas_coordinates_to_screen_coordinates(
&self,
canvas_x: f32,
canvas_y: f32,
offset_x: f32,
offset_y: f32
) -> (f32, f32)
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.
sourcepub fn screen_mouse_position_to_canvas(
&self,
offset_x: f32,
offset_y: f32
) -> (f32, f32)
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
sourcepub fn draw_to_screen(&self)
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.
sourcepub fn rotate_add(&mut self, rotation: f32)
pub fn rotate_add(&mut self, rotation: f32)
Rotate the camera by a factor. The factor is in degrees.
sourcepub fn rotate_to(&mut self, rotation: f32)
pub fn rotate_to(&mut self, rotation: f32)
Rotate the camera to a factor. The factor is in degrees.
sourcepub fn move_camera(&mut self, offset_x: f32, offset_y: f32)
pub fn move_camera(&mut self, offset_x: f32, offset_y: f32)
Move the camera by a factor in pixels.
sourcepub fn move_camera_to(&mut self, offset_x: f32, offset_y: f32)
pub fn move_camera_to(&mut self, offset_x: f32, offset_y: f32)
Set the camera offset to a factor in pixels.