public class Rotate extends AbstractTransform
To rotate a renderable on itself, use the following lines:
int rx = x + renderable.getWidth() / 2;
int ry = y + renderable.getHeight() / 2;
rotation.setRotationCenter(rx, ry);
rotation.setAngle(78);
rotation.draw(gc, renderable, rx, ry, GraphicsContext.HCENTER | GraphicsContext.VCENTER);
To rotate a renderable around a circle, use the following lines:
rotation.setRotationCenter(rx, ry);
for (int i = 0; i < 360; i += 45) {
rotation.setAngle(i);
rotation.draw(gc, renderable, rx - diameter / 2, ry - diameter / 2,
GraphicsContext.TOP | GraphicsContext.LEFT);
}
| Constructor and Description |
|---|
Rotate() |
| Modifier and Type | Method and Description |
|---|---|
void |
drawBilinear(GraphicsContext gc,
Renderable renderable,
int x,
int y,
int anchor)
Draws the renderable applying the current rotation.
|
void |
drawNearestNeighbor(GraphicsContext gc,
Renderable renderable,
int x,
int y,
int anchor)
Draws the renderable applying the current rotation.
|
int |
getAngle()
Returns the current rotation angle.
|
int |
getRotationX()
Returns the current X coordinate.
|
int |
getRotationY()
Returns the current Y coordinate.
|
void |
setAngle(int angle)
Sets the new rotation angle.
|
void |
setRotationCenter(int x,
int y)
Sets the new rotation center coordinates.
|
getAlpha, getTranslateX, getTranslateY, isMirrored, resetAlpha, resetTranslate, setAlpha, setMirror, translatepublic int getAngle()
public void setAngle(int angle)
angle - the new rotation anglepublic void setRotationCenter(int x,
int y)
x - the x coordinatey - the y coordinatepublic int getRotationX()
public int getRotationY()
public void drawBilinear(GraphicsContext gc, Renderable renderable, int x, int y, int anchor)
bilinear algorithm to
render the renderable. This algorithm performs better rendering than nearest neighbor algorithm but
it is slower to apply.gc - the GraphicsContext where to render the drawing.renderable - the Renderable to draw.x - the x coordinate of the image reference anchor pointy - the y coordinate of the image reference anchor pointanchor - position of the image reference point around the anchor pointjava.lang.NullPointerException - if @{code image} or @{code gc} is @{code null}java.lang.IllegalArgumentException - if anchor is not a valid value (BASELINE is illegal).java.lang.UnsupportedOperationException - when the renderable cannot be rotated (not implemented)drawNearestNeighbor(GraphicsContext, Renderable, int, int, int)public void drawNearestNeighbor(GraphicsContext gc, Renderable renderable, int x, int y, int anchor)
nearest neighbor algorithm
to render the conent. This algorithm is faster than bilinear algorithm but its rendering is more
simple.gc - the GraphicsContext where render the drawing.renderable - the Renderable to draw.x - the x coordinate of the image reference anchor pointy - the y coordinate of the image reference anchor pointanchor - position of the image reference point around the anchor pointjava.lang.NullPointerException - if @{code image} or @{code gc} is @{code null}java.lang.IllegalArgumentException - if anchor is not a valid value (BASELINE is illegal).java.lang.UnsupportedOperationException - when the renderable cannot be rotated (not implemented)drawBilinear(GraphicsContext, Renderable, int, int, int)