java.lang.Object
technology.sola.engine.graphics.screen.Viewport

@NullMarked public class Viewport extends Object
Viewport contains various information about the current viewport used. This is primarily used to keep track of the correct AspectRatioSizing based on the current AspectMode and screen width and height.
  • Constructor Details

    • Viewport

      public Viewport(int canvasWidth, int canvasHeight)
      Creates an instance of the viewport given the canvas's width and height.
      Parameters:
      canvasWidth - the width of the canvas (renderer)
      canvasHeight - the height of the canvas (renderer)
  • Method Details

    • getAspectMode

      public AspectMode getAspectMode()
      Returns:
      the current AspectMode
    • setAspectMode

      public void setAspectMode(AspectMode aspectMode)
      Updates the AspectMode used and recalculates AspectRatioSizing.
      Parameters:
      aspectMode - the new AspectMode
    • getAspectRatioSizing

      public AspectRatioSizing getAspectRatioSizing()
      Returns:
      the current AspectRatioSizing
    • getRendererToAspectRatioX

      public float getRendererToAspectRatioX()
      Returns:
      the ratio of canvasWidth to AspectRatioSizing.width()
    • getRendererToAspectRatioY

      public float getRendererToAspectRatioY()
      Returns:
      the ratio of canvasHeight to AspectRatioSizing.height()
    • resize

      public void resize(int screenWidth, int screenHeight)
      Recalculates the AspectRatioSizing using the current AspectMode and the new screen width and height.
      Parameters:
      screenWidth - the width of the screen
      screenHeight - the height of the screen