Search in sources :

Example 31 with Pattern

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

the class ValueFigure method drawFigure.

@Override
public 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 (!isEnabled()) {
        setDisabledState(graphics);
    }
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, bounds);
    graphics.fillOval(bounds);
    disposeGradientPattern(graphics, gradient);
    // Outline
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawOval(bounds);
    // Icon
    // drawIconImage(graphics, bounds);
    int top = 0, right = 0, left = 0, bottom = 0;
    int offset = 6;
    switch(((IIconic) getDiagramModelObject()).getImagePosition()) {
        case IIconic.ICON_POSITION_TOP_LEFT:
            top = bounds.height / offset;
            left = bounds.width / offset;
            break;
        case IIconic.ICON_POSITION_TOP_RIGHT:
            top = bounds.height / offset;
            right = -(bounds.width / offset);
            break;
        case IIconic.ICON_POSITION_BOTTOM_LEFT:
            bottom = -(bounds.height / offset);
            left = bounds.width / offset;
            break;
        case IIconic.ICON_POSITION_BOTTOM_RIGHT:
            bottom = -(bounds.height / offset);
            right = -(bounds.width / offset);
            break;
    }
    drawIconImage(graphics, bounds, top, right, bottom, left);
    // Rectangle iconArea = new Rectangle(bounds.x + (bounds.width / 6), bounds.y + (bounds.height / 6),
    // bounds.width - (bounds.width / 3), bounds.height - (bounds.height / 3));
    // drawIconImage(graphics, iconArea, 0, 0, 0, 0);
    graphics.popState();
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern) IIconic(com.archimatetool.model.IIconic) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Example 32 with Pattern

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

the class PrincipleFigure 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);
    }
    // Fill
    graphics.setAlpha(getAlpha());
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, rect);
    Path path = new Path(null);
    int divisions = 24;
    int div1 = 8;
    int div2 = 16;
    int fractionX = rect.width / divisions;
    int fractionY = rect.height / divisions;
    int corner = Math.min(fractionX, fractionY);
    path.moveTo(rect.x + corner, rect.y + corner);
    path.cubicTo(rect.x + fractionX * div1, rect.y, rect.x + fractionX * div2, rect.y, rect.x + rect.width - corner, rect.y + corner);
    path.cubicTo(rect.x + rect.width, rect.y + fractionY * div1, rect.x + rect.width, rect.y + fractionY * div2, rect.x + rect.width - corner, rect.y + rect.height - corner);
    path.cubicTo(rect.x + fractionX * div2, rect.y + rect.height, rect.x + fractionX * div1, rect.y + rect.height, rect.x + corner, rect.y + rect.height - corner);
    path.cubicTo(rect.x, rect.y + fractionY * div2, rect.x, rect.y + fractionY * div1, rect.x + corner, rect.y + corner);
    path.close();
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    // Lines
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawPath(path);
    path.dispose();
    graphics.setBackgroundColor(getLineColor());
    Point center = rect.getCenter();
    int width = Math.max(1, Math.round((rect.height - 2.0f * graphics.getLineWidth()) / 20.0f));
    if (width >= rect.width / 2) {
        width = Math.max(1, rect.width / 4);
    }
    graphics.fillPolygon(new int[] { center.x - Math.round(width), rect.y + 3 * width, center.x + Math.round(width), rect.y + 3 * width, center.x + Math.round(0.8f * width), rect.y + rect.height - 7 * width, center.x - Math.round(0.8f * width), rect.y + rect.height - 7 * width });
    graphics.fillPolygon(new int[] { center.x + Math.round(0.8f * width), rect.y + rect.height - 5 * width, center.x - Math.round(0.8f * width), rect.y + rect.height - 5 * width, center.x - Math.round(0.8f * width), rect.y + rect.height - 3 * width, center.x + Math.round(0.8F * width), rect.y + rect.height - 3 * width });
    // 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) Point(org.eclipse.draw2d.geometry.Point)

Example 33 with Pattern

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

the class ServiceFigureDelegate method drawFigure.

@Override
public void drawFigure(Graphics graphics) {
    graphics.pushState();
    Rectangle bounds = getBounds();
    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);
    Dimension arc = getArc();
    graphics.setAlpha(getAlpha());
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, bounds);
    graphics.fillRoundRectangle(new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height), arc.width, arc.height);
    disposeGradientPattern(graphics, gradient);
    // Outline
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawRoundRectangle(new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height), arc.width, arc.height);
    // Image Icon
    Rectangle imageArea = new Rectangle(bounds.x + arc.width / 6, bounds.y + arc.height / 6, bounds.width - arc.width / 3, bounds.height - arc.height / 3);
    getOwner().drawIconImage(graphics, bounds, imageArea, 0, 0, 0, 0);
    graphics.popState();
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Dimension(org.eclipse.draw2d.geometry.Dimension)

Example 34 with Pattern

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

the class MaterialFigure 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 'figureHeight'
    setFigurePositionFromTextPosition(rect, 10 / 9.0);
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    graphics.setAlpha(getAlpha());
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, rect);
    Path path = new Path(null);
    int figureWidth = rect.width;
    int figureHeight = rect.height;
    // width < height or same
    if (rect.width <= rect.height) {
        figureHeight = rect.width - (rect.width / 10);
    } else // height < width
    {
        figureWidth = rect.height + (rect.width / 10);
        // remove possible error in width calculation
        figureWidth = Math.min(figureWidth, rect.width);
    }
    int xMargin = (rect.width - figureWidth) / 2;
    int yMargin = (rect.height - figureHeight) / 2;
    path.moveTo(rect.x + xMargin + figureWidth / 4, rect.y + yMargin);
    path.lineTo(rect.x + xMargin, rect.y + yMargin + figureHeight / 2);
    path.lineTo(rect.x + xMargin + figureWidth / 4, rect.y + yMargin + figureHeight);
    path.lineTo(rect.x + xMargin + 3 * figureWidth / 4, rect.y + yMargin + figureHeight);
    path.lineTo(rect.x + xMargin + figureWidth, rect.y + yMargin + figureHeight / 2);
    path.lineTo(rect.x + xMargin + 3 * figureWidth / 4, rect.y + yMargin);
    path.lineTo(rect.x + xMargin + figureWidth / 4, rect.y + yMargin);
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawPath(path);
    path.dispose();
    path = new Path(null);
    // Inner lines
    path.moveTo(rect.x + xMargin + 3 * figureWidth / 8, rect.y + yMargin + figureHeight / 10);
    path.lineTo(rect.x + xMargin + figureWidth / 6, rect.y + yMargin + figureHeight / 2);
    path.moveTo(rect.x + xMargin + figureWidth / 3, rect.y + yMargin + figureHeight - figureHeight / 7);
    path.lineTo(rect.x + xMargin + figureWidth - figureWidth / 3, rect.y + yMargin + figureHeight - figureHeight / 7);
    path.moveTo(rect.x + xMargin + figureWidth - 3 * figureWidth / 8, rect.y + yMargin + figureHeight / 10);
    path.lineTo(rect.x + xMargin + figureWidth - figureWidth / 6, rect.y + yMargin + figureHeight / 2);
    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) Point(org.eclipse.draw2d.geometry.Point)

Example 35 with Pattern

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

the class ParallelogramFigureDelegate method drawFigure.

@Override
public void drawFigure(Graphics graphics) {
    graphics.pushState();
    Rectangle bounds = getBounds();
    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);
    PointList points = new PointList();
    points.addPoint(bounds.x + FLANGE, bounds.y);
    points.addPoint(bounds.x + bounds.width, bounds.y);
    points.addPoint(bounds.x + bounds.width - FLANGE, bounds.y + bounds.height);
    points.addPoint(bounds.x, bounds.y + bounds.height);
    graphics.setAlpha(getAlpha());
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    // Fill
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, bounds);
    Path path = FigureUtils.createPathFromPoints(points);
    graphics.fillPath(path);
    path.dispose();
    disposeGradientPattern(graphics, gradient);
    // Outline
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawPolygon(points);
    // Slash
    if (fWithSlash) {
        graphics.drawLine(bounds.x + FLANGE + 20, bounds.y, bounds.x + 20, bounds.y + bounds.height);
    }
    // Icon
    // getOwner().drawIconImage(graphics, bounds);
    getOwner().drawIconImage(graphics, bounds, 0, 0, 0, 0);
    graphics.popState();
}
Also used : Path(org.eclipse.swt.graphics.Path) PointList(org.eclipse.draw2d.geometry.PointList) Pattern(org.eclipse.swt.graphics.Pattern) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Aggregations

Pattern (org.eclipse.swt.graphics.Pattern)71 Rectangle (org.eclipse.draw2d.geometry.Rectangle)44 Path (org.eclipse.swt.graphics.Path)40 Point (org.eclipse.draw2d.geometry.Point)22 Device (org.eclipse.swt.graphics.Device)12 Point (org.eclipse.swt.graphics.Point)11 Rectangle (org.eclipse.swt.graphics.Rectangle)10 Color (org.eclipse.swt.graphics.Color)7 Font (org.eclipse.swt.graphics.Font)6 Image (org.eclipse.swt.graphics.Image)6 Transform (org.eclipse.swt.graphics.Transform)6 GC (org.eclipse.swt.graphics.GC)5 IIconic (com.archimatetool.model.IIconic)4 PointList (org.eclipse.draw2d.geometry.PointList)4 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)4 Region (org.eclipse.swt.graphics.Region)3 Dimension (org.eclipse.draw2d.geometry.Dimension)2 Cursor (org.eclipse.swt.graphics.Cursor)2 RGB (org.eclipse.swt.graphics.RGB)2 TextLayout (org.eclipse.swt.graphics.TextLayout)2