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

The following examples show how to use javafx.scene.canvas.GraphicsContext#strokeOval() . 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: WriteFxImageBenchmark.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
public static void initalizeImage() {
    noisePixels = ByteBuffer.allocate(w * h * 4);
    noiseBuffer = new PixelBuffer<>(w, h, noisePixels, PixelFormat.getByteBgraPreInstance());
    testimage = new WritableImage(noiseBuffer);
    final Canvas noiseCanvas = new Canvas(w, h);
    final GraphicsContext noiseContext = noiseCanvas.getGraphicsContext2D();
    final byte[] randomArray = new byte[w * h * 4];
    new Random().nextBytes(randomArray);
    noiseContext.getPixelWriter().setPixels(0, 0, w, h, PixelFormat.getByteBgraInstance(), randomArray, 0, w);
    noiseCanvas.snapshot(null, testimage);

    final Canvas easyCanvas = new Canvas(w2, h2);
    final GraphicsContext easyContext = easyCanvas.getGraphicsContext2D();
    easyContext.setStroke(Color.BLUE);
    easyContext.strokeOval(20, 30, 40, 50);
    easyContext.setStroke(Color.RED);
    easyContext.strokeOval(30, 40, 50, 60);
    easyContext.setStroke(Color.GREEN);
    easyContext.strokeOval(40, 50, 60, 70);
    easyContext.setStroke(Color.ORANGE);
    easyContext.strokeRect(0, 0, w2, h2);
    testimage2 = easyCanvas.snapshot(null, null);

    initialized.set(true);
}
 
Example 2
Source File: SubcircuitPeer.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);
	
	if(mouseEntered) {
		double width = getScreenWidth();
		double height = getScreenHeight();
		
		graphics.setLineWidth(1.5);
		graphics.strokeOval(getScreenX() + (width - 13) / 2,
		                    getScreenY() + (height - 13) / 2,
		                    13,
		                    13);
		
		graphics.setLineWidth(2.5);
		graphics.strokeLine(getScreenX() + width / 2 + 4.6,
		                    getScreenY() + height / 2 + 4.6,
		                    getScreenX() + width / 2 + 10,
		                    getScreenY() + height / 2 + 10);
	}
}
 
Example 3
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 4
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 5
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 6
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 7
Source File: DebugDrawJavaFX.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void drawCircle(Vec2 center, float radius, Vec2 axis, Color3f color) {
  GraphicsContext g = getGraphics();
  Color s = cpool.getColor(color.x, color.y, color.z, 1f);
  saveState(g);
  double scaling = transformGraphics(g, center) * radius;
  g.setLineWidth(stroke / scaling);
  g.scale(radius, radius);
  g.setStroke(s);
  g.strokeOval(circle.getMinX(), circle.getMinX(), circle.getWidth(), circle.getHeight());
  if (axis != null) {
    g.rotate(MathUtils.atan2(axis.y, axis.x));
    g.strokeLine(0, 0, 1, 0);
  }
  restoreState(g);
}
 
Example 8
Source File: DebugDrawJavaFX.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void drawSolidCircle(Vec2 center, float radius, Vec2 axis, Color3f color) {
  GraphicsContext g = getGraphics();
  Color f = cpool.getColor(color.x, color.y, color.z, .4f);
  Color s = cpool.getColor(color.x, color.y, color.z, 1f);
  saveState(g);
  double scaling = transformGraphics(g, center) * radius;
  g.setLineWidth(stroke / scaling);
  g.scale(radius, radius);
  g.setFill(f);
  g.fillOval(circle.getMinX(), circle.getMinX(), circle.getWidth(), circle.getHeight());
  g.setStroke(s);
  g.strokeOval(circle.getMinX(), circle.getMinX(), circle.getWidth(), circle.getHeight());
  if (axis != null) {
    g.rotate(MathUtils.atan2(axis.y, axis.x));
    g.strokeLine(0, 0, 1, 0);
  }
  restoreState(g);
}
 
Example 9
Source File: WriteFxImageTests.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
@Start
public void setUp(@SuppressWarnings("unused") final Stage stage) {
    int w = 200;
    int h = 300;
    // generate test image with simple shapes
    final Canvas originalCanvas = new Canvas(w, h);
    final GraphicsContext originalContext = originalCanvas.getGraphicsContext2D();
    originalContext.setStroke(Color.BLUE);
    originalContext.strokeOval(20, 30, 40, 50);
    originalContext.setStroke(Color.RED);
    originalContext.strokeOval(30, 40, 50, 60);
    originalContext.setStroke(Color.GREEN);
    originalContext.strokeOval(40, 50, 60, 70);
    originalContext.setStroke(Color.ORANGE);
    originalContext.strokeRect(0, 0, w, h);
    imageOvals = originalCanvas.snapshot(null, null);

    //generate test image with noise data (not very compressible)
    final Canvas noiseCanvas = new Canvas(600, 333);
    final GraphicsContext noiseContext = noiseCanvas.getGraphicsContext2D();
    byte[] randomArray = new byte[600 * 333 * 4];
    new Random().nextBytes(randomArray);
    noiseContext.getPixelWriter().setPixels(0, 0, 600, 333, PixelFormat.getByteBgraInstance(), randomArray, 0, 600);
    imageRandom = noiseCanvas.snapshot(null, null);

    // generate test image with minimal dimensions
    final Canvas onexoneCanvas = new Canvas(1, 1);
    final GraphicsContext onexoneContext = onexoneCanvas.getGraphicsContext2D();
    onexoneContext.getPixelWriter().setArgb(0, 0, 0xdeadbeef);
    image1x1 = onexoneCanvas.snapshot(null, null);
}
 
Example 10
Source File: GatePeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public final void paint(GraphicsContext graphics, CircuitState circuitState) {
	graphics.setFill(Color.WHITE);
	graphics.setStroke(Color.BLACK);
	
	for(int i = 0; i < getConnections().size() - 1; i++) {
		if(getComponent().getNegateInputs()[i]) {
			PortConnection c = getConnections().get(i);
			int x = c.getX() * GuiUtils.BLOCK_SIZE;
			int y = c.getY() * GuiUtils.BLOCK_SIZE;
			
			switch(getProperties().getValue(Properties.DIRECTION)) {
				case WEST:
					x -= GuiUtils.BLOCK_SIZE;
				case EAST:
					y -= GuiUtils.BLOCK_SIZE * 0.5;
					break;
				case NORTH:
					y -= GuiUtils.BLOCK_SIZE;
				case SOUTH:
					x -= GuiUtils.BLOCK_SIZE * 0.5;
					break;
			}
			
			graphics.fillOval(x, y, GuiUtils.BLOCK_SIZE, GuiUtils.BLOCK_SIZE);
			graphics.strokeOval(x, y, GuiUtils.BLOCK_SIZE, GuiUtils.BLOCK_SIZE);
		}
	}
	
	GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION));
	GuiUtils.rotateGraphics(this, graphics, getProperties().getValue(Properties.DIRECTION));
	
	if(hasNegatedInput) {
		graphics.translate(GuiUtils.BLOCK_SIZE, 0);
	}
	
	paintGate(graphics, circuitState);
}
 
Example 11
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 12
Source File: DebugDrawJavaFX.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void drawCircle(Vec2 center, float radius, Color3f color) {
  GraphicsContext g = getGraphics();
  Color s = cpool.getColor(color.x, color.y, color.z, 1.0f);
  saveState(g);
  double scaling = transformGraphics(g, center) * radius;
  g.setLineWidth(stroke / scaling);
  g.scale(radius, radius);
  g.setStroke(s);
  g.strokeOval(circle.getMinX(), circle.getMinX(), circle.getWidth(), circle.getHeight());
  restoreState(g);
}
 
Example 13
Source File: SimpleLineChartSkin.java    From Enzo with Apache License 2.0 5 votes vote down vote up
private void drawBullet(final GraphicsContext CTX, final double X, final double Y, final Paint COLOR) {
    double iconSize = 0.04 * size;
    CTX.save();
    CTX.setLineWidth(0.0125 * height);
    CTX.setStroke(getSkinnable().getSeriesStroke());
    CTX.setFill(COLOR);
    CTX.strokeOval(X - iconSize * 0.5, Y - iconSize * 0.5, iconSize, iconSize);
    CTX.fillOval(X - iconSize * 0.5, Y - iconSize * 0.5, iconSize, iconSize);
    CTX.restore();
}
 
Example 14
Source File: BrushOverlay.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void drawOverlays(final GraphicsContext g)
{

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

		final double scaledRadius = this.viewerRadius.get();

		if (x + scaledRadius > 0 &&
				x - scaledRadius < width &&
				y + scaledRadius > 0 &&
				y - scaledRadius < height)
		{
			final double depth            = brushDepth.get();
			final double depthScaleFactor = 5;
			if (depth > 1)
			{
				//					g.setStroke( Color.BLACK.deriveColor( 0.0, 1.0, 1.0, 0.5 ) );
				g.setStroke(Color.WHEAT.deriveColor(0.0, 1.0, 1.0, 0.5));
				g.setFill(Color.WHITE.deriveColor(0.0, 1.0, 1.0, 0.5));
				g.setFont(Font.font(g.getFont().getFamily(), 15.0));
				g.setLineWidth(this.strokeWidth);
				g.strokeOval(
						x - scaledRadius,
						y - scaledRadius + depth * depthScaleFactor,
						2 * scaledRadius + 1,
						2 * scaledRadius + 1
				            );
				//					g.fillRect( x - scaledRadius, y, 2 * scaledRadius + 1, depth *
				// depthScaleFactor );
				g.strokeLine(x - scaledRadius, y + depth * depthScaleFactor, x - scaledRadius, y);
				g.strokeLine(x + scaledRadius + 1, y + depth * depthScaleFactor, x + scaledRadius + 1, y);
				g.fillText("depth=" + depth, x + scaledRadius + 1, y + depth * depthScaleFactor + scaledRadius +
						1);
			}

			g.setStroke(Color.WHITE);
			g.setLineWidth(this.strokeWidth);
			g.strokeOval(x - scaledRadius, y - scaledRadius, 2 * scaledRadius + 1, 2 * scaledRadius + 1);

			this.viewer.getScene().setCursor( Cursor.NONE );
			return;
		}
	}
	if (wasVisible)
	{
		this.viewer.getScene().setCursor(Cursor.DEFAULT);
		wasVisible = false;
	}
}
 
Example 15
Source File: TransistorPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState state) {
	GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION));
	GuiUtils.rotateGraphics(this, graphics, getProperties().getValue(Properties.DIRECTION));
	
	int x = getScreenX();
	int y = getScreenY();
	int width = getScreenWidth() > getScreenHeight() ? getScreenWidth() : getScreenHeight();
	int height = getScreenWidth() > getScreenHeight() ? getScreenHeight() : getScreenWidth();
	
	boolean gateLoc = getProperties().getValue(GATE_LOCATION_PROPERTY);
	switch(getProperties().getValue(Properties.DIRECTION)) {
		case WEST:
		case SOUTH:
			gateLoc = !gateLoc;
			break;
	}
	
	int yOff = gateLoc ? 0 : height;
	int m = gateLoc ? 1 : -1;
	
	graphics.setStroke(Color.BLACK);
	graphics.setLineWidth(2);
	
	graphics.beginPath();
	graphics.moveTo(x, y + height - yOff);
	graphics.lineTo(x + width / 3.0, y + height - yOff);
	graphics.lineTo(x + width / 3.0, y + yOff + m * height * 0.7);
	graphics.lineTo(x + 2.0 * width / 3.0, y + yOff + m * height * 0.7);
	graphics.lineTo(x + 2.0 * width / 3.0, y + height - yOff);
	graphics.lineTo(x + width, y + height - yOff);
	
	graphics.moveTo(x + width / 3.0, y + yOff + m * height * 0.5);
	graphics.lineTo(x + 2.0 * width / 3.0, y + yOff + m * height * 0.5);
	graphics.stroke();
	
	graphics.setLineWidth(1);
	
	graphics.beginPath();
	graphics.moveTo(x + width * 0.5 - 1.5, y + yOff + m * (height * 0.7 + 3));
	graphics.lineTo(x + width * 0.5 + 3.0, y + yOff + m * (height * 0.7 + 5));
	graphics.lineTo(x + width * 0.5 - 1.5, y + yOff + m * (height * 0.7 + 7));
	graphics.stroke();
	
	if(getProperties().getValue(TRANSISTOR_TYPE_PROPERTY)) {
		graphics.strokeOval(x + width * 0.5 - 3, y + (gateLoc ? 3 : height - 9), 6, 6);
	} else {
		graphics.strokeLine(x + width * 0.5, y + yOff, x + width * 0.5, y + height * 0.5);
	}
}
 
Example 16
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);
	}
}