javafx.scene.canvas.GraphicsContext Java Examples

The following examples show how to use javafx.scene.canvas.GraphicsContext. 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: 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 #2
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 #3
Source File: BlinkControlHandler.java    From arma-dialog-creator with MIT License 6 votes vote down vote up
/**
 Will manipulate {@link GraphicsContext#getGlobalAlpha()} based on an internal clock.
 */
public void paint(@NotNull GraphicsContext gc) {
	long now = System.currentTimeMillis();
	long timePast = now - lastPaint;
	lastPaint = now;

	if (!blinkDurationSet) {
		return;
	}

	if (blinkIn) {
		blinkDurationPast += timePast;
		if (blinkDurationPast >= blinkDuration) {
			blinkIn = false;
			blinkDurationPast = (long) blinkDuration;
		}
	} else {
		blinkDurationPast -= timePast;
		if (blinkDurationPast <= 0) {
			blinkIn = true;
			blinkDurationPast = 0;
		}
	}
	gc.setGlobalAlpha(blinkDurationPast / blinkDuration);
}
 
Example #4
Source File: GuiUtils.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Draws a clock input (triangle symbol) facing the southern border
 */
public static void drawClockInput(GraphicsContext graphics, Connection connection, Direction direction) {
	double x = connection.getScreenX() + connection.getScreenWidth() * 0.5;
	double y = connection.getScreenY() + connection.getScreenWidth() * 0.5;
	
	switch(direction) {
		case NORTH:
			graphics.strokeLine(x - 5, y, x, y + 6);
			graphics.strokeLine(x, y + 6, x + 5, y);
			break;
		case SOUTH:
			graphics.strokeLine(x - 5, y, x, y - 6);
			graphics.strokeLine(x, y - 6, x + 5, y);
			break;
		case EAST:
			graphics.strokeLine(x, y - 5, x - 6, y);
			graphics.strokeLine(x - 6, y, x, y + 5);
			break;
		case WEST:
			graphics.strokeLine(x, y - 5, x + 6, y);
			graphics.strokeLine(x + 6, y, x, y + 5);
			break;
	}
}
 
Example #5
Source File: HexDisplay.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);
	GuiUtils.drawShape(graphics::fillRect, this);
	graphics.setStroke(Color.BLACK);
	GuiUtils.drawShape(graphics::strokeRect, this);
	
	drawDigit(graphics, -1);
	
	WireValue value = circuitState.getLastReceived(getComponent().getPort(0));
	if(value.isValidValue()) {
		drawDigit(graphics, value.getValue());
	}
}
 
Example #6
Source File: PlainAmpSkin.java    From Medusa with Apache License 2.0 6 votes vote down vote up
private void drawLed(final GraphicsContext CTX) {
    CTX.clearRect(0, 0, ledSize, ledSize);
    CTX.setFill(frameGradient);
    CTX.fillOval(0, 0, ledSize, ledSize);

    CTX.save();
    if (gauge.isLedOn()) {
        CTX.setEffect(ledOnShadow);
        CTX.setFill(ledOnGradient);
    } else {
        CTX.setEffect(ledOffShadow);
        CTX.setFill(ledOffGradient);
    }
    CTX.fillOval(0.14 * ledSize, 0.14 * ledSize, 0.72 * ledSize, 0.72 * ledSize);
    CTX.restore();

    CTX.setFill(highlightGradient);
    CTX.fillOval(0.21 * ledSize, 0.21 * ledSize, 0.58 * ledSize, 0.58 * ledSize);
}
 
Example #7
Source File: DiagramCanvas.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Paints the panel and all the graph elements in aDiagramView.
 * Called after the panel is resized.
 */
public void paintPanel()
{
	GraphicsContext context = getGraphicsContext2D();
	context.setFill(Color.WHITE); 
	context.fillRect(0, 0, getWidth(), getHeight());
	if(UserPreferences.instance().getBoolean(BooleanPreference.showGrid)) 
	{
		Grid.draw(context, new Rectangle(0, 0, (int) getWidth(), (int) getHeight()));
	}
	DiagramType.viewerFor(aDiagram).draw(aDiagram, context);
	aController.synchronizeSelectionModel();
	aController.getSelectionModel().forEach( selected -> ViewerUtilities.drawSelectionHandles(selected, context));
	aController.getSelectionModel().getRubberband().ifPresent( rubberband -> ToolGraphics.drawRubberband(context, rubberband));
	aController.getSelectionModel().getLasso().ifPresent( lasso -> ToolGraphics.drawLasso(context, lasso));
}
 
Example #8
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 #9
Source File: DefaultControlTreeItemGraphic.java    From arma-dialog-creator with MIT License 6 votes vote down vote up
private void fillBox(Color color) {
	GraphicsContext gc = box.getGraphicsContext2D();
	gc.save();
	gc.clearRect(0, 0, box.getWidth(), box.getHeight());
	gc.setFill(color);
	gc.fillRect(0, 0, box.getWidth(), box.getHeight());
	gc.restore();

	//generate hex string and bind it to tooltip
	final double f = 255.0;
	int r = (int) (color.getRed() * f);
	int g = (int) (color.getGreen() * f);
	int b = (int) (color.getBlue() * f);
	String opacity = DecimalFormat.getNumberInstance().format(color.getOpacity() * 100);

	Tooltip.install(box, new Tooltip(String.format(
			"red:%d, green:%d, blue:%d, opacity:%s%%", r, g, b, opacity))
	);
}
 
Example #10
Source File: NandGatePeer.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.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 #11
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 #12
Source File: Hexagon.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
public void renderCoordinates(GraphicsContext gc) {
    final Text text = new Text(position.getCoordinates());
    if (map != null) {
        // TODO re-enable font
        // text.setFont(map.getFont());
    }
    final double textWidth = text.getBoundsInLocal().getWidth();
    final double textHeight = text.getBoundsInLocal().getHeight();
    final double x = getGraphicsXoffset() - textWidth / 2;
    final double y = getGraphicsYoffset() + textHeight / 4;
    text.setX(x);
    text.setY(y);
    // Not sure why, but 4 seems like a good value
    gc.strokeText(position.getCoordinates(), x, y);
    // root.getChildren().add(text);
}
 
Example #13
Source File: Helper.java    From Medusa with Apache License 2.0 6 votes vote down vote up
public static final void rotateContextForText(final GraphicsContext CTX, final double START_ANGLE, final double ANGLE, final TickLabelOrientation ORIENTATION) {
    switch (ORIENTATION) {
        case ORTHOGONAL:
            if ((360 - START_ANGLE - ANGLE) % 360 > 90 && (360 - START_ANGLE - ANGLE) % 360 < 270) {
                CTX.rotate((180 - START_ANGLE - ANGLE) % 360);
            } else {
                CTX.rotate((360 - START_ANGLE - ANGLE) % 360);
            }
            break;
        case TANGENT:
            if ((360 - START_ANGLE - ANGLE - 90) % 360 > 90 && (360 - START_ANGLE - ANGLE - 90) % 360 < 270) {
                CTX.rotate((90 - START_ANGLE - ANGLE) % 360);
            } else {
                CTX.rotate((270 - START_ANGLE - ANGLE) % 360);
            }
            break;
        case HORIZONTAL:
        default:
            break;
    }
}
 
Example #14
Source File: GridRenderer.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
protected void drawHorizontalMajorGridLines(final GraphicsContext gc, final Axis yAxis,
        final double xAxisWidthSnapped, final double yAxisHeight) {
    if (!horMajorGridStyleNode.isVisible() && !horMinorGridStyleNode.isVisible()) {
        return;
    }
    final double zeroSnapped = snap(0);
    applyGraphicsStyleFromLineStyle(gc, horMajorGridStyleNode);
    ObservableList<TickMark> tickMarks = yAxis.getTickMarks();
    for (int i = 0; i < tickMarks.size(); i++) {
        double y = snap(yAxis.getDisplayPosition(tickMarks.get(i).getValue()));
        if (y >= 0 && y < yAxisHeight) {
            // gc.strokeLine(zeroSnapped, y, xAxisWidthSnapped, y);
            DashPatternStyle.strokeDashedLine(gc, zeroSnapped, y, xAxisWidthSnapped, y);
        }
    }
}
 
Example #15
Source File: GridRenderer.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
protected void drawHorizontalMinorGridLines(final GraphicsContext gc, final Axis yAxis,
        final double xAxisWidthSnapped, final double yAxisHeight) {
    if (!yAxis.isLogAxis() && !horMinorGridStyleNode.isVisible()) {
        return;
    }
    final double zeroSnapped = snap(0);
    applyGraphicsStyleFromLineStyle(gc, horMinorGridStyleNode);
    ObservableList<TickMark> tickMarks = yAxis.getMinorTickMarks();
    for (int i = 0; i < tickMarks.size(); i++) {
        double y = snap(yAxis.getDisplayPosition(tickMarks.get(i).getValue()));
        if (y >= 0 && y < yAxisHeight) {
            // gc.strokeLine(zeroSnapped, y, xAxisWidthSnapped, y);
            DashPatternStyle.strokeDashedLine(gc, zeroSnapped, y, xAxisWidthSnapped, y);
        }
    }
}
 
Example #16
Source File: NegatorPeer.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(), "-x");
	graphics.setFill(Color.BLACK);
	graphics.fillText("-x",
	                  getScreenX() + (getScreenWidth() - bounds.getWidth()) * 0.5,
	                  getScreenY() + (getScreenHeight() + bounds.getHeight()) * 0.45);
}
 
Example #17
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 #18
Source File: Helper.java    From charts with Apache License 2.0 6 votes vote down vote up
public static final void rotateContextForText(final GraphicsContext CTX, final double START_ANGLE, final double ANGLE, final TickLabelOrientation ORIENTATION) {
    switch (ORIENTATION) {
        case ORTHOGONAL:
            if ((360 - START_ANGLE - ANGLE) % 360 > 90 && (360 - START_ANGLE - ANGLE) % 360 < 270) {
                CTX.rotate((180 - START_ANGLE - ANGLE) % 360);
            } else {
                CTX.rotate((360 - START_ANGLE - ANGLE) % 360);
            }
            break;
        case TANGENT:
            if ((360 - START_ANGLE - ANGLE - 90) % 360 > 90 && (360 - START_ANGLE - ANGLE - 90) % 360 < 270) {
                CTX.rotate((90 - START_ANGLE - ANGLE) % 360);
            } else {
                CTX.rotate((270 - START_ANGLE - ANGLE) % 360);
            }
            break;
        case HORIZONTAL:
        default:
            break;
    }
}
 
Example #19
Source File: StateTransitionEdgeViewer.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
private void drawArrowHead(Edge pEdge, GraphicsContext pGraphics)
{
	if( isSelfEdge(pEdge) )
	{
		Point connectionPoint2 = getSelfEdgeConnectionPoints(pEdge).getPoint2();
		if( getPosition(pEdge) == 1 )
		{
			ArrowHead.V.view().draw(pGraphics, new Point(connectionPoint2.getX()+SELF_EDGE_OFFSET, 
					connectionPoint2.getY()-SELF_EDGE_OFFSET/4), getConnectionPoints(pEdge).getPoint2());
		}
		else
		{
			ArrowHead.V.view().draw(pGraphics, new Point(connectionPoint2.getX()-SELF_EDGE_OFFSET/4, 
					connectionPoint2.getY()-SELF_EDGE_OFFSET), getConnectionPoints(pEdge).getPoint2());
		}
	}
	else
	{
		ArrowHead.V.view().draw(pGraphics, Conversions.toPoint(getControlPoint(pEdge)), getConnectionPoints(pEdge).getPoint2());
	}
}
 
Example #20
Source File: ActorNodeViewer.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void draw(Node pNode, GraphicsContext pGraphics)
{	
	Rectangle bounds = getBounds(pNode);
	Dimension nameBox = NAME_VIEWER.getDimension(((ActorNode)pNode).getName());
	Rectangle namebox = new Rectangle(bounds.getX() + (int)((bounds.getWidth() - nameBox.getWidth()) / 2.0), 
			bounds.getY() + HEIGHT, nameBox.getWidth(), nameBox.getHeight());
	NAME_VIEWER.draw(((ActorNode)pNode).getName(), pGraphics, namebox);
	ToolGraphics.strokeSharpPath(pGraphics, createStickManPath(pNode), LineStyle.SOLID);
}
 
Example #21
Source File: LabeledStraightEdgeViewer.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void draw(Edge pEdge, GraphicsContext pGraphics)
{
	super.draw(pEdge, pGraphics);
	String label = aLabelExtractor.apply(pEdge);
	if( label.length() > 0 )
	{
		STRING_VIEWER.draw(label, pGraphics, getConnectionPoints(pEdge).spanning().translated(0, SHIFT));
	}
}
 
Example #22
Source File: ChartCanvas.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws the content of the canvas and updates the 
 * {@code renderingInfo} attribute with the latest rendering 
 * information.
 */
public final void draw() {
    GraphicsContext ctx = getGraphicsContext2D();
    ctx.save();
    double width = getWidth();
    double height = getHeight();
    if (width > 0 && height > 0) {
        ctx.clearRect(0, 0, width, height);
        this.info = new ChartRenderingInfo();
        this.chart.draw(this.g2, new Rectangle((int) width, (int) height), 
                this.anchor, this.info);
    }
    ctx.restore();
    this.anchor = null;
}
 
Example #23
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 #24
Source File: ToolGraphics.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws four handles on pGraphics centered at the four corners of 
 * pBounds.
 * 
 * @param pGraphics The graphics context on which to draw the handles.
 * @param pBounds Defines the four points where to draw the handles
 */
public static void drawHandles(GraphicsContext pGraphics, Rectangle pBounds)
{
	drawHandle(pGraphics, pBounds.getX(), pBounds.getY());
	drawHandle(pGraphics, pBounds.getX(), pBounds.getMaxY());
	drawHandle(pGraphics, pBounds.getMaxX(), pBounds.getY());
	drawHandle(pGraphics, pBounds.getMaxX(), pBounds.getMaxY());
}
 
Example #25
Source File: TagBoard.java    From OpenLabeler with Apache License 2.0 5 votes vote down vote up
private void clearLastDrawing(GraphicsContext gc, List<Point2D> points, Point2D lastPt) {
   List<Point2D> clearPts = new ArrayList<>();
   clearPts.addAll(points);
   if (lastPt != null) {
      clearPts.add(lastPt);
   }
   var bounds = AppUtils.getBounds(clearPts.toArray(new Point2D[] {}));
   bounds = AppUtils.insetBounds(bounds, -10d);
   gc.clearRect(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight());
}
 
Example #26
Source File: ShipImage.java    From logbook-kai with MIT License 5 votes vote down vote up
/**
 * HPゲージ
 * @param chara キャラクター
 * @param canvas Canvas
 * @param gc GraphicsContext
 */
private static void writeHpGauge(Chara chara, Canvas canvas, GraphicsContext gc) {
    double w = canvas.getWidth();
    double h = canvas.getHeight();
    double gaugeWidth = 7;
    double hpPer = (double) chara.getNowhp() / (double) chara.getMaxhp();
    gc.drawImage(createGauge(gaugeWidth, h, hpPer, ShipImage::hpGaugeColor, HPGAUGE_CACHE), w - gaugeWidth, 0);
}
 
Example #27
Source File: Helper.java    From charts with Apache License 2.0 5 votes vote down vote up
public static final void drawTextWithBackground(final GraphicsContext CTX, final String TEXT, final Font FONT, final Color TEXT_BACKGROUND, final Color TEXT_FILL, final double X, final double Y) {
    CtxDimension dim = getTextDimension(TEXT, FONT);
    double textWidth  = dim.getWidth() * 1.2;
    double textHeight = dim.getHeight();
    CTX.save();
    CTX.setFont(FONT);
    CTX.setTextBaseline(VPos.CENTER);
    CTX.setTextAlign(TextAlignment.CENTER);
    CTX.setFill(TEXT_BACKGROUND);
    CTX.fillRect(X - textWidth * 0.5, Y - textHeight * 0.5, textWidth, textHeight);
    CTX.setFill(TEXT_FILL);
    CTX.fillText(TEXT, X, Y);
    CTX.restore();
}
 
Example #28
Source File: GuiUtils.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void setBitColor(GraphicsContext graphics, WireValue value) {
	if(value.getBitSize() == 1) {
		setBitColor(graphics, value.getBit(0));
	} else if(value.isValidValue()) {
		graphics.setStroke(Color.BLACK);
		graphics.setFill(Color.BLACK);
	} else {
		graphics.setStroke(X_MULTIBIT_COLOR);
		graphics.setFill(X_MULTIBIT_COLOR);
	}
}
 
Example #29
Source File: Helper.java    From Medusa with Apache License 2.0 5 votes vote down vote up
public static final void drawTimeSections(final Clock CLOCK, final GraphicsContext CTX, final List<TimeSection> SECTIONS, final double SIZE,
                                          final double XY_INSIDE, final double XY_OUTSIDE, final double WH_INSIDE, final double WH_OUTSIDE,
                                          final double LINE_WIDTH) {
    if (SECTIONS.isEmpty()) return;
    TickLabelLocation tickLabelLocation = CLOCK.getTickLabelLocation();
    ZonedDateTime     time              = CLOCK.getTime();
    boolean           isAM              = time.get(ChronoField.AMPM_OF_DAY) == 0;
    double            xy                = TickLabelLocation.INSIDE == tickLabelLocation ? XY_INSIDE * SIZE : XY_OUTSIDE * SIZE;
    double            wh                = TickLabelLocation.INSIDE == tickLabelLocation ? WH_INSIDE * SIZE : WH_OUTSIDE * SIZE;
    double            offset            = 90;
    int               listSize          = SECTIONS.size();
    double            angleStep         = 360.0 / 60.0;
    boolean           highlightSections = CLOCK.isHighlightSections();
    for (int i = 0 ; i < listSize ; i++) {
        TimeSection section   = SECTIONS.get(i);
        LocalTime   start     = section.getStart();
        LocalTime   stop      = section.getStop();
        boolean     isStartAM = start.get(ChronoField.AMPM_OF_DAY) == 0;
        boolean     isStopAM  = stop.get(ChronoField.AMPM_OF_DAY) == 0;
        boolean     draw      = isAM ? (isStartAM || isStopAM) :(!isStartAM || !isStopAM);
        if (draw) {
            double sectionStartAngle = (start.getHour() % 12 * 5.0 + start.getMinute() / 12.0 + start.getSecond() / 300.0) * angleStep + 180;
            double sectionAngleExtend = ((stop.getHour() - start.getHour()) % 12 * 5.0 + (stop.getMinute() - start.getMinute()) / 12.0 + (stop.getSecond() - start.getSecond()) / 300.0) * angleStep;
            //TODO: Add an indicator to the section like -1 or similar
            // check if start was already yesterday
            if (start.getHour() > stop.getHour()) { sectionAngleExtend = (360.0 - Math.abs(sectionAngleExtend)); }
            CTX.save();
            if (highlightSections) {
                CTX.setStroke(section.contains(time.toLocalTime()) ? section.getHighlightColor() : section.getColor());
            } else {
                CTX.setStroke(section.getColor());
            }
            CTX.setLineWidth(SIZE * LINE_WIDTH);
            CTX.setLineCap(StrokeLineCap.BUTT);
            CTX.strokeArc(xy, xy, wh, wh, -(offset + sectionStartAngle), -sectionAngleExtend, ArcType.OPEN);
            CTX.restore();
        }
    }
}
 
Example #30
Source File: ViewUtils.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a circle with default attributes, without a drop shadow.
 * 
 * @param pGraphics The graphics context.
 * @param pX The x-coordinate of the top-left of the circle.
 * @param pY The y-coordinate of the top-left of the circle.
 * @param pFill The color with which to fill the circle.
 * @param pWidth The width of the oval to draw
 * @param pHeight The height of the oval to draw.
 * @param pShadow True to include a drop shadow.
 */
public static void drawOval(GraphicsContext pGraphics, int pX, int pY, int pWidth, int pHeight, Paint pFill, boolean pShadow)
{
	assert pWidth > 0 && pHeight > 0 && pFill != null && pGraphics != null;
	Paint oldFill = pGraphics.getFill();
	pGraphics.setFill(pFill);
	if( pShadow )
	{
		pGraphics.setEffect(DROP_SHADOW);
	}
	pGraphics.fillOval(pX + 0.5, pY + 0.5, pWidth, pHeight);
	pGraphics.strokeOval(pX + 0.5, pY + 0.5, pWidth, pHeight);
	pGraphics.setFill(oldFill);
	pGraphics.setEffect(null);
}