Package playn.core
Class Canvas
java.lang.Object
playn.core.Canvas
- All Implemented Interfaces:
AutoCloseable,Closeable
A 2D drawing canvas. Rendering is performed by the CPU into a bitmap.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumValues that may be used withsetCompositeOperation(Composite).static interfaceFacilitates drawing images and image regions to a canvas.static enumValues that may be used withsetLineCap(LineCap).static enumValues that may be used withsetLineJoin(LineJoin).Nested classes/interfaces inherited from interface react.Closeable
Closeable.Set, Closeable.Util -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionabstract Canvasclear()Clears the entire canvas torgba(0, 0, 0, 0).abstract CanvasclearRect(float x, float y, float width, float height) Clears the specified region torgba (0, 0, 0, 0).abstract CanvasIntersects the current clip with the specified path.abstract CanvasclipRect(float x, float y, float width, float height) Intersects the current clip with the supplied rectangle.voidclose()Informs the platform that this canvas, and its backing image will no longer be used.createGradient(Gradient.Config config) Creates a gradient fill pattern.Creates a path object.draw(Canvas.Drawable image, float x, float y) Drawsimageat the specified location(x, y).draw(Canvas.Drawable image, float x, float y, float w, float h) Draws a scaled image at the specified location(x, y)size(w x h).draw(Canvas.Drawable image, float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh) Draws a subregion of a image(sw x sh) @ (sx, sy)at the specified size(dw x dh)and location(dx, dy).abstract CanvasdrawArc(float cx, float cy, float r, float startAngle, float arcAngle) Draws an arc of a circle centered at cx, cy, with radius r.drawCentered(Canvas.Drawable image, float x, float y) Drawsimagecentered at the specified location.abstract CanvasdrawLine(float x0, float y0, float x1, float y1) Draws a line between the two specified points.abstract CanvasdrawPoint(float x, float y) Draws a single point at the specified location.abstract CanvasDraws text at the specified location.abstract CanvasfillCircle(float x, float y, float radius) Fills a circle at the specified center and radius.abstract CanvasFills the specified path.abstract CanvasfillRect(float x, float y, float width, float height) Fills the specified rectangle.abstract CanvasfillRoundRect(float x, float y, float width, float height, float radius) Fills the specified rounded rectangle.abstract CanvasfillText(TextLayout text, float x, float y) Fills the text at the specified location.abstract Canvasrestore()Restores the canvas's previous state.abstract Canvasrotate(float radians) Rotates the current transformation matrix by the specified angle in radians.abstract Canvassave()The save and restore methods preserve and restore the state of the canvas, but not specific paths or graphics.abstract Canvasscale(float x, float y) Scales the current transformation matrix by the specified amount.abstract CanvassetAlpha(float alpha) Set the global alpha value to be used for all painting.abstract CanvassetCompositeOperation(Canvas.Composite composite) Sets the Porter-Duff composite operation to be used for all painting.abstract CanvassetFillColor(int color) Sets the color to be used for fill operations.abstract CanvassetFillGradient(Gradient gradient) Sets the gradient to be used for fill operations.abstract CanvassetFillPattern(Pattern pattern) Sets the pattern to be used for fill operations.abstract CanvassetLineCap(Canvas.LineCap cap) Sets the line-cap mode for strokes.abstract CanvassetLineJoin(Canvas.LineJoin join) Sets the line-join mode for strokes.abstract CanvassetMiterLimit(float miter) Sets the miter limit for strokes.abstract CanvassetStrokeColor(int color) Sets the color for strokes.abstract CanvassetStrokeWidth(float strokeWidth) Sets the width for strokes, in pixels.abstract Imagesnapshot()Returns an immutable snapshot of the image that backs this canvas.abstract CanvasstrokeCircle(float x, float y, float radius) Strokes a circle at the specified center and radius.abstract CanvasstrokePath(Path path) Strokes the specified path.abstract CanvasstrokeRect(float x, float y, float width, float height) Strokes the specified rectangle.abstract CanvasstrokeRoundRect(float x, float y, float width, float height, float radius) Strokes the specified rounded rectangle.abstract CanvasstrokeText(TextLayout text, float x, float y) Strokes the text at the specified location.CallstoTexture(Texture.Config)with the default texture config.toTexture(Texture.Config config) A helper function for creating a texture from this canvas's image, and then disposing this canvas.abstract Canvastransform(float m11, float m12, float m21, float m22, float dx, float dy) Multiplies the current transformation matrix by the given matrix.abstract Canvastranslate(float x, float y) Translates the current transformation matrix by the given amount.
-
Field Details
-
image
The image that underlies this canvas. -
width
public final float widthThe width of this canvas. -
height
public final float heightThe height of this canvas.
-
-
Method Details
-
snapshot
Returns an immutable snapshot of the image that backs this canvas. Subsequent changes to this canvas will not be reflected in the returned image. If you are going to render a canvas image into another canvas image a lot, using a snapshot can improve performance. -
close
public void close()Informs the platform that this canvas, and its backing image will no longer be used. On some platforms this can free up memory earlier than if we waited for the canvas to be garbage collected.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
clear
Clears the entire canvas torgba(0, 0, 0, 0). -
clearRect
Clears the specified region torgba (0, 0, 0, 0). -
clip
Intersects the current clip with the specified path. -
clipRect
Intersects the current clip with the supplied rectangle. -
createPath
Creates a path object. -
createGradient
Creates a gradient fill pattern. -
draw
Drawsimageat the specified location(x, y). -
drawCentered
Drawsimagecentered at the specified location. Subtractsimage.width/2from x andimage.height/2from y. -
draw
Draws a scaled image at the specified location(x, y)size(w x h). -
draw
public Canvas draw(Canvas.Drawable image, float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh) Draws a subregion of a image(sw x sh) @ (sx, sy)at the specified size(dw x dh)and location(dx, dy). TODO (jgw): Document whether out-of-bounds source coordinates clamp, repeat, or do nothing. -
drawLine
Draws a line between the two specified points. -
drawPoint
Draws a single point at the specified location. -
drawArc
Draws an arc of a circle centered at cx, cy, with radius r.The start and arc angles are specified in radians. Angles are interpreted such that 0 radians is at the 3 o'clock position. Positive values indicate a counter-clockwise rotation while negative values indicate a clockwise rotation.
-
drawText
Draws text at the specified location. The text will be drawn in the current fill color. -
fillCircle
Fills a circle at the specified center and radius. -
fillPath
Fills the specified path. -
fillRect
Fills the specified rectangle. -
fillRoundRect
Fills the specified rounded rectangle.- Parameters:
x- the x coordinate of the upper left of the rounded rectangle.y- the y coordinate of the upper left of the rounded rectangle.width- the width of the rounded rectangle.height- the width of the rounded rectangle.radius- the radius of the circle to use for the corner.
-
fillText
Fills the text at the specified location. The text will use the current fill color. -
restore
Restores the canvas's previous state.- See Also:
-
rotate
Rotates the current transformation matrix by the specified angle in radians. -
save
The save and restore methods preserve and restore the state of the canvas, but not specific paths or graphics. The following values are saved:- transformation matrix
- clipping path
- stroke color
- stroke width
- line cap
- line join
- miter limit
- fill color or gradient
- composite operation
-
scale
Scales the current transformation matrix by the specified amount. -
setAlpha
Set the global alpha value to be used for all painting.Values outside the range [0,1] will be clamped to the range [0,1].
- Parameters:
alpha- alpha value in range [0,1] where 0 is transparent and 1 is opaque
-
setCompositeOperation
Sets the Porter-Duff composite operation to be used for all painting. -
setFillColor
Sets the color to be used for fill operations. This replaces any existing fill gradient or pattern. -
setFillGradient
Sets the gradient to be used for fill operations. This replaces any existing fill color or pattern. -
setFillPattern
Sets the pattern to be used for fill operations. This replaces any existing fill color or gradient. -
setLineCap
Sets the line-cap mode for strokes. -
setLineJoin
Sets the line-join mode for strokes. -
setMiterLimit
Sets the miter limit for strokes. -
setStrokeColor
Sets the color for strokes. -
setStrokeWidth
Sets the width for strokes, in pixels. -
strokeCircle
Strokes a circle at the specified center and radius. -
strokePath
Strokes the specified path. -
strokeRect
Strokes the specified rectangle. -
strokeRoundRect
Strokes the specified rounded rectangle.- Parameters:
x- the x coordinate of the upper left of the rounded rectangle.y- the y coordinate of the upper left of the rounded rectangle.width- the width of the rounded rectangle.height- the width of the rounded rectangle.radius- the radius of the circle to use for the corner.
-
strokeText
Strokes the text at the specified location. The text will use the current stroke configuration (color, width, etc.). -
toTexture
CallstoTexture(Texture.Config)with the default texture config. -
toTexture
A helper function for creating a texture from this canvas's image, and then disposing this canvas. This is useful for situations where you create a canvas, draw something in it, turn it into a texture and then never use the canvas again. -
transform
Multiplies the current transformation matrix by the given matrix. -
translate
Translates the current transformation matrix by the given amount.
-