public class TransformPainter extends Object
TransformPainter
class offers a set of static methods to render elements (image, renderable
character) with a transformation.
The transformation (rotate, scale etc.) is applied during the drawing: the source element is not updated (for instance the source image is not rotated: this is its rendering on the graphics context which is rotated).
Modifier and Type | Class and Description |
---|---|
static class |
TransformPainter.Flip
Specify the flip to apply when drawing an image.
|
Constructor and Description |
---|
TransformPainter() |
Modifier and Type | Method and Description |
---|---|
static void |
drawDeformedImage(GraphicsContext gc,
Image image,
int x,
int y,
int[] xys)
Draws a deformed image at the given anchor top-left point.
The deformed image is identified by its four corner points. |
static void |
drawFlippedImage(GraphicsContext gc,
Image image,
int x,
int y,
TransformPainter.Flip flip)
Draws the image in the graphics context at given anchor top-left position, using the given flip.
|
static void |
drawFlippedImage(GraphicsContext gc,
Image image,
int x,
int y,
TransformPainter.Flip flip,
int alpha)
Draws the image in the graphics context at given anchor top-left position, using the given flip and opacity
level.
|
static void |
drawRotatedCharBilinear(GraphicsContext gc,
Font font,
char c,
int x,
int y,
int rx,
int ry,
float angle)
Draws the character applying the given rotation.
|
static void |
drawRotatedCharBilinear(GraphicsContext gc,
Font font,
char c,
int x,
int y,
int rx,
int ry,
float angle,
int alpha)
Draws the character applying the given rotation and opacicity level.
|
static void |
drawRotatedCharNearestNeighbor(GraphicsContext gc,
Font font,
char c,
int x,
int y,
int rx,
int ry,
float angle)
Draws the character applying the given rotation.
|
static void |
drawRotatedCharNearestNeighbor(GraphicsContext gc,
Font font,
char c,
int x,
int y,
int rx,
int ry,
float angle,
int alpha)
Draws the character applying the given rotation and opacity level.
|
static void |
drawRotatedImageBilinear(GraphicsContext gc,
Image image,
int x,
int y,
int rx,
int ry,
float angle)
Draws the image applying the given rotation.
|
static void |
drawRotatedImageBilinear(GraphicsContext gc,
Image image,
int x,
int y,
int rx,
int ry,
float angle,
int alpha)
Draws the image applying the given rotation fixing the opacity level.
|
static void |
drawRotatedImageNearestNeighbor(GraphicsContext gc,
Image image,
int x,
int y,
int rx,
int ry,
float angle)
Draws the image applying the given rotation.
|
static void |
drawRotatedImageNearestNeighbor(GraphicsContext gc,
Image image,
int x,
int y,
int rx,
int ry,
float angle,
int alpha)
Draws the image applying the given rotation and opacity level.
|
static void |
drawScaledCharBilinear(GraphicsContext gc,
char character,
Font font,
int x,
int y,
float factorX,
float factorY)
Draws the character in the graphics context at given anchor top-left position and using the given scaling factor.
|
static void |
drawScaledImageBilinear(GraphicsContext gc,
Image image,
int x,
int y,
float factorX,
float factorY)
Draws the image in the graphics context at given anchor top-left position and using the given scaling factor.
|
static void |
drawScaledImageBilinear(GraphicsContext gc,
Image image,
int x,
int y,
float factorX,
float factorY,
int alpha)
Draws the image in the graphics context at given anchor top-left position and using the given scaling factor and
opacity level.
|
static void |
drawScaledImageNearestNeighbor(GraphicsContext gc,
Image image,
int x,
int y,
float factorX,
float factorY)
Draws the image in the graphics context at given anchor top-left position and using the given scaling factor.
|
static void |
drawScaledImageNearestNeighbor(GraphicsContext gc,
Image image,
int x,
int y,
float factorX,
float factorY,
int alpha)
Draws the image in the graphics context at given anchor top-left position and using the given scaling factor and
opacity level.
|
static void |
drawScaledRenderableStringBilinear(GraphicsContext gc,
RenderableString string,
int x,
int y,
float factorX,
float factorY)
Draws the renderable string in the graphics context at given anchor top-left position and using the given scaling
factor.
|
static void |
drawScaledStringBilinear(GraphicsContext gc,
String string,
Font font,
int x,
int y,
float factorX,
float factorY)
Draws the string in the graphics context at given anchor top-left position and using the given scaling factor.
|
static void |
drawScaledSubstringBilinear(GraphicsContext gc,
String string,
int offset,
int length,
Font font,
int x,
int y,
float factorX,
float factorY)
Draws the substring in the graphics context at given anchor top-left position and using the given scaling factor.
|
public static void drawFlippedImage(GraphicsContext gc, Image image, int x, int y, TransformPainter.Flip flip)
Equivalent to calling drawFlippedImage(GraphicsContext, Image, int, int, Flip, int)
with
GraphicsContext.OPAQUE
as alpha.
gc
- the graphics context where to render the drawing.image
- the image to drawx
- the x coordinate of the image reference anchor top-left pointy
- the y coordinate of the image reference anchor top-left pointflip
- the flip to apply.public static void drawFlippedImage(GraphicsContext gc, Image image, int x, int y, TransformPainter.Flip flip, int alpha)
In addition with drawFlippedImage(GraphicsContext, Image, int, int, Flip)
, this method allows to specify
the global opacity value to apply during the image rendering.
gc
- the graphics context where to render the drawing.image
- the image to drawx
- the x coordinate of the image reference anchor top-left pointy
- the y coordinate of the image reference anchor top-left pointflip
- the flip to apply.alpha
- the global opacity rendering value.IllegalArgumentException
- if the given alpha is not a value between GraphicsContext.TRANSPARENT
and
GraphicsContext.OPAQUE
.public static void drawDeformedImage(GraphicsContext gc, Image image, int x, int y, int[] xys)
gc
- the graphics context where to render the drawing.image
- the image to drawx
- the x coordinate of the anchor top-left pointy
- the y coordinate of the anchor top-left pointxys
- the array of coordinates : x1,y1,x2,y2,x3,y3,x4,y4.IllegalArgumentException
- if the @{code xys} length is different than 2*4.public static void drawRotatedImageBilinear(GraphicsContext gc, Image image, int x, int y, int rx, int ry, float angle)
bilinear
algorithm to render the
content. This algorithm performs better rendering than nearest neighbor
algorithm but it is slower
to apply.
The rotation is specified by the center and the angle. The reference point is the graphical object top-left corner. The rotation point is relative to the current translation of the graphics context where the graphical object will be drawn.
To rotate an image on itself, use the following lines:
int rx = x + image.getWidth() / 2;
int ry = y + image.getHeight() / 2;
TransformPainter.drawRotatedImageBilinear(gc, image, x, y, rx, ry, 78);
To rotate an image around a circle, use the following lines:
for (int i = 0; i < 360; i += 45) {
TransformPainter.drawRotatedImageBilinear(gc, image, rx - diameter / 2, ry - diameter / 2, rx, ry, i);
}
Equivalent to calling drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float, int)
with GraphicsContext.OPAQUE
as alpha.
gc
- the graphics context where to render the drawing.image
- the image to draw.x
- the x coordinate of the image reference anchor top-left pointy
- the y coordinate of the image reference anchor top-left pointrx
- the rotation center X coordinate.ry
- the rotation center Y coordinate.angle
- the rotation angle.drawRotatedImageNearestNeighbor(GraphicsContext, Image, int, int, int, int, float)
public static void drawRotatedImageBilinear(GraphicsContext gc, Image image, int x, int y, int rx, int ry, float angle, int alpha)
bilinear
algorithm to render the content. This algorithm performs better rendering than nearest neighbor
algorithm but it is slower to apply.
Some rotation samples are described in method comment
drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float)
.
In addition with drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float)
, this
method allows to specify the global opacity value to apply during the image rendering.
gc
- the graphics context where to render the drawing.image
- the image to draw.x
- the x coordinate of the image reference anchor top-left pointy
- the y coordinate of the image reference anchor top-left pointrx
- the rotation center X coordinate.ry
- the rotation center Y coordinate.angle
- the rotation angle.alpha
- the global opacity rendering value.IllegalArgumentException
- if the given alpha is not a value between GraphicsContext.TRANSPARENT
and
GraphicsContext.OPAQUE
.drawRotatedImageNearestNeighbor(GraphicsContext, Image, int, int, int, int, float, int)
public static void drawRotatedImageNearestNeighbor(GraphicsContext gc, Image image, int x, int y, int rx, int ry, float angle)
nearest neighbor
algorithm to
render the content. This algorithm is faster than bilinear
algorithm but its rendering is more
simple.
Some rotation samples are described in method comment
drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float)
.
Equivalent to calling
drawRotatedImageNearestNeighbor(GraphicsContext, Image, int, int, int, int, float, int)
with
GraphicsContext.OPAQUE
as alpha.
gc
- the graphics context where render the drawing.image
- the image to draw.x
- the x coordinate of the image reference anchor top-left pointy
- the y coordinate of the image reference anchor top-left pointrx
- the rotation center X coordinate.ry
- the rotation center Y coordinate.angle
- the rotation angle.drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float)
public static void drawRotatedImageNearestNeighbor(GraphicsContext gc, Image image, int x, int y, int rx, int ry, float angle, int alpha)
nearest neighbor
algorithm to render the content. This algorithm is faster than bilinear
algorithm but its rendering
is more simple.
Some rotation samples are described in method comment
drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float)
.
In addition with drawRotatedImageNearestNeighbor(GraphicsContext, Image, int, int, int, int, float)
,
this method allows to specify the global opacity value to apply during the image rendering.
gc
- the graphics context where render the drawing.image
- the image to draw.x
- the x coordinate of the image reference anchor top-left pointy
- the y coordinate of the image reference anchor top-left pointrx
- the rotation center X coordinate.ry
- the rotation center Y coordinate.angle
- the rotation angle.alpha
- the global opacity rendering value.IllegalArgumentException
- if the given alpha is not a value between GraphicsContext.TRANSPARENT
and
GraphicsContext.OPAQUE
.drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float, int)
public static void drawRotatedCharBilinear(GraphicsContext gc, Font font, char c, int x, int y, int rx, int ry, float angle)
bilinear
algorithm to render
the content. This algorithm performs better rendering than nearest neighbor
algorithm but it is
slower to apply.
This method only supports characters in the range U+0000 to U+FFFF. It does not handle characters with code points greater than U+FFFF, which are represented as a pair of char values (referred to as "surrogate pair").
Some rotation samples are described in method comment
drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float)
.
Equivalent to calling
drawRotatedCharBilinear(GraphicsContext, Font, char, int, int, int, int, float, int)
with
GraphicsContext.OPAQUE
as alpha.
gc
- the graphics context where to render the drawing.font
- the font to use.c
- the character to draw.x
- the x coordinate of the character reference anchor top-left pointy
- the y coordinate of the character reference anchor top-left pointrx
- the rotation center X coordinate.ry
- the rotation center Y coordinate.angle
- the rotation angle.drawRotatedCharNearestNeighbor(GraphicsContext, Font, char, int, int, int, int, float)
public static void drawRotatedCharBilinear(GraphicsContext gc, Font font, char c, int x, int y, int rx, int ry, float angle, int alpha)
bilinear
algorithm to render the content. This algorithm performs better rendering than nearest neighbor
algorithm but it is slower to apply.
This method only supports characters in the range U+0000 to U+FFFF. It does not handle characters with code points greater than U+FFFF, which are represented as a pair of char values (referred to as "surrogate pair").
Some rotation samples are described in method comment
drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float)
.
In addition with drawRotatedCharBilinear(GraphicsContext, Font, char, int, int, int, int, float)
, this
method allows to specify the global opacity value to apply during the image rendering.
gc
- the graphics context where to render the drawing.font
- the font to use.c
- the character to draw.x
- the x coordinate of the character reference anchor top-left pointy
- the y coordinate of the character reference anchor top-left pointrx
- the rotation center X coordinate.ry
- the rotation center Y coordinate.angle
- the rotation angle.alpha
- the global opacity rendering value.IllegalArgumentException
- if the given alpha is not a value between GraphicsContext.TRANSPARENT
and
GraphicsContext.OPAQUE
.drawRotatedCharNearestNeighbor(GraphicsContext, Font, char, int, int, int, int, float, int)
public static void drawRotatedCharNearestNeighbor(GraphicsContext gc, Font font, char c, int x, int y, int rx, int ry, float angle)
nearest neighbor
algorithm to
render the content. This algorithm is faster than bilinear
algorithm but its rendering is more
simple.
This method only supports characters in the range U+0000 to U+FFFF. It does not handle characters with code points greater than U+FFFF, which are represented as a pair of char values (referred to as "surrogate pair").
Some rotation samples are described in method comment
drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float)
.
Equivalent to calling
drawRotatedCharNearestNeighbor(GraphicsContext, Font, char, int, int, int, int, float, int)
with
GraphicsContext.OPAQUE
as alpha.
gc
- the graphics context where render the drawing.font
- the font to use.c
- the character to draw.x
- the x coordinate of the character reference anchor top-left pointy
- the y coordinate of the character reference anchor top-left pointrx
- the rotation center X coordinate.ry
- the rotation center Y coordinate.angle
- the rotation angle.drawRotatedCharBilinear(GraphicsContext, Font, char, int, int, int, int, float)
public static void drawRotatedCharNearestNeighbor(GraphicsContext gc, Font font, char c, int x, int y, int rx, int ry, float angle, int alpha)
nearest neighbor
algorithm to render the content. This algorithm is faster than
bilinear
algorithm but its rendering is more simple.
This method only supports characters in the range U+0000 to U+FFFF. It does not handle characters with code points greater than U+FFFF, which are represented as a pair of char values (referred to as "surrogate pair").
Some rotation samples are described in method comment
drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float)
.
In addition with drawRotatedCharNearestNeighbor(GraphicsContext, Font, char, int, int, int, int, float)
,
this method allows to specify the global opacity value to apply during the image rendering.
gc
- the graphics context where render the drawing.font
- the font to use.c
- the character to draw.x
- the x coordinate of the character reference anchor top-left pointy
- the y coordinate of the character reference anchor top-left pointrx
- the rotation center X coordinate.ry
- the rotation center Y coordinate.angle
- the rotation angle.alpha
- the global opacity rendering value.IllegalArgumentException
- if the given alpha is not a value between GraphicsContext.TRANSPARENT
and
GraphicsContext.OPAQUE
.drawRotatedCharBilinear(GraphicsContext, Font, char, int, int, int, int, float, int)
public static void drawScaledImageBilinear(GraphicsContext gc, Image image, int x, int y, float factorX, float factorY)
bilinear
algorithm to render the image. This algorithm performs better
rendering than nearest neighbor
algorithm but it is slower to apply.
Equivalent to calling drawScaledImageBilinear(GraphicsContext, Image, int, int, float, float, int)
with
GraphicsContext.OPAQUE
as alpha.
gc
- the graphics context where to render the drawing.image
- the image to drawx
- the x coordinate of the image reference anchor top-left pointy
- the y coordinate of the image reference anchor top-left pointfactorX
- the scaling X factor.factorY
- the scaling Y factor.IllegalArgumentException
- if a factor is lower than to zero.public static void drawScaledImageBilinear(GraphicsContext gc, Image image, int x, int y, float factorX, float factorY, int alpha)
bilinear
algorithm to render the image. This algorithm performs
better rendering than nearest neighbor
algorithm but it is slower to apply.
In addition with drawScaledImageBilinear(GraphicsContext, Image, int, int, float, float)
, this method
allows to specify the global opacity value to apply during the image rendering.
gc
- the graphics context where to render the drawing.image
- the image to drawx
- the x coordinate of the image reference anchor top-left pointy
- the y coordinate of the image reference anchor top-left pointfactorX
- the scaling X factor.factorY
- the scaling Y factor.alpha
- the global opacity rendering value.IllegalArgumentException
- if the given alpha is not a value between GraphicsContext.TRANSPARENT
and
GraphicsContext.OPAQUE
or if a factor is lower than to zero.public static void drawScaledImageNearestNeighbor(GraphicsContext gc, Image image, int x, int y, float factorX, float factorY)
nearest neighbor
algorithm to render the image. This algorithm is faster than
bilinear
algorithm but its rendering is more simple.
Equivalent to calling
drawScaledImageNearestNeighbor(GraphicsContext, Image, int, int, float, float, int)
with
GraphicsContext.OPAQUE
as alpha.
gc
- the graphics context where to render the drawing.image
- the image to drawx
- the x coordinate of the image reference anchor top-left pointy
- the y coordinate of the image reference anchor top-left pointfactorX
- the scaling X factor.factorY
- the scaling Y factor.IllegalArgumentException
- if a factor is lower than to zero.public static void drawScaledImageNearestNeighbor(GraphicsContext gc, Image image, int x, int y, float factorX, float factorY, int alpha)
nearest neighbor
algorithm to render the image. This algorithm
is faster than bilinear
algorithm but its rendering is more simple.
In addition with drawScaledImageNearestNeighbor(GraphicsContext, Image, int, int, float, float)
, this
method allows to specify the global opacity value to apply during the image rendering.
gc
- the graphics context where to render the drawing.image
- the image to drawx
- the x coordinate of the image reference anchor top-left pointy
- the y coordinate of the image reference anchor top-left pointfactorX
- the scaling X factor.factorY
- the scaling Y factor.alpha
- the global opacity rendering value.IllegalArgumentException
- if the given alpha is not a value between GraphicsContext.TRANSPARENT
and
GraphicsContext.OPAQUE
or if a factor is lower than to zero.public static void drawScaledCharBilinear(GraphicsContext gc, char character, Font font, int x, int y, float factorX, float factorY)
bilinear
algorithm to render the character.
This method only supports characters in the range U+0000 to U+FFFF. It does not handle characters with code points greater than U+FFFF, which are represented as a pair of char values (referred to as "surrogate pair").
gc
- the graphics context where to render the drawing.character
- the character to drawfont
- the font to use.x
- the x coordinate of the character reference anchor top-left pointy
- the y coordinate of the character reference anchor top-left pointfactorX
- the scaling X factor.factorY
- the scaling Y factor.IllegalArgumentException
- if a factor is lower than to zero.public static void drawScaledStringBilinear(GraphicsContext gc, String string, Font font, int x, int y, float factorX, float factorY)
bilinear
algorithm to render the string.gc
- the graphics context where to render the drawing.string
- the string to drawfont
- the font to use.x
- the x coordinate of the character reference anchor top-left pointy
- the y coordinate of the character reference anchor top-left pointfactorX
- the scaling X factor.factorY
- the scaling Y factor.IllegalArgumentException
- if a factor is lower than to zero.public static void drawScaledSubstringBilinear(GraphicsContext gc, String string, int offset, int length, Font font, int x, int y, float factorX, float factorY)
bilinear
algorithm to render the string.gc
- the graphics context where to render the drawing.string
- the string to drawoffset
- the index of the first character of the string.length
- the number of characters of the string.font
- the font to use.x
- the x coordinate of the character reference anchor top-left pointy
- the y coordinate of the character reference anchor top-left pointfactorX
- the scaling X factor.factorY
- the scaling Y factor.IllegalArgumentException
- if a factor is lower than to zero.StringIndexOutOfBoundsException
- if the given offset and length do not specify a valid range within the given string.public static void drawScaledRenderableStringBilinear(GraphicsContext gc, RenderableString string, int x, int y, float factorX, float factorY)
bilinear
algorithm to render the renderable string.gc
- the graphics context where to render the drawing.string
- the renderable string to drawx
- the x coordinate of the character reference anchor top-left pointy
- the y coordinate of the character reference anchor top-left pointfactorX
- the scaling X factor.factorY
- the scaling Y factor.IllegalArgumentException
- if a factor is lower than to zero.