Java Code Examples for org.eclipse.swt.SWT#FILL_WINDING

The following examples show how to use org.eclipse.swt.SWT#FILL_WINDING . 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: SvgLoader.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private static Integer parseRule(String s) {
	if(s != null) {
		if("evenodd".equals(s)) { //$NON-NLS-1$
			return SWT.FILL_EVEN_ODD;
		} else if("winding".equals(s)) { //$NON-NLS-1$
			return SWT.FILL_WINDING;
		}
	}
	return null;
}
 
Example 2
Source File: SWT2AWT.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Converts an SWT {@link PathData} into an equivalent AWT
 * {@link PathIterator}.
 * 
 * @param pathData
 *            the {@link PathData} to convert.
 * @param windingRule
 *            the winding rule to use when constructing the
 *            {@link PathIterator}, i.e. one of {@link SWT#FILL_WINDING} or
 *            {@link SWT#FILL_EVEN_ODD}.
 * @return a new {@link PathIterator} representing the same path
 */
public static PathIterator toAWTPathIterator(PathData pathData, int windingRule) {
	if (windingRule != SWT.FILL_WINDING && windingRule != SWT.FILL_EVEN_ODD) {
		throw new IllegalArgumentException(
				"Unsupported winding rule. Must be one of SWT.FILL_WINDING or SWT.FILL_EVEN_ODD");
	}
	Path2D.Double path = new Path2D.Double(
			windingRule == SWT.FILL_EVEN_ODD ? Path2D.WIND_EVEN_ODD : Path2D.WIND_NON_ZERO);
	int j = 0;
	byte[] types = pathData.types;
	float[] points = pathData.points;
	double x, y, x2, y2, x3, y3;
	for (int i = 0; i < types.length; i++) {

		switch (types[i]) {
		case SWT.PATH_MOVE_TO:
			x = points[j++];
			y = points[j++];
			path.moveTo(x, y);
			break;
		case SWT.PATH_LINE_TO:
			x = points[j++];
			y = points[j++];
			path.lineTo(x, y);
			break;
		case SWT.PATH_QUAD_TO:
			x = points[j++];
			y = points[j++];
			x2 = points[j++];
			y2 = points[j++];
			path.quadTo(x, y, x2, y2);
			break;
		case SWT.PATH_CUBIC_TO:
			x = points[j++];
			y = points[j++];
			x2 = points[j++];
			y2 = points[j++];
			x3 = points[j++];
			y3 = points[j++];
			path.curveTo(x, y, x2, y2, x3, y3);
			break;
		case SWT.PATH_CLOSE:
			path.closePath();
			break;
		default:
			break;
		}
	}
	return path.getPathIterator(null);
}
 
Example 3
Source File: SWTConversionTests.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void test_AWT_Path() {
	PathIterator pathIteratorBefore = new java.awt.geom.Path2D.Double(
			new java.awt.geom.RoundRectangle2D.Double(0, 0, 100, 80, 10, 10)).getPathIterator(null);

	PathData swtPathData = AWT2SWT.toSWTPathData(pathIteratorBefore);
	int windingRuleSWT = pathIteratorBefore.getWindingRule() == java.awt.geom.Path2D.WIND_EVEN_ODD
			? SWT.FILL_EVEN_ODD : SWT.FILL_WINDING;

	PathIterator pathIteratorAfter = SWT2AWT.toAWTPathIterator(swtPathData, windingRuleSWT);

	while (!pathIteratorBefore.isDone()) {
		assertFalse(pathIteratorAfter.isDone());

		float[] coordsBefore = new float[6];
		float[] coordsAfter = new float[6];
		int typeBefore = pathIteratorBefore.currentSegment(coordsBefore);
		int typeAfter = pathIteratorAfter.currentSegment(coordsAfter);
		assertEquals(typeBefore, typeAfter);

		int numCoords = 0;
		switch (typeBefore) {
		case java.awt.geom.PathIterator.SEG_MOVETO:
		case java.awt.geom.PathIterator.SEG_LINETO:
			numCoords = 2;
			break;
		case java.awt.geom.PathIterator.SEG_QUADTO:
			numCoords = 4;
			break;
		case java.awt.geom.PathIterator.SEG_CUBICTO:
			numCoords = 6;
			break;
		}

		for (int i = 0; i < numCoords; i++) {
			assertTrue(PrecisionUtils.equal(coordsBefore[i], coordsAfter[i]));
		}

		pathIteratorBefore.next();
		pathIteratorAfter.next();
	}
}