prime31 / Nez

Nez is a free 2D focused framework that works with MonoGame and FNA
MIT License
1.78k stars 362 forks source link

Add `SceneResolutionPolicy.BestFitPixelPerfect` #722

Open cgbeutler opened 2 years ago

cgbeutler commented 2 years ago

There are nice PixelPerfect options for each policy except for BestFit. It would be nice have best fit in there as well. With the rise of Ultra-wide monitors, settings like NoBorderPixelPerfect can get problematic. BestFitPixelPerfect would allow the targetting of a range of sizes and aspect ratios all at once.

As far as how it should work goes, it would match BestFit, but snap scaling to integer values.

For example, the following settings would be fairly ideal for most 2D games:

Scene.SetDefaultDesignResolution(960, 540, Scene.SceneResolutionPolicy.NoBorderPixelPerfect, 480, 156);

That setting snap up to a 2x zoom when 960 width and 768 height are surpassed, as the minimal area within the bleed padding can now fit in the window.

I could also see doing a padSize instead of a bleedSize, as additive rendering wiggle room may be simpler on the user than the subtractive nature of bleed. That would make it not match BestFit, though, so it'd have to have a different name.

cgbeutler commented 2 years ago

Got it working on my fork here: https://github.com/prime31/Nez/commit/fcdb729d69b360b93f2bf9ef3e67ee60aacc2673

If the feature is actually desired by anyone else, then I can make a PR. This is what it looks like in action:

poison

The red rectangle is the minimal area within the bleed size. When a multiple of that area can be displayed, it snaps up a zoom level.