Class Canvas

java.lang.Object
nl.colorize.multimedialib.renderer.Canvas

public class Canvas extends Object
Defines how the application graphics should be displayed. This consists of both the canvas size and the targeted framerate.

In most applications, the canvas resolution is independent of the screen resolution of the device. This allows applications to have a reasonably consistent user interface across devices with different screen sizes, as the canvas can be scaled depending on the difference between preferred canvas size and the actual screen size. The canvas is then used to convert between the two coordinate systems. How this scaling behaves when faced with different screen sizes, resolutions, and aspect ratios is controlled by the canvas' ScaleStrategy.

In some cases no scaling is necessary, and the application will simply use the native resolution of the screen. This is referred to as a "flexible" or "native" canvas, which does not have a preferred size or aspect ratio and will simply translate screen coordinates 1-to-1.

  • Constructor Details

    • Canvas

      public Canvas(int preferredWidth, int preferredHeight, ScaleStrategy scaleStrategy)
  • Method Details

    • resizeScreen

      public void resizeScreen(int screenWidth, int screenHeight)
      Sets the screen dimensions to the specified values. This method should be called by the renderer when the application window is first created, and whenever the window is resized.
    • offsetScreen

      public void offsetScreen(int offsetX, int offsetY)
      Offset the canvas position on the screen. This is mainly needed for when the screen contains system UI such as a status bar or window title where no application graphics can be displayed.
    • getWidth

      public int getWidth()
    • getHeight

      public int getHeight()
    • getBounds

      public Rect getBounds()
    • getCenter

      public Point2D getCenter()
    • isLandscape

      public boolean isLandscape()
    • isPortait

      public boolean isPortait()
    • getZoomLevel

      public float getZoomLevel()
      Returns the zoom level that indicates how canvas pixels should be displayed relative to screen pixels. This is based on the current screen size, the canvas' preferred size, and its ScaleStrategy.
    • toCanvasX

      public float toCanvasX(int screenX)
    • toCanvasX

      public float toCanvasX(Point2D point)
    • toCanvasY

      public float toCanvasY(int screenY)
    • toCanvasY

      public float toCanvasY(Point2D point)
    • toScreenX

      public float toScreenX(float canvasX)
    • toScreenX

      public float toScreenX(Point2D point)
    • toScreenY

      public float toScreenY(float canvasY)
    • toScreenY

      public float toScreenY(Point2D point)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getPreferredWidth

      public int getPreferredWidth()
    • getPreferredHeight

      public int getPreferredHeight()
    • getScaleStrategy

      public ScaleStrategy getScaleStrategy()
    • getScreenWidth

      public int getScreenWidth()
    • getScreenHeight

      public int getScreenHeight()
    • getOffsetX

      public int getOffsetX()
    • getOffsetY

      public int getOffsetY()