Java Code Examples for javafx.scene.canvas.GraphicsContext#closePath()
The following examples show how to use
javafx.scene.canvas.GraphicsContext#closePath() .
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: NandGatePeer.java From CircuitSim with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void paintGate(GraphicsContext graphics, CircuitState circuitState) { int x = getScreenX(); int y = getScreenY(); int width = 4 * GuiUtils.BLOCK_SIZE; int height = 4 * GuiUtils.BLOCK_SIZE; graphics.beginPath(); graphics.moveTo(x, y); graphics.lineTo(x, y + height); graphics.arc(x + width * 0.3, y + height * 0.5, width * 0.5, height * 0.5, 270, 180); graphics.closePath(); graphics.setFill(Color.WHITE); graphics.setStroke(Color.BLACK); graphics.fill(); graphics.stroke(); graphics.fillOval(x + width * 0.8, y + height * 0.5 - width * 0.1, width * 0.2, width * 0.2); graphics.strokeOval(x + width * 0.8, y + height * 0.5 - width * 0.1, width * 0.2, width * 0.2); }
Example 2
Source File: OrGatePeer.java From CircuitSim with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void paintGate(GraphicsContext graphics, CircuitState circuitState) { int x = getScreenX(); int y = getScreenY(); int width = 4 * GuiUtils.BLOCK_SIZE; int height = 4 * GuiUtils.BLOCK_SIZE; graphics.beginPath(); graphics.moveTo(x, y + height); graphics.arc(x, y + height * 0.5, width * 0.25, height * 0.5, 270, 180); graphics.arcTo(x + width * 0.66, y, x + width * 1.25, y + height, width); graphics.arcTo(x + width * 0.66, y + height, x, y + height, width); graphics.closePath(); graphics.setFill(Color.WHITE); graphics.setStroke(Color.BLACK); graphics.fill(); graphics.stroke(); }
Example 3
Source File: Helper.java From OEE-Designer with MIT License | 6 votes |
public static final void drawRoundedRect(final GraphicsContext CTX, final CtxBounds BOUNDS, final CtxCornerRadii RADII) { double x = BOUNDS.getX(); double y = BOUNDS.getY(); double width = BOUNDS.getWidth(); double height = BOUNDS.getHeight(); double xPlusWidth = x + width; double yPlusHeight = y + height; CTX.beginPath(); CTX.moveTo(x + RADII.getTopLeft(), y); CTX.lineTo(xPlusWidth - RADII.getTopRight(), y); CTX.quadraticCurveTo(xPlusWidth, y, xPlusWidth, y + RADII.getTopRight()); CTX.lineTo(xPlusWidth, yPlusHeight - RADII.getBottomRight()); CTX.quadraticCurveTo(xPlusWidth, yPlusHeight, xPlusWidth - RADII.getBottomRight(), yPlusHeight); CTX.lineTo(x + RADII.getBottomLeft(), yPlusHeight); CTX.quadraticCurveTo(x, yPlusHeight, x, yPlusHeight - RADII.getBottomLeft()); CTX.lineTo(x, y + RADII.getTopLeft()); CTX.quadraticCurveTo(x, y, x + RADII.getTopLeft(), y); CTX.closePath(); }
Example 4
Source File: Helper.java From charts with Apache License 2.0 | 6 votes |
public static final void drawRoundedRect(final GraphicsContext CTX, final CtxBounds BOUNDS, final CtxCornerRadii RADII) { double x = BOUNDS.getX(); double y = BOUNDS.getY(); double width = BOUNDS.getWidth(); double height = BOUNDS.getHeight(); double xPlusWidth = x + width; double yPlusHeight = y + height; CTX.beginPath(); CTX.moveTo(x + RADII.getTopLeft(), y); CTX.lineTo(xPlusWidth - RADII.getTopRight(), y); CTX.quadraticCurveTo(xPlusWidth, y, xPlusWidth, y + RADII.getTopRight()); CTX.lineTo(xPlusWidth, yPlusHeight - RADII.getBottomRight()); CTX.quadraticCurveTo(xPlusWidth, yPlusHeight, xPlusWidth - RADII.getBottomRight(), yPlusHeight); CTX.lineTo(x + RADII.getBottomLeft(), yPlusHeight); CTX.quadraticCurveTo(x, yPlusHeight, x, yPlusHeight - RADII.getBottomLeft()); CTX.lineTo(x, y + RADII.getTopLeft()); CTX.quadraticCurveTo(x, y, x + RADII.getTopLeft(), y); CTX.closePath(); }
Example 5
Source File: AndGatePeer.java From CircuitSim with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void paintGate(GraphicsContext graphics, CircuitState circuitState) { int x = getScreenX(); int y = getScreenY(); int width = 4 * GuiUtils.BLOCK_SIZE; int height = 4 * GuiUtils.BLOCK_SIZE; graphics.beginPath(); graphics.moveTo(x, y); graphics.lineTo(x, y + height); graphics.arc(x + width * 0.5, y + height * 0.5, width * 0.5, height * 0.5, 270, 180); graphics.closePath(); graphics.setFill(Color.WHITE); graphics.setStroke(Color.BLACK); graphics.fill(); graphics.stroke(); }
Example 6
Source File: Helper.java From tilesfx with Apache License 2.0 | 6 votes |
public static final void drawRoundedRect(final GraphicsContext CTX, final CtxBounds BOUNDS, final CtxCornerRadii RADII) { double x = BOUNDS.getX(); double y = BOUNDS.getY(); double width = BOUNDS.getWidth(); double height = BOUNDS.getHeight(); double xPlusWidth = x + width; double yPlusHeight = y + height; CTX.beginPath(); CTX.moveTo(x + RADII.getTopLeft(), y); CTX.lineTo(xPlusWidth - RADII.getTopRight(), y); CTX.quadraticCurveTo(xPlusWidth, y, xPlusWidth, y + RADII.getTopRight()); CTX.lineTo(xPlusWidth, yPlusHeight - RADII.getBottomRight()); CTX.quadraticCurveTo(xPlusWidth, yPlusHeight, xPlusWidth - RADII.getBottomRight(), yPlusHeight); CTX.lineTo(x + RADII.getBottomLeft(), yPlusHeight); CTX.quadraticCurveTo(x, yPlusHeight, x, yPlusHeight - RADII.getBottomLeft()); CTX.lineTo(x, y + RADII.getTopLeft()); CTX.quadraticCurveTo(x, y, x + RADII.getTopLeft(), y); CTX.closePath(); }
Example 7
Source File: NorGatePeer.java From CircuitSim with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void paintGate(GraphicsContext graphics, CircuitState circuitState) { int x = getScreenX(); int y = getScreenY(); int width = 4 * GuiUtils.BLOCK_SIZE; int height = 4 * GuiUtils.BLOCK_SIZE; graphics.beginPath(); graphics.moveTo(x, y + height); graphics.arc(x, y + height * 0.5, width * 0.25, height * 0.5, 270, 180); graphics.arcTo(x + width * 0.66, y, x + width, y + height * 1.3, width * 0.7); graphics.arcTo(x + width * 0.66, y + height, x, y + height, width * 0.7); graphics.closePath(); graphics.setFill(Color.WHITE); graphics.setStroke(Color.BLACK); graphics.fill(); graphics.stroke(); graphics.fillOval(x + width * 0.8, y + height * 0.5 - width * 0.1, width * 0.2, width * 0.2); graphics.strokeOval(x + width * 0.8, y + height * 0.5 - width * 0.1, width * 0.2, width * 0.2); }
Example 8
Source File: StructuredTextRenderer.java From arma-dialog-creator with MIT License | 6 votes |
public void paint(@NotNull GraphicsContext gc, CanvasContext canvasContext) { boolean preview = paintPreview(canvasContext); if (preview) { blinkControlHandler.paint(gc); if (this.mouseOver) { canvasContext.paintLast(tooltipRenderFunc); } } super.paint(gc, canvasContext); gc.beginPath(); gc.rect(x1, y1, getWidth(), getHeight()); gc.closePath(); gc.clip(); //prevent text going out of bounds gc.setFill(defaultSectionData.textColor == null ? Color.RED : defaultSectionData.textColor); gc.setFont(defaultSectionData.font); gc.fillText(this.text, x1 + (int) (getWidth() * .025), y1 + (int) (getHeight() * .025)); }
Example 9
Source File: GeneralPath.java From chart-fx with Apache License 2.0 | 6 votes |
public int draw(final GraphicsContext gc) { int count = 0; for (final Segment segment : drawList) { switch (segment.type) { case GC_LINETO: gc.lineTo(segment.x, segment.y); count++; break; case GC_MOVETO: gc.moveTo(segment.x, segment.y); count++; break; case GC_BEGINPATH: gc.beginPath(); break; case GC_CLOSEPATH: gc.closePath(); gc.stroke(); break; default: break; } } return count; }
Example 10
Source File: ControlledBufferPeer.java From CircuitSim with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void paint(GraphicsContext graphics, CircuitState circuitState) { GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION)); GuiUtils.rotateGraphics(this, graphics, getProperties().getValue(Properties.DIRECTION)); graphics.beginPath(); graphics.moveTo(getScreenX(), getScreenY()); graphics.lineTo(getScreenX() + getScreenWidth(), getScreenY() + getScreenHeight() * 0.5); graphics.lineTo(getScreenX(), getScreenY() + getScreenHeight()); graphics.closePath(); graphics.setFill(Color.WHITE); graphics.fill(); graphics.setStroke(Color.BLACK); graphics.stroke(); }
Example 11
Source File: Helper.java From Medusa with Apache License 2.0 | 5 votes |
public static final void drawTriangle(final GraphicsContext CTX, final double PIX, final double PIY, final double PO1X, final double PO1Y, final double PO2X, final double PO2Y) { CTX.beginPath(); CTX.moveTo(PIX, PIY); CTX.lineTo(PO1X, PO1Y); CTX.lineTo(PO2X, PO2Y); CTX.closePath(); CTX.fill(); }
Example 12
Source File: RoundLcdClock.java From Enzo with Apache License 2.0 | 5 votes |
private void drawAlarmIcon(final GraphicsContext CTX, final Paint COLOR) { double iconSize = 0.1 * size; CTX.save(); CTX.translate((size - iconSize) * 0.5, size * 0.25); CTX.beginPath(); CTX.moveTo(0.6875 * iconSize, 0.875 * iconSize); CTX.bezierCurveTo(0.625 * iconSize, 0.9375 * iconSize, 0.5625 * iconSize, iconSize, 0.5 * iconSize, iconSize); CTX.bezierCurveTo(0.4375 * iconSize, iconSize, 0.375 * iconSize, 0.9375 * iconSize, 0.375 * iconSize, 0.875 * iconSize); CTX.bezierCurveTo(0.375 * iconSize, 0.875 * iconSize, 0.6875 * iconSize, 0.875 * iconSize, 0.6875 * iconSize, 0.875 * iconSize); CTX.closePath(); CTX.moveTo(iconSize, 0.8125 * iconSize); CTX.bezierCurveTo(0.6875 * iconSize, 0.5625 * iconSize, 0.9375 * iconSize, 0.0, 0.5 * iconSize, 0.0); CTX.bezierCurveTo(0.5 * iconSize, 0.0, 0.5 * iconSize, 0.0, 0.5 * iconSize, 0.0); CTX.bezierCurveTo(0.5 * iconSize, 0.0, 0.5 * iconSize, 0.0, 0.5 * iconSize, 0.0); CTX.bezierCurveTo(0.125 * iconSize, 0.0, 0.375 * iconSize, 0.5625 * iconSize, 0.0, 0.8125 * iconSize); CTX.bezierCurveTo(0.0, 0.8125 * iconSize, 0.0, 0.8125 * iconSize, 0.0, 0.8125 * iconSize); CTX.bezierCurveTo(0.0, 0.8125 * iconSize, 0.0, 0.8125 * iconSize, 0.0, 0.8125 * iconSize); CTX.bezierCurveTo(0.0, 0.8125 * iconSize, 0.0, 0.8125 * iconSize, 0.0625 * iconSize, 0.8125 * iconSize); CTX.bezierCurveTo(0.0625 * iconSize, 0.8125 * iconSize, 0.5 * iconSize, 0.8125 * iconSize, 0.5 * iconSize, 0.8125 * iconSize); CTX.bezierCurveTo(0.5 * iconSize, 0.8125 * iconSize, iconSize, 0.8125 * iconSize, iconSize, 0.8125 * iconSize); CTX.bezierCurveTo(iconSize, 0.8125 * iconSize, iconSize, 0.8125 * iconSize, iconSize, 0.8125 * iconSize); CTX.bezierCurveTo(iconSize, 0.8125 * iconSize, iconSize, 0.8125 * iconSize, iconSize, 0.8125 * iconSize); CTX.bezierCurveTo(iconSize, 0.8125 * iconSize, iconSize, 0.8125 * iconSize, iconSize, 0.8125 * iconSize); CTX.closePath(); CTX.setFill(COLOR); CTX.fill(); CTX.restore(); }
Example 13
Source File: BasicTextRenderer.java From arma-dialog-creator with MIT License | 5 votes |
/** Will paint the text where there renderer wants to. This will also create a clip for the text. The text will be clipped if it exceeds the width of the control. @param gc context to use */ public void paint(GraphicsContext gc) { gc.save(); gc.beginPath(); //don't let the text render past the control's bounds gc.rect(renderer.getLeftX(), renderer.getTopY(), renderer.getWidth(), renderer.getHeight()); gc.closePath(); gc.clip(); paint(gc, getTextX(), getTextY()); gc.restore(); }
Example 14
Source File: Patterns.java From FXyzLib with GNU General Public License v3.0 | 4 votes |
public static final ImagePattern createCarbonKevlarPattern() { final double WIDTH = 12; final double HEIGHT = 12; final Canvas CANVAS = new Canvas(WIDTH, HEIGHT); final GraphicsContext CTX = CANVAS.getGraphicsContext2D(); double offsetY = 0; /// 1= border=yellow=dark======================================================== CTX.beginPath(); CTX.rect(0, 0, WIDTH * 0.5, HEIGHT * 0.5); CTX.closePath(); CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(105, 105, 0)), new Stop(1, Color.rgb(98, 98, 0)))); CTX.fill(); // 2=body=yellow============================== CTX.beginPath(); CTX.rect(WIDTH * 0.083333, 0, WIDTH * 0.333333, HEIGHT * 0.416666); CTX.closePath(); offsetY = 0; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(138, 138, 0)), new Stop(1, Color.rgb(130, 130, 0)))); CTX.fill(); // 3=border=yellow=dark============================= CTX.beginPath(); CTX.rect(WIDTH * 0.5, HEIGHT * 0.5, WIDTH * 0.5, HEIGHT * 0.5); CTX.closePath(); offsetY = 0.5; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(105, 105, 0)), new Stop(1, Color.rgb(98, 98, 0)))); CTX.fill(); // 4=body=yellow============================================================ CTX.beginPath(); CTX.rect(WIDTH * 0.583333, HEIGHT * 0.5, WIDTH * 0.333333, HEIGHT * 0.416666); CTX.closePath(); offsetY = 0.5; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(138, 138, 0)), new Stop(1, Color.rgb(130, 130, 0)))); CTX.fill(); // 5= border=gray=dark============================ CTX.beginPath(); CTX.rect(WIDTH * 0.5, 0, WIDTH * 0.5, HEIGHT * 0.5); CTX.closePath(); offsetY = 0; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(48, 48, 48)), new Stop(1, Color.rgb(30, 30, 30)))); CTX.fill(); // 6=body=gray============================= CTX.beginPath(); CTX.rect(WIDTH * 0.583333, HEIGHT * 0.083333, WIDTH * 0.333333, HEIGHT * 0.416666); CTX.closePath(); offsetY = 0.083333; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(53, 53, 53)), new Stop(1, Color.rgb(45, 45, 45)))); CTX.fill(); // 7= border=gray=dark============================= CTX.beginPath(); CTX.rect(0, HEIGHT * 0.5, WIDTH * 0.5, HEIGHT * 0.5); CTX.closePath(); offsetY = 0.5; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(48, 48, 48)), new Stop(1, Color.rgb(40, 40, 40)))); CTX.fill(); // 8= body=gray=light============================== CTX.beginPath(); CTX.rect(WIDTH * 0.083333, HEIGHT * 0.583333, WIDTH * 0.333333, HEIGHT * 0.416666); CTX.closePath(); offsetY = 0.583333; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(53, 53, 53)), new Stop(1, Color.rgb(45, 45, 45)))); CTX.fill(); final Image PATTERN_IMAGE = CANVAS.snapshot(new SnapshotParameters(), null); final ImagePattern PATTERN = new ImagePattern(PATTERN_IMAGE, 0, 0, WIDTH, HEIGHT, false); return PATTERN; }
Example 15
Source File: Patterns.java From FXyzLib with GNU General Public License v3.0 | 4 votes |
public static final ImagePattern createLightCarbonPattern() { final double WIDTH = 12; final double HEIGHT = 12; final Canvas CANVAS = new Canvas(WIDTH, HEIGHT); final GraphicsContext CTX = CANVAS.getGraphicsContext2D(); double offsetY = 0; CTX.beginPath(); CTX.rect(0, 0, WIDTH * 0.5, HEIGHT * 0.5); CTX.closePath(); CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(108, 108, 108)), new Stop(1, Color.rgb(100, 100, 100)))); CTX.fill(); CTX.beginPath(); CTX.rect(WIDTH * 0.083333, 0, WIDTH * 0.333333, HEIGHT * 0.416666); CTX.closePath(); offsetY = 0; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(142, 142, 142)), new Stop(1, Color.rgb(130, 130, 130)))); CTX.fill(); CTX.beginPath(); CTX.rect(WIDTH * 0.5, HEIGHT * 0.5, WIDTH * 0.5, HEIGHT * 0.5); CTX.closePath(); offsetY = 0.5; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(108, 108, 108)), new Stop(1, Color.rgb(100, 100, 100)))); CTX.fill(); CTX.beginPath(); CTX.rect(WIDTH * 0.583333, HEIGHT * 0.5, WIDTH * 0.333333, HEIGHT * 0.416666); CTX.closePath(); offsetY = 0.5; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(142, 142, 142)), new Stop(1, Color.rgb(130, 130, 130)))); CTX.fill(); CTX.beginPath(); CTX.rect(WIDTH * 0.5, 0, WIDTH * 0.5, HEIGHT * 0.5); CTX.closePath(); offsetY = 0; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(152, 152, 152)), new Stop(1, Color.rgb(146, 146, 146)))); CTX.fill(); CTX.beginPath(); CTX.rect(WIDTH * 0.583333, HEIGHT * 0.083333, WIDTH * 0.333333, HEIGHT * 0.416666); CTX.closePath(); offsetY = 0.083333; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(160, 160, 160)), new Stop(1, Color.rgb(152, 152, 152)))); CTX.fill(); CTX.beginPath(); CTX.rect(0, HEIGHT * 0.5, WIDTH * 0.5, HEIGHT * 0.5); CTX.closePath(); offsetY = 0.5; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(152, 152, 152)), new Stop(1, Color.rgb(146, 146, 146)))); CTX.fill(); CTX.beginPath(); CTX.rect(WIDTH * 0.083333, HEIGHT * 0.583333, WIDTH * 0.333333, HEIGHT * 0.416666); CTX.closePath(); offsetY = 0.583333; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(160, 160, 160)), new Stop(1, Color.rgb(152, 152, 152)))); CTX.fill(); final Image PATTERN_IMAGE = CANVAS.snapshot(new SnapshotParameters(), null); final ImagePattern PATTERN = new ImagePattern(PATTERN_IMAGE, 0, 0, WIDTH, HEIGHT, false); return PATTERN; }
Example 16
Source File: DecoderPeer.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 17
Source File: Patterns.java From FXyzLib with GNU General Public License v3.0 | 4 votes |
public static final ImagePattern createCarbonPattern() { final double WIDTH = 12; final double HEIGHT = 12; final Canvas CANVAS = new Canvas(WIDTH, HEIGHT); final GraphicsContext CTX = CANVAS.getGraphicsContext2D(); double offsetY = 0; CTX.beginPath(); CTX.rect(0, 0, WIDTH * 0.5, HEIGHT * 0.5); CTX.closePath(); CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(35, 35, 35)), new Stop(1, Color.rgb(23, 23, 23)))); CTX.fill(); CTX.beginPath(); CTX.rect(WIDTH * 0.083333, 0, WIDTH * 0.333333, HEIGHT * 0.416666); CTX.closePath(); offsetY = 0; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(38, 38, 38)), new Stop(1, Color.rgb(30, 30, 30)))); CTX.fill(); CTX.beginPath(); CTX.rect(WIDTH * 0.5, HEIGHT * 0.5, WIDTH * 0.5, HEIGHT * 0.5); CTX.closePath(); offsetY = 0.5; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(35, 35, 35)), new Stop(1, Color.rgb(23, 23, 23)))); CTX.fill(); CTX.beginPath(); CTX.rect(WIDTH * 0.583333, HEIGHT * 0.5, WIDTH * 0.333333, HEIGHT * 0.416666); CTX.closePath(); offsetY = 0.5; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(38, 38, 38)), new Stop(1, Color.rgb(30, 30, 30)))); CTX.fill(); CTX.beginPath(); CTX.rect(WIDTH * 0.5, 0, WIDTH * 0.5, HEIGHT * 0.5); CTX.closePath(); offsetY = 0; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(48, 48, 48)), new Stop(1, Color.rgb(40, 40, 40)))); CTX.fill(); CTX.beginPath(); CTX.rect(WIDTH * 0.583333, HEIGHT * 0.083333, WIDTH * 0.333333, HEIGHT * 0.416666); CTX.closePath(); offsetY = 0.083333; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(53, 53, 53)), new Stop(1, Color.rgb(45, 45, 45)))); CTX.fill(); CTX.beginPath(); CTX.rect(0, HEIGHT * 0.5, WIDTH * 0.5, HEIGHT * 0.5); CTX.closePath(); offsetY = 0.5; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(48, 48, 48)), new Stop(1, Color.rgb(40, 40, 40)))); CTX.fill(); CTX.beginPath(); CTX.rect(WIDTH * 0.083333, HEIGHT * 0.583333, WIDTH * 0.333333, HEIGHT * 0.416666); CTX.closePath(); offsetY = 0.583333; CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(53, 53, 53)), new Stop(1, Color.rgb(45, 45, 45)))); CTX.fill(); final Image PATTERN_IMAGE = CANVAS.snapshot(new SnapshotParameters(), null); final ImagePattern PATTERN = new ImagePattern(PATTERN_IMAGE, 0, 0, WIDTH, HEIGHT, false); return PATTERN; }
Example 18
Source File: ComboRenderer.java From arma-dialog-creator with MIT License | 4 votes |
public void paint(@NotNull GraphicsContext gc, CanvasContext canvasContext) { boolean preview = paintPreview(canvasContext); if (!isEnabled()) { Color oldTextColor = textRenderer.getTextColor(); super.paint(gc, canvasContext); textRenderer.setTextColor(colorDisabled); textRenderer.paint(gc); textRenderer.setTextColor(oldTextColor); //in Arma 3, when combo is disabled, the arrow isn't visible } else { if (preview) { blinkControlHandler.paint(gc); if (this.mouseOver) { canvasContext.paintLast(tooltipRenderFunc); } } Color textColor = textRenderer.getTextColor(); if (preview && focused && !menuDown) { Color backgroundColor = getBackgroundColor(); textRenderer.setTextColor(colorSelect); setBackgroundColor(colorSelectBackground); super.paint(gc, canvasContext); textRenderer.paint(gc); textRenderer.setTextColor(textColor); setBackgroundColor(backgroundColor); } else { super.paint(gc, canvasContext); textRenderer.paint(gc); } if (preview && menuDown) { paintArrow(gc, arrowFull_combo); { //draw drop down menu final int textPadding = (int) Math.round(getWidth() * BasicTextRenderer.TEXT_PADDING); int textAndScrollbarWidth = textRenderer.getTextWidth() + textPadding + ScrollbarRenderer.SCROLLBAR_WIDTH; int menuX1 = x1; int menuY1 = y2; int menuX2 = textAndScrollbarWidth > getWidth() ? x1 + textAndScrollbarWidth : x2; int menuY2 = y2 + menuHeightInPixels; gc.setStroke(backgroundColor); Region.fillRectangle(gc, menuX1, menuY1, menuX2, menuY2); scrollbarRenderer.paint(gc, true, menuX2 - ScrollbarRenderer.SCROLLBAR_WIDTH, menuY1, menuHeightInPixels); //this is to guarantee that the text purposefully placed out of bounds on the control are clipped gc.rect(menuX1, menuY1, menuX2 - menuX1 - ScrollbarRenderer.SCROLLBAR_WIDTH, menuY2 - menuY1); gc.closePath(); gc.clip(); //draw text for drop down menu int allTextHeight = 0; int leftTextX = x1 + textPadding; int textHeight = textRenderer.getTextLineHeight(); while (allTextHeight <= menuHeightInPixels && textHeight > 0) { //<= to make sure text goes out of bounds of menu to force scrollbar int rowY1 = menuY1 + allTextHeight; int rowY2 = rowY1 + textHeight; if (mouseOverY >= rowY1 && mouseOverY < rowY2) { //mouse is over this row gc.setStroke(colorSelectBackground); Region.fillRectangle(gc, x1, rowY1, menuX2, rowY2); gc.setStroke(backgroundColor); textRenderer.setTextColor(colorSelect); textRenderer.paint(gc, leftTextX, menuY1 + allTextHeight); textRenderer.setTextColor(textColor); } else { textRenderer.paint(gc, leftTextX, menuY1 + allTextHeight); } allTextHeight += textHeight; } } } else { paintArrow(gc, arrowEmpty_combo); } } }
Example 19
Source File: ErrorDataSetRenderer.java From chart-fx with Apache License 2.0 | 4 votes |
protected static void drawPolyLineLine(final GraphicsContext gc, final CachedDataPoints localCachedPoints) { gc.save(); DefaultRenderColorScheme.setLineScheme(gc, localCachedPoints.defaultStyle, localCachedPoints.dataSetIndex + localCachedPoints.dataSetStyleIndex); DefaultRenderColorScheme.setGraphicsContextAttributes(gc, localCachedPoints.defaultStyle); if (localCachedPoints.allowForNaNs) { gc.beginPath(); gc.moveTo(localCachedPoints.xValues[0], localCachedPoints.yValues[0]); boolean lastIsFinite = true; double xLastValid = 0.0; double yLastValid = 0.0; for (int i = 0; i < localCachedPoints.actualDataCount; i++) { final double x0 = localCachedPoints.xValues[i]; final double y0 = localCachedPoints.yValues[i]; if (Double.isFinite(x0) && Double.isFinite(y0)) { if (!lastIsFinite) { gc.moveTo(x0, y0); lastIsFinite = true; continue; } gc.lineTo(x0, y0); xLastValid = x0; yLastValid = y0; lastIsFinite = true; } else { lastIsFinite = false; } } gc.moveTo(xLastValid, yLastValid); gc.closePath(); gc.stroke(); } else { if (gc.getLineDashes() != null) { gc.strokePolyline(localCachedPoints.xValues, localCachedPoints.yValues, localCachedPoints.actualDataCount); } else { for (int i = 0; i < localCachedPoints.actualDataCount - 1; i++) { final double x1 = localCachedPoints.xValues[i]; final double x2 = localCachedPoints.xValues[i + 1]; final double y1 = localCachedPoints.yValues[i]; final double y2 = localCachedPoints.yValues[i + 1]; gc.strokeLine(x1, y1, x2, y2); } } } gc.restore(); }
Example 20
Source File: ErrorDataSetRenderer.java From chart-fx with Apache License 2.0 | 4 votes |
protected static void drawPolyLineHistogramBezier(final GraphicsContext gc, final CachedDataPoints localCachedPoints) { final int n = localCachedPoints.actualDataCount; if (n < 2) { drawPolyLineLine(gc, localCachedPoints); return; } // need to allocate new array :-( final double[] xCp1 = DoubleArrayCache.getInstance().getArrayExact(n); final double[] yCp1 = DoubleArrayCache.getInstance().getArrayExact(n); final double[] xCp2 = DoubleArrayCache.getInstance().getArrayExact(n); final double[] yCp2 = DoubleArrayCache.getInstance().getArrayExact(n); BezierCurve.calcCurveControlPoints(localCachedPoints.xValues, localCachedPoints.yValues, xCp1, yCp1, xCp2, yCp2, localCachedPoints.actualDataCount); gc.save(); DefaultRenderColorScheme.setLineScheme(gc, localCachedPoints.defaultStyle, localCachedPoints.dataSetIndex + localCachedPoints.dataSetStyleIndex); DefaultRenderColorScheme.setGraphicsContextAttributes(gc, localCachedPoints.defaultStyle); // use stroke as fill colour gc.setFill(gc.getStroke()); gc.beginPath(); for (int i = 0; i < n - 1; i++) { final double x0 = localCachedPoints.xValues[i]; final double x1 = localCachedPoints.xValues[i + 1]; final double y0 = localCachedPoints.yValues[i]; final double y1 = localCachedPoints.yValues[i + 1]; // coordinates of first Bezier control point. final double xc0 = xCp1[i]; final double yc0 = yCp1[i]; // coordinates of the second Bezier control point. final double xc1 = xCp2[i]; final double yc1 = yCp2[i]; gc.moveTo(x0, y0); gc.bezierCurveTo(xc0, yc0, xc1, yc1, x1, y1); } gc.moveTo(localCachedPoints.xValues[n - 1], localCachedPoints.yValues[n - 1]); gc.closePath(); gc.stroke(); gc.restore(); // release arrays to Cache DoubleArrayCache.getInstance().add(xCp1); DoubleArrayCache.getInstance().add(yCp1); DoubleArrayCache.getInstance().add(xCp2); DoubleArrayCache.getInstance().add(yCp2); }