Search in sources :

Example 91 with Path

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

the class LocationFigure 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 92 with Path

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

the class MeaningFigure method drawFigure.

@Override
public void drawFigure(Graphics graphics) {
    graphics.pushState();
    Rectangle bounds = getBounds().getCopy();
    // Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
    setLineWidth(graphics, 1, bounds);
    // The following is the most awful code to draw a cloud...
    graphics.setAlpha(getAlpha());
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    // Main fill
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, bounds);
    Path path = new Path(null);
    path.addArc(bounds.x, bounds.y, bounds.width / 3 * 2, bounds.height / 3 * 2, 0, 360);
    graphics.fillPath(path);
    path.dispose();
    path = new Path(null);
    path.addArc(bounds.x + bounds.width / 3 - 1, bounds.y, bounds.width / 3 * 2, bounds.height / 3 * 2, 0, 360);
    graphics.fillPath(path);
    path.dispose();
    path = new Path(null);
    path.addArc(bounds.x, bounds.y + bounds.height / 3, bounds.width / 5 * 3, bounds.height / 3 * 2 - 1, 0, 360);
    graphics.fillPath(path);
    path.dispose();
    path = new Path(null);
    path.addArc(bounds.x + bounds.width / 3, bounds.y + bounds.height / 4, bounds.width / 5 * 3, bounds.height / 3 * 2, 0, 360);
    graphics.fillPath(path);
    path.dispose();
    disposeGradientPattern(graphics, gradient);
    // Outline
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    path = new Path(null);
    path.addArc(bounds.x, bounds.y, bounds.width / 3 * 2, bounds.height / 3 * 2, 60, 149);
    graphics.drawPath(path);
    path.dispose();
    path = new Path(null);
    path.addArc(bounds.x + bounds.width / 3 - 1, bounds.y, bounds.width / 3 * 2, bounds.height / 3 * 2, -38, 157);
    graphics.drawPath(path);
    path.dispose();
    path = new Path(null);
    path.addArc(bounds.x, bounds.y + bounds.height / 3, bounds.width / 5 * 3, bounds.height / 3 * 2 - 1, -41, -171);
    graphics.drawPath(path);
    path.dispose();
    path = new Path(null);
    path.addArc(bounds.x + bounds.width / 3, bounds.y + bounds.height / 4, bounds.width / 5 * 3, bounds.height / 3 * 2, 7, -120);
    graphics.drawPath(path);
    path.dispose();
    // Icon
    drawIconImage(graphics, bounds);
    graphics.popState();
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Example 93 with Path

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

the class CourseOfActionFigure 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);
    // Should match '3.1 / 2.5' (values used in getRadius() and getCenter())
    setFigurePositionFromTextPosition(rect, 1.24);
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    graphics.setAlpha(getAlpha());
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, rect);
    Path path = new Path(null);
    int radius = getRadius(rect);
    Point center = getCenter(rect);
    path.addArc((float) center.preciseX() - radius, (float) center.preciseY() - radius, (radius * 2), (radius * 2), 0, 360);
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    // Lines
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawPath(path);
    path.dispose();
    graphics.setBackgroundColor(getLineColor());
    int radius2 = Math.round(radius * 2f / 3f - (graphics.getLineWidth() / 2));
    graphics.drawOval(center.x - radius2, center.y - radius2, 2 * radius2, 2 * radius2);
    int radius3 = Math.round(radius / 3.0F - (graphics.getLineWidth() / 2));
    graphics.fillOval(center.x - radius3, center.y - radius3, 2 * radius3, 2 * radius3);
    int x = Math.round(center.x - radius * 2f);
    int y = Math.round(center.y + radius * 2f);
    Point intersection = getCircleIntersection(x, y, center.preciseX() - radius3, center.preciseY() - radius3, center.preciseX() - radius3, center.preciseY() - radius3, radius);
    if (intersection != null) {
        // Need this so line doesn't draw out of bounds at bottom of rect
        graphics.setClip(rect);
        int arrowLength = (int) (radius3 * 1.5f);
        // int arrowLineWidth = Math.round(graphics.getLineWidth() * 1.5f);
        int arrowLineWidth = Math.max(3, arrowLength / 5);
        graphics.setLineWidth(arrowLineWidth);
        graphics.fillPolygon(new int[] { intersection.x, intersection.y, intersection.x - arrowLength, intersection.y - arrowLength / 3, intersection.x - arrowLength / 3, intersection.y + arrowLength });
        graphics.setLineCap(SWT.CAP_ROUND);
        graphics.drawLine(x, rect.y + rect.height, x + (intersection.x - x) / 3, intersection.y + (y - intersection.y) / 3);
        graphics.drawLine(x + (intersection.x - x) / 3, intersection.y + (y - intersection.y) / 3, intersection.x - arrowLineWidth, intersection.y + arrowLineWidth);
    }
    // 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 94 with Path

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

the class CourseOfActionFigure 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);
    // triangle of shortcut glyph
    Path path = new Path(null);
    Point pt = getIconOrigin();
    float x = pt.x - 5.4f, y = pt.y + 9f;
    path.moveTo(x, y);
    path.lineTo(x + 6f, y + 1f);
    path.lineTo(x + 3f, y + 6.2f);
    graphics.fillPath(path);
    path.dispose();
    // line of shortcut glyph
    path = new Path(null);
    graphics.setLineWidthFloat(2f);
    path.addArc(pt.x - 7.5f, pt.y + 12f, 10, 10, 90, 80);
    graphics.drawPath(path);
    path.dispose();
    // 2 circles and blob
    graphics.setLineWidthFloat(1.2f);
    path = new Path(null);
    pt = getIconOrigin();
    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.popState();
}
Also used : Path(org.eclipse.swt.graphics.Path) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 95 with Path

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

the class GroupFigure method drawFigure.

@Override
protected void drawFigure(Graphics graphics) {
    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);
    graphics.setAlpha(getAlpha());
    if (getDiagramModelObject().getBorderType() == IDiagramModelGroup.BORDER_TABBED) {
        tabWidth = (int) (bounds.width / INSET);
        tabHeight = TOPBAR_HEIGHT;
        if (getDiagramModelObject().getTextPosition() == ITextPosition.TEXT_POSITION_TOP) {
            int textWidth = FigureUtilities.getTextExtents(getText(), getFont()).width;
            tabWidth = Math.min(Math.max(tabWidth, textWidth + 8), bounds.width);
            // Tab height is calculated from font height
            int textHeight = FigureUtilities.getFontMetrics(getFont()).getHeight();
            // Tab height is calculated from the text control height which includes all text
            // int textHeight = getTextControl().getBounds().height;
            tabHeight = Math.max(TOPBAR_HEIGHT, textHeight);
        }
        // Top Rectangle
        graphics.setBackgroundColor(ColorFactory.getDarkerColor(getFillColor()));
        Path path1 = new Path(null);
        path1.moveTo(bounds.x, bounds.y);
        path1.lineTo(bounds.x + tabWidth, bounds.y);
        path1.lineTo(bounds.x + tabWidth, bounds.y + tabHeight);
        path1.lineTo(bounds.x, bounds.y + tabHeight);
        path1.lineTo(bounds.x, bounds.y);
        graphics.fillPath(path1);
        path1.dispose();
        // Main rectangle
        graphics.setBackgroundColor(getFillColor());
        Pattern gradient = applyGradientPattern(graphics, bounds);
        Path path2 = new Path(null);
        path2.moveTo(bounds.x, bounds.y + tabHeight);
        path2.lineTo(bounds.x + bounds.width, bounds.y + tabHeight);
        path2.lineTo(bounds.x + bounds.width, bounds.y + bounds.height);
        path2.lineTo(bounds.x, bounds.y + bounds.height);
        graphics.fillPath(path2);
        path2.dispose();
        disposeGradientPattern(graphics, gradient);
        // Icon
        if (getIconicDelegate() != null) {
            getIconicDelegate().setTopOffset(tabHeight);
            drawIconImage(graphics, bounds);
        }
        // Line
        graphics.setForegroundColor(getLineColor());
        graphics.setAlpha(getLineAlpha());
        Path path = new Path(null);
        path.moveTo(bounds.x, bounds.y + tabHeight);
        path.lineTo(bounds.x, bounds.y);
        path.lineTo(bounds.x + tabWidth, bounds.y);
        path.lineTo(bounds.x + tabWidth, bounds.y + tabHeight);
        graphics.drawPath(path);
        path.dispose();
        graphics.drawRectangle(bounds.x, bounds.y + tabHeight, bounds.width, bounds.height - tabHeight);
    } else {
        graphics.setBackgroundColor(getFillColor());
        Pattern gradient = applyGradientPattern(graphics, bounds);
        graphics.fillRectangle(bounds);
        disposeGradientPattern(graphics, gradient);
        // Icon
        if (getIconicDelegate() != null) {
            getIconicDelegate().setTopOffset(0);
            drawIconImage(graphics, bounds);
        }
        // Line
        graphics.setForegroundColor(getLineColor());
        graphics.setAlpha(getLineAlpha());
        graphics.drawRectangle(bounds);
    }
    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