Search in sources :

Example 36 with Path

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

the class EquipmentFigure method drawIconCog.

/**
 * Draw a Cog with choosen number of "segments"
 */
private void drawIconCog(Graphics graphics, Point center, int segments, int r1, int r2, int r3) {
    // Draw outer Cog
    PointList outer = new PointList();
    final double halfSeg = Math.PI / (2 * segments);
    final double delta = halfSeg / 4;
    for (int i = 0; i < segments; i++) {
        outer.addPoint(new PolarPoint(r2, 2 * Math.PI * i / segments - halfSeg).toAbsolutePoint(center));
        outer.addPoint(new PolarPoint(r3, 2 * Math.PI * i / segments - halfSeg + delta).toAbsolutePoint(center));
        outer.addPoint(new PolarPoint(r3, 2 * Math.PI * i / segments + halfSeg - delta).toAbsolutePoint(center));
        outer.addPoint(new PolarPoint(r2, 2 * Math.PI * i / segments + halfSeg).toAbsolutePoint(center));
    }
    graphics.drawPolygon(outer);
    // Draw inner circle
    Path path = new Path(null);
    path.addArc(center.x - r1, center.y - r1, 2 * r1, 2 * r1, 0, 360);
    graphics.drawPath(path);
    path.dispose();
}
Also used : Path(org.eclipse.swt.graphics.Path) PointList(org.eclipse.draw2d.geometry.PointList) PolarPoint(com.archimatetool.editor.diagram.figures.PolarPoint) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) PolarPoint(com.archimatetool.editor.diagram.figures.PolarPoint)

Example 37 with Path

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

the class EquipmentFigure 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);
    int xCenter = rect.x + rect.width / 2;
    int yCenter = rect.y + rect.height / 2;
    int width1 = Math.min(rect.width, rect.height) * 2 / 3;
    Rectangle rect1 = new Rectangle(xCenter - width1 * 2 / 3, (yCenter - width1 / 2) + (width1 / 4), width1, width1);
    Path path1 = getPathShape(rect1);
    graphics.fillPath(path1);
    int width2 = Math.min(rect.width, rect.height) * 1 / 2;
    Rectangle rect2 = new Rectangle(xCenter, (int) (yCenter - (width2 * 0.96f)), width2, width2);
    Path path2 = getPathShape(rect2);
    graphics.fillPath(path2);
    disposeGradientPattern(graphics, gradient);
    // Lines
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawPath(path1);
    graphics.drawPath(path2);
    path1.dispose();
    path2.dispose();
    drawCircle(graphics, rect1);
    drawCircle(graphics, rect2);
    // 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) PolarPoint(com.archimatetool.editor.diagram.figures.PolarPoint)

Example 38 with Path

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

the class FacilityFigure method getFigurePath.

private Path getFigurePath(Rectangle rect) {
    final float buildingHeightFactor = 2f;
    Path path = new Path(null);
    int figureWidth = 0;
    int figureHeight = 0;
    // width < height or same
    if (rect.width <= rect.height) {
        figureWidth = rect.width;
        figureHeight = rect.width;
    } else // height < width
    {
        figureHeight = rect.height;
        figureWidth = rect.height;
    }
    int xMargin = (rect.width - figureWidth) / 2;
    int yMargin = (rect.height - figureHeight) / 2;
    int xTooth = figureWidth / 4 + figureWidth / 20;
    int yTooth = figureHeight / 5;
    path.moveTo(rect.x + xMargin, rect.y + yMargin);
    path.lineTo(rect.x + xMargin, rect.y + yMargin + figureHeight);
    path.lineTo(rect.x + xMargin + figureWidth, rect.y + yMargin + figureHeight);
    path.lineTo(rect.x + xMargin + figureWidth, rect.y + yMargin + figureHeight / buildingHeightFactor);
    path.lineTo(rect.x + xMargin + figureWidth - xTooth, rect.y + yMargin + figureHeight / buildingHeightFactor + yTooth);
    path.lineTo(rect.x + xMargin + figureWidth - xTooth, rect.y + yMargin + figureHeight / buildingHeightFactor);
    path.lineTo(rect.x + xMargin + figureWidth - 2 * xTooth, rect.y + yMargin + figureHeight / buildingHeightFactor + yTooth);
    path.lineTo(rect.x + xMargin + figureWidth - 2 * xTooth, rect.y + yMargin + figureHeight / buildingHeightFactor);
    path.lineTo(rect.x + xMargin + figureWidth - 3 * xTooth, rect.y + yMargin + figureHeight / buildingHeightFactor + yTooth);
    path.lineTo(rect.x + xMargin + figureWidth - 3 * xTooth, rect.y + yMargin);
    path.close();
    return path;
}
Also used : Path(org.eclipse.swt.graphics.Path) Point(org.eclipse.draw2d.geometry.Point)

Example 39 with Path

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

the class AbstractDiagramConnectionFigure method clipTextLabel.

/**
 * Clip the text label so it doesn't draw on the connection
 */
protected void clipTextLabel(Graphics graphics) {
    // Margin around label
    final int labelMargin = 1;
    // Save dimensions of original clipping area and label
    Rectangle g = graphics.getClip(new Rectangle());
    Rectangle l = getFlowPage().getBounds().getCopy();
    // Label margin
    l.expand(labelMargin, labelMargin);
    // Create a Path that fills the clipping area minus the label
    Path path = new Path(null);
    path.moveTo(g.x, g.y);
    path.lineTo(l.x, l.y);
    path.lineTo(l.x + l.width, l.y);
    path.lineTo(l.x + l.width, l.y + l.height);
    path.lineTo(l.x, l.y + l.height);
    path.lineTo(l.x, l.y);
    path.lineTo(g.x, g.y);
    path.lineTo(g.x, g.y + g.height);
    path.lineTo(g.x + g.width, g.y + g.height);
    path.lineTo(g.x + g.width, g.y);
    path.lineTo(g.x, g.y);
    graphics.clipPath(path);
    super.paintFigure(graphics);
    path.dispose();
}
Also used : Path(org.eclipse.swt.graphics.Path) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point)

Example 40 with Path

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

the class LocationFigure method getFigurePath.

private Path getFigurePath(Rectangle rect) {
    int figureWidth = 0;
    int figureHeight = 0;
    // width < height or same
    if (rect.width <= rect.height) {
        figureWidth = rect.width;
        figureHeight = rect.width;
    } else // height < width
    {
        figureHeight = rect.height;
        figureWidth = rect.height;
    }
    int yMargin = (rect.height - figureHeight) / 2;
    int xCenter = rect.x + rect.width / 2;
    float diameter = (figureWidth / 4) * 3;
    Path path = new Path(null);
    path.addArc(xCenter - diameter / 2, rect.y + yMargin, diameter, diameter, -35, 250);
    path.lineTo(xCenter, rect.y + rect.height - yMargin);
    path.close();
    return path;
}
Also used : Path(org.eclipse.swt.graphics.Path) 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