Class Canvas
- java.lang.Object
-
- nl.colorize.multimedialib.renderer.Canvas
-
public class Canvas extends java.lang.ObjectRepresents the resolution of the application graphics independently from the device's screen resolution. The canvas is initially created with a preferred width and height. When the screen or window is resized, the canvas will also be resized while keeping its original aspect ratio.Having a consistent canvas size across different devices ensures a consistent user experience in situations where the same application is used across a variety of devices with different screen sizes. This class is then used to translate between the two coordinate systems.
Alternatively, a flexible canvas can be created. In this case, the canvas follows the screen resolution without considering the requested width/height or aspect ratio.
-
-
Constructor Summary
Constructors Constructor Description Canvas(int preferredWidth, int preferredHeight, boolean flexible)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RectgetBounds()intgetHeight()intgetWidth()floatgetZoomLevel()voidoffsetScreen(int offsetX, int offsetY)Offset the canvas position on the screen.voidresizeScreen(int screenWidth, int screenHeight)Sets the screen dimensions to the specified values.floattoCanvasX(int screenX)floattoCanvasY(int screenY)floattoScreenX(float canvasX)floattoScreenY(float canvasY)java.lang.StringtoString()
-
-
-
Method Detail
-
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()
-
getZoomLevel
public float getZoomLevel()
-
toCanvasX
public float toCanvasX(int screenX)
-
toCanvasY
public float toCanvasY(int screenY)
-
toScreenX
public float toScreenX(float canvasX)
-
toScreenY
public float toScreenY(float canvasY)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-