tetra icon indicating copy to clipboard operation
tetra copied to clipboard

Add some utility methods to ScreenScaler

Open TimerErTim opened this issue 2 years ago • 1 comments

This PR would add some useful utility methods to the ScreenScaler struct.

First of all the current sizes (inner and outer) can easily be retrieved. Furthermore a scaling factor can be calculated. The scaling factor is a single floating point number, representing how much unscaled objects need to be scaled up (or down respectively) in order to fit the screen using the ScalingMode of the screen scaler.

Motivation

This would allow easy integration of 3rd party libraries using the OpenGL context (e.g. UI libraries).

fn update(&mut self, ctx: &mut Context) -> Result<(), Error> {
    self.ui_scale = self.scaler.scale_factor();
}

fn draw(&mut self, ctx: &mut Context) -> Result<(), Error> {
    ui_library::draw(ctx, &self.ui, self.ui_scale); // Just some pseudo usage example of a 3rd party library
}

TimerErTim avatar Sep 10 '22 18:09 TimerErTim

This seems like a no-brainer to add - I'll probably merge this after work :)

17cupsofcoffee avatar Sep 13 '22 09:09 17cupsofcoffee

Sorry for the delay - thank you for the PR!

17cupsofcoffee avatar Sep 17 '22 18:09 17cupsofcoffee

No problem! Thanks for merging

TimerErTim avatar Sep 17 '22 21:09 TimerErTim