Skip to content
Snippets Groups Projects
Commit 6982b420 authored by stepan's avatar stepan
Browse files

FastR Grid: support view port rotation (rectangles and text)

parent c2d127f9
Branches
No related tags found
No related merge requests found
......@@ -145,7 +145,7 @@ public final class GridTextNode extends RBaseNode {
// actual drawing
if (draw && doDraw) {
text(loc.x, loc.y, text, hjust, vjust, rotation, gpar.getDrawingContext(i), dev);
text(loc.x, loc.y, text, hjust, vjust, rotation + vpTransform.rotationAngle, gpar.getDrawingContext(i), dev);
}
// or bounds checking
......@@ -210,13 +210,13 @@ public final class GridTextNode extends RBaseNode {
// transcribed from engine.c
private void text(double x, double y, String text, double xadjIn, double yadj, double rotation, DrawingContext drawingCtx, GridDevice device) {
private void text(double x, double y, String text, double xadjIn, double yadj, double rotationDegrees, DrawingContext drawingCtx, GridDevice device) {
if (!Double.isFinite(yadj)) {
throw RInternalError.unimplemented("'exact' vertical centering, see engine.c:1700");
}
double xadj = Double.isFinite(xadjIn) ? xadjIn : 0.5;
double radRotation = Math.toRadians(rotation);
double radRotation = Math.toRadians(rotationDegrees);
double cosRot = Math.cos(radRotation);
double sinRot = Math.sin(radRotation);
String[] lines = text.split("\n");
......
......@@ -130,7 +130,7 @@ public abstract class LPoints extends RExternalBuiltinNode.Arg4 {
if (cex > 0 && yc < 0.5) {
yc = 0.5;
}
dev.drawRect(drawingCtx, x - xc, y - yc, x + xc, y + yc);
dev.drawRect(drawingCtx, x - xc, y - yc, x + xc, y + yc, 0);
return drawingCtx;
}
......
......@@ -65,7 +65,7 @@ public abstract class LRect extends RExternalBuiltinNode.Arg6 {
Point origLoc = Point.fromUnits(unitToInches, xVec, yVec, i, conversionCtx);
Point transLoc = TransformMatrix.transLocation(origLoc, vpTransform.transform);
Point loc = transLoc.justify(size, getDataAtMod(hjust, i), getDataAtMod(vjust, i));
dev.drawRect(gpar.getDrawingContext(i), loc.x, loc.y, size.getWidth(), size.getHeight());
dev.drawRect(gpar.getDrawingContext(i), loc.x, loc.y, size.getWidth(), size.getHeight(), Math.toRadians(vpTransform.rotationAngle));
}
return RNull.instance;
}
......
......@@ -25,7 +25,10 @@ import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector;
* Holds the data of a viewport needed to perform transformations.
*/
public final class ViewPortTransform {
private final double rotationAngle;
/**
* Angle in radians.
*/
public final double rotationAngle;
public final double[][] transform;
public final Size size;
......
......@@ -86,10 +86,10 @@ public final class BufferedJFrameDevice implements GridDevice {
}
@Override
public void drawRect(DrawingContext ctx, double leftX, double topY, double width, double height) {
inner.drawRect(ctx, leftX, topY, width, height);
public void drawRect(DrawingContext ctx, double leftX, double topY, double width, double height, double rotationAnticlockWise) {
inner.drawRect(ctx, leftX, topY, width, height, rotationAnticlockWise);
if (buffer != null) {
drawActions.add(() -> inner.drawRect(ctx, leftX, topY, width, height));
drawActions.add(() -> inner.drawRect(ctx, leftX, topY, width, height, rotationAnticlockWise));
}
}
......
......@@ -46,7 +46,11 @@ public interface GridDevice {
default void flush() {
}
void drawRect(DrawingContext ctx, double leftX, double topY, double width, double height);
/**
* Draws a rectangle at given position, the center of the rotation should be the center of the
* rectangle. The rotation is given in radians.
*/
void drawRect(DrawingContext ctx, double leftX, double topY, double width, double height, double rotationAnticlockWise);
/**
* Connects given points with a line, there has to be at least two points in order to actually
......
......@@ -83,9 +83,19 @@ public final class JFrameDevice implements GridDevice {
}
@Override
public void drawRect(DrawingContext ctx, double leftX, double topY, double width, double height) {
public void drawRect(DrawingContext ctx, double leftX, double topY, double width, double height, double rotationAnticlockWise) {
setContext(ctx);
drawShape(ctx, new Rectangle2D.Double(leftX, topY, width, height));
if (rotationAnticlockWise == 0.) {
drawShape(ctx, new Rectangle2D.Double(leftX, topY, width, height));
return;
}
AffineTransform oldTr = graphics.getTransform();
AffineTransform newTr = new AffineTransform(oldTr);
newTr.translate(leftX + width / 2, topY + height / 2);
newTr.rotate(rotationAnticlockWise);
graphics.setTransform(newTr);
drawShape(ctx, new Rectangle2D.Double(-(width / 2), -(height / 2), width, height));
graphics.setTransform(oldTr);
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment