Search in sources :

Example 81 with Path

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

the class AssessmentFigure method drawFigure.

@Override
protected void drawFigure(Graphics graphics) {
    if (getDiagramModelArchimateObject().getType() == 0) {
        super.drawFigure(graphics);
        drawIcon(graphics);
        return;
    }
    graphics.pushState();
    Rectangle rect = getBounds().getCopy();
    rect.width--;
    rect.height--;
    Rectangle imageBounds = rect.getCopy();
    // Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
    setLineWidth(graphics, 1, rect);
    setFigurePositionFromTextPosition(rect);
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    int radius = getRadius(rect);
    Point center = getCenter(rect);
    // Fill
    graphics.setAlpha(getAlpha());
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, rect);
    Path path = new Path(null);
    path.addArc((float) center.preciseX() - radius, (float) center.preciseY() - radius, (radius * 2), (radius * 2), 0.0F, 360.0F);
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    // Lines
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawPath(path);
    path.dispose();
    double ratio = 2.5d;
    int x1 = (int) (center.x - radius * ratio);
    int y1 = (int) (center.y + radius * ratio);
    Point intersection = getCircleIntersection(x1, y1, center.preciseX(), center.preciseY(), center.preciseX(), center.preciseY(), radius);
    if (intersection != null) {
        // Need this so line doesn't draw out of bounds at bottom of rect
        graphics.setClip(rect);
        graphics.drawLine((int) Math.round(intersection.preciseX()), (int) Math.round(intersection.preciseY() - 1), x1, y1);
    }
    // Image Icon
    drawIconImage(graphics, imageBounds, 0, 0, 0, 0);
    graphics.popState();
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 82 with Path

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

the class DistributionNetworkFigure method drawIcon.

/**
 * Draw the icon
 */
@Override
protected void drawIcon(Graphics graphics) {
    if (!isIconVisible()) {
        return;
    }
    graphics.pushState();
    graphics.setForegroundColor(isEnabled() ? ColorConstants.black : ColorConstants.gray);
    graphics.setLineWidthFloat(1.5f);
    Point pt = getIconOrigin();
    Path path = new Path(null);
    path.moveTo(pt.x + 1, pt.y - 2);
    path.lineTo(pt.x + 14, pt.y - 2);
    path.moveTo(pt.x + 1, pt.y + 2);
    path.lineTo(pt.x + 14, pt.y + 2);
    graphics.drawPath(path);
    path.dispose();
    path = new Path(null);
    path.moveTo(pt.x + 4, pt.y - 5);
    path.lineTo(pt.x - 1, pt.y);
    path.lineTo(pt.x + 4, pt.y + 5);
    path.moveTo(pt.x + 11, pt.y - 5);
    path.lineTo(pt.x + 16, pt.y);
    path.lineTo(pt.x + 11, pt.y + 5);
    graphics.drawPath(path);
    path.dispose();
    graphics.popState();
}
Also used : Path(org.eclipse.swt.graphics.Path) Point(org.eclipse.draw2d.geometry.Point)

Example 83 with Path

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

the class EquipmentFigure method getPathShape.

private Path getPathShape(Rectangle rect) {
    Path path = new Path(null);
    int figureWidth = rect.width;
    int figureHeight = rect.height;
    if (rect.width > rect.height) {
        figureWidth = rect.height;
        figureHeight = rect.height;
    } else {
        figureWidth = rect.width;
        figureHeight = rect.width;
    }
    PrecisionPoint center = new PrecisionPoint();
    center.setPreciseLocation((rect.x + figureWidth / 2), (rect.y + figureHeight / 2));
    int alphaFirstCircle = 14;
    int betaFirstCircle = 31;
    int alphaSecondCircle = 22;
    int betaSecondCirlce = 23;
    int xMargin = (rect.width - figureWidth) / 2;
    int yMargin = (rect.height - figureHeight) / 2;
    PrecisionPoint firstPoint = new PrecisionPoint();
    firstPoint.setPreciseLocation((rect.x + figureWidth / 2), rect.y);
    PrecisionPoint secondPoint = new PrecisionPoint();
    secondPoint.setPreciseLocation((rect.x + figureWidth / 2) - figureWidth / 5.9d, rect.y + figureHeight / 6.5d);
    PrecisionPoint firstCirclePoint = new PrecisionPoint();
    firstCirclePoint = rotatePoint(firstPoint, center, alphaFirstCircle);
    PrecisionPoint secondCirclePoint = new PrecisionPoint();
    secondCirclePoint = rotatePoint(secondPoint, center, alphaSecondCircle);
    secondCirclePoint = rotatePoint(secondCirclePoint, center, betaSecondCirlce);
    path.moveTo((float) firstPoint.preciseX() + xMargin, (float) firstPoint.preciseY() + yMargin);
    path.lineTo((float) firstCirclePoint.preciseX() + xMargin, (float) firstCirclePoint.preciseY() + yMargin);
    path.lineTo((float) secondCirclePoint.preciseX() + xMargin, (float) secondCirclePoint.preciseY() + yMargin);
    secondCirclePoint = rotatePoint(secondCirclePoint, center, alphaSecondCircle);
    path.lineTo((float) secondCirclePoint.preciseX() + xMargin, (float) secondCirclePoint.preciseY() + yMargin);
    for (int i = 0; i < 7; i++) {
        firstCirclePoint = rotatePoint(firstCirclePoint, center, betaFirstCircle);
        path.lineTo((float) firstCirclePoint.preciseX() + xMargin, (float) firstCirclePoint.preciseY() + yMargin);
        firstCirclePoint = rotatePoint(firstCirclePoint, center, alphaFirstCircle);
        path.lineTo((float) firstCirclePoint.preciseX() + xMargin, (float) firstCirclePoint.preciseY() + yMargin);
        secondCirclePoint = rotatePoint(secondCirclePoint, center, betaSecondCirlce);
        path.lineTo((float) secondCirclePoint.preciseX() + xMargin, (float) secondCirclePoint.preciseY() + yMargin);
        secondCirclePoint = rotatePoint(secondCirclePoint, center, alphaSecondCircle);
        path.lineTo((float) secondCirclePoint.preciseX() + xMargin, (float) secondCirclePoint.preciseY() + yMargin);
    }
    path.close();
    return path;
}
Also used : Path(org.eclipse.swt.graphics.Path) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) PolarPoint(com.archimatetool.editor.diagram.figures.PolarPoint) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 84 with Path

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

the class FacilityFigure method drawFigure.

@Override
protected void drawFigure(Graphics graphics) {
    if (getFigureDelegate() != null) {
        getFigureDelegate().drawFigure(graphics);
        drawIcon(graphics);
        return;
    }
    graphics.pushState();
    Rectangle rect = getBounds().getCopy();
    rect.width--;
    rect.height--;
    Rectangle imageBounds = rect.getCopy();
    // Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
    setLineWidth(graphics, 1, rect);
    setFigurePositionFromTextPosition(rect);
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    graphics.setAlpha(getAlpha());
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, rect);
    Path path = getFigurePath(rect);
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    // Lines
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawPath(path);
    path.dispose();
    // Image Icon
    drawIconImage(graphics, imageBounds, 0, 0, 0, 0);
    graphics.popState();
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Example 85 with Path

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

the class GapFigure method drawFigure.

@Override
protected void drawFigure(Graphics graphics) {
    if (getDiagramModelArchimateObject().getType() == 0) {
        super.drawFigure(graphics);
        drawIcon(graphics);
        return;
    }
    graphics.pushState();
    Rectangle rect = getBounds().getCopy();
    rect.width--;
    rect.height--;
    Rectangle imageBounds = rect.getCopy();
    // Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
    setLineWidth(graphics, 1, rect);
    // Should match 'widthFraction' formula
    setFigurePositionFromTextPosition(rect, 5 / 3.0);
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    graphics.setAlpha(getAlpha());
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, rect);
    // 3/10ths of width
    int widthFraction = 3 * (rect.width / 10);
    int circleRadius = widthFraction;
    // height < width
    if (rect.height < rect.width) {
        // half height or 3/10ths
        circleRadius = Math.min(rect.height / 2, widthFraction);
    }
    int xCenter = rect.x + rect.width / 2;
    int yCenter = rect.y + rect.height / 2;
    Path path = new Path(null);
    path.addArc(xCenter - circleRadius, yCenter - circleRadius, circleRadius * 2, circleRadius * 2, 0, 360);
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawPath(path);
    path.dispose();
    graphics.drawLine(xCenter - (circleRadius + circleRadius / 2), yCenter - circleRadius / 4, xCenter + (circleRadius + circleRadius / 2), yCenter - circleRadius / 4);
    graphics.drawLine(xCenter - (circleRadius + circleRadius / 2), yCenter + circleRadius / 4, xCenter + (circleRadius + circleRadius / 2), yCenter + circleRadius / 4);
    // Image Icon
    drawIconImage(graphics, imageBounds, 0, 0, 0, 0);
    graphics.popState();
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point)

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