[−][src]Struct tetra::graphics::scaling::ScreenScaler
A wrapper for a Canvas
that handles scaling the image to fit the screen.
Examples
struct GameState { scaler: ScreenScaler, } impl GameState { fn new(ctx: &mut Context) -> tetra::Result<GameState> { Ok(GameState { scaler: ScreenScaler::with_window_size(ctx, 128, 128, ScalingMode::ShowAllPixelPerfect)? }) } } impl State for GameState { fn draw(&mut self, ctx: &mut Context) -> tetra::Result { graphics::set_canvas(ctx, self.scaler.canvas()); // Draw your scene here... graphics::reset_canvas(ctx); graphics::clear(ctx, Color::BLACK); graphics::draw(ctx, &self.scaler, Vec2::new(0.0, 0.0)); Ok(()) } fn event(&mut self, _ctx: &mut Context, event: Event) -> tetra::Result { if let Event::Resized { width, height } = event { // Ensure your scaler is kept aware of screen size changes! self.scaler.set_outer_size(width, height); } Ok(()) } }
Methods
impl ScreenScaler
[src]
pub fn new(
ctx: &mut Context,
inner_width: i32,
inner_height: i32,
outer_width: i32,
outer_height: i32,
mode: ScalingMode
) -> Result<ScreenScaler>
[src]
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.
pub fn with_window_size(
ctx: &mut Context,
inner_width: i32,
inner_height: i32,
mode: ScalingMode
) -> Result<ScreenScaler>
[src]
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.
pub fn set_outer_size(&mut self, outer_width: i32, outer_height: i32)
[src]
Updates the scaler's outer size (i.e. the size of the box that the screen will be scaled to fit within).
pub fn canvas(&self) -> &Canvas
[src]
Returns a reference to the canvas that is being scaled.
pub fn mode(&self) -> ScalingMode
[src]
Returns the current scaling mode.
pub fn set_mode(&mut self, mode: ScalingMode)
[src]
Sets the scaling mode that should be used.
pub fn project(&self, position: Vec2<f32>) -> Vec2<f32>
[src]
Converts a point from window co-ordinates to scaled screen co-ordinates.
pub fn unproject(&self, position: Vec2<f32>) -> Vec2<f32>
[src]
Converts a point from scaled screen co-ordinates to window co-ordinates.
pub fn mouse_position(&self, ctx: &Context) -> Vec2<f32>
[src]
Returns the position of the mouse in scaled screen co-ordinates.
This is a shortcut for calling .project(input::get_mouse_position(ctx))
.
pub fn mouse_x(&self, ctx: &Context) -> f32
[src]
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
.
pub fn mouse_y(&self, ctx: &Context) -> f32
[src]
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
.
Trait Implementations
impl Debug for ScreenScaler
[src]
impl Drawable for ScreenScaler
[src]
fn draw<P>(&self, ctx: &mut Context, params: P) where
P: Into<DrawParams>,
[src]
P: Into<DrawParams>,
Auto Trait Implementations
impl !RefUnwindSafe for ScreenScaler
impl !Send for ScreenScaler
impl !Sync for ScreenScaler
impl Unpin for ScreenScaler
impl !UnwindSafe for ScreenScaler
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> SetParameter for T
fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
T: Parameter<Self>,
T: Parameter<Self>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,