- java.lang.Object
-
- org.arakhne.afc.nodefx.ZoomableGraphicsContext
-
public class ZoomableGraphicsContext extends Object
This class is used to issue draw calls to aZoomableCanvasusing a buffer.The
ZoomableGraphicsContextis a wrapper to theGraphicsContextembedded within theZoomableCanvas.The coordinates that are supported by the
ZoomableGraphicsContextare document coordinates (not the screen coordinates). Consequently, theZoomableGraphicsContexttranslates any coordinates from the document standard to the JavaFX standard.- Since:
- 15.0
- Version:
- 17.0 2020-01-04 14:41:52
- Author:
- Stéphane GALLAND
- See Also:
ZoomableCanvas,GraphicsContext- Maven Group Id:
- org.arakhne.afc.advanced
- Maven Artifact Id:
- nodefx
-
-
Constructor Summary
Constructors Constructor Description ZoomableGraphicsContext(javafx.scene.canvas.GraphicsContext gc, javafx.beans.property.DoubleProperty scale, javafx.beans.property.ReadOnlyObjectProperty<Rectangle2afp<?,?,?,?,?,?>> documentBounds, javafx.beans.property.ReadOnlyObjectProperty<Rectangle2afp<?,?,?,?,?,?>> visibleArea, javafx.beans.property.DoubleProperty canvasWidth, javafx.beans.property.DoubleProperty canvasHeight, javafx.beans.property.IntegerProperty drawableElementBudget, CenteringTransform centeringTransform)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapplyEffect(javafx.scene.effect.Effect effect)Applies the given effect to the entire bounds of the canvas and stores the result back into the same canvas.voidarc(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 radians.voidarcTo(double x1, double y1, double x2, double y2, double radius)Adds segments to the current path to make an arc.voidbeginPath()Resets the current path to empty.voidbezierCurveTo(double xc1, double yc1, double xc2, double yc2, double x1, double y1)Adds segments to the current path to make a cubic Bezier curve.voidclearRect(double x, double y, double width, double height)Clears a portion of the canvas with a transparent color value.voidclip()Intersects the current clip with the current path and applies it to subsequent rendering operation as an anti-aliased mask.voidclosePath()Closes the path.booleanconsumeBudget()Consume the budget.doubledoc2fxAngle(double angle)Transform a document angle to its JavaFX equivalent.Point2ddoc2fxRectBase(double x, double y, double width, double height)Transform a document rectangle's minimum point to its JavaFX equivalent.doubledoc2fxSize(double size)Transform a document size (or distance) to its JavaFX equivalent.doubledoc2fxX(double x)Transform a document x coordinate to its JavaFX equivalent.doubledoc2fxY(double y)Transform a document y coordinate to its JavaFX equivalent.voiddrawImage(javafx.scene.image.Image img, double x, double y)Draws an image at the given x, y position using the width and height of the given image.voiddrawImage(javafx.scene.image.Image img, double x, double y, double width, double height)Draws an image into the given destination rectangle of the canvas.voiddrawImage(javafx.scene.image.Image img, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh)Draws the specified source rectangle of the given image to the given destination rectangle of the Canvas.voidfill()Fills the path with the current fill paint.voidfillArc(double x, double y, double width, double height, double startAngle, double arcExtent, javafx.scene.shape.ArcType closure)Fills an arc using the current fill paint.voidfillOval(double x, double y, double width, double height)Fills an oval using the current fill paint.voidfillRect(double x, double y, double width, double height)Fills a rectangle using the current fill paint.voidfillRoundRect(double x, double y, double width, double height, double arcWidth, double arcHeight)Fills a rounded rectangle using the current fill paint.voidfillText(String text, double x, double y)Fills the given string of text at position x, y with the current fill paint attribute.voidfillText(String text, double x, double y, double maxWidth)Fills text and includes a maximum width of the string.doublefx2docAngle(double angle)Transform a JavaFX angle to its document equivalent.Point2dfx2docRectBase(double x, double y, double width, double height)Transform a JavaFX rectangle's minimum point to its document equivalent.doublefx2docSize(double size)Transform a JavaFX size (or distance) to its document equivalent.doublefx2docX(double x)Transform a JavaFX x coordinate to its document equivalent.doublefx2docY(double y)Transform a JavaFX y coordinate to its document equivalent.intgetBudget()Replies the budget.ZoomableCanvas<?>getCanvas()Gets theZoomableCanvasthat theGraphicsContextis issuing draw commands to.Rectangle2afp<?,?,?,?,?,?>getDocumentBounds()Replies the document bounds in document coordinates.javafx.scene.effect.EffectgetEffect(javafx.scene.effect.Effect effect)Gets a copy of the effect to be applied after the next draw call.javafx.scene.paint.PaintgetFill()Gets the current fill paint attribute.javafx.scene.shape.FillRulegetFillRule()Get the filling rule attribute for determining the interior of paths in fill and clip operations.javafx.scene.text.FontgetFont()Gets the current Font.javafx.scene.text.FontSmoothingTypegetFontSmoothingType()Gets the current Font Smoothing Type.doublegetGlobalAlpha()Gets the current global alpha.javafx.scene.effect.BlendModegetGlobalBlendMode()Gets the global blend mode.LevelOfDetailsgetLevelOfDetails()Replies the current level of details.javafx.scene.shape.StrokeLineCapgetLineCap()Gets the current stroke line cap.double[]getLineDashesInMeters()Gets a copy of the current line dash array in meters.double[]getLineDashesInPixels()Gets a copy of the current line dash array in pixels.doublegetLineDashOffsetInMeters()Gets the current line dash offset in meters.doublegetLineDashOffsetInPixels()Gets the current line dash offset in pixels.javafx.scene.shape.StrokeLineJoingetLineJoin()Gets the current stroke line join.doublegetLineWidthInMeters()Gets the current line width in meters.doublegetLineWidthInPixels()Gets the current line width in pixels.doublegetMiterLimitInMeters()Gets the current miter limit in meters.doublegetMiterLimitInPixels()Gets the current miter limit in pixels.javafx.scene.image.PixelWritergetPixelWriter()Returns aPixelWriterobject that can be used to modify the pixels of theCanvasassociated with thisGraphicsContext.intgetState()Replies the user-defined state of the context.javafx.scene.paint.PaintgetStroke()Gets the current stroke.javafx.scene.text.TextAlignmentgetTextAlign()Gets the currentTextAlignment.javafx.geometry.VPosgetTextBaseline()Gets the current Text Baseline.Rectangle2afp<?,?,?,?,?,?>getVisibleArea()Replies the bounds of the visible area in document coordinates.javafx.scene.canvas.GraphicsContextgetWrappedGraphicsContext2D()Gets theGraphicsContextthat is wrapped by this object.voidlineTo(double x1, double y1)Adds segments to the current path to make a line to the given x,y coordinate.voidmoveTo(double x0, double y0)Issues a move command for the current path to the given x,y coordinate.voidprepareRendering()Prepare the rendering by reseting the budget and the state.voidquadraticCurveTo(double xc, double yc, double x1, double y1)Adds segments to the current path to make a quadratic Bezier curve.voidrect(double x, double y, double width, double height)Adds path elements to the current path to make a rectangle.voidrestore()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.javafx.scene.paint.Colorrgb(int color)Parse the given RGB color.javafx.scene.paint.Colorrgba(int color)Parse the given RGBA color.javafx.scene.paint.Colorrgba(int rgb, double opacity)Parse the given RGBA color.javafx.scene.paint.Colorrgba(javafx.scene.paint.Color rgb, double opacity)Parse the given RGBA color.voidrotate(double radians)Rotates the current transform in radians.voidsave()Saves the following attributes onto a stack.voidscale(double x, double y)Scales the current transform by x, y.voidsetEffect(javafx.scene.effect.Effect effect)Sets the effect to be applied after the next draw call, or null to disable effects.voidsetFill(javafx.scene.paint.Paint paint)Sets the current fill paint attribute.voidsetFillRule(javafx.scene.shape.FillRule fillRule)Set the filling rule attribute for determining the interior of paths in fill or clip operations.voidsetFont(javafx.scene.text.Font font)Sets the current Font.voidsetFontSmoothingType(javafx.scene.text.FontSmoothingType fontsmoothing)Sets the current Font Smoothing Type.voidsetGlobalAlpha(double alpha)Sets the global alpha of the current state.voidsetGlobalBlendMode(javafx.scene.effect.BlendMode op)Sets the global blend mode.voidsetLineCap(javafx.scene.shape.StrokeLineCap cap)Sets the current stroke line cap.voidsetLineDashesInMeters(double... dashes)Sets the current stroke line dash pattern in meters to a normalized copy of the argument.voidsetLineDashesInPixels(double... dashes)Sets the current stroke line dash pattern in pixels to a normalized copy of the argument.voidsetLineDashOffsetInMeters(double dashOffset)Sets the line dash offset in meters.voidsetLineDashOffsetInPixels(double dashOffset)Sets the line dash offset in pixels.voidsetLineJoin(javafx.scene.shape.StrokeLineJoin join)Sets the current stroke line join.voidsetLineWidthInMeters(double lw)Sets the current line width in meters.voidsetLineWidthInPixels(double lw)Sets the current line width in pixels.voidsetMiterLimitInMeters(double ml)Sets the current miter limit in meters.voidsetMiterLimitInPixels(double ml)Sets the current miter limit in pixels.voidsetState(int state)Change the user-defined state of the context.voidsetStroke(javafx.scene.paint.Paint paint)Sets the current stroke paint attribute.voidsetTextAlign(javafx.scene.text.TextAlignment align)Defines horizontal text alignment, relative to the textxorigin.voidsetTextBaseline(javafx.geometry.VPos baseline)Sets the current Text Baseline.voidstroke()Strokes the path with the current stroke paint.voidstrokeArc(double x, double y, double width, double height, double startAngle, double arcExtent, javafx.scene.shape.ArcType closure)Strokes an Arc using the current stroke paint.voidstrokeLine(double x1, double y1, double x2, double y2)Strokes a line using the current stroke paint.voidstrokeOval(double x, double y, double width, double height)Strokes an oval using the current stroke paint.voidstrokeRect(double x, double y, double width, double height)Strokes a rectangle using the current stroke paint.voidstrokeRoundRect(double x, double y, double width, double height, double arcWidth, double arcHeight)Strokes a rounded rectangle using the current stroke paint.voidstrokeText(String text, double x, double y)Draws the given string of text at position x, y with the current stroke paint attribute.voidstrokeText(String text, double x, double y, double maxWidth)Draws text with stroke paint and includes a maximum width of the string.voidtranslate(double x, double y)Translates the current transform by x, y.
-
-
-
Constructor Detail
-
ZoomableGraphicsContext
public ZoomableGraphicsContext(javafx.scene.canvas.GraphicsContext gc, javafx.beans.property.DoubleProperty scale, javafx.beans.property.ReadOnlyObjectProperty<Rectangle2afp<?,?,?,?,?,?>> documentBounds, javafx.beans.property.ReadOnlyObjectProperty<Rectangle2afp<?,?,?,?,?,?>> visibleArea, javafx.beans.property.DoubleProperty canvasWidth, javafx.beans.property.DoubleProperty canvasHeight, javafx.beans.property.IntegerProperty drawableElementBudget, CenteringTransform centeringTransform)Constructor.- Parameters:
gc- the JavaFX graphics context.scale- is the scaling value.documentBounds- the bounds of the document.visibleArea- the visible part of the document.canvasWidth- width of the graphical canvas.canvasHeight- height of the graphical canvas.drawableElementBudget- the drawable element budget.centeringTransform- is the transform to apply to the points to change from/to the coordinate system from the "global" document coordinate system to/from the "centered" document coordinate system.
-
-
Method Detail
-
prepareRendering
public void prepareRendering()
Prepare the rendering by reseting the budget and the state.- See Also:
getBudget(),getState()
-
getBudget
public int getBudget()
Replies the budget.- Returns:
- the budget.
-
consumeBudget
public boolean consumeBudget()
Consume the budget.- Returns:
trueif an unit of the budget is consumed.falseif no consumption.
-
getState
public int getState()
Replies the user-defined state of the context.- Returns:
- the state.
-
setState
public void setState(int state)
Change the user-defined state of the context.- Parameters:
state- the state.
-
getLevelOfDetails
public LevelOfDetails getLevelOfDetails()
Replies the current level of details.- Returns:
- the level of details.
-
getDocumentBounds
@Pure public Rectangle2afp<?,?,?,?,?,?> getDocumentBounds()
Replies the document bounds in document coordinates.- Returns:
- the document bounds.
-
getVisibleArea
@Pure public Rectangle2afp<?,?,?,?,?,?> getVisibleArea()
Replies the bounds of the visible area in document coordinates.- Returns:
- the visible area bounds.
-
getCanvas
@Pure public ZoomableCanvas<?> getCanvas()
Gets theZoomableCanvasthat theGraphicsContextis issuing draw commands to. There is only ever oneZoomableCanvasfor aGraphicsContext.- Returns:
- Canvas the canvas that this
GraphicsContextis issuing draw commands to.
-
getWrappedGraphicsContext2D
@Pure public javafx.scene.canvas.GraphicsContext getWrappedGraphicsContext2D()
Gets theGraphicsContextthat is wrapped by this object.- Returns:
- the wrapped
GraphicsContext.
-
rgb
@Pure public javafx.scene.paint.Color rgb(int color)
Parse the given RGB color.Opacity is always
1.- Parameters:
color- the RGB color.- Returns:
- the JavaFX color.
-
rgba
@Pure public javafx.scene.paint.Color rgba(int color)
Parse the given RGBA color.- Parameters:
color- the RGBA color.- Returns:
- the JavaFX color.
-
rgba
@Pure public javafx.scene.paint.Color rgba(int rgb, double opacity)Parse the given RGBA color.- Parameters:
rgb- the RGB color.opacity- the opacity, 0 for fully transparent, 1 for fully opaque.- Returns:
- the JavaFX color.
-
rgba
@Pure public javafx.scene.paint.Color rgba(javafx.scene.paint.Color rgb, double opacity)Parse the given RGBA color. The opacity component of the given color is replaced by the given opacity.- Parameters:
rgb- the color.opacity- the opacity, 0 for fully transparent, 1 for fully opaque.- Returns:
- the JavaFX color.
- Since:
- 16.0
-
doc2fxX
@Pure public double doc2fxX(double x)
Transform a document x coordinate to its JavaFX equivalent.- Parameters:
x- the document x coordinate.- Returns:
- the JavaFX x coordinate.
-
fx2docX
@Pure public double fx2docX(double x)
Transform a JavaFX x coordinate to its document equivalent.- Parameters:
x- the document x coordinate.- Returns:
- the JavaFX x coordinate.
-
doc2fxY
@Pure public double doc2fxY(double y)
Transform a document y coordinate to its JavaFX equivalent.- Parameters:
y- the document y coordinate.- Returns:
- the JavaFX y coordinate.
-
fx2docY
@Pure public double fx2docY(double y)
Transform a JavaFX y coordinate to its document equivalent.- Parameters:
y- the JavaFX y coordinate.- Returns:
- the document y coordinate.
-
doc2fxSize
@Pure public double doc2fxSize(double size)
Transform a document size (or distance) to its JavaFX equivalent.The JavaFX size
fx_xis equal to:fx_size = size * scale- Parameters:
size- the document size.- Returns:
- the JavaFX size.
-
fx2docSize
@Pure public double fx2docSize(double size)
Transform a JavaFX size (or distance) to its document equivalent.The document size
doc_sizeis equal to:doc_size = size / scale- Parameters:
size- the JavaFX size.- Returns:
- the document size.
-
doc2fxAngle
@Pure public double doc2fxAngle(double angle)
Transform a document angle to its JavaFX equivalent.- Parameters:
angle- the document angle.- Returns:
- the JavaFX angle.
-
fx2docAngle
@Pure public double fx2docAngle(double angle)
Transform a JavaFX angle to its document equivalent.- Parameters:
angle- the JavaFX angle.- Returns:
- the document angle.
-
doc2fxRectBase
@Pure public Point2d doc2fxRectBase(double x, double y, double width, double height)
Transform a document rectangle's minimum point to its JavaFX equivalent.- Parameters:
x- the document x coordinate.y- the document y coordinate.width- the document width.height- the document height.- Returns:
- the rectangle's minimum point into the JavaFX coordinates.
- Since:
- 16.0
-
fx2docRectBase
@Pure public Point2d fx2docRectBase(double x, double y, double width, double height)
Transform a JavaFX rectangle's minimum point to its document equivalent.- Parameters:
x- the JavaFX x coordinate.y- the JavaFX y coordinate.width- the JavaFX width.height- the JavaFX height.- Returns:
- the rectangle's minimum point into the document FX coordinates.
- Since:
- 16.0
-
save
public void save()
Saves the following attributes onto a stack.- Global Alpha
- Global Blend Operation
- Transform
- Fill Paint
- Stroke Paint
- Line Width
- Line Cap
- Line Join
- Miter Limit
- Clip
- Font
- Text Align
- Text Baseline
- Effect
- Fill Rule
-
restore
public 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. If the stack is empty then nothing is changed.- Global Alpha
- Global Blend Operation
- Transform
- Fill Paint
- Stroke Paint
- Line Width
- Line Cap
- Line Join
- Miter Limit
- Clip
- Font
- Text Align
- Text Baseline
- Effect
- Fill Rule
-
translate
public void translate(double x, double y)Translates the current transform by x, y.- Parameters:
x- value to translate along the x axis.y- value to translate along the y axis.
-
scale
public void scale(double x, double y)Scales the current transform by x, y.- Parameters:
x- value to scale in the x axis.y- value to scale in the y axis.
-
rotate
public void rotate(double radians)
Rotates the current transform in radians.- Parameters:
radians- value in radians to rotate the current transform.
-
setGlobalAlpha
public void setGlobalAlpha(double alpha)
Sets the global alpha of the current state. The default value is1.0. Any valid double can be set, but only values in the range[0.0, 1.0]are valid and the nearest value in that range will be used for rendering. The global alpha is a common attribute used for nearly all rendering methods as specified in the Rendering Attributes Table ofGraphicsContext.- Parameters:
alpha- the new alpha value, clamped to[0.0, 1.0]during actual use.
-
getGlobalAlpha
public double getGlobalAlpha()
Gets the current global alpha. The default value is1.0. The global alpha is a common attribute used for nearly all rendering methods as specified in the Rendering Attributes Table ofGraphicsContext.- Returns:
- the current global alpha.
-
setGlobalBlendMode
public void setGlobalBlendMode(javafx.scene.effect.BlendMode op)
Sets the global blend mode. The default value isSRC_OVER. Anullvalue will be ignored and the current value will remain unchanged. The blend mode is a common attribute used for nearly all rendering methods as specified in the Rendering Attributes Table ofGraphicsContext.- Parameters:
op- theBlendModethat will be set or null.
-
getGlobalBlendMode
public javafx.scene.effect.BlendMode getGlobalBlendMode()
Gets the global blend mode. The default value isSRC_OVER. The blend mode is a common attribute used for nearly all rendering methods as specified in the Rendering Attributes Table ofGraphicsContext.- Returns:
- the global
BlendModeof the current state.
-
setFill
public void setFill(javafx.scene.paint.Paint paint)
Sets the current fill paint attribute. The default value isBLACK. The fill paint is a fill attribute used for any of the fill methods as specified in the Rendering Attributes Table ofGraphicsContext. Anullvalue will be ignored and the current value will remain unchanged.- Parameters:
paint- ThePaintto be used as the fillPaintor null.
-
getFill
public javafx.scene.paint.Paint getFill()
Gets the current fill paint attribute. The default value isBLACK. The fill paint is a fill attribute used for any of the fill methods as specified in the Rendering Attributes Table ofGraphicsContext.- Returns:
- The
Paintto be used as the fillPaint.
-
setStroke
public void setStroke(javafx.scene.paint.Paint paint)
Sets the current stroke paint attribute. The default value isBLACK. The stroke paint is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext. Anullvalue will be ignored and the current value will remain unchanged.- Parameters:
paint- The Paint to be used as the stroke Paint or null.
-
getStroke
public javafx.scene.paint.Paint getStroke()
Gets the current stroke. The default value isBLACK. The stroke paint is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext.- Returns:
- the
Paintto be used as the strokePaint.
-
setLineWidthInPixels
public void setLineWidthInPixels(double lw)
Sets the current line width in pixels. The default value is1.0. The line width is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext. An infinite or non-positive value outside of the range(0, +inf)will be ignored and the current value will remain unchanged.- Parameters:
lw- pixel value in the range {0-positive infinity}, with any other value being ignored and leaving the value unchanged.- See Also:
setLineWidthInMeters(double)
-
setLineWidthInMeters
public void setLineWidthInMeters(double lw)
Sets the current line width in meters. The default value is1.0 * scale. The line width is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext. An infinite or non-positive value outside of the range(0, +inf)will be ignored and the current value will remain unchanged.- Parameters:
lw- metric value in the range {0-positive infinity}, with any other value being ignored and leaving the value unchanged.- See Also:
setLineWidthInPixels(double)
-
getLineWidthInPixels
public double getLineWidthInPixels()
Gets the current line width in pixels. The default value is1.0. The line width is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext.- Returns:
- pixel value between 0 and infinity.
- See Also:
getLineWidthInMeters()
-
getLineWidthInMeters
public double getLineWidthInMeters()
Gets the current line width in meters. The default value is1.0. The line width is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext.- Returns:
- metric value between 0 and infinity.
- See Also:
getLineWidthInPixels()
-
setLineCap
public void setLineCap(javafx.scene.shape.StrokeLineCap cap)
Sets the current stroke line cap. The default value isSQUARE. The line cap is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext. Anullvalue will be ignored and the current value will remain unchanged.- Parameters:
cap-StrokeLineCapwith a value of Butt, Round, or Square or null.
-
getLineCap
public javafx.scene.shape.StrokeLineCap getLineCap()
Gets the current stroke line cap. The default value isSQUARE. The line cap is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext.- Returns:
StrokeLineCapwith a value of Butt, Round, or Square.
-
setLineJoin
public void setLineJoin(javafx.scene.shape.StrokeLineJoin join)
Sets the current stroke line join. The default value isStrokeLineJoin.MITER. The line join is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext. Anullvalue will be ignored and the current value will remain unchanged.- Parameters:
join-StrokeLineJoinwith a value of Miter, Bevel, or Round or null.
-
getLineJoin
public javafx.scene.shape.StrokeLineJoin getLineJoin()
Gets the current stroke line join. The default value isStrokeLineJoin.MITER. The line join is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext.- Returns:
StrokeLineJoinwith a value of Miter, Bevel, or Round.
-
setMiterLimitInPixels
public void setMiterLimitInPixels(double ml)
Sets the current miter limit in pixels. The default value is10.0. The miter limit is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext. An infinite or non-positive value outside of the range(0, +inf)will be ignored and the current value will remain unchanged.- Parameters:
ml- pixel miter limit value between 0 and positive infinity with any other value being ignored and leaving the value unchanged.- See Also:
setMiterLimitInMeters(double)
-
setMiterLimitInMeters
public void setMiterLimitInMeters(double ml)
Sets the current miter limit in meters. The default value is10.0 * scale. The miter limit is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext. An infinite or non-positive value outside of the range(0, +inf)will be ignored and the current value will remain unchanged.- Parameters:
ml- metric miter limit value between 0 and positive infinity with any other value being ignored and leaving the value unchanged.- See Also:
setMiterLimitInPixels(double)
-
getMiterLimitInPixels
public double getMiterLimitInPixels()
Gets the current miter limit in pixels. The default value is10.0. The miter limit is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext.- Returns:
- the pixel miter limit value in the range
0.0-positive infinity - See Also:
getMiterLimitInMeters()
-
getMiterLimitInMeters
public double getMiterLimitInMeters()
Gets the current miter limit in meters. The default value is10.0 * scale. The miter limit is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext.- Returns:
- the metric miter limit value in the range
0.0-positive infinity
-
setLineDashesInPixels
public void setLineDashesInPixels(double... dashes)
Sets the current stroke line dash pattern in pixels to a normalized copy of the argument. The default value isnull. The line dash array is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext. If the array isnullor empty or contains all0elements then dashing will be disabled and the current dash array will be set tonull. If any of the elements of the array are a negative, infinite, or NaN value outside the range[0, +inf)then the entire array will be ignored and the current dash array will remain unchanged. If the array is an odd length then it will be treated as if it were two copies of the array appended to each other.- Parameters:
dashes- the array of finite non-negative dash lengths.- See Also:
setLineDashesInMeters(double...)
-
setLineDashesInMeters
public void setLineDashesInMeters(double... dashes)
Sets the current stroke line dash pattern in meters to a normalized copy of the argument. The default value isnull. The line dash array is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext. If the array isnullor empty or contains all0elements then dashing will be disabled and the current dash array will be set tonull. If any of the elements of the array are a negative, infinite, or NaN value outside the range[0, +inf)then the entire array will be ignored and the current dash array will remain unchanged. If the array is an odd length then it will be treated as if it were two copies of the array appended to each other.- Parameters:
dashes- the array of finite non-negative dash lengths- See Also:
setLineDashesInPixels(double...)
-
getLineDashesInPixels
public double[] getLineDashesInPixels()
Gets a copy of the current line dash array in pixels. The default value isnull. The array may be normalized by the validation tests in thesetLineDashesInPixels(double...)method. The line dash array is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext.- Returns:
- a copy of the current line dash array.
- See Also:
getLineDashesInMeters()
-
getLineDashesInMeters
public double[] getLineDashesInMeters()
Gets a copy of the current line dash array in meters. The default value isnull. The array may be normalized by the validation tests in thesetLineDashesInMeters(double...)method. The line dash array is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext.- Returns:
- a copy of the current line dash array.
- See Also:
getLineDashesInPixels()
-
setLineDashOffsetInPixels
public void setLineDashOffsetInPixels(double dashOffset)
Sets the line dash offset in pixels. The default value is0.0. The line dash offset is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext. An infinite or NaN value outside of the range(-inf, +inf)will be ignored and the current value will remain unchanged.- Parameters:
dashOffset- the line dash offset in the range(-inf, +inf)- See Also:
setLineDashOffsetInMeters(double)
-
setLineDashOffsetInMeters
public void setLineDashOffsetInMeters(double dashOffset)
Sets the line dash offset in meters. The default value is0.0 * scale. The line dash offset is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext. An infinite or NaN value outside of the range(-inf, +inf)will be ignored and the current value will remain unchanged.- Parameters:
dashOffset- the line dash offset in the range(-inf, +inf)- See Also:
setLineDashOffsetInPixels(double)
-
getLineDashOffsetInPixels
public double getLineDashOffsetInPixels()
Gets the current line dash offset in pixels. The default value is0.0. The line dash offset is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext.- Returns:
- the line dash offset in the range
(-inf, +inf) - See Also:
getLineDashOffsetInMeters()
-
getLineDashOffsetInMeters
public double getLineDashOffsetInMeters()
Gets the current line dash offset in meters. The default value is0.0. The line dash offset is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table ofGraphicsContext.- Returns:
- the line dash offset in the range
(-inf, +inf) - See Also:
getLineDashOffsetInPixels()
-
setFont
public void setFont(javafx.scene.text.Font font)
Sets the current Font. The default value is specified byFont.getDefault(). The font is a text attribute used for any of the text methods as specified in the Rendering Attributes Table ofGraphicsContext. Anullvalue will be ignored and the current value will remain unchanged.- Parameters:
font- the Font or null.
-
getFont
public javafx.scene.text.Font getFont()
Gets the current Font. The default value is specified byFont.getDefault(). The font is a text attribute used for any of the text methods as specified in the Rendering Attributes Table ofGraphicsContext.- Returns:
- the Font
-
setFontSmoothingType
public void setFontSmoothingType(javafx.scene.text.FontSmoothingType fontsmoothing)
Sets the current Font Smoothing Type. The default value isGRAY. The font smoothing type is a text attribute used for any of the text methods as specified in the Rendering Attributes Table ofGraphicsContext. Anullvalue will be ignored and the current value will remain unchanged.Note that the
FontSmoothingTypevalue ofLCDis only supported over an opaque background.LCDtext will generally appear asGRAYtext over transparent or partially transparent pixels, and in some implementations it may not be supported at all on aCanvasbecause the required support does not exist for surfaces which contain an alpha channel as allCanvasobjects do.- Parameters:
fontsmoothing- theFontSmoothingTypeor null
-
getFontSmoothingType
public javafx.scene.text.FontSmoothingType getFontSmoothingType()
Gets the current Font Smoothing Type. The default value isGRAY. The font smoothing type is a text attribute used for any of the text methods as specified in the Rendering Attributes Table ofGraphicsContext.- Returns:
- the
FontSmoothingType
-
setTextAlign
public void setTextAlign(javafx.scene.text.TextAlignment align)
Defines horizontal text alignment, relative to the textxorigin. The default value isLEFT. The text alignment is a text attribute used for any of the text methods as specified in the Rendering Attributes Table ofGraphicsContext.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:
- Left: the left edge of the horizontal bounds will be at
x. - Center: the center, halfway between left and right edge, of the
horizontal bounds will be at
x. - Right: the right edge of the horizontal bounds will be at
x.
Note: Canvas does not support line wrapping, therefore the text alignment Justify is identical to left aligned text.
A
nullvalue will be ignored and the current value will remain unchanged.- Parameters:
align-TextAlignmentwith values of Left, Center, Right or null.
- Left: the left edge of the horizontal bounds will be at
-
getTextAlign
public javafx.scene.text.TextAlignment getTextAlign()
Gets the currentTextAlignment. The default value isLEFT. The text alignment is a text attribute used for any of the text methods as specified in the Rendering Attributes Table ofGraphicsContext.- Returns:
TextAlignmentwith values of Left, Center, Right, or Justify.
-
setTextBaseline
public void setTextBaseline(javafx.geometry.VPos baseline)
Sets the current Text Baseline. The default value isBASELINE. The text baseline is a text attribute used for any of the text methods as specified in the Rendering Attributes Table ofGraphicsContext. Anullvalue will be ignored and the current value will remain unchanged.- Parameters:
baseline-VPoswith values of Top, Center, Baseline, or Bottom or null.
-
getTextBaseline
public javafx.geometry.VPos getTextBaseline()
Gets the current Text Baseline. The default value isBASELINE. The text baseline is a text attribute used for any of the text methods as specified in the Rendering Attributes Table ofGraphicsContext.- Returns:
VPoswith values of Top, Center, Baseline, or Bottom
-
fillText
public void fillText(String text, double x, double y)
Fills the given string of text at position x, y with the current fill paint attribute. Anulltext value will be ignored.This method will be affected by any of the global common, fill, or text attributes as specified in the Rendering Attributes Table of
GraphicsContext.- Parameters:
text- the string of text or null.x- position on the x axis.y- position on the y axis.
-
fillText
public void fillText(String text, double x, double y, double maxWidth)
Fills text and includes a maximum width of the string. If the width of the text extends past max width, then it will be sized to fit. Anulltext value will be ignored.This method will be affected by any of the global common, fill, or text attributes as specified in the Rendering Attributes Table of
GraphicsContext.- Parameters:
text- the string of text or null.x- position on the x axis.y- position on the y axis.maxWidth- maximum width the text string can have.
-
strokeText
public void strokeText(String text, double x, double y)
Draws the given string of text at position x, y with the current stroke paint attribute. Anulltext value will be ignored.This method will be affected by any of the global common, stroke, or text attributes as specified in the Rendering Attributes Table of
GraphicsContext.- Parameters:
text- the string of text or null.x- position on the x axis.y- position on the y axis.
-
strokeText
public void strokeText(String text, double x, double y, double maxWidth)
Draws text with stroke paint and includes a maximum width of the string. If the width of the text extends past max width, then it will be sized to fit. Anulltext value will be ignored.This method will be affected by any of the global common, stroke, or text attributes as specified in the Rendering Attributes Table of
GraphicsContext.- Parameters:
text- the string of text or null.x- position on the x axis.y- position on the y axis.maxWidth- maximum width the text string can have.
-
setFillRule
public void setFillRule(javafx.scene.shape.FillRule fillRule)
Set the filling rule attribute for determining the interior of paths in fill or clip operations. The default value isFillRule.NON_ZERO. Anullvalue will be ignored and the current value will remain unchanged. The fill rule is a path attribute used for any of the fill or clip path methods as specified in the Rendering Attributes Table ofGraphicsContext.- Parameters:
fillRule-FillRulewith a value of Even_odd or Non_zero or null.
-
getFillRule
public javafx.scene.shape.FillRule getFillRule()
Get the filling rule attribute for determining the interior of paths in fill and clip operations. The default value isFillRule.NON_ZERO. The fill rule is a path attribute used for any of the fill or clip path methods as specified in the Rendering Attributes Table ofGraphicsContext.- Returns:
- current fill rule.
-
beginPath
public void beginPath()
-
moveTo
public void moveTo(double x0, double y0)Issues a move command for the current path to the given x,y coordinate. The coordinates are transformed by the current transform as they are added to the path and unaffected by subsequent changes to the transform. The current path is a path attribute used for any of the path methods as specified in the Rendering Attributes Table ofGraphicsContextand is not affected by thesave()andrestore()operations.- Parameters:
x0- the X position for the move to command.y0- the Y position for the move to command.
-
lineTo
public void lineTo(double x1, double y1)Adds segments to the current path to make a line to the given x,y coordinate. The coordinates are transformed by the current transform as they are added to the path and unaffected by subsequent changes to the transform. The current path is a path attribute used for any of the path methods as specified in the Rendering Attributes Table ofGraphicsContextand is not affected by thesave()andrestore()operations.- Parameters:
x1- the X coordinate of the ending point of the line.y1- the Y coordinate of the ending point of the line.
-
quadraticCurveTo
public void quadraticCurveTo(double xc, double yc, double x1, double y1)Adds segments to the current path to make a quadratic Bezier curve. The coordinates are transformed by the current transform as they are added to the path and unaffected by subsequent changes to the transform. The current path is a path attribute used for any of the path methods as specified in the Rendering Attributes Table ofGraphicsContextand is not affected by thesave()andrestore()operations.- Parameters:
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 point
-
bezierCurveTo
public 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. The coordinates are transformed by the current transform as they are added to the path and unaffected by subsequent changes to the transform. The current path is a path attribute used for any of the path methods as specified in the Rendering Attributes Table ofGraphicsContextand is not affected by thesave()andrestore()operations.- Parameters:
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.
-
arcTo
public void arcTo(double x1, double y1, double x2, double y2, double radius)Adds segments to the current path to make an arc. The coordinates are transformed by the current transform as they are added to the path and unaffected by subsequent changes to the transform. The current path is a path attribute used for any of the path methods as specified in the Rendering Attributes Table ofGraphicsContextand is not affected by thesave()andrestore()operations.If
p0is the current point in the path andp1is the point specified by(x1, y1)andp2is the point specified by(x2, y2), then the arc segments appended will be segments along the circumference of a circle of the specified radius touching and inscribed into the convex (interior) side ofp0->p1->p2. The path will contain a line segment (if needed) to the tangent point between that circle andp0->p1followed by circular arc segments to reach the tangent point between the circle andp1->p2and will end with the current point at that tangent point (not atp2). Note that the radius and circularity of the arc segments will be measured or considered relative to the current transform, but the resulting segments that are computed from those untransformed points will then be transformed when they are added to the path. Since all computation is done in untransformed space, but the pre-existing path segments are all transformed, the ability to correctly perform the computation may implicitly depend on being able to inverse transform the current end of the current path back into untransformed coordinates.If there is no way to compute and inscribe the indicated circle for any reason then the entire operation will simply append segments to force a line to point
p1. Possible reasons that the computation may fail include:- The current path is empty.
- The segments
p0->p1->p2are colinear. - the current transform is non-invertible so that the current end point of the current path cannot be untransformed for computation.
- Parameters:
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}.
-
arc
public 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 radians. This Euclidean orientation sweeps from East to North, then West, then South, then back to East. The coordinates are transformed by the current transform as they are added to the path and unaffected by subsequent changes to the transform. The current path is a path attribute used for any of the path methods as specified in the Rendering Attributes Table ofGraphicsContextand is not affected by thesave()andrestore()operations.- Parameters:
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 range0-2PIlength- the length of the baseline of the arc.
-
rect
public void rect(double x, double y, double width, double height)Adds path elements to the current path to make a rectangle. The coordinates are transformed by the current transform as they are added to the path and unaffected by subsequent changes to the transform. The current path is a path attribute used for any of the path methods as specified in the Rendering Attributes Table ofGraphicsContextand is not affected by thesave()andrestore()operations.- Parameters:
x- x position of the upper left corner of the rectangle.y- y position of the upper left corner of the rectangle.width- width of the rectangle.height- height of the rectangle.
-
closePath
public void closePath()
-
fill
public void fill()
Fills the path with the current fill paint.This method will be affected by any of the global common, fill, or path attributes as specified in the Rendering Attributes Table of
GraphicsContext. Note that the path segments were transformed as they were originally added to the current path so the current transform will not affect those path segments again, but it may affect other attributes in affect at the time of thefill()operation.
-
stroke
public void stroke()
Strokes the path with the current stroke paint.This method will be affected by any of the global common, stroke, or path attributes as specified in the Rendering Attributes Table of
GraphicsContext. Note that the path segments were transformed as they were originally added to the current path so the current transform will not affect those path segments again, but it may affect other attributes in affect at the time of thestroke()operation.
-
clip
public void clip()
Intersects the current clip with the current path and applies it to subsequent rendering operation as an anti-aliased mask. The current clip is a common attribute used for nearly all rendering operations as specified in the Rendering Attributes Table ofGraphicsContext.This method will itself be affected only by the path attributes as specified in the Rendering Attributes Table of
GraphicsContext. Note that the path segments were transformed as they were originally added to the current path so the current transform will not affect those path segments again, but it may affect other attributes in affect at the time of thestroke()operation.
-
clearRect
public void clearRect(double x, double y, double width, double height)Clears a portion of the canvas with a transparent color value.This method will be affected only by the current transform, clip, and effect.
- Parameters:
x- X position of the upper left corner of the rectangle.y- Y position of the upper left corner of the rectangle.width- width of the rectangle.height- height of the rectangle.
-
fillRect
public void fillRect(double x, double y, double width, double height)Fills a rectangle using the current fill paint.This method will be affected by any of the global common or fill attributes as specified in the Rendering Attributes Table of
GraphicsContext.- Parameters:
x- the X position of the upper left corner of the rectangle.y- the Y position of the upper left corner of the rectangle.width- the width of the rectangle.height- the height of the rectangle.
-
strokeRect
public void strokeRect(double x, double y, double width, double height)Strokes a rectangle using the current stroke paint.This method will be affected by any of the global common or stroke attributes as specified in the Rendering Attributes Table of
GraphicsContext.- Parameters:
x- the X position of the upper left corner of the rectangle.y- the Y position of the upper left corner of the rectangle.width- the width of the rectangle.height- the height of the rectangle.
-
fillOval
public void fillOval(double x, double y, double width, double height)Fills an oval using the current fill paint.This method will be affected by any of the global common or fill attributes as specified in the Rendering Attributes Table of
GraphicsContext.- Parameters:
x- the X coordinate of the upper left bound of the oval.y- the Y coordinate of the upper left bound of the oval.width- the width at the center of the oval.height- the height at the center of the oval.
-
strokeOval
public void strokeOval(double x, double y, double width, double height)Strokes an oval using the current stroke paint.This method will be affected by any of the global common or stroke attributes as specified in the Rendering Attributes Table of
GraphicsContext.- Parameters:
x- the X coordinate of the upper left bound of the oval.y- the Y coordinate of the upper left bound of the oval.width- the width at the center of the oval.height- the height at the center of the oval.
-
fillArc
public void fillArc(double x, double y, double width, double height, double startAngle, double arcExtent, javafx.scene.shape.ArcType closure)Fills an arc using the current fill paint. AnullArcType or non positive width or height will cause the render command to be ignored.This method will be affected by any of the global common or fill attributes as specified in the Rendering Attributes Table of
GraphicsContext.- Parameters:
x- the X coordinate of the arc.y- the Y coordinate of the arc.width- the width of the arc.height- the height of the arc.startAngle- the starting angle of the arc in radians.arcExtent- the angular extent of the arc in radians.closure- closure type (Round, Chord, Open) or null.
-
strokeArc
public void strokeArc(double x, double y, double width, double height, double startAngle, double arcExtent, javafx.scene.shape.ArcType closure)Strokes an Arc using the current stroke paint. AnullArcType or non positive width or height will cause the render command to be ignored.This method will be affected by any of the global common or stroke attributes as specified in the Rendering Attributes Table of
GraphicsContext.- Parameters:
x- the X coordinate of the arc.y- the Y coordinate of the arc.width- the width of the arc.height- the height of the arc.startAngle- the starting angle of the arc in radians.arcExtent- arcExtent the angular extent of the arc in radians.closure- closure type (Round, Chord, Open) or null
-
fillRoundRect
public void fillRoundRect(double x, double y, double width, double height, double arcWidth, double arcHeight)Fills a rounded rectangle using the current fill paint.This method will be affected by any of the global common or fill attributes as specified in the Rendering Attributes Table of
GraphicsContext.- Parameters:
x- the X coordinate of the upper left bound of the oval.y- the Y coordinate of the upper left bound of the oval.width- the width at the center of the oval.height- the height at the center of the oval.arcWidth- the arc width of the rectangle corners.arcHeight- the arc height of the rectangle corners.
-
strokeRoundRect
public void strokeRoundRect(double x, double y, double width, double height, double arcWidth, double arcHeight)Strokes a rounded rectangle using the current stroke paint.This method will be affected by any of the global common or stroke attributes as specified in the Rendering Attributes Table of
GraphicsContext.- Parameters:
x- the X coordinate of the upper left bound of the oval.y- the Y coordinate of the upper left bound of the oval.width- the width at the center of the oval.height- the height at the center of the oval.arcWidth- the arc width of the rectangle corners.arcHeight- the arc height of the rectangle corners.
-
strokeLine
public void strokeLine(double x1, double y1, double x2, double y2)Strokes a line using the current stroke paint.This method will be affected by any of the global common or stroke attributes as specified in the Rendering Attributes Table of
GraphicsContext.- Parameters:
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.
-
drawImage
public void drawImage(javafx.scene.image.Image img, double x, double y)Draws an image at the given x, y position using the width and height of the given image. Anullimage value or an image still in progress will be ignored.This method will be affected by any of the global common attributes as specified in the Rendering Attributes Table of
GraphicsContext.- Parameters:
img- the image to be drawn or null.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.
-
drawImage
public void drawImage(javafx.scene.image.Image img, double x, double y, double width, double height)Draws an image into the given destination rectangle of the canvas. The Image is scaled to fit into the destination rectangle. Anullimage value or an image still in progress will be ignored.This method will be affected by any of the global common attributes as specified in the Rendering Attributes Table of
GraphicsContext.- Parameters:
img- the image to be drawn or null.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.width- the width of the destination rectangle.height- the height of the destination rectangle.
-
drawImage
public void drawImage(javafx.scene.image.Image img, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh)Draws the specified source rectangle of the given image to the given destination rectangle of the Canvas. Anullimage value or an image still in progress will be ignored.This method will be affected by any of the global common attributes as specified in the Rendering Attributes Table of
GraphicsContext.- Parameters:
img- the image to be drawn or null.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.
-
getPixelWriter
public javafx.scene.image.PixelWriter getPixelWriter()
Returns aPixelWriterobject that can be used to modify the pixels of theCanvasassociated with thisGraphicsContext. All coordinates in thePixelWritermethods on the returned object will be in device space since they refer directly to pixels and no other rendering attributes will be applied when modifying pixels using this object.- Returns:
- the
PixelWriterfor modifying the pixels of thisCanvas
-
setEffect
public void setEffect(javafx.scene.effect.Effect effect)
Sets the effect to be applied after the next draw call, or null to disable effects. The current effect is a common attribute used for nearly all rendering operations as specified in the Rendering Attributes Table ofGraphicsContext.- Parameters:
effect- the effect to use, or null to disable effects
-
getEffect
public javafx.scene.effect.Effect getEffect(javafx.scene.effect.Effect effect)
Gets a copy of the effect to be applied after the next draw call. A null return value means that no effect will be applied after subsequent rendering calls. The current effect is a common attribute used for nearly all rendering operations as specified in the Rendering Attributes Table ofGraphicsContext.- Parameters:
effect- anEffectobject that may be used to store the copy of the current effect, if it is of a compatible type- Returns:
- the current effect used for all rendering calls, or null if there is no current effect
-
applyEffect
public void applyEffect(javafx.scene.effect.Effect effect)
Applies the given effect to the entire bounds of the canvas and stores the result back into the same canvas. Anullvalue will be ignored. The effect will be applied without any other rendering attributes and under an Identity coordinate transform. Since the effect is applied to the entire bounds of the canvas, some effects may have a confusing result, such as a Reflection effect that will apply its reflection off of the bottom of the canvas even if only a portion of the canvas has been rendered to and will not be visible unless a negative offset is used to bring the reflection back into view.- Parameters:
effect- the effect to apply onto the entire destination or null.
-
-