17cupsofcoffee / tetra

🎮 A simple 2D game framework written in Rust
MIT License
907 stars 63 forks source link

Add some utility methods to ScreenScaler #327

Closed TimerErTim closed 1 year ago

TimerErTim commented 1 year ago

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
}
17cupsofcoffee commented 1 year ago

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

17cupsofcoffee commented 1 year ago

Sorry for the delay - thank you for the PR!

TimerErTim commented 1 year ago

No problem! Thanks for merging