Java Code Examples for javafx.scene.canvas.GraphicsContext#rotate()
The following examples show how to use
javafx.scene.canvas.GraphicsContext#rotate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DebugDrawJavaFX.java From jbox2d with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void drawCircle(Vec2 center, float radius, Vec2 axis, Color3f color) { GraphicsContext g = getGraphics(); Color s = cpool.getColor(color.x, color.y, color.z, 1f); saveState(g); double scaling = transformGraphics(g, center) * radius; g.setLineWidth(stroke / scaling); g.scale(radius, radius); g.setStroke(s); g.strokeOval(circle.getMinX(), circle.getMinX(), circle.getWidth(), circle.getHeight()); if (axis != null) { g.rotate(MathUtils.atan2(axis.y, axis.x)); g.strokeLine(0, 0, 1, 0); } restoreState(g); }
Example 2
Source File: DebugDrawJavaFX.java From jbox2d with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void drawSolidCircle(Vec2 center, float radius, Vec2 axis, Color3f color) { GraphicsContext g = getGraphics(); Color f = cpool.getColor(color.x, color.y, color.z, .4f); Color s = cpool.getColor(color.x, color.y, color.z, 1f); saveState(g); double scaling = transformGraphics(g, center) * radius; g.setLineWidth(stroke / scaling); g.scale(radius, radius); g.setFill(f); g.fillOval(circle.getMinX(), circle.getMinX(), circle.getWidth(), circle.getHeight()); g.setStroke(s); g.strokeOval(circle.getMinX(), circle.getMinX(), circle.getWidth(), circle.getHeight()); if (axis != null) { g.rotate(MathUtils.atan2(axis.y, axis.x)); g.strokeLine(0, 0, 1, 0); } restoreState(g); }
Example 3
Source File: GuiUtils.java From CircuitSim with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Source orientation is assumed EAST */ public static void rotateGraphics(GuiElement element, GraphicsContext graphics, Direction direction) { int x = element.getScreenX(); int y = element.getScreenY(); int width = element.getScreenWidth(); int height = element.getScreenHeight(); graphics.translate(x + width * 0.5, y + height * 0.5); switch(direction) { case NORTH: graphics.rotate(270); graphics.translate(-x - height * 0.5, -y - width * 0.5); break; case SOUTH: graphics.rotate(90); graphics.translate(-x - height * 0.5, -y - width * 0.5); break; case WEST: graphics.rotate(180); default: graphics.translate(-x - width * 0.5, -y - height * 0.5); } }
Example 4
Source File: SunburstChart.java From tilesfx with Apache License 2.0 | 6 votes |
private static void rotateContextForText(final GraphicsContext CTX, final double START_ANGLE, final double ANGLE, final TextOrientation ORIENTATION) { switch (ORIENTATION) { case TANGENT: if ((360 - START_ANGLE - ANGLE) % 360 > 90 && (360 - START_ANGLE - ANGLE) % 360 < 270) { CTX.rotate((180 - START_ANGLE - ANGLE) % 360); } else { CTX.rotate((360 - START_ANGLE - ANGLE) % 360); } break; case ORTHOGONAL: if ((360 - START_ANGLE - ANGLE - 90) % 360 > 90 && (360 - START_ANGLE - ANGLE - 90) % 360 < 270) { CTX.rotate((90 - START_ANGLE - ANGLE) % 360); } else { CTX.rotate((270 - START_ANGLE - ANGLE) % 360); } break; case HORIZONTAL: default: break; } }
Example 5
Source File: Helper.java From Medusa with Apache License 2.0 | 6 votes |
public static final void rotateContextForText(final GraphicsContext CTX, final double START_ANGLE, final double ANGLE, final TickLabelOrientation ORIENTATION) { switch (ORIENTATION) { case ORTHOGONAL: if ((360 - START_ANGLE - ANGLE) % 360 > 90 && (360 - START_ANGLE - ANGLE) % 360 < 270) { CTX.rotate((180 - START_ANGLE - ANGLE) % 360); } else { CTX.rotate((360 - START_ANGLE - ANGLE) % 360); } break; case TANGENT: if ((360 - START_ANGLE - ANGLE - 90) % 360 > 90 && (360 - START_ANGLE - ANGLE - 90) % 360 < 270) { CTX.rotate((90 - START_ANGLE - ANGLE) % 360); } else { CTX.rotate((270 - START_ANGLE - ANGLE) % 360); } break; case HORIZONTAL: default: break; } }
Example 6
Source File: CircularPlot.java From charts with Apache License 2.0 | 6 votes |
private void rotateContextForText(final GraphicsContext CTX, final double START_ANGLE, final double TEXT_ANGLE, final TickLabelOrientation ORIENTATION) { switch (ORIENTATION) { case ORTHOGONAL: if ((360 - START_ANGLE - TEXT_ANGLE) % 360 > 90 && (360 - START_ANGLE - TEXT_ANGLE) % 360 < 270) { CTX.rotate((180 - START_ANGLE - TEXT_ANGLE) % 360); } else { CTX.rotate((360 - START_ANGLE - TEXT_ANGLE) % 360); } break; case TANGENT: if ((360 - START_ANGLE - TEXT_ANGLE - 90) % 360 > 90 && (360 - START_ANGLE - TEXT_ANGLE - 90) % 360 < 270) { CTX.rotate((90 - START_ANGLE - TEXT_ANGLE) % 360); } else { CTX.rotate((270 - START_ANGLE - TEXT_ANGLE) % 360); } break; case HORIZONTAL: default: break; } }
Example 7
Source File: ConcentricRingChart.java From charts with Apache License 2.0 | 6 votes |
private void drawTextAlongArc(final GraphicsContext CTX, final String TEXT, final double CENTER_X, final double CENTER_Y, final double RADIUS, final double ANGLE){ int length = TEXT.length(); double charSpacer = (7 / RADIUS) * size * 0.13; double textAngle = (charSpacer * (length + 0.5)); if (ANGLE > textAngle) { CTX.save(); CTX.translate(CENTER_X, CENTER_Y); CTX.rotate(ANGLE - (charSpacer * (length + 0.5))); for (int i = 0; i < length; i++) { CTX.save(); CTX.translate(0, -1 * RADIUS); char c = TEXT.charAt(i); CTX.fillText(Character.toString(c), 0, 0); CTX.restore(); CTX.rotate(charSpacer); } CTX.restore(); } }
Example 8
Source File: ComparisonRingChart.java From charts with Apache License 2.0 | 6 votes |
private void drawTextAlongArc(final boolean UPPER, final GraphicsContext CTX, final String TEXT, final double CENTER_X, final double CENTER_Y, final double RADIUS, final double ANGLE){ int length = TEXT.length(); double charSpacer = (7 / RADIUS) * size * 0.13; double textAngle = (charSpacer * (length + 0.5)); double offset = UPPER ? 90 : -90; if (ANGLE + offset > textAngle) { CTX.save(); CTX.translate(CENTER_X, CENTER_Y); CTX.rotate(ANGLE - (charSpacer * (length + 0.5))); for (int i = 0; i < length; i++) { CTX.save(); CTX.translate(0, -1 * RADIUS); char c = TEXT.charAt(i); CTX.fillText(Character.toString(c), 0, 0); CTX.restore(); CTX.rotate(charSpacer); } CTX.restore(); } }
Example 9
Source File: SunburstChart.java From OEE-Designer with MIT License | 6 votes |
private static void rotateContextForText(final GraphicsContext CTX, final double START_ANGLE, final double ANGLE, final TextOrientation ORIENTATION) { switch (ORIENTATION) { case TANGENT: if ((360 - START_ANGLE - ANGLE) % 360 > 90 && (360 - START_ANGLE - ANGLE) % 360 < 270) { CTX.rotate((180 - START_ANGLE - ANGLE) % 360); } else { CTX.rotate((360 - START_ANGLE - ANGLE) % 360); } break; case ORTHOGONAL: if ((360 - START_ANGLE - ANGLE - 90) % 360 > 90 && (360 - START_ANGLE - ANGLE - 90) % 360 < 270) { CTX.rotate((90 - START_ANGLE - ANGLE) % 360); } else { CTX.rotate((270 - START_ANGLE - ANGLE) % 360); } break; case HORIZONTAL: default: break; } }
Example 10
Source File: AbstractAxis.java From chart-fx with Apache License 2.0 | 6 votes |
protected static void drawTickMarkLabel(final GraphicsContext gc, final double x, final double y, final double scaleFont, final TickMark tickMark) { gc.save(); gc.setFont(tickMark.getFont()); gc.setFill(tickMark.getFill()); gc.setTextAlign(tickMark.getTextAlignment()); gc.setTextBaseline(tickMark.getTextOrigin()); gc.translate(x, y); if (tickMark.getRotate() != 0.0) { gc.rotate(tickMark.getRotate()); } gc.setGlobalAlpha(tickMark.getOpacity()); if (scaleFont != 1.0) { gc.scale(scaleFont, 1.0); } gc.fillText(tickMark.getText(), 0, 0); // gc.fillText(tickMark.getText(), x, y);C gc.restore(); }
Example 11
Source File: TintedImageHelperRenderer.java From arma-dialog-creator with MIT License | 5 votes |
/** This method applies to {@link #setToPreviewMode(boolean)} */ public void paintTintedImage(@NotNull GraphicsContext gc) { gc.save(); if (rotated) { gc.translate(x + w / 2, y + h / 2); //move to center gc.rotate(rotateDeg); } if (flipped) { gc.scale(-1, 1); } gc.setFill(Color.TRANSPARENT); gc.setEffect(previewMode ? effect2 : effect1); gc.fillRect(0, 0, 1, 1); //this is just to trigger drawing the effect. Won't draw anything itself gc.restore(); }
Example 12
Source File: MiscHelpers.java From arma-dialog-creator with MIT License | 5 votes |
public static void paintRotatedImage(@NotNull GraphicsContext gc, @NotNull Image img, int x, int y, int w, int h, double rotateDeg) { gc.save(); gc.translate(x + w / 2, y + h / 2); //move to center gc.rotate(rotateDeg); gc.drawImage(img, -w / 2, -h / 2, w, h); gc.restore(); }
Example 13
Source File: Helper.java From charts with Apache License 2.0 | 4 votes |
public static final void rotateCtx(final GraphicsContext CTX, final double X, final double Y, final double ANGLE) { CTX.translate(X, Y); CTX.rotate(ANGLE); CTX.translate(-X, -Y); }
Example 14
Source File: GaugeSkin.java From Enzo with Apache License 2.0 | 4 votes |
private void drawTickMarks(final GraphicsContext CTX) { if (getSkinnable().isHistogramEnabled()) { double xy; double wh; double step = 0; double OFFSET = 90 - getSkinnable().getStartAngle(); double ANGLE_EXTEND = (getSkinnable().getMaxValue()) * angleStep; CTX.setStroke(Color.rgb(200, 200, 200)); CTX.setLineWidth(size * 0.001); CTX.setLineCap(StrokeLineCap.BUTT); for (int i = 0 ; i < 5 ; i++) { xy = (size - (0.435 + step) * size) / 2; wh = size * (0.435 + step); CTX.strokeArc(xy, xy, wh, wh, -OFFSET, -ANGLE_EXTEND, ArcType.OPEN); step += 0.075; } } double sinValue; double cosValue; double startAngle = getSkinnable().getStartAngle(); double orthText = Gauge.TickLabelOrientation.ORTHOGONAL == getSkinnable().getTickLabelOrientation() ? 0.33 : 0.31; Point2D center = new Point2D(size * 0.5, size * 0.5); for (double angle = 0, counter = getSkinnable().getMinValue() ; Double.compare(counter, getSkinnable().getMaxValue()) <= 0 ; angle -= angleStep, counter++) { sinValue = Math.sin(Math.toRadians(angle + startAngle)); cosValue = Math.cos(Math.toRadians(angle + startAngle)); Point2D innerMainPoint = new Point2D(center.getX() + size * 0.368 * sinValue, center.getY() + size * 0.368 * cosValue); Point2D innerMediumPoint = new Point2D(center.getX() + size * 0.388 * sinValue, center.getY() + size * 0.388 * cosValue); Point2D innerMinorPoint = new Point2D(center.getX() + size * 0.3975 * sinValue, center.getY() + size * 0.3975 * cosValue); Point2D outerPoint = new Point2D(center.getX() + size * 0.432 * sinValue, center.getY() + size * 0.432 * cosValue); Point2D textPoint = new Point2D(center.getX() + size * orthText * sinValue, center.getY() + size * orthText * cosValue); CTX.setStroke(getSkinnable().getTickMarkFill()); if (counter % getSkinnable().getMajorTickSpace() == 0) { // Draw major tickmark CTX.setLineWidth(size * 0.0055); CTX.strokeLine(innerMainPoint.getX(), innerMainPoint.getY(), outerPoint.getX(), outerPoint.getY()); // Draw text CTX.save(); CTX.translate(textPoint.getX(), textPoint.getY()); switch(getSkinnable().getTickLabelOrientation()) { case ORTHOGONAL: if ((360 - startAngle - angle) % 360 > 90 && (360 - startAngle - angle) % 360 < 270) { CTX.rotate((180 - startAngle - angle) % 360); } else { CTX.rotate((360 - startAngle - angle) % 360); } break; case TANGENT: if ((360 - startAngle - angle - 90) % 360 > 90 && (360 - startAngle - angle - 90) % 360 < 270) { CTX.rotate((90 - startAngle - angle) % 360); } else { CTX.rotate((270 - startAngle - angle) % 360); } break; case HORIZONTAL: default: break; } CTX.setFont(Font.font("Verdana", FontWeight.NORMAL, 0.045 * size)); CTX.setTextAlign(TextAlignment.CENTER); CTX.setTextBaseline(VPos.CENTER); CTX.setFill(getSkinnable().getTickLabelFill()); CTX.fillText(Integer.toString((int) counter), 0, 0); CTX.restore(); } else if (getSkinnable().getMinorTickSpace() % 2 != 0 && counter % 5 == 0) { CTX.setLineWidth(size * 0.0035); CTX.strokeLine(innerMediumPoint.getX(), innerMediumPoint.getY(), outerPoint.getX(), outerPoint.getY()); } else if (counter % getSkinnable().getMinorTickSpace() == 0) { CTX.setLineWidth(size * 0.00225); CTX.strokeLine(innerMinorPoint.getX(), innerMinorPoint.getY(), outerPoint.getX(), outerPoint.getY()); } } }
Example 15
Source File: CustomPlainAmpSkin.java From medusademo with Apache License 2.0 | 4 votes |
private void drawTickMarks(final GraphicsContext CTX) { double sinValue; double cosValue; double orthText = TickLabelOrientation.ORTHOGONAL == gauge.getTickLabelOrientation() ? 0.61 : 0.62; Point2D center = new Point2D(width * 0.5, height * 1.4); double minorTickSpace = gauge.getMinorTickSpace(); double minValue = gauge.getMinValue(); //double maxValue = gauge.getMaxValue(); double tmpAngleStep = angleStep * minorTickSpace; int decimals = gauge.getTickLabelDecimals(); BigDecimal minorTickSpaceBD = BigDecimal.valueOf(minorTickSpace); BigDecimal majorTickSpaceBD = BigDecimal.valueOf(gauge.getMajorTickSpace()); BigDecimal mediumCheck2 = BigDecimal.valueOf(2 * minorTickSpace); BigDecimal mediumCheck5 = BigDecimal.valueOf(5 * minorTickSpace); BigDecimal counterBD = BigDecimal.valueOf(minValue); double counter = minValue; Font tickLabelFont = Fonts.robotoCondensedRegular((decimals == 0 ? 0.07 : 0.068) * height); CTX.setFont(tickLabelFont); for (double angle = 0 ; Double.compare(-ANGLE_RANGE - tmpAngleStep, angle) < 0 ; angle -= tmpAngleStep) { sinValue = Math.sin(Math.toRadians(angle + START_ANGLE)); cosValue = Math.cos(Math.toRadians(angle + START_ANGLE)); Point2D innerPoint = new Point2D(center.getX() + width * 0.51987097 * sinValue, center.getY() + width * 0.51987097 * cosValue); Point2D outerMinorPoint = new Point2D(center.getX() + width * 0.55387097 * sinValue, center.getY() + width * 0.55387097 * cosValue); Point2D outerMediumPoint = new Point2D(center.getX() + width * 0.56387097 * sinValue, center.getY() + width * 0.56387097 * cosValue); Point2D outerPoint = new Point2D(center.getX() + width * 0.58387097 * sinValue, center.getY() + width * 0.58387097 * cosValue); Point2D textPoint = new Point2D(center.getX() + width * orthText * sinValue, center.getY() + width * orthText * cosValue); CTX.setStroke(gauge.getTickMarkColor()); if (Double.compare(counterBD.remainder(majorTickSpaceBD).doubleValue(), 0.0) == 0) { // Draw major tickmark CTX.setLineWidth(height * 0.0055); CTX.strokeLine(innerPoint.getX(), innerPoint.getY(), outerPoint.getX(), outerPoint.getY()); // Draw text CTX.save(); CTX.translate(textPoint.getX(), textPoint.getY()); switch(gauge.getTickLabelOrientation()) { case ORTHOGONAL: if ((360 - START_ANGLE - angle) % 360 > 90 && (360 - START_ANGLE - angle) % 360 < 270) { CTX.rotate((180 - START_ANGLE - angle) % 360); } else { CTX.rotate((360 - START_ANGLE - angle) % 360); } break; case TANGENT: if ((360 - START_ANGLE - angle - 90) % 360 > 90 && (360 - START_ANGLE - angle - 90) % 360 < 270) { CTX.rotate((90 - START_ANGLE - angle) % 360); } else { CTX.rotate((270 - START_ANGLE - angle) % 360); } break; case HORIZONTAL: default: break; } CTX.setTextAlign(TextAlignment.CENTER); CTX.setTextBaseline(VPos.CENTER); CTX.setFill(gauge.getTickLabelColor()); CTX.fillText(String.format(locale, "%." + decimals + "f", counter), 0, 0); CTX.restore(); } else if (gauge.getMediumTickMarksVisible() && Double.compare(minorTickSpaceBD.remainder(mediumCheck2).doubleValue(), 0.0) != 0.0 && Double.compare(counterBD.remainder(mediumCheck5).doubleValue(), 0.0) == 0.0) { CTX.setLineWidth(height * 0.0035); CTX.strokeLine(innerPoint.getX(), innerPoint.getY(), outerMediumPoint.getX(), outerMediumPoint.getY()); } else if (gauge.getMinorTickMarksVisible() && Double.compare(counterBD.remainder(minorTickSpaceBD).doubleValue(), 0.0) == 0) { CTX.setLineWidth(height * 0.00225); CTX.strokeLine(innerPoint.getX(), innerPoint.getY(), outerMinorPoint.getX(), outerMinorPoint.getY()); } counterBD = counterBD.add(minorTickSpaceBD); counter = counterBD.doubleValue(); } }
Example 16
Source File: MultiplexerPeer.java From CircuitSim with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void paint(GraphicsContext graphics, CircuitState circuitState) { GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION)); Direction direction = getProperties().getValue(Properties.DIRECTION); int x = getScreenX(); int y = getScreenY(); int width = 3 * GuiUtils.BLOCK_SIZE; int height = (getComponent().getNumInputs() + 2) * GuiUtils.BLOCK_SIZE; int zeroXOffset = 0; switch(direction) { case NORTH: graphics.translate(x, y); graphics.rotate(270); graphics.translate(-x - width, -y); case EAST: zeroXOffset = 2; graphics.beginPath(); graphics.moveTo(x, y); graphics.lineTo(x + width, y + Math.min(20, height * 0.2)); graphics.lineTo(x + width, y + height - Math.min(20, height * 0.2)); graphics.lineTo(x, y + height); graphics.closePath(); break; case SOUTH: graphics.translate(x, y); graphics.rotate(270); graphics.translate(-x - width, -y); case WEST: zeroXOffset = width - 10; graphics.beginPath(); graphics.moveTo(x + width, y); graphics.lineTo(x, y + Math.min(20, height * 0.2)); graphics.lineTo(x, y + height - Math.min(20, height * 0.2)); graphics.lineTo(x + width, y + height); graphics.closePath(); break; } graphics.setFill(Color.WHITE); graphics.fill(); graphics.setStroke(Color.BLACK); graphics.stroke(); graphics.setFill(Color.DARKGRAY); graphics.fillText("0", x + zeroXOffset, y + 13); }
Example 17
Source File: DemultiplexerPeer.java From CircuitSim with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void paint(GraphicsContext graphics, CircuitState circuitState) { GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION)); Direction direction = getProperties().getValue(Properties.DIRECTION); int x = getScreenX(); int y = getScreenY(); int width = 3 * GuiUtils.BLOCK_SIZE; int height = (getComponent().getNumOutputs() + 2) * GuiUtils.BLOCK_SIZE; int zeroXOffset = 0; switch(direction) { case SOUTH: graphics.translate(x, y); graphics.rotate(270); graphics.translate(-x - width, -y); case WEST: zeroXOffset = 2; graphics.beginPath(); graphics.moveTo(x, y); graphics.lineTo(x + width, y + Math.min(20, height * 0.2)); graphics.lineTo(x + width, y + height - Math.min(20, height * 0.2)); graphics.lineTo(x, y + height); graphics.closePath(); break; case NORTH: graphics.translate(x, y); graphics.rotate(270); graphics.translate(-x - width, -y); case EAST: zeroXOffset = width - 10; graphics.beginPath(); graphics.moveTo(x + width, y); graphics.lineTo(x, y + Math.min(20, height * 0.2)); graphics.lineTo(x, y + height - Math.min(20, height * 0.2)); graphics.lineTo(x + width, y + height); graphics.closePath(); break; } graphics.setFill(Color.WHITE); graphics.fill(); graphics.setStroke(Color.BLACK); graphics.stroke(); graphics.setFill(Color.DARKGRAY); graphics.fillText("0", x + zeroXOffset, y + 13); }
Example 18
Source File: LabelledMarkerRenderer.java From chart-fx with Apache License 2.0 | 4 votes |
/** * Draws vertical markers with vertical (default) labels attached to the top * * @param gc the graphics context from the Canvas parent * @param chart instance of the calling chart * @param dataSet instance of the data set that is supposed to be drawn * @param indexMin minimum index of data set to be drawn * @param indexMax maximum index of data set to be drawn */ protected void drawVerticalLabelledMarker(final GraphicsContext gc, final XYChart chart, final DataSet dataSet, final int indexMin, final int indexMax) { Axis xAxis = this.getFirstAxis(Orientation.HORIZONTAL); if (xAxis == null) { xAxis = chart.getFirstAxis(Orientation.HORIZONTAL); } if (xAxis == null) { if (LOGGER.isWarnEnabled()) { LOGGER.atWarn().addArgument(LabelledMarkerRenderer.class.getSimpleName()).log("{}::drawVerticalLabelledMarker(...) getFirstAxis(HORIZONTAL) returned null skip plotting"); } return; } gc.save(); setGraphicsContextAttributes(gc, dataSet.getStyle()); gc.setTextAlign(TextAlignment.LEFT); final double height = chart.getCanvas().getHeight(); double lastLabel = -Double.MAX_VALUE; double lastFontSize = 0; for (int i = indexMin; i < indexMax; i++) { final double screenX = (int) xAxis.getDisplayPosition(dataSet.get(DataSet.DIM_X, i)); final String label = dataSet.getDataLabel(i); if (label == null) { continue; } final String pointStyle = dataSet.getStyle(i); if (pointStyle != null) { gc.save(); setGraphicsContextAttributes(gc, pointStyle); } gc.strokeLine(screenX, 0, screenX, height); if (Math.abs(screenX - lastLabel) > lastFontSize && !label.isEmpty()) { gc.save(); gc.setLineWidth(0.8); gc.setLineDashes(1.0); gc.translate(Math.ceil(screenX + 3), Math.ceil(0.01 * height)); gc.rotate(+90); gc.fillText(label, 0.0, 0); gc.restore(); lastLabel = screenX; lastFontSize = gc.getFont().getSize(); } if (pointStyle != null) { gc.restore(); } } gc.restore(); }
Example 19
Source File: PlainAmpSkin.java From Medusa with Apache License 2.0 | 4 votes |
private void drawTickMarks(final GraphicsContext CTX) { double sinValue; double cosValue; double orthText = TickLabelOrientation.ORTHOGONAL == gauge.getTickLabelOrientation() ? 0.61 : 0.62; Point2D center = new Point2D(width * 0.5, height * 1.4); double minorTickSpace = gauge.getMinorTickSpace(); double minValue = gauge.getMinValue(); //double maxValue = gauge.getMaxValue(); double tmpAngleStep = angleStep * minorTickSpace; int decimals = gauge.getTickLabelDecimals(); BigDecimal minorTickSpaceBD = BigDecimal.valueOf(minorTickSpace); BigDecimal majorTickSpaceBD = BigDecimal.valueOf(gauge.getMajorTickSpace()); BigDecimal mediumCheck2 = BigDecimal.valueOf(2 * minorTickSpace); BigDecimal mediumCheck5 = BigDecimal.valueOf(5 * minorTickSpace); BigDecimal counterBD = BigDecimal.valueOf(minValue); double counter = minValue; Font tickLabelFont = Fonts.robotoCondensedRegular((decimals == 0 ? 0.07 : 0.068) * height); CTX.setFont(tickLabelFont); for (double angle = 0 ; Double.compare(-ANGLE_RANGE - tmpAngleStep, angle) < 0 ; angle -= tmpAngleStep) { sinValue = Math.sin(Math.toRadians(angle + START_ANGLE)); cosValue = Math.cos(Math.toRadians(angle + START_ANGLE)); Point2D innerPoint = new Point2D(center.getX() + width * 0.51987097 * sinValue, center.getY() + width * 0.51987097 * cosValue); Point2D outerMinorPoint = new Point2D(center.getX() + width * 0.55387097 * sinValue, center.getY() + width * 0.55387097 * cosValue); Point2D outerMediumPoint = new Point2D(center.getX() + width * 0.56387097 * sinValue, center.getY() + width * 0.56387097 * cosValue); Point2D outerPoint = new Point2D(center.getX() + width * 0.58387097 * sinValue, center.getY() + width * 0.58387097 * cosValue); Point2D textPoint = new Point2D(center.getX() + width * orthText * sinValue, center.getY() + width * orthText * cosValue); CTX.setStroke(gauge.getTickMarkColor()); if (Double.compare(counterBD.remainder(majorTickSpaceBD).doubleValue(), 0.0) == 0) { // Draw major tickmark CTX.setLineWidth(height * 0.0055); CTX.strokeLine(innerPoint.getX(), innerPoint.getY(), outerPoint.getX(), outerPoint.getY()); // Draw text CTX.save(); CTX.translate(textPoint.getX(), textPoint.getY()); switch(gauge.getTickLabelOrientation()) { case ORTHOGONAL: if ((360 - START_ANGLE - angle) % 360 > 90 && (360 - START_ANGLE - angle) % 360 < 270) { CTX.rotate((180 - START_ANGLE - angle) % 360); } else { CTX.rotate((360 - START_ANGLE - angle) % 360); } break; case TANGENT: if ((360 - START_ANGLE - angle - 90) % 360 > 90 && (360 - START_ANGLE - angle - 90) % 360 < 270) { CTX.rotate((90 - START_ANGLE - angle) % 360); } else { CTX.rotate((270 - START_ANGLE - angle) % 360); } break; case HORIZONTAL: default: break; } CTX.setTextAlign(TextAlignment.CENTER); CTX.setTextBaseline(VPos.CENTER); CTX.setFill(gauge.getTickLabelColor()); CTX.fillText(String.format(locale, "%." + decimals + "f", counter), 0, 0); CTX.restore(); } else if (gauge.getMediumTickMarksVisible() && Double.compare(minorTickSpaceBD.remainder(mediumCheck2).doubleValue(), 0.0) != 0.0 && Double.compare(counterBD.remainder(mediumCheck5).doubleValue(), 0.0) == 0.0) { CTX.setLineWidth(height * 0.0035); CTX.strokeLine(innerPoint.getX(), innerPoint.getY(), outerMediumPoint.getX(), outerMediumPoint.getY()); } else if (gauge.getMinorTickMarksVisible() && Double.compare(counterBD.remainder(minorTickSpaceBD).doubleValue(), 0.0) == 0) { CTX.setLineWidth(height * 0.00225); CTX.strokeLine(innerPoint.getX(), innerPoint.getY(), outerMinorPoint.getX(), outerMinorPoint.getY()); } counterBD = counterBD.add(minorTickSpaceBD); counter = counterBD.doubleValue(); } }
Example 20
Source File: AmpSkin.java From Medusa with Apache License 2.0 | 4 votes |
private void drawTickMarks(final GraphicsContext CTX) { double sinValue; double cosValue; double orthText = TickLabelOrientation.ORTHOGONAL == gauge.getTickLabelOrientation() ? 0.51 : 0.52; Point2D center = new Point2D(width * 0.5, height * 0.77); double minorTickSpace = gauge.getMinorTickSpace(); double minValue = gauge.getMinValue(); //double maxValue = gauge.getMaxValue(); double tmpAngleStep = angleStep * minorTickSpace; int decimals = gauge.getTickLabelDecimals(); BigDecimal minorTickSpaceBD = BigDecimal.valueOf(minorTickSpace); BigDecimal majorTickSpaceBD = BigDecimal.valueOf(gauge.getMajorTickSpace()); BigDecimal mediumCheck2 = BigDecimal.valueOf(2 * minorTickSpace); BigDecimal mediumCheck5 = BigDecimal.valueOf(5 * minorTickSpace); BigDecimal counterBD = BigDecimal.valueOf(minValue); double counter = minValue; Font tickLabelFont = Fonts.robotoCondensedRegular((decimals == 0 ? 0.045 : 0.038) * height); CTX.setFont(tickLabelFont); for (double angle = 0 ; Double.compare(-ANGLE_RANGE - tmpAngleStep, angle) < 0 ; angle -= tmpAngleStep) { sinValue = Math.sin(Math.toRadians(angle + START_ANGLE)); cosValue = Math.cos(Math.toRadians(angle + START_ANGLE)); Point2D innerPoint = new Point2D(center.getX() + width * 0.41987097 * sinValue, center.getY() + width * 0.41987097 * cosValue); Point2D outerMinorPoint = new Point2D(center.getX() + width * 0.45387097 * sinValue, center.getY() + width * 0.45387097 * cosValue); Point2D outerMediumPoint = new Point2D(center.getX() + width * 0.46387097 * sinValue, center.getY() + width * 0.46387097 * cosValue); Point2D outerPoint = new Point2D(center.getX() + width * 0.48387097 * sinValue, center.getY() + width * 0.48387097 * cosValue); Point2D textPoint = new Point2D(center.getX() + width * orthText * sinValue, center.getY() + width * orthText * cosValue); CTX.setStroke(gauge.getTickMarkColor()); if (Double.compare(counterBD.remainder(majorTickSpaceBD).doubleValue(), 0.0) == 0) { // Draw major tickmark CTX.setLineWidth(height * 0.0055); CTX.strokeLine(innerPoint.getX(), innerPoint.getY(), outerPoint.getX(), outerPoint.getY()); // Draw text CTX.save(); CTX.translate(textPoint.getX(), textPoint.getY()); switch(gauge.getTickLabelOrientation()) { case ORTHOGONAL: if ((360 - START_ANGLE - angle) % 360 > 90 && (360 - START_ANGLE - angle) % 360 < 270) { CTX.rotate((180 - START_ANGLE - angle) % 360); } else { CTX.rotate((360 - START_ANGLE - angle) % 360); } break; case TANGENT: if ((360 - START_ANGLE - angle - 90) % 360 > 90 && (360 - START_ANGLE - angle - 90) % 360 < 270) { CTX.rotate((90 - START_ANGLE - angle) % 360); } else { CTX.rotate((270 - START_ANGLE - angle) % 360); } break; case HORIZONTAL: default: break; } CTX.setTextAlign(TextAlignment.CENTER); CTX.setTextBaseline(VPos.CENTER); CTX.setFill(gauge.getTickLabelColor()); CTX.fillText(String.format(locale, "%." + decimals + "f", counter), 0, 0); CTX.restore(); } else if (gauge.getMediumTickMarksVisible() && Double.compare(minorTickSpaceBD.remainder(mediumCheck2).doubleValue(), 0.0) != 0.0 && Double.compare(counterBD.remainder(mediumCheck5).doubleValue(), 0.0) == 0.0) { CTX.setLineWidth(height * 0.0035); CTX.strokeLine(innerPoint.getX(), innerPoint.getY(), outerMediumPoint.getX(), outerMediumPoint.getY()); } else if (gauge.getMinorTickMarksVisible() && Double.compare(counterBD.remainder(minorTickSpaceBD).doubleValue(), 0.0) == 0) { CTX.setLineWidth(height * 0.00225); CTX.strokeLine(innerPoint.getX(), innerPoint.getY(), outerMinorPoint.getX(), outerMinorPoint.getY()); } counterBD = counterBD.add(minorTickSpaceBD); counter = counterBD.doubleValue(); } }