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

The following examples show how to use javafx.scene.canvas.GraphicsContext#setFont() . 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: AdderPeer.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));
	
	graphics.setFill(Color.WHITE);
	graphics.setStroke(Color.BLACK);
	GuiUtils.drawShape(graphics::fillRect, this);
	GuiUtils.drawShape(graphics::strokeRect, this);
	
	graphics.setFont(GuiUtils.getFont(16, true));
	Bounds bounds = GuiUtils.getBounds(graphics.getFont(), "+");
	graphics.setFill(Color.BLACK);
	graphics.fillText("+",
	                  getScreenX() + (getScreenWidth() - bounds.getWidth()) * 0.5,
	                  getScreenY() + (getScreenHeight() + bounds.getHeight()) * 0.45);
}
 
Example 2
Source File: AbstractAxis.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
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 3
Source File: ConstantPeer.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));
	
	graphics.setFont(GuiUtils.getFont(16));
	graphics.setFill(Color.GRAY);
	graphics.setStroke(Color.GRAY);
	
	graphics.fillRoundRect(getScreenX(), getScreenY(), getScreenWidth(), getScreenHeight(), 10, 10);
	graphics.strokeRoundRect(getScreenX(), getScreenY(), getScreenWidth(), getScreenHeight(), 10, 10);
	
	if(value.getBitSize() > 1) {
		graphics.setFill(Color.BLACK);
	} else {
		GuiUtils.setBitColor(graphics, value.getBit(0));
	}
	
	GuiUtils.drawValue(graphics, value.toString(), getScreenX(), getScreenY(), getScreenWidth());
}
 
Example 4
Source File: FillOverlay.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void drawOverlays(final GraphicsContext g)
{

	if (visible && this.viewer.isMouseInside())
	{

		{
			this.viewer.getScene().setCursor(Cursor.CROSSHAIR);
			g.setFill(Color.WHITE);
			g.setFont(Font.font(g.getFont().getFamily(), 15.0));
			g.fillText("Fill 3D", x + 5, y - 5);
			//				this.viewer.getScene().setCursor( Cursor.NONE );
			return;
		}
	}
	if (wasVisible)
	{
		this.viewer.getScene().setCursor(Cursor.DEFAULT);
		wasVisible = false;
	}
}
 
Example 5
Source File: DividerPeer.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));
	
	graphics.setFill(Color.WHITE);
	graphics.setStroke(Color.BLACK);
	GuiUtils.drawShape(graphics::fillRect, this);
	GuiUtils.drawShape(graphics::strokeRect, this);
	
	graphics.setFont(GuiUtils.getFont(16, true));
	Bounds bounds = GuiUtils.getBounds(graphics.getFont(), "÷");
	graphics.setFill(Color.BLACK);
	graphics.fillText("÷",
	                  getScreenX() + (getScreenWidth() - bounds.getWidth()) * 0.5,
	                  getScreenY() + (getScreenHeight() + bounds.getHeight()) * 0.45);
}
 
Example 6
Source File: LetterAvatar.java    From youtube-comment-suite with MIT License 6 votes vote down vote up
private void draw() {
    Canvas canvas = new Canvas(scale, scale);
    GraphicsContext gc = canvas.getGraphicsContext2D();

    gc.setFill(Color.TRANSPARENT);
    gc.fillRect(0, 0, scale, scale);

    gc.setFill(background);
    gc.fillRect(0, 0, scale, scale);

    gc.setFill(Color.WHITE);
    gc.setTextAlign(TextAlignment.CENTER);
    gc.setTextBaseline(VPos.CENTER);
    gc.setFont(Font.font("Tahoma", FontWeight.SEMI_BOLD, scale * 0.6));

    gc.fillText(String.valueOf(character), Math.round(scale / 2.0), Math.round(scale / 2.0));
    Platform.runLater(() -> canvas.snapshot(null, this));
}
 
Example 7
Source File: DefaultRenderColorScheme.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
public static void setGraphicsContextAttributes(final GraphicsContext gc, final String style) {
    if ((gc == null) || (style == null)) {
        return;
    }

    final Color strokeColor = StyleParser.getColorPropertyValue(style, XYChartCss.STROKE_COLOR);
    if (strokeColor != null) {
        gc.setStroke(strokeColor);
    }

    final Color fillColor = StyleParser.getColorPropertyValue(style, XYChartCss.FILL_COLOR);
    if (fillColor != null) {
        gc.setFill(fillColor);
    }

    final Double strokeWidth = StyleParser.getFloatingDecimalPropertyValue(style, XYChartCss.STROKE_WIDTH);
    if (strokeWidth != null) {
        gc.setLineWidth(strokeWidth);
    }

    final Font font = StyleParser.getFontPropertyValue(style);
    if (font != null) {
        gc.setFont(font);
    }

    final double[] dashPattern = StyleParser.getFloatingDecimalArrayPropertyValue(style,
            XYChartCss.STROKE_DASH_PATTERN);
    if (dashPattern != null) {
        gc.setLineDashes(dashPattern);
    }
}
 
Example 8
Source File: RegisterPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState circuitState) {
	GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION));
	
	graphics.setFill(Color.WHITE);
	GuiUtils.drawShape(graphics::fillRect, this);
	
	String value = circuitState.getLastPushed(getComponent().getPort(Register.PORT_OUT)).toHexString();
	
	int x = getScreenX();
	int y = getScreenY();
	int width = getScreenWidth();
	int height = getScreenHeight();
	
	graphics.setFill(Color.BLACK);
	graphics.setFont(GuiUtils.getFont(13));
	for(int i = 0; i * 4 < value.length(); i++) {
		int endIndex = i * 4 + 4 > value.length() ? value.length() : 4 * i + 4;
		String toPrint = value.substring(4 * i, endIndex);
		Bounds bounds = GuiUtils.getBounds(graphics.getFont(), toPrint, false);
		graphics.fillText(toPrint, x + width * 0.5 - bounds.getWidth() * 0.5, y + 11 + 10 * i);
	}
	graphics.setStroke(Color.BLACK);
	GuiUtils.drawShape(graphics::strokeRect, this);
	
	graphics.setFill(Color.GRAY);
	graphics.setFont(GuiUtils.getFont(10));
	graphics.fillText("D", x + 3, y + height * 0.5 + 6);
	graphics.fillText("Q", x + width - 10, y + height * 0.5 + 6);
	graphics.fillText("en", x + 3, y + height - 7);
	graphics.fillText("0", x + width - 13, y + height - 4);
	
	graphics.setStroke(Color.BLACK);
	GuiUtils.drawClockInput(graphics, clockConnection, Direction.SOUTH);
}
 
Example 9
Source File: ComparatorPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState circuitState) {
	GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION));
	
	graphics.setStroke(Color.BLACK);
	graphics.setFill(Color.WHITE);
	GuiUtils.drawShape(graphics::fillRect, this);
	GuiUtils.drawShape(graphics::strokeRect, this);
	
	graphics.setFont(GuiUtils.getFont(12, true));
	graphics.setFill(Color.BLACK);
	graphics.fillText("<", getScreenX() + getScreenWidth() - 12, getScreenY() + 12);
	graphics.fillText("=", getScreenX() + getScreenWidth() - 12, getScreenY() + 24);
	graphics.fillText(">", getScreenX() + getScreenWidth() - 12, getScreenY() + 35);
}
 
Example 10
Source File: SRFlipFlopPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState state) {
	GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION));
	
	graphics.setFill(Color.WHITE);
	graphics.setStroke(Color.BLACK);
	GuiUtils.drawShape(graphics::fillRect, this);
	GuiUtils.drawShape(graphics::strokeRect, this);
	
	int x = getScreenX();
	int y = getScreenY();
	int width = getScreenWidth();
	int height = getScreenHeight();
	
	State bit = state.getLastPushed(getComponent().getPort(SRFlipFlop.PORT_Q)).getBit(0);
	GuiUtils.setBitColor(graphics, bit);
	graphics.fillOval(x + width * 0.5 - 10, y + height * 0.5 - 10, 20, 20);
	
	graphics.setFill(Color.WHITE);
	graphics.setFont(GuiUtils.getFont(16));
	graphics.fillText(String.valueOf(bit.repr), x + width * 0.5 - 5, y + height * 0.5 + 6);
	
	graphics.setFill(Color.GRAY);
	graphics.setFont(GuiUtils.getFont(10));
	graphics.fillText("Q", x + width - 10, y + 13);
	graphics.fillText("1", x + 7, y + height - 4);
	graphics.fillText("en", x + width * 0.5 - 6, y + height - 4);
	graphics.fillText("0", x + width - 13, y + height - 4);
	graphics.fillText("S", x + 3, y + 13);
	graphics.fillText("R", x + 3, y + height - 7);
	
	graphics.setStroke(Color.BLACK);
	GuiUtils.drawClockInput(graphics, clockConnection, Direction.WEST);
}
 
Example 11
Source File: PinPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState circuitState) {
	GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION));
	
	graphics.setFont(GuiUtils.getFont(16, true));
	Port port = getComponent().getPort(Pin.PORT);
	WireValue value = isInput() ? circuitState.getLastPushed(port)
	                            : circuitState.getLastReceived(port);
	if(circuitState.isShortCircuited(port.getLink())) {
		graphics.setFill(Color.RED);
	} else {
		if(value.getBitSize() == 1) {
			GuiUtils.setBitColor(graphics, value.getBit(0));
		} else {
			graphics.setFill(Color.WHITE);
		}
	}
	graphics.setStroke(Color.BLACK);
	
	if(isInput()) {
		GuiUtils.drawShape(graphics::fillRect, this);
		GuiUtils.drawShape(graphics::strokeRect, this);
	} else {
		graphics.fillRoundRect(getScreenX(), getScreenY(), getScreenWidth(), getScreenHeight(), 20, 20);
		graphics.strokeRoundRect(getScreenX(), getScreenY(), getScreenWidth(), getScreenHeight(), 20, 20);
	}
	
	graphics.setFill(port.getLink().getBitSize() > 1 ? Color.BLACK : Color.WHITE);
	GuiUtils.drawValue(graphics, value.toString(), getScreenX(), getScreenY(), getScreenWidth());
}
 
Example 12
Source File: DeckView.java    From Solitaire with GNU General Public License v2.0 5 votes vote down vote up
private Canvas createNewGameImage()
{
	double width = CardImages.getBack().getWidth();
	double height = CardImages.getBack().getHeight();
	Canvas canvas = new Canvas( width, height );
	GraphicsContext context = canvas.getGraphicsContext2D();
	
	// The reset image
	context.setStroke(Color.DARKGREEN);
	context.setLineWidth(IMAGE_NEW_LINE_WIDTH);
	context.strokeOval(width/4, height/2-width/4 + IMAGE_FONT_SIZE, width/2, width/2);

	// The text
	
	context.setTextAlign(TextAlignment.CENTER);
	context.setTextBaseline(VPos.CENTER);
	context.setFill(Color.DARKKHAKI);
	context.setFont(Font.font(Font.getDefault().getName(), IMAGE_FONT_SIZE));
	
	
	
	if( GameModel.instance().isCompleted() )
	{
		context.fillText("You won!", Math.round(width/2), IMAGE_FONT_SIZE);
	}
	else
	{
		context.fillText("Give up?", Math.round(width/2), IMAGE_FONT_SIZE);
	}
	context.setTextAlign(TextAlignment.CENTER);
	return canvas;
}
 
Example 13
Source File: DFlipFlopPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState state) {
	GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION));
	
	graphics.setFill(Color.WHITE);
	graphics.setStroke(Color.BLACK);
	GuiUtils.drawShape(graphics::fillRect, this);
	GuiUtils.drawShape(graphics::strokeRect, this);
	
	int x = getScreenX();
	int y = getScreenY();
	int width = getScreenWidth();
	int height = getScreenHeight();
	
	State bit = state.getLastPushed(getComponent().getPort(DFlipFlop.PORT_Q)).getBit(0);
	GuiUtils.setBitColor(graphics, bit);
	graphics.fillOval(x + width * 0.5 - 10, y + height * 0.5 - 10, 20, 20);
	
	graphics.setFill(Color.WHITE);
	graphics.setFont(GuiUtils.getFont(16));
	graphics.fillText(String.valueOf(bit.repr), x + width * 0.5 - 5, y + height * 0.5 + 6);
	
	graphics.setFill(Color.GRAY);
	graphics.setFont(GuiUtils.getFont(10));
	graphics.fillText("D", x + 3, y + height - 7);
	graphics.fillText("Q", x + width - 10, y + 13);
	graphics.fillText("1", x + 7, y + height - 4);
	graphics.fillText("en", x + width * 0.5 - 6, y + height - 4);
	graphics.fillText("0", x + width - 13, y + height - 4);
	
	graphics.setStroke(Color.BLACK);
	GuiUtils.drawClockInput(graphics, clockConnection, Direction.WEST);
}
 
Example 14
Source File: RAMPeer.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));
	
	graphics.setFill(Color.WHITE);
	GuiUtils.drawShape(graphics::fillRect, this);
	
	graphics.setStroke(Color.BLACK);
	GuiUtils.drawShape(graphics::strokeRect, this);
	
	graphics.setStroke(Color.BLACK);
	GuiUtils.drawClockInput(graphics, clockConnection, Direction.SOUTH);
	
	WireValue addressVal = circuitState.getLastReceived(getComponent().getPort(RAM.PORT_ADDRESS));
	WireValue valueVal;
	if(addressVal.isValidValue()) {
		int val = getComponent().load(circuitState, addressVal.getValue());
		valueVal = WireValue.of(val, getComponent().getDataBits());
	} else {
		valueVal = new WireValue(getComponent().getDataBits());
	}
	
	String address = addressVal.toHexString();
	String value = valueVal.toHexString();
	
	int x = getScreenX();
	int y = getScreenY();
	int width = getScreenWidth();
	int height = getScreenHeight();
	
	graphics.setFont(GuiUtils.getFont(11, true));
	
	String text = "RAM";
	Bounds bounds = GuiUtils.getBounds(graphics.getFont(), text);
	graphics.setFill(Color.BLACK);
	graphics.fillText(text,
	                  x + (width - bounds.getWidth()) * 0.5,
	                  y + (height + bounds.getHeight()) * 0.2);
	
	// Draw address
	text = "A: " + address;
	double addrY = y + bounds.getHeight() + 12;
	graphics.fillText(text, x + 13, addrY);
	
	// Draw data afterward
	bounds = GuiUtils.getBounds(graphics.getFont(), text);
	graphics.fillText("D: " + value, x + 13, addrY + bounds.getHeight());
	
	graphics.setFill(Color.GRAY);
	graphics.setFont(GuiUtils.getFont(10));
	graphics.fillText("A", x + 3, y + height * 0.5 - 1);
	graphics.fillText("D", x + width - 9, y + height * 0.5 - 1);
	graphics.fillText("en", x + width * 0.5 - 11.5, y + height - 3.5);
	graphics.fillText("L", x + width * 0.5 + 2, y + height - 3.5);
	
	if(isSeparateLoadStore()) {
		graphics.fillText("Din", x + 3, y + height * 0.5 + 20);
		graphics.fillText("St", x + width * 0.5 + 8.5, y + height - 3.5);
		graphics.fillText("0", x + width * 0.5 + 21.5, y + height - 3.5);
	} else {
		graphics.fillText("0", x + width * 0.5 + 11.5, y + height - 3.5);
	}
}
 
Example 15
Source File: PlainAmpSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
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: CustomPlainAmpSkin.java    From medusademo with Apache License 2.0 4 votes vote down vote up
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 17
Source File: BitExtenderPeer.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));
	
	graphics.setStroke(Color.BLACK);
	graphics.setFill(Color.WHITE);
	GuiUtils.drawShape(graphics::fillRect, this);
	GuiUtils.drawShape(graphics::strokeRect, this);
	
	graphics.setFont(GuiUtils.getFont(12, true));
	graphics.setFill(Color.BLACK);
	
	graphics.fillText(String.valueOf(getComponent().getInputBitSize()),
	                    getScreenX() + 3, getScreenY() + getScreenHeight() * 0.5 + 5);
	
	
	String outputString = String.valueOf(getComponent().getOutputBitSize());
	Bounds outputBounds = GuiUtils.getBounds(graphics.getFont(), outputString);
	
	graphics.fillText(outputString,
	                  getScreenX() + getScreenWidth() - outputBounds.getWidth() - 3,
	                  getScreenY() + getScreenHeight() * 0.5 + 5);
	
	String typeString = "";
	switch(getComponent().getExtensionType()) {
		case ZERO:
			typeString = "0";
			break;
		case ONE:
			typeString = "1";
			break;
		case SIGN:
			typeString = "sign";
			break;
	}
	
	Bounds typeBounds = GuiUtils.getBounds(graphics.getFont(), typeString);
	graphics.fillText(typeString,
	                  getScreenX() + (getScreenWidth() - typeBounds.getWidth()) * 0.5,
	                  getScreenY() + typeBounds.getHeight());
	
	graphics.setFont(GuiUtils.getFont(10, true));
	String extendString = "extend";
	Bounds extendBounds = GuiUtils.getBounds(graphics.getFont(), extendString);
	graphics.fillText(extendString,
	                  getScreenX() + (getScreenWidth() - extendBounds.getWidth()) * 0.5,
	                  getScreenY() + getScreenHeight() - 5);
}
 
Example 18
Source File: ModernSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void drawTickMarks(final GraphicsContext CTX) {
    double               sinValue;
    double               cosValue;
    double               centerX                = size * 0.5;
    double               centerY                = size * 0.5;
    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;
    boolean              majorTickMarksVisible  = gauge.getMajorTickMarksVisible();
    boolean              mediumTickMarksVisible = gauge.getMediumTickMarksVisible();
    boolean              tickLabelsVisible      = gauge.getTickLabelsVisible();
    TickLabelOrientation tickLabelOrientation   = gauge.getTickLabelOrientation();
    Color                tickMarkColor          = gauge.getTickMarkColor();
    Color                majorTickMarkColor     = tickMarkColor;
    Color                mediumTickMarkColor    = tickMarkColor;
    Color                tickLabelColor         = gauge.getTickLabelColor();

    double innerPointX;
    double innerPointY;
    double outerPointX;
    double outerPointY;
    double innerMediumPointX;
    double innerMediumPointY;
    double outerMediumPointX;
    double outerMediumPointY;
    double textPointX;
    double textPointY;

    double orthTextFactor = 0.46; //TickLabelOrientation.ORTHOGONAL == gauge.getTickLabelOrientation() ? 0.46 : 0.46;

    Font tickLabelFont = Fonts.robotoCondensedLight((decimals == 0 ? 0.047 : 0.040) * size);
    CTX.setFont(tickLabelFont);
    CTX.setTextAlign(TextAlignment.CENTER);
    CTX.setTextBaseline(VPos.CENTER);

    CTX.setLineCap(StrokeLineCap.BUTT);
    CTX.setLineWidth(size * 0.0035);
    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));

        innerPointX       = centerX + size * 0.375 * sinValue;
        innerPointY       = centerY + size * 0.375 * cosValue;
        outerPointX       = centerX + size * 0.425 * sinValue;
        outerPointY       = centerY + size * 0.425 * cosValue;
        innerMediumPointX = centerX + size * 0.35 * sinValue;
        innerMediumPointY = centerY + size * 0.35 * cosValue;
        outerMediumPointX = centerX + size * 0.4 * sinValue;
        outerMediumPointY = centerY + size * 0.4 * cosValue;
        textPointX        = centerX + size * orthTextFactor * sinValue;
        textPointY        = centerY + size * orthTextFactor * cosValue;

        // Set the general tickmark color
        CTX.setStroke(tickMarkColor);

        if (Double.compare(counterBD.remainder(majorTickSpaceBD).doubleValue(), 0.0) == 0) {
            // Draw major tick mark
            if (majorTickMarksVisible) {
                CTX.setFill(majorTickMarkColor);
                CTX.setStroke(majorTickMarkColor);
                CTX.strokeLine(innerPointX, innerPointY, outerPointX, outerPointY);
            }
            // Draw tick label text
            if (tickLabelsVisible) {
                CTX.save();
                CTX.translate(textPointX, textPointY);

                Helper.rotateContextForText(CTX, START_ANGLE, angle, tickLabelOrientation);

                CTX.setFill(tickLabelColor);
                if (TickLabelOrientation.HORIZONTAL == tickLabelOrientation &&
                    (Double.compare(counter, minValue) == 0 ||
                    Double.compare(counter, maxValue) == 0)) {
                        CTX.setFill(Color.TRANSPARENT);
                }
                CTX.fillText(String.format(locale, "%." + decimals + "f", counter), 0, 0);
                CTX.restore();
            }
        } else if (mediumTickMarksVisible &&
                   Double.compare(minorTickSpaceBD.remainder(mediumCheck2).doubleValue(), 0.0) != 0.0 &&
                   Double.compare(counterBD.remainder(mediumCheck5).doubleValue(), 0.0) == 0.0) {
            // Draw medium tick mark
            CTX.setFill(mediumTickMarkColor);
            CTX.setStroke(mediumTickMarkColor);
            CTX.strokeLine(innerMediumPointX, innerMediumPointY, outerMediumPointX, outerMediumPointY);
        }
        counterBD = counterBD.add(minorTickSpaceBD);
        counter   = counterBD.doubleValue();
    }
}
 
Example 19
Source File: GridRenderer.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
protected void drawPolarGrid(final GraphicsContext gc, XYChart xyChart) {
    final Axis xAxis = xyChart.getXAxis();
    final Axis yAxis = xyChart.getYAxis();
    final double xAxisWidth = xyChart.getCanvas().getWidth();
    final double yAxisHeight = xyChart.getCanvas().getHeight();
    final double xRange = xAxis.getWidth();
    final double yRange = yAxis.getHeight();
    final double xCentre = xRange / 2;
    final double yCentre = yRange / 2;
    final double maxRadius = 0.5 * Math.min(xRange, yRange) * 0.9;
    if (xAxis instanceof Node) {
        ((Node) xAxis).setVisible(false);
    }

    gc.save();
    if (verMajorGridStyleNode.isVisible() || verMinorGridStyleNode.isVisible()) {
        applyGraphicsStyleFromLineStyle(gc, verMajorGridStyleNode);
        for (double phi = 0.0; phi <= 360; phi += xyChart.getPolarStepSize().get()) {
            final double x = xCentre + maxRadius * Math.sin(phi * GridRenderer.DEG_TO_RAD);
            final double y = yCentre - maxRadius * Math.cos(phi * GridRenderer.DEG_TO_RAD);
            final double xl = xCentre + maxRadius * Math.sin(phi * GridRenderer.DEG_TO_RAD) * 1.05;
            final double yl = yCentre - maxRadius * Math.cos(phi * GridRenderer.DEG_TO_RAD) * 1.05;

            gc.strokeLine(xCentre, yCentre, x, y);

            gc.save();
            gc.setFont(yAxis.getTickLabelFont());
            gc.setStroke(yAxis.getTickLabelFill());
            gc.setLineDashes(null);
            gc.setTextBaseline(VPos.CENTER);
            if (phi < 350) {
                if (phi < 20) {
                    gc.setTextAlign(TextAlignment.CENTER);
                } else if (phi <= 160) {
                    gc.setTextAlign(TextAlignment.LEFT);
                } else if (phi <= 200) {
                    gc.setTextAlign(TextAlignment.CENTER);
                } else {
                    gc.setTextAlign(TextAlignment.RIGHT);
                }
                gc.strokeText(String.valueOf(phi), xl, yl);
            }
            gc.restore();

        }

        if (xAxis.isLogAxis() || verMinorGridStyleNode.isVisible()) {
            applyGraphicsStyleFromLineStyle(gc, verMinorGridStyleNode);
            xAxis.getMinorTickMarks().stream().mapToDouble(TickMark::getPosition).forEach(xPos -> {
                if (xPos > 0 && xPos <= xAxisWidth) {
                    gc.strokeLine(xPos, 0, xPos, yAxisHeight);
                }
            });
        }
    }

    drawPolarCircle(gc, yAxis, yRange, xCentre, yCentre, maxRadius);

    gc.restore();
}
 
Example 20
Source File: BulletChartSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void drawTickMarks(final GraphicsContext CTX) {
    tickMarkCanvas.setCache(false);
    CTX.clearRect(0, 0, tickMarkCanvas.getWidth(), tickMarkCanvas.getHeight());
    CTX.setFill(gauge.getMajorTickMarkColor());

    List<Section> tickMarkSections         = gauge.getTickMarkSections();
    List<Section> tickLabelSections        = gauge.getTickLabelSections();
    Color         majorTickMarkColor       = gauge.getTickMarkColor();
    Color         tickLabelColor           = gauge.getTickLabelColor();
    boolean       smallRange               = Double.compare(gauge.getRange(), 10.0) <= 0;
    double        minValue                 = gauge.getMinValue();
    double        maxValue                 = gauge.getMaxValue();
    double        tmpStepSize              = smallRange ? stepSize / 10 : stepSize;
    Font          tickLabelFont            = Fonts.robotoRegular(0.1 * size);
    boolean       tickMarkSectionsVisible  = gauge.getTickMarkSectionsVisible();
    boolean       tickLabelSectionsVisible = gauge.getTickLabelSectionsVisible();
    double        offsetX                  = 0.18345865 * width;
    double        offsetY                  = 0.1 * height;
    double        innerPointX              = 0;
    double        innerPointY              = 0;
    double        outerPointX              = 0.07 * width;
    double        outerPointY              = 0.08 * height;
    double        textPointX               = Orientation.HORIZONTAL == orientation ? 0.55 * tickMarkCanvas.getWidth() : outerPointX + size * 0.05;
    double        textPointY               = 0.7 * tickMarkCanvas.getHeight();
    BigDecimal    minorTickSpaceBD         = BigDecimal.valueOf(gauge.getMinorTickSpace());
    BigDecimal    majorTickSpaceBD         = BigDecimal.valueOf(gauge.getMajorTickSpace());
    BigDecimal    counterBD                = BigDecimal.valueOf(gauge.getMinValue());
    double        counter                  = minValue;
    double        range                    = gauge.getRange();

    for (double i = 0 ; Double.compare(i, range) <= 0 ; i++) {
        if (Orientation.VERTICAL == orientation) {
            innerPointY = counter * tmpStepSize + offsetY;
            outerPointY = innerPointY;
            textPointY  = innerPointY;
        } else {
            innerPointX = counter * tmpStepSize + offsetX;
            outerPointX = innerPointX;
            textPointX  = innerPointX;
        }

        // Set the general tickmark color
        CTX.setStroke(gauge.getTickMarkColor());
        if (Double.compare(counterBD.remainder(majorTickSpaceBD).doubleValue(), 0.0) == 0) {
            // Draw major tick mark
            if (gauge.getMajorTickMarksVisible()) {
                CTX.setFill(tickMarkSectionsVisible ? Helper.getColorOfSection(tickMarkSections, counter, majorTickMarkColor) : majorTickMarkColor);
                CTX.setStroke(tickMarkSectionsVisible ? Helper.getColorOfSection(tickMarkSections, counter, majorTickMarkColor) : majorTickMarkColor);
                CTX.setLineWidth(1);
                CTX.strokeLine(innerPointX, innerPointY, outerPointX, outerPointY);
            }
            // Draw tick label text
            if (gauge.getTickLabelsVisible()) {
                CTX.save();
                CTX.translate(textPointX, textPointY);
                CTX.setFont(tickLabelFont);
                CTX.setTextAlign(Orientation.HORIZONTAL == orientation ? TextAlignment.CENTER : TextAlignment.LEFT);
                CTX.setTextBaseline(VPos.CENTER);
                CTX.setFill(tickLabelSectionsVisible ? Helper.getColorOfSection(tickLabelSections, counter, tickLabelColor) : tickLabelColor);
                if (Orientation.VERTICAL == orientation) {
                    CTX.fillText(Integer.toString((int) (maxValue - counter)), 0, 0);
                } else {
                    CTX.fillText(Integer.toString((int) counter), 0, 0);
                }
                CTX.restore();
            }
        }
        counterBD = counterBD.add(minorTickSpaceBD);
        counter   = counterBD.doubleValue();
        if (counter > maxValue) break;
    }

    tickMarkCanvas.setCache(true);
    tickMarkCanvas.setCacheHint(CacheHint.QUALITY);
}