Search in sources :

Example 41 with Path

use of org.eclipse.swt.graphics.Path 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 42 with Path

use of org.eclipse.swt.graphics.Path 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)

Example 43 with Path

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

the class ValueStreamFigure method drawFigure.

@Override
protected void drawFigure(Graphics graphics) {
    if (getFigureDelegate() != null) {
        getFigureDelegate().drawFigure(graphics);
        drawIcon(graphics);
        return;
    }
    graphics.pushState();
    Rectangle bounds = getBounds().getCopy();
    bounds.width--;
    bounds.height--;
    // Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
    setLineWidth(graphics, 1, bounds);
    int indent = Math.min(bounds.height / 2, bounds.width / 2);
    int centre_y = bounds.y + bounds.height / 2;
    int point_startx = bounds.x + bounds.width - indent;
    graphics.setAlpha(getAlpha());
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    // Shape
    Path path = new Path(null);
    path.moveTo(bounds.x, bounds.y);
    path.lineTo(bounds.x + indent, centre_y);
    path.lineTo(bounds.x, bounds.y + bounds.height);
    path.lineTo(point_startx, bounds.y + bounds.height);
    path.lineTo(bounds.x + bounds.width, centre_y);
    path.lineTo(point_startx, bounds.y);
    path.lineTo(bounds.x, bounds.y);
    path.lineTo(bounds.x + indent, centre_y);
    // Fill
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, bounds);
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    // Outline
    graphics.setForegroundColor(getLineColor());
    graphics.drawPath(path);
    path.dispose();
    // Icon
    // drawIconImage(graphics, bounds);
    int top = 0, right = 0, left = 0, bottom = 0;
    switch(((IIconic) getDiagramModelObject()).getImagePosition()) {
        case IIconic.ICON_POSITION_TOP_LEFT:
        case IIconic.ICON_POSITION_BOTTOM_LEFT:
            left = 10;
            break;
        case IIconic.ICON_POSITION_TOP_RIGHT:
        case IIconic.ICON_POSITION_BOTTOM_RIGHT:
            right = -indent;
            break;
        case IIconic.ICON_POSITION_MIDDLE_LEFT:
            left = indent;
            break;
        case IIconic.ICON_POSITION_MIDDLE_RIGHT:
            right = -10;
            break;
    }
    drawIconImage(graphics, bounds, top, right, bottom, left);
    graphics.popState();
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) IIconic(com.archimatetool.model.IIconic) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point)

Example 44 with Path

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

the class StakeholderFigure method drawIcon.

/**
 * Draw the icon
 */
private void drawIcon(Graphics graphics) {
    if (!isIconVisible()) {
        return;
    }
    graphics.pushState();
    graphics.setLineWidth(1);
    graphics.setForegroundColor(isEnabled() ? ColorConstants.black : ColorConstants.gray);
    Point pt = getIconOrigin();
    Path path = new Path(null);
    path.addArc(pt.x, pt.y, 8, 7, 90, 180);
    path.lineTo(pt.x + 11, pt.y + 7);
    path.moveTo(pt.x + 3.5f, pt.y);
    path.lineTo(pt.x + 11, pt.y);
    graphics.drawPath(path);
    path.dispose();
    graphics.drawOval(pt.x + 8, pt.y, 7, 7);
    graphics.popState();
}
Also used : Path(org.eclipse.swt.graphics.Path) Point(org.eclipse.draw2d.geometry.Point)

Example 45 with Path

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

the class OutcomeFigure method drawIcon.

/**
 * Draw the icon
 */
private void drawIcon(Graphics graphics) {
    if (!isIconVisible()) {
        return;
    }
    graphics.pushState();
    graphics.setLineWidth(1);
    graphics.setForegroundColor(isEnabled() ? ColorConstants.black : ColorConstants.gray);
    graphics.setBackgroundColor(isEnabled() ? ColorConstants.black : ColorConstants.gray);
    Point pt = getIconOrigin();
    Path path = new Path(null);
    graphics.setLineWidthFloat(1.2f);
    // circles
    path.addArc(pt.x, pt.y, 13, 13, 0, 360);
    path.addArc(pt.x + 2.5f, pt.y + 2.5f, 8, 8, 0, 360);
    path.addArc(pt.x + 5f, pt.y + 5f, 3, 3, 0, 360);
    path.addArc(pt.x + 6f, pt.y + 6f, 1f, 1f, 0, 360);
    graphics.drawPath(path);
    path.dispose();
    graphics.setLineWidth(1);
    // lines
    path = new Path(null);
    path.moveTo(pt.x + 6.0f, pt.y + 7.0f);
    path.lineTo(pt.x + 15.5f, pt.y - 2.5f);
    path.moveTo(pt.x + 13.0f, pt.y + 0.0f);
    path.lineTo(pt.x + 14.0f, pt.y - 5.0f);
    path.moveTo(pt.x + 13.0f, pt.y + 0.0f);
    path.lineTo(pt.x + 18.0f, pt.y - 1.0f);
    graphics.drawPath(path);
    path.dispose();
    graphics.popState();
}
Also used : Path(org.eclipse.swt.graphics.Path) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Aggregations

Path (org.eclipse.swt.graphics.Path)103 Point (org.eclipse.draw2d.geometry.Point)49 Pattern (org.eclipse.swt.graphics.Pattern)40 Rectangle (org.eclipse.draw2d.geometry.Rectangle)37 Device (org.eclipse.swt.graphics.Device)13 Point (org.eclipse.swt.graphics.Point)11 Transform (org.eclipse.swt.graphics.Transform)10 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)8 Font (org.eclipse.swt.graphics.Font)8 Rectangle (org.eclipse.swt.graphics.Rectangle)7 PointList (org.eclipse.draw2d.geometry.PointList)6 GC (org.eclipse.swt.graphics.GC)6 PolarPoint (com.archimatetool.editor.diagram.figures.PolarPoint)4 Color (org.eclipse.swt.graphics.Color)4 Image (org.eclipse.swt.graphics.Image)4 Region (org.eclipse.swt.graphics.Region)4 IIconic (com.archimatetool.model.IIconic)3 Dimension (org.eclipse.draw2d.geometry.Dimension)2 SWTException (org.eclipse.swt.SWTException)2 Cursor (org.eclipse.swt.graphics.Cursor)2