Spec-Zone .ru
спецификации, руководства, описания, API
|
public final class GraphicsContext
extends java.lang.Object
Canvas
using a buffer.
Each call pushes the necessary parameters onto the buffer
where it is executed on the image of the Canvas
node.
A Canvas
only contains one GraphicsContext
, and only one buffer.
If it is not attached to any scene, then it can be modified by any thread,
as long as it is only used from one thread at a time. Once a Canvas
node is attached to a scene, it must be modified on the JavaFX Application
Thread.
Calling any method on the GraphicsContext
is considered modifying
its corresponding Canvas
and is subject to the same threading
rules.
A GraphicsContext
also manages a stack of state objects that can
be saved or restored at anytime.
Example:
import javafx.scene.*; import javafx.scene.paint.*; import javafx.scene.canvas.*; Group root = new Group(); Scene s = new Scene(root, 300, 300, Color.BLACK); final Canvas canvas = new Canvas(250,250); GraphicsContext gc = canvas.getGraphicsContext2D(); gc.setFill(Color.BLUE); gc.fillRect(75,75,100,100); root.getChildren().add(canvas);
Modifier and Type | Method and Description |
---|---|
void |
appendSVGPath(java.lang.String svgpath)
Appends an SVG Path string to the current path.
|
void |
applyEffect(Effect e)
Applies the given effect to the entire canvas.
|
void |
arc(double centerX,
double centerY,
double radiusX,
double radiusY,
double startAngle,
double length)
Adds path elements to the current path to make an arc that uses Euclidean
degrees.
|
void |
arcTo(double x1,
double y1,
double x2,
double y2,
double radius)
Adds segments to the current path to make an arc.
|
void |
beginPath()
Starts a Path
|
void |
bezierCurveTo(double xc1,
double yc1,
double xc2,
double yc2,
double x1,
double y1)
Adds segments to the current path to make a cubic bezier curve.
|
void |
clearRect(double x,
double y,
double w,
double h)
Clears a portion of the canvas with a transparent color value.
|
void |
clip()
Clips using the current path
|
void |
closePath()
Closes the path.
|
void |
drawImage(Image img,
double x,
double y)
Draws an image at the given x, y position using the width
and height of the given image.
|
void |
drawImage(Image img,
double x,
double y,
double w,
double h)
Draws an image into the given destination rectangle of the canvas.
|
void |
drawImage(Image img,
double sx,
double sy,
double sw,
double sh,
double dx,
double dy,
double dw,
double dh)
Draws the current source rectangle of the given image to the given
destination rectangle of the Canvas.
|
void |
fill()
Fills the path with the current fill paint.
|
void |
fillArc(double x,
double y,
double w,
double h,
double startAngle,
double arcExtent,
ArcType closure)
Fills an arc using the current fill paint.
|
void |
fillOval(double x,
double y,
double w,
double h)
Fills an oval using the current fill paint.
|
void |
fillPolygon(double[] xPoints,
double[] yPoints,
int nPoints)
Fills a polygon with the given points using the currently set fill paint.
|
void |
fillRect(double x,
double y,
double w,
double h)
Fills a rectangle using the current fill paint.
|
void |
fillRoundRect(double x,
double y,
double w,
double h,
double arcWidth,
double arcHeight)
Fills a rounded rectangle using the current fill paint.
|
void |
fillText(java.lang.String text,
double x,
double y)
Fills the given string of text at position x, y (0,0 at top left)
with the current fill paint attribute.
|
void |
fillText(java.lang.String text,
double x,
double y,
double maxWidth)
Fills text and includes a maximum width of the string.
|
Canvas |
getCanvas()
Gets the
Canvas that the GraphicsContext is issuing draw
commands to. |
Effect |
getEffect(Effect e)
Gets a copy of the effect to be applied after the next draw call.
|
Paint |
getFill()
Gets the current fill attribute.
|
FillRule |
getFillRule()
Get the filling rule constant for determining the interior of the path.
|
Font |
getFont()
Gets the current Font.
|
double |
getGlobalAlpha()
Gets the current global alpha.
|
BlendMode |
getGlobalBlendMode()
Gets the global blend mode.
|
StrokeLineCap |
getLineCap()
Gets the current stroke line cap.
|
StrokeLineJoin |
getLineJoin()
Gets the current stroke line join.
|
double |
getLineWidth()
Gets the current line width.
|
double |
getMiterLimit()
Gets the current miter limit.
|
PixelWriter |
getPixelWriter()
Returns a
PixelWriter object that can be used to modify
the pixels of the Canvas associated with this
GraphicsContext . |
Paint |
getStroke()
Gets the current stroke.
|
TextAlignment |
getTextAlign()
Gets the current
TextAlignment . |
VPos |
getTextBaseline()
Gets the current Text Baseline.
|
Affine |
getTransform()
Returns a copy of the current transform.
|
Affine |
getTransform(Affine xform)
Returns a copy of the current transform.
|
boolean |
isPointInPath(double x,
double y)
Returns true if the the given x,y point is inside the path.
|
void |
lineTo(double x1,
double y1)
Adds segments to the current path to make a line at the given x,y
coordinate.
|
void |
moveTo(double x0,
double y0)
Issues a move command for the current path to the given x,y coordinate.
|
void |
quadraticCurveTo(double xc,
double yc,
double x1,
double y1)
Adds segments to the current path to make a quadratic curve.
|
void |
rect(double x,
double y,
double w,
double h)
Adds path elements to the current path to make a rectangle.
|
void |
restore()
Pops the state off of the stack, setting the following attributes to their
value at the time when that state was pushed onto the stack.
|
void |
rotate(double degrees)
Rotates the current transform in degrees.
|
void |
save()
Saves the following attributes onto a stack.
|
void |
scale(double x,
double y)
Scales the current transform by x, y.
|
void |
setEffect(Effect e)
Sets the effect to be applied after the next draw call, or null to
disable effects.
|
void |
setFill(Paint p)
Sets the current fill attribute.
|
void |
setFillRule(FillRule fillRule)
Set the filling rule constant for determining the interior of the path.
|
void |
setFont(Font f)
Sets the current Font.
|
void |
setGlobalAlpha(double alpha)
Sets the global alpha of the current state.
|
void |
setGlobalBlendMode(BlendMode op)
Sets the global blend mode.
|
void |
setLineCap(StrokeLineCap cap)
Sets the current stroke line cap.
|
void |
setLineJoin(StrokeLineJoin join)
Sets the current stroke line join.
|
void |
setLineWidth(double lw)
Sets the current line width.
|
void |
setMiterLimit(double ml)
Sets the current miter limit.
|
void |
setStroke(Paint p)
Sets the current stroke.
|
void |
setTextAlign(TextAlignment align)
Defines horizontal text alignment, relative to the text
x origin. |
void |
setTextBaseline(VPos baseline)
Sets the current Text Baseline.
|
void |
setTransform(Affine xform)
Sets the current transform.
|
void |
setTransform(double mxx,
double myx,
double mxy,
double myy,
double mxt,
double myt)
Sets the current transform.
|
void |
stroke()
Strokes the path with the current stroke paint.
|
void |
strokeArc(double x,
double y,
double w,
double h,
double startAngle,
double arcExtent,
ArcType closure)
Strokes an Arc using the current stroke paint.
|
void |
strokeLine(double x1,
double y1,
double x2,
double y2)
Strokes a line using the current stroke paint.
|
void |
strokeOval(double x,
double y,
double w,
double h)
Strokes a rectangle using the current stroke paint.
|
void |
strokePolygon(double[] xPoints,
double[] yPoints,
int nPoints)
Strokes a polygon with the given points using the currently set stroke paint.
|
void |
strokePolyline(double[] xPoints,
double[] yPoints,
int nPoints)
Draws a polyline with the given points using the currently set stroke
paint attribute.
|
void |
strokeRect(double x,
double y,
double w,
double h)
Strokes a rectangle using the current stroke paint.
|
void |
strokeRoundRect(double x,
double y,
double w,
double h,
double arcWidth,
double arcHeight)
Strokes a rounded rectangle using the current stroke paint.
|
void |
strokeText(java.lang.String text,
double x,
double y)
draws the given string of text at position x, y (0,0 at top left)
with the current stroke paint attribute.
|
void |
strokeText(java.lang.String text,
double x,
double y,
double maxWidth)
Draws text with stroke paint and includes a maximum width of the string.
|
void |
transform(Affine xform)
Concatenates the input with the current transform.
|
void |
transform(double mxx,
double myx,
double mxy,
double myy,
double mxt,
double myt)
Concatenates the input with the current transform.
|
void |
translate(double x,
double y)
Translates the current transform by x, y.
|
public Canvas getCanvas()
Canvas
that the GraphicsContext
is issuing draw
commands to. There is only ever one Canvas
for a
GraphicsContext
.GraphicsContext
is issuing draw
commands to.public void save()
public void restore()
public void translate(double x, double y)
x
- value to translate along the x axis.y
- value to translate along the y axis.public void scale(double x, double y)
x
- value to scale in the x axis.y
- value to scale in the y axis.public void rotate(double degrees)
degrees
- value in degrees to rotate the current transform.public void transform(double mxx, double myx, double mxy, double myy, double mxt, double myt)
mxx
- - the X coordinate scaling element of the 3x4 matrixmyx
- - the Y coordinate shearing element of the 3x4 matrixmxy
- - the X coordinate shearing element of the 3x4 matrixmyy
- - the Y coordinate scaling element of the 3x4 matrixmxt
- - the X coordinate translation element of the 3x4 matrixmyt
- - the Y coordinate translation element of the 3x4 matrixpublic void transform(Affine xform)
xform
- The affine to be concatenated with the current transform.public void setTransform(double mxx, double myx, double mxy, double myy, double mxt, double myt)
mxx
- - the X coordinate scaling element of the 3x4 matrixmyx
- - the Y coordinate shearing element of the 3x4 matrixmxy
- - the X coordinate shearing element of the 3x4 matrixmyy
- - the Y coordinate scaling element of the 3x4 matrixmxt
- - the X coordinate translation element of the 3x4 matrixmyt
- - the Y coordinate translation element of the 3x4 matrixpublic void setTransform(Affine xform)
xform
- The affine to be copied and used as the current transform.public Affine getTransform(Affine xform)
xform
- A transform object that will be used to hold the result.
If xform is non null, then this method will copy the current transform
into that object. If xform is null a new transform object will be
constructed. In either case, the return value is a copy of the current
transform.public Affine getTransform()
public void setGlobalAlpha(double alpha)
alpha
- value in the range 0.0-1.0
. The value is clamped if it is
out of range.public double getGlobalAlpha()
public void setGlobalBlendMode(BlendMode op)
op
- the BlendMode
that will be set.public BlendMode getGlobalBlendMode()
BlendMode
of the current state.public void setFill(Paint p)
p
- The Paint
to be used as the fill Paint
.public Paint getFill()
Paint
to be used as the fill Paint
.public void setStroke(Paint p)
p
- The Paint to be used as the stroke Paint.public Paint getStroke()
Paint
to be used as the stroke Paint
.public void setLineWidth(double lw)
lw
- value in the range {0-positive infinity}, with any other value
being ignored and leaving the value unchanged.public double getLineWidth()
public void setLineCap(StrokeLineCap cap)
cap
- StrokeLineCap
with a value of Butt, Round, or Square.public StrokeLineCap getLineCap()
StrokeLineCap
with a value of Butt, Round, or Square.public void setLineJoin(StrokeLineJoin join)
join
- StrokeLineJoin
with a value of Miter, Bevel, or Round.public StrokeLineJoin getLineJoin()
StrokeLineJoin
with a value of Miter, Bevel, or Round.public void setMiterLimit(double ml)
ml
- miter limit value between 0 and positive infinity with
any other value being ignored and leaving the value unchanged.public double getMiterLimit()
0.0-positive infinity
public void setFont(Font f)
f
- the Fontpublic Font getFont()
public void setTextAlign(TextAlignment align)
x
origin.
Let horizontal bounds represent the logical width of a single line of text. Where each line of text has a separate horizontal bounds.
Then TextAlignment is specified as:
x
.
x
.
x
.
Note: Canvas does not support line wrapping, therefore the text alignment Justify is identical to left aligned text.
align
- TextAlignment
with values of Left, Center, Right.public TextAlignment getTextAlign()
TextAlignment
.TextAlignment
with values of Left, Center, Right, or
Justify.public void setTextBaseline(VPos baseline)
baseline
- VPos
with values of Top, Center, Baseline, or Bottompublic VPos getTextBaseline()
VPos
with values of Top, Center, Baseline, or Bottompublic void fillText(java.lang.String text, double x, double y)
text
- the string of text.x
- position on the x axis.y
- position on the y axis.public void strokeText(java.lang.String text, double x, double y)
text
- the string of text.x
- position on the x axis.y
- position on the y axis.public void fillText(java.lang.String text, double x, double y, double maxWidth)
text
- the string of text.x
- position on the x axis.y
- position on the y axis.maxWidth
- maximum width the text string can have.public void strokeText(java.lang.String text, double x, double y, double maxWidth)
text
- the string of text.x
- position on the x axis.y
- position on the y axis.maxWidth
- maximum width the text string can have.public void setFillRule(FillRule fillRule)
FillRile.EVEN_ODD
or FillRule.NON_ZERO
.
The default value is FillRule.NON_ZERO
.public FillRule getFillRule()
FillRule.NON_ZERO
.public void beginPath()
public void moveTo(double x0, double y0)
x0
- the X position for the move to command.y0
- the Y position for the move to command.public void lineTo(double x1, double y1)
x1
- the X coordinate of the ending point of the line.y1
- the Y coordinate of the ending point of the line.public void quadraticCurveTo(double xc, double yc, double x1, double y1)
xc
- the X coordinate of the control pointyc
- the Y coordinate of the control pointx1
- the X coordinate of the end pointy1
- the Y coordinate of the end pointpublic void bezierCurveTo(double xc1, double yc1, double xc2, double yc2, double x1, double y1)
xc1
- the X coordinate of first bezier control point.yc1
- the Y coordinate of the first bezier control point.xc2
- the X coordinate of the second bezier control point.yc2
- the Y coordinate of the second bezier control point.x1
- the X coordinate of the end point.y1
- the Y coordinate of the end point.public void arcTo(double x1, double y1, double x2, double y2, double radius)
x1
- the X coordinate of the first point of the arc.y1
- the Y coordinate of the first point of the arc.x2
- the X coordinate of the second point of the arc.y2
- the Y coordinate of the second point of the arc.radius
- the radius of the arc in the range {0.0-positive infinity}.public void arc(double centerX, double centerY, double radiusX, double radiusY, double startAngle, double length)
centerX
- the center x position of the arc.centerY
- the center y position of the arc.radiusX
- the x radius of the arc.radiusY
- the y radius of the arc.startAngle
- the starting angle of the arc in the range 0-360.0
length
- the length of the baseline of the arc.public void rect(double x, double y, double w, double h)
x
- x position of the upper left corner of the rectangle.y
- y position of the upper left corner of the rectangle.w
- width of the rectangle.h
- height of the rectangle.public void appendSVGPath(java.lang.String svgpath)
svgpath
- the SVG Path string.public void closePath()
public void fill()
public void stroke()
public void clip()
public boolean isPointInPath(double x, double y)
x
- the X coordinate to use for the check.y
- the Y coordinate to use for the check.public void clearRect(double x, double y, double w, double h)
x
- X position of the upper left corner of the rectangle.y
- Y position of the upper left corner of the rectangle.w
- width of the rectangle.h
- height of the rectangle.public void fillRect(double x, double y, double w, double h)
x
- the X position of the upper left corner of the rectangle.y
- the Y position of the upper left corner of the rectangle.w
- the width of the rectangle.h
- the height of the rectangle.public void strokeRect(double x, double y, double w, double h)
x
- the X position of the upper left corner of the rectangle.y
- the Y position of the upper left corner of the rectangle.w
- the width of the rectangle.h
- the height of the rectangle.public void fillOval(double x, double y, double w, double h)
x
- the X coordinate of the upper left bound of the oval.y
- the Y coordinate of the upper left bound of the oval.w
- the width at the center of the oval.h
- the height at the center of the oval.public void strokeOval(double x, double y, double w, double h)
x
- the X coordinate of the upper left bound of the oval.y
- the Y coordinate of the upper left bound of the oval.w
- the width at the center of the oval.h
- the height at the center of the oval.public void fillArc(double x, double y, double w, double h, double startAngle, double arcExtent, ArcType closure)
x
- the X coordinate of the arc.y
- the Y coordinate of the arc.w
- the width of the arc.h
- the height of the arc.startAngle
- the starting angle of the arc in degrees.arcExtent
- the angular extent of the arc in degrees.closure
- closure type (Round, Chord, Open).public void strokeArc(double x, double y, double w, double h, double startAngle, double arcExtent, ArcType closure)
x
- the X coordinate of the arc.y
- the Y coordinate of the arc.w
- the width of the arc.h
- the height of the arc.startAngle
- the starting angle of the arc in degrees.arcExtent
- arcExtent the angular extent of the arc in degrees.closure
- closure type (Round, Chord, Open).public void fillRoundRect(double x, double y, double w, double h, double arcWidth, double arcHeight)
x
- the X coordinate of the upper left bound of the oval.y
- the Y coordinate of the upper left bound of the oval.w
- the width at the center of the oval.h
- the height at the center of the oval.arcWidth
- the arc width of the rectangle corners.arcHeight
- the arc height of the rectangle corners.public void strokeRoundRect(double x, double y, double w, double h, double arcWidth, double arcHeight)
x
- the X coordinate of the upper left bound of the oval.y
- the Y coordinate of the upper left bound of the oval.w
- the width at the center of the oval.h
- the height at the center of the oval.arcWidth
- the arc width of the rectangle corners.arcHeight
- the arc height of the rectangle corners.public void strokeLine(double x1, double y1, double x2, double y2)
x1
- the X coordinate of the starting point of the line.y1
- the Y coordinate of the starting point of the line.x2
- the X coordinate of the ending point of the line.y2
- the Y coordinate of the ending point of the line.public void fillPolygon(double[] xPoints, double[] yPoints, int nPoints)
xPoints
- array containing the x coordinates of the polygon's points.yPoints
- array containing the y coordinates of the polygon's points.nPoints
- the number of points that make the polygon.public void strokePolygon(double[] xPoints, double[] yPoints, int nPoints)
xPoints
- array containing the x coordinates of the polygon's points.yPoints
- array containing the y coordinates of the polygon's points.nPoints
- the number of points that make the polygon.public void strokePolyline(double[] xPoints, double[] yPoints, int nPoints)
xPoints
- array containing the x coordinates of the polyline's points.yPoints
- array containing the y coordinates of the polyline's points.nPoints
- the number of points that make the polyline.public void drawImage(Image img, double x, double y)
img
- the image to be drawn.x
- the X coordinate on the destination for the upper left of the image.y
- the Y coordinate on the destination for the upper left of the image.public void drawImage(Image img, double x, double y, double w, double h)
img
- the image to be drawn.x
- the X coordinate on the destination for the upper left of the image.y
- the Y coordinate on the destination for the upper left of the image.w
- the width of the destination rectangle.h
- the height of the destination rectangle.public void drawImage(Image img, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh)
img
- the image to be drawn.sx
- the source rectangle's X coordinate position.sy
- the source rectangle's Y coordinate position.sw
- the source rectangle's width.sh
- the source rectangle's height.dx
- the destination rectangle's X coordinate position.dy
- the destination rectangle's Y coordinate position.dw
- the destination rectangle's width.dh
- the destination rectangle's height.public PixelWriter getPixelWriter()
PixelWriter
object that can be used to modify
the pixels of the Canvas
associated with this
GraphicsContext
.
All coordinates in the PixelWriter
methods on the returned
object will be in device space since they refer directly to pixels.PixelWriter
for modifying the pixels of this
Canvas
public void setEffect(Effect e)
e
- the effect to use, or null to disable effectspublic Effect getEffect(Effect e)
e
- an Effect
object that may be used to store the
copy of the current effect, if it is of a compatible typepublic void applyEffect(Effect e)
e
- the effect to apply onto the entire destination.Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. Use is subject to