Struct tetra::graphics::scaling::ScreenScaler
source · pub struct ScreenScaler { /* private fields */ }
Expand description
Implementations§
source§impl ScreenScaler
impl ScreenScaler
sourcepub fn new(
ctx: &mut Context,
inner_width: i32,
inner_height: i32,
outer_width: i32,
outer_height: i32,
mode: ScalingMode
) -> Result<ScreenScaler>
pub fn new( ctx: &mut Context, inner_width: i32, inner_height: i32, outer_width: i32, outer_height: i32, mode: ScalingMode ) -> Result<ScreenScaler>
Returns a new ScreenScaler
, with the specified inner and outer width and height.
The mode will determine how the image is scaled to fit the screen.
sourcepub fn from_canvas(
canvas: Canvas,
outer_width: i32,
outer_height: i32,
mode: ScalingMode
) -> Result<ScreenScaler>
pub fn from_canvas( canvas: Canvas, outer_width: i32, outer_height: i32, mode: ScalingMode ) -> Result<ScreenScaler>
Returns a new ScreenScaler
, using the given canvas for drawing.
The mode will determine how the image is scaled to fit the screen.
sourcepub fn with_window_size(
ctx: &mut Context,
inner_width: i32,
inner_height: i32,
mode: ScalingMode
) -> Result<ScreenScaler>
pub fn with_window_size( ctx: &mut Context, inner_width: i32, inner_height: i32, mode: ScalingMode ) -> Result<ScreenScaler>
Returns a new ScreenScaler
, with the specified inner width and height, and the outer
size set to the current dimensions of the window.
sourcepub fn set_outer_size(&mut self, outer_width: i32, outer_height: i32)
pub fn set_outer_size(&mut self, outer_width: i32, outer_height: i32)
Updates the scaler’s outer size (i.e. the size of the box that the screen will be scaled to fit within).
sourcepub fn outer_size(&self) -> (i32, i32)
pub fn outer_size(&self) -> (i32, i32)
Returns the scaler’s outer size (i.e. the size of the box that the screen will be scaled to
fit within).
The format is (width, height).
sourcepub fn inner_size(&self) -> (i32, i32)
pub fn inner_size(&self) -> (i32, i32)
Returns the scaler’s inner size (i.e. the logical screen size).
The format is (width, height).
sourcepub fn scale_factor(&self) -> f32
pub fn scale_factor(&self) -> f32
Returns the optimal scale factor for the current ScalingMode
and configured sizes.
This can be used for simple use cases where scaling by canvas is not
feasible (e.g. 3rd party UI libraries).
sourcepub fn mode(&self) -> ScalingMode
pub fn mode(&self) -> ScalingMode
Returns the current scaling mode.
sourcepub fn set_mode(&mut self, mode: ScalingMode)
pub fn set_mode(&mut self, mode: ScalingMode)
Sets the scaling mode that should be used.
sourcepub fn project(&self, position: Vec2<f32>) -> Vec2<f32>
pub fn project(&self, position: Vec2<f32>) -> Vec2<f32>
Converts a point from window co-ordinates to scaled screen co-ordinates.
sourcepub fn unproject(&self, position: Vec2<f32>) -> Vec2<f32>
pub fn unproject(&self, position: Vec2<f32>) -> Vec2<f32>
Converts a point from scaled screen co-ordinates to window co-ordinates.
sourcepub fn mouse_position(&self, ctx: &Context) -> Vec2<f32>
pub fn mouse_position(&self, ctx: &Context) -> Vec2<f32>
Returns the position of the mouse in scaled screen co-ordinates.
This is a shortcut for calling .project(input::get_mouse_position(ctx))
.
sourcepub fn mouse_x(&self, ctx: &Context) -> f32
pub fn mouse_x(&self, ctx: &Context) -> f32
Returns the X co-ordinate of the mouse in scaled screen co-ordinates.
This is a shortcut for calling project(input::get_mouse_position(ctx)).x
.
sourcepub fn mouse_y(&self, ctx: &Context) -> f32
pub fn mouse_y(&self, ctx: &Context) -> f32
Returns the Y co-ordinate of the mouse in scaled screen co-ordinates.
This is a shortcut for calling project(input::get_mouse_position(ctx)).y
.