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

The following examples show how to use javafx.scene.canvas.GraphicsContext#getLineWidth() . 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
/**
 * Strokes and fills a path, by converting the elements to integer coordinates and then
 * aligning them to the center of the pixels, so that it aligns precisely
 * with the JavaFX coordinate system. See the documentation for 
 * javafx.scene.shape.Shape for details.
 * 
 * @param pGraphics The graphics context.
 * @param pPath The path to stroke
 * @param pFill The fill color for the path.
 * @param pShadow True to include a drop shadow.
 */
public static void strokeAndFillSharpPath(GraphicsContext pGraphics, Path pPath, Paint pFill, boolean pShadow)
{
	double width = pGraphics.getLineWidth();
	Paint fill = pGraphics.getFill();
	pGraphics.setLineWidth(LINE_WIDTH);
	pGraphics.setFill(pFill);
	applyPath(pGraphics, pPath);
	
	if( pShadow )
	{
		pGraphics.setEffect(DROP_SHADOW);
	}
	pGraphics.fill();
	pGraphics.stroke();
	pGraphics.setLineWidth(width);
	pGraphics.setFill(fill);
	pGraphics.setEffect(null);
}
 
Example 2
Source File: Region.java    From arma-dialog-creator with MIT License 5 votes vote down vote up
/** Draw the crisp border of a rectangle without filling it */
static void strokeRectangle(GraphicsContext gc, int x1, int y1, int x2, int y2) {
	final double antiAlias = gc.getLineWidth() % 2 != 0 ? 0.5 : 0;
	double x1a = x1 + antiAlias;
	double y1a = y1 + antiAlias;
	double x2a = x2 - antiAlias;
	double y2a = y2 - antiAlias;

	gc.strokeLine(x1a, y1a, x2a, y1a); //top left to top right
	gc.strokeLine(x2a, y1a, x2a, y2a); //top right to bottom right
	gc.strokeLine(x2a, y2a, x1a, y2a); //bottom right to bottom left
	gc.strokeLine(x1a, y2a, x1a, y1a); //bottom left to top left
}
 
Example 3
Source File: Region.java    From arma-dialog-creator with MIT License 5 votes vote down vote up
/** Draw a crisp line */
static void strokeLine(GraphicsContext gc, int x1, int y1, int x2, int y2) {
	final double antiAlias = gc.getLineWidth() % 2 != 0 ? 0.5 : 0;
	double x1a = x1 + antiAlias;
	double y1a = y1 + antiAlias;
	double x2a = x2 - antiAlias;
	double y2a = y2 + antiAlias;

	gc.strokeLine(x1a, y1a, x2a, y2a);
}
 
Example 4
Source File: Region.java    From arma-dialog-creator with MIT License 5 votes vote down vote up
/** Fills a crisp rectangle (will use {@link GraphicsContext#getStroke()}) as fill color */
static void fillRectangle(GraphicsContext gc, int x1, int y1, int x2, int y2) {
	final double antiAlias = gc.getLineWidth() % 2 != 0 ? 0.5 : 0;
	for (int y = y1; y < y2; y++) {
		gc.strokeLine(x1 + antiAlias, y + antiAlias, x2 - antiAlias, y + antiAlias);
	}
}
 
Example 5
Source File: ToolGraphics.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Strokes a path, by converting the elements to integer coordinates and then
 * aligning them to the center of the pixels, so that it aligns precisely
 * with the JavaFX coordinate system. See the documentation for 
 * javafx.scene.shape.Shape for details.
 * 
 * @param pGraphics The graphics context.
 * @param pPath The path to stroke
 * @param pStyle The line style for the path.
 */
public static void strokeSharpPath(GraphicsContext pGraphics, Path pPath, LineStyle pStyle)
{
	double[] oldDash = pGraphics.getLineDashes();
	pGraphics.setLineDashes(pStyle.getLineDashes());
	double width = pGraphics.getLineWidth();
	pGraphics.setLineWidth(LINE_WIDTH);
	applyPath(pGraphics, pPath);
	pGraphics.stroke();
	pGraphics.setLineDashes(oldDash);
	pGraphics.setLineWidth(width);
}
 
Example 6
Source File: StateTransitionEdgeViewer.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
private void drawSelfEdge(Edge pEdge, GraphicsContext pGraphics)
{
	Arc arc = (Arc) getShape(pEdge);
	double width = pGraphics.getLineWidth();
	pGraphics.setLineWidth(LINE_WIDTH);
	pGraphics.strokeArc(arc.getCenterX(), arc.getCenterY(), arc.getRadiusX(), arc.getRadiusY(), arc.getStartAngle(), 
			arc.getLength(), arc.getType());
	pGraphics.setLineWidth(width);
}
 
Example 7
Source File: DebugDrawJavaFX.java    From jbox2d with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void saveState(GraphicsContext g) {
  oldTrans = g.getTransform();
  oldStroke = g.getLineWidth();
}