Search in sources :

Example 1 with PathData

use of org.eclipse.swt.graphics.PathData in project archi by archimatetool.

the class GraphicsToGraphics2DAdaptor method createPathAWT.

private GeneralPath createPathAWT(Path path) {
    GeneralPath pathAWT = new GeneralPath();
    PathData pathData = path.getPathData();
    int idx = 0;
    for (int i = 0; i < pathData.types.length; i++) {
        switch(pathData.types[i]) {
            case SWT.PATH_MOVE_TO:
                pathAWT.moveTo(pathData.points[idx++] + transX, pathData.points[idx++] + transY);
                break;
            case SWT.PATH_LINE_TO:
                pathAWT.lineTo(pathData.points[idx++] + transX, pathData.points[idx++] + transY);
                break;
            case SWT.PATH_CUBIC_TO:
                pathAWT.curveTo(pathData.points[idx++] + transX, pathData.points[idx++] + transY, pathData.points[idx++] + transX, pathData.points[idx++] + transY, pathData.points[idx++] + transX, pathData.points[idx++] + transY);
                break;
            case SWT.PATH_QUAD_TO:
                pathAWT.quadTo(pathData.points[idx++] + transX, pathData.points[idx++] + transY, pathData.points[idx++] + transX, pathData.points[idx++] + transY);
                break;
            case SWT.PATH_CLOSE:
                pathAWT.closePath();
                break;
            default:
                dispose();
                SWT.error(SWT.ERROR_INVALID_ARGUMENT);
        }
    }
    int swtWindingRule = ((appliedState.graphicHints & FILL_RULE_MASK) >> FILL_RULE_SHIFT) - FILL_RULE_WHOLE_NUMBER;
    if (swtWindingRule == SWT.FILL_WINDING) {
        pathAWT.setWindingRule(Path2D.WIND_NON_ZERO);
    } else if (swtWindingRule == SWT.FILL_EVEN_ODD) {
        pathAWT.setWindingRule(Path2D.WIND_EVEN_ODD);
    } else {
        SWT.error(SWT.ERROR_INVALID_ARGUMENT);
    }
    return pathAWT;
}
Also used : GeneralPath(java.awt.geom.GeneralPath) PathData(org.eclipse.swt.graphics.PathData) Point(org.eclipse.draw2d.geometry.Point) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint)

Example 2 with PathData

use of org.eclipse.swt.graphics.PathData in project archi by archimatetool.

the class SWTGraphics method clipPath.

/**
 * Simple implementation of clipping a Path within the context of current
 * clipping rectangle for now (not region) <li>Note that this method wipes
 * out the clipping rectangle area, hence if clients need to reset it call
 * {@link #restoreState()}
 *
 * @see org.eclipse.draw2d.Graphics#clipPath(org.eclipse.swt.graphics.Path)
 */
@Override
public void clipPath(Path path) {
    initTransform(false);
    if (((appliedState.graphicHints ^ currentState.graphicHints) & FILL_RULE_MASK) != 0) {
        // If there is a pending change to the fill rule, apply it first.
        gc.setFillRule(((currentState.graphicHints & FILL_RULE_MASK) >> FILL_RULE_SHIFT) - FILL_RULE_WHOLE_NUMBER);
        // As long as the FILL_RULE is stored in a single bit, just toggling
        // it works.
        appliedState.graphicHints ^= FILL_RULE_MASK;
    }
    Rectangle clipping = currentState.relativeClip != null ? getClip(new Rectangle()) : new Rectangle();
    if (!clipping.isEmpty()) {
        Path flatPath = new Path(path.getDevice(), path, 0.01f);
        PathData pathData = flatPath.getPathData();
        flatPath.dispose();
        Region region = new Region(path.getDevice());
        loadPath(region, pathData.points, pathData.types);
        region.intersect(new org.eclipse.swt.graphics.Rectangle(clipping.x, clipping.y, clipping.width, clipping.height));
        gc.setClipping(region);
        appliedState.relativeClip = currentState.relativeClip = null;
        region.dispose();
    }
}
Also used : Path(org.eclipse.swt.graphics.Path) Rectangle(org.eclipse.draw2d.geometry.Rectangle) PathData(org.eclipse.swt.graphics.PathData) Region(org.eclipse.swt.graphics.Region)

Example 3 with PathData

use of org.eclipse.swt.graphics.PathData in project archi by archimatetool.

the class ScaledGraphics method createScaledPath.

/**
 * Scales given path by zoom factor
 *
 * @param path
 *            Path to be scaled
 * @return Scaled path
 */
private Path createScaledPath(Path path) {
    PathData p = path.getPathData();
    for (int i = 0; i < p.points.length; i += 2) {
        p.points[i] = (float) (p.points[i] * zoom + fractionalX);
        p.points[i + 1] = (float) (p.points[i + 1] * zoom + fractionalY);
    }
    Path scaledPath = new Path(path.getDevice());
    int index = 0;
    for (int i = 0; i < p.types.length; i++) {
        byte type = p.types[i];
        switch(type) {
            case SWT.PATH_MOVE_TO:
                scaledPath.moveTo(p.points[index], p.points[index + 1]);
                index += 2;
                break;
            case SWT.PATH_LINE_TO:
                scaledPath.lineTo(p.points[index], p.points[index + 1]);
                index += 2;
                break;
            case SWT.PATH_CUBIC_TO:
                scaledPath.cubicTo(p.points[index], p.points[index + 1], p.points[index + 2], p.points[index + 3], p.points[index + 4], p.points[index + 5]);
                index += 6;
                break;
            case SWT.PATH_QUAD_TO:
                scaledPath.quadTo(p.points[index], p.points[index + 1], p.points[index + 2], p.points[index + 3]);
                index += 4;
                break;
            case SWT.PATH_CLOSE:
                scaledPath.close();
                break;
        }
    }
    return scaledPath;
}
Also used : Path(org.eclipse.swt.graphics.Path) PathData(org.eclipse.swt.graphics.PathData) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

PathData (org.eclipse.swt.graphics.PathData)3 Point (org.eclipse.draw2d.geometry.Point)2 Path (org.eclipse.swt.graphics.Path)2 GradientPaint (java.awt.GradientPaint)1 Paint (java.awt.Paint)1 GeneralPath (java.awt.geom.GeneralPath)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 Region (org.eclipse.swt.graphics.Region)1