Package paintingcanvas.canvas
Class Canvas
- java.lang.Object
-
- paintingcanvas.canvas.Canvas
-
public class Canvas extends java.lang.Object
The internal canvas component that is used to draw to the screen
-
-
Field Summary
Fields Modifier and Type Field Description java.util.List<Animation>
animations
the list of animations that are currently runningprotected java.lang.Object
animationSync
Sync with animations: Notifies on animation finishstatic java.lang.Object
drawableSync
Sync with drawables: Use when modifying a drawablejava.util.List<Drawable<?>>
elements
the elements that are currently on the canvasstatic int
fps
the fps of the canvasint
frame
The current frameprotected java.lang.Object
frameSync
Sync with frame: Notifies on end of framestatic Canvas
globalInstance
CanvasOptions
options
The options for the behavior of the canvas, seeCanvasOptions
CanvasPanel
panel
A CanvasComponent, which handles all the rendering n stuffjava.util.List<RenderLifecycle>
renderLifecycles
The RenderLifecycle: allows you to write code to run before and after a frame is renderedjava.awt.Dimension
startSize
the initial size of the Canvasjava.awt.geom.Point2D.Float
translation
-
Constructor Summary
Constructors Constructor Description Canvas()
Initializes the canvas with a default size of 900x600 and a title of "Canvas"Canvas(int width, int height, java.lang.String title)
Initializes the canvasCanvas(int width, int height, java.lang.String title, CanvasOptions options)
Initializes the canvas
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Canvas
getGlobalInstance()
Get the global instance of the Canvas (used internally to access the Canvas)int
getHeight()
Get the height of the canvasjava.awt.Point
getMousePos()
Get the mouse position in the canvas.int
getWidth()
Get the width of the canvasvoid
render()
void
setBackgroundColor(java.awt.Color color)
Sets the background color of the canvasvoid
setTitle(java.lang.String title)
Set the title of this canvasvoid
sleep()
Sleeps until all animations finish.void
sleep(double seconds)
Sleeps for the specified amount of seconds
-
-
-
Field Detail
-
fps
public static final int fps
the fps of the canvas- See Also:
- Constant Field Values
-
globalInstance
public static Canvas globalInstance
-
startSize
public final java.awt.Dimension startSize
the initial size of the Canvas
-
translation
public final java.awt.geom.Point2D.Float translation
-
elements
public final java.util.List<Drawable<?>> elements
the elements that are currently on the canvas
-
animations
public final java.util.List<Animation> animations
the list of animations that are currently running
-
panel
public final CanvasPanel panel
A CanvasComponent, which handles all the rendering n stuff
-
animationSync
protected final java.lang.Object animationSync
Sync with animations: Notifies on animation finish
-
frameSync
protected final java.lang.Object frameSync
Sync with frame: Notifies on end of frame
-
drawableSync
public static final java.lang.Object drawableSync
Sync with drawables: Use when modifying a drawable
-
frame
public int frame
The current frame
-
renderLifecycles
public java.util.List<RenderLifecycle> renderLifecycles
The RenderLifecycle: allows you to write code to run before and after a frame is rendered
-
options
public CanvasOptions options
The options for the behavior of the canvas, seeCanvasOptions
-
-
Constructor Detail
-
Canvas
public Canvas()
Initializes the canvas with a default size of 900x600 and a title of "Canvas"
-
Canvas
public Canvas(int width, int height, java.lang.String title)
Initializes the canvas- Parameters:
width
- the width of the canvasheight
- the height of the canvastitle
- the title of the canvas
-
Canvas
public Canvas(int width, int height, java.lang.String title, CanvasOptions options)
Initializes the canvas- Parameters:
width
- the width of the canvasheight
- the height of the canvastitle
- the title of the canvasoptions
- options for the canvas
-
-
Method Detail
-
getGlobalInstance
public static Canvas getGlobalInstance()
Get the global instance of the Canvas (used internally to access the Canvas)- Returns:
- The global instance of Canvas
-
setBackgroundColor
public void setBackgroundColor(java.awt.Color color)
Sets the background color of the canvas- Parameters:
color
- the new background color
-
getWidth
public int getWidth()
Get the width of the canvas- Returns:
- The width of the canvas
-
getHeight
public int getHeight()
Get the height of the canvas- Returns:
- The height of the canvas
-
setTitle
public void setTitle(java.lang.String title)
Set the title of this canvas- Parameters:
title
- the new title
-
sleep
public void sleep()
Sleeps until all animations finish.Circle c = new Circle(200, 200, 50); c.animate().with(Animation.colorTo(Color.RED), 2) .with(Animation.moveBy(100, 0), 2); canvas.sleep() c.setColor(Color.BLUE);
-
sleep
public void sleep(double seconds)
Sleeps for the specified amount of secondsCircle c = new Circle(200, 200, 50); canvas.sleep(1); // Sleeps for 1 second c.setColor(Color.RED);
- Parameters:
seconds
- The number of seconds to sleep for
-
render
public void render()
-
getMousePos
public java.awt.Point getMousePos()
Get the mouse position in the canvas.Point mousePos = canvas.getMousePos(); if (mousePos != null) { int x = mousePos.x; int y = mousePos.y; }
- Returns:
- The mouse position, or
null
if the mouse is not hovering over the canvas
-
-