Java Code Examples for javafx.scene.canvas.GraphicsContext#beginPath()

The following examples show how to use javafx.scene.canvas.GraphicsContext#beginPath() . 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: ToolGraphics.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
private static void applyPath(GraphicsContext pGraphics, Path pPath)
{
	pGraphics.beginPath();
	for(PathElement element : pPath.getElements())
	{
		if(element instanceof MoveTo)
		{
			pGraphics.moveTo(((int)((MoveTo) element).getX()) + 0.5, ((int)((MoveTo) element).getY()) + 0.5);
		}
		else if(element instanceof LineTo)
		{
			pGraphics.lineTo(((int)((LineTo) element).getX()) + 0.5, ((int)((LineTo) element).getY()) + 0.5);
		}
		else if (element instanceof QuadCurveTo)
		{
			QuadCurveTo curve = (QuadCurveTo) element;
			pGraphics.quadraticCurveTo(((int)curve.getControlX())+0.5, ((int)curve.getControlY()) + 0.5, 
					((int) curve.getX()) + 0.5, ((int) curve.getY()) + 0.5);
		}
	}
}
 
Example 2
Source File: ControlledBufferPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 3
Source File: XnorGatePeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 + width * 0.1, y + height);
	graphics.arc(x + width * 0.1, 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 + width * 0.1, y + height, width * 0.7);
	graphics.closePath();
	
	graphics.setFill(Color.WHITE);
	graphics.setStroke(Color.BLACK);
	graphics.fill();
	graphics.stroke();
	
	graphics.strokeArc(x - width * 0.3, y, width * 0.5, height, 270, 180, ArcType.OPEN);
	
	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 4
Source File: Helper.java    From charts with Apache License 2.0 6 votes vote down vote up
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: Path.java    From charts with Apache License 2.0 6 votes vote down vote up
public void draw(final GraphicsContext CTX, final boolean FILL, final boolean STROKE) {
    PathIterator pi = getPathIterator(new Affine());

    CTX.setFillRule(WindingRule.WIND_EVEN_ODD == pi.getWindingRule() ? FillRule.EVEN_ODD : FillRule.NON_ZERO);
    CTX.beginPath();

    double[] seg = new double[6];
    int      segType;

    while(!pi.isDone()) {
        segType = pi.currentSegment(seg);
        switch (segType) {
            case PathIterator.MOVE_TO  : CTX.moveTo(seg[0], seg[1]); break;
            case PathIterator.LINE_TO  : CTX.lineTo(seg[0], seg[1]); break;
            case PathIterator.QUAD_TO  : CTX.quadraticCurveTo(seg[0], seg[1], seg[2], seg[3]);break;
            case PathIterator.BEZIER_TO: CTX.bezierCurveTo(seg[0], seg[1], seg[2], seg[3], seg[4], seg[5]);break;
            case PathIterator.CLOSE    : CTX.closePath();break;
            default                    : break;
        }
        pi.next();
    }

    if (FILL)   { CTX.setFill(fill); CTX.fill(); }
    if (STROKE) { CTX.setStroke(stroke); CTX.stroke(); }
}
 
Example 6
Source File: Helper.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
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: AndGatePeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 8
Source File: StructuredTextRenderer.java    From arma-dialog-creator with MIT License 6 votes vote down vote up
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: XorGatePeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 + width * 0.1, y + height);
	graphics.arc(x + width * 0.1, 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 + width * 0.1, y + height, width);
	graphics.closePath();
	
	graphics.setFill(Color.WHITE);
	graphics.setStroke(Color.BLACK);
	graphics.fill();
	graphics.stroke();
	
	graphics.strokeArc(x - width * 0.3, y, width * 0.5, height, 270, 180, ArcType.OPEN);
}
 
Example 10
Source File: NorGatePeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 11
Source File: NotGatePeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void paintGate(GraphicsContext graphics, CircuitState circuitState) {
	int x = getScreenX();
	int y = getScreenY();
	int width = 3 * GuiUtils.BLOCK_SIZE;
	int height = 2 * GuiUtils.BLOCK_SIZE;
	
	graphics.beginPath();
	graphics.moveTo(x, y);
	graphics.lineTo(x, y + height);
	graphics.lineTo(x + width * 0.7, y + height * 0.5);
	graphics.closePath();
	
	graphics.setFill(Color.WHITE);
	graphics.setStroke(Color.BLACK);
	graphics.fill();
	graphics.stroke();
	
	graphics.fillOval(x + width * 0.7, y + height * 0.5 - width * 0.125, width * 0.25, width * 0.25);
	graphics.strokeOval(x + width * 0.7, y + height * 0.5 - width * 0.125, width * 0.25, width * 0.25);
}
 
Example 12
Source File: Helper.java    From Medusa with Apache License 2.0 5 votes vote down vote up
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 13
Source File: RoundLcdClock.java    From Enzo with Apache License 2.0 5 votes vote down vote up
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 14
Source File: StructuredTextRenderer.java    From arma-dialog-creator with MIT License 5 votes vote down vote up
/** Note (July 29, 2017) this is the implementation for painting structured text. Notice it isn't done yet */
@Deprecated
private void paintStructuredText(@NotNull GraphicsContext gc) {
	final int controlWidth = getWidth();
	gc.beginPath();
	gc.rect(x1, y1, controlWidth, getHeight());
	gc.closePath();
	gc.clip(); //prevent text going out of bounds


	int rowWidth = 0;
	int rowY = y1;

	for (GraphicTextSection section : sections) {
		gc.setFont(section.font);
		if (section.textColor == null) {
			gc.setFill(defaultSectionData.textColor);
		} else {
			gc.setFill(section.textColor);
		}

		boolean outOfBounds = section.textWidth + rowWidth > controlWidth;
		if (outOfBounds) {
			FontMetrics fontMetrics = new FontMetrics(section.font);
			StringBuilder sb = new StringBuilder(section.text);
			//break the text into multiple lines
			while (section.textWidth + rowWidth > controlWidth) {

			}
		} else {

		}
	}
}
 
Example 15
Source File: DemultiplexerPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@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 16
Source File: DecoderPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@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: MultiplexerPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@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 18
Source File: Tunnel.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState circuitState) {
	Direction direction = getProperties().getValue(Properties.DIRECTION);
	
	boolean isIncompatible = isIncompatible();
	
	graphics.setStroke(Color.BLACK);
	graphics.setFill(isIncompatible ? Color.ORANGE : Color.WHITE);
	
	int block = GuiUtils.BLOCK_SIZE;
	int x = getScreenX();
	int y = getScreenY();
	int width = getScreenWidth();
	int height = getScreenHeight();
	
	int xOff = 0;
	int yOff = 0;
	
	switch(direction) {
		case EAST:
			xOff = -block;
			graphics.beginPath();
			graphics.moveTo(x + width, y + height * 0.5);
			graphics.lineTo(x + width - block, y + height);
			graphics.lineTo(x, y + height);
			graphics.lineTo(x, y);
			graphics.lineTo(x + width - block, y);
			graphics.closePath();
			break;
		case WEST:
			xOff = block;
			graphics.beginPath();
			graphics.moveTo(x, y + height * 0.5);
			graphics.lineTo(x + block, y);
			graphics.lineTo(x + width, y);
			graphics.lineTo(x + width, y + height);
			graphics.lineTo(x + block, y + height);
			graphics.closePath();
			break;
		case NORTH:
			yOff = block;
			graphics.beginPath();
			graphics.moveTo(x + width * 0.5, y);
			graphics.lineTo(x + width, y + block);
			graphics.lineTo(x + width, y + height);
			graphics.lineTo(x, y + height);
			graphics.lineTo(x, y + block);
			graphics.closePath();
			break;
		case SOUTH:
			yOff = -block;
			graphics.beginPath();
			graphics.moveTo(x + width * 0.5, y + height);
			graphics.lineTo(x, y + height - block);
			graphics.lineTo(x, y);
			graphics.lineTo(x + width, y);
			graphics.lineTo(x + width, y + height - block);
			graphics.closePath();
			break;
	}
	
	graphics.fill();
	graphics.stroke();
	
	if(!label.isEmpty()) {
		Bounds bounds = GuiUtils.getBounds(graphics.getFont(), label);
		graphics.setFill(Color.BLACK);
		graphics.fillText(label,
		                  x + xOff + ((width - xOff) - bounds.getWidth()) * 0.5,
		                  y + yOff + ((height - yOff) + bounds.getHeight()) * 0.4);
	}
	
	if(isIncompatible) {
		PortConnection port = getConnections().get(0);
		
		graphics.setFill(Color.BLACK);
		graphics.fillText(String.valueOf(bitSize),
		                  port.getScreenX() + 11,
		                  port.getScreenY() + 21);
		
		graphics.setStroke(Color.ORANGE);
		graphics.setFill(Color.ORANGE);
		graphics.strokeOval(port.getScreenX() - 2, port.getScreenY() - 2, 10, 10);
		graphics.fillText(String.valueOf(bitSize),
		                  port.getScreenX() + 10,
		                  port.getScreenY() + 20);
	}
}
 
Example 19
Source File: Patterns.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
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 20
Source File: Patterns.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
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;
}