Search in sources :

Example 21 with Pattern

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

the class CylinderFigureDelegate method drawFigure.

@Override
public void drawFigure(Graphics graphics) {
    graphics.pushState();
    Rectangle rect = getBounds();
    rect.width--;
    rect.height--;
    // Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
    setLineWidth(graphics, 1, rect);
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    graphics.setAlpha(getAlpha());
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, rect);
    Path path = new Path(null);
    path.addArc(rect.x, rect.y, rect.width / OFFSET, rect.height, 90, 180);
    path.lineTo((rect.x + rect.width) - (rect.width / OFFSET * 2), rect.y + rect.height);
    path.addArc((rect.x + rect.width) - (rect.width / OFFSET), rect.y, rect.width / OFFSET, rect.height, 270, 180);
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    // Lines
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawPath(path);
    path.dispose();
    graphics.drawLine(rect.x + (rect.width / OFFSET / 2), rect.y, (rect.x + rect.width) - (rect.width / OFFSET / 2), rect.y);
    graphics.drawArc((rect.x + rect.width) - (rect.width / OFFSET), rect.y, rect.width / OFFSET, rect.height, 90, 180);
    // Image Icon
    getOwner().drawIconImage(graphics, rect, 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 22 with Pattern

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

the class DeviceFigure method drawFigure.

@Override
public 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 height_indent = bounds.height / 6;
    graphics.setAlpha(getAlpha());
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    // Bottom part
    graphics.setBackgroundColor(ColorFactory.getDarkerColor(getFillColor()));
    Path path = new Path(null);
    path.moveTo(bounds.x, bounds.y + bounds.height);
    path.lineTo(bounds.x + INDENT + 1, bounds.y + bounds.height - height_indent);
    path.lineTo(bounds.x + bounds.width - INDENT, bounds.y + bounds.height - height_indent);
    path.lineTo(bounds.x + bounds.width, bounds.y + bounds.height);
    path.lineTo(bounds.x, bounds.y + bounds.height);
    graphics.fillPath(path);
    path.dispose();
    graphics.setForegroundColor(getLineColor());
    graphics.setAlpha(getLineAlpha());
    graphics.drawLine(bounds.x, bounds.y + bounds.height, bounds.x + bounds.width, bounds.y + bounds.height);
    graphics.drawLine(bounds.x, bounds.y + bounds.height, bounds.x + INDENT + 1, bounds.y + bounds.height - height_indent);
    graphics.drawLine(bounds.x + bounds.width, bounds.y + bounds.height, bounds.x + bounds.width - INDENT + 1, bounds.y + bounds.height - height_indent);
    // Top part
    Rectangle rect = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height - height_indent);
    graphics.setBackgroundColor(getFillColor());
    graphics.setAlpha(getAlpha());
    Pattern gradient = applyGradientPattern(graphics, bounds);
    graphics.fillRoundRectangle(rect, 30, 30);
    disposeGradientPattern(graphics, gradient);
    graphics.setForegroundColor(getLineColor());
    graphics.setAlpha(getLineAlpha());
    rect = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height - height_indent);
    graphics.drawRoundRectangle(rect, 30, 30);
    // Image icon
    Rectangle imageArea = new Rectangle(bounds.x + 3, bounds.y + 3, bounds.width - 6, bounds.height - height_indent - 6);
    drawIconImage(graphics, bounds, imageArea, 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 23 with Pattern

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

the class DriverFigure 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);
    int lineWidth = (int) (Math.sqrt(rect.width * rect.height) / 20);
    graphics.setLineWidth(lineWidth);
    setFigurePositionFromTextPosition(rect);
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    // Fill
    graphics.setAlpha(getAlpha());
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, rect);
    Path path = new Path(null);
    int radius = getRadius(rect);
    int actualRadius = getRadius(rect) - Math.round(radius / 10.0f) - lineWidth / 2;
    Point center = rect.getCenter();
    path.addArc((float) center.preciseX() - actualRadius, (float) center.preciseY() - actualRadius, (actualRadius * 2), (actualRadius * 2), 0, 360);
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    // Outline
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawPath(path);
    path.dispose();
    graphics.setLineWidth(1);
    int topLeftX = (int) Math.round(center.x + radius * Math.cos(TOPLEFT_ANGLE_RADIAN));
    int topLeftY = (int) Math.round(center.y + radius * Math.sin(TOPLEFT_ANGLE_RADIAN));
    int bottomRightX = (int) Math.round(center.x + radius * Math.cos(BOTTOMRIGHT_ANGLE_RADIAN));
    int bottomRightY = (int) Math.round(center.y + radius * Math.sin(BOTTOMRIGHT_ANGLE_RADIAN));
    graphics.drawLine(topLeftX, topLeftY, bottomRightX, bottomRightY);
    graphics.drawLine(center.x - radius, center.y, center.x + radius, center.y);
    int bottomLeftX = (int) Math.round(center.x + radius * Math.cos(BOTTOMLEFT_ANGLE_RADIAN));
    int bottomLeftY = (int) Math.round(center.y + radius * Math.sin(BOTTOMLEFT_ANGLE_RADIAN));
    int topRightX = (int) Math.round(center.x + radius * Math.cos(TOPRIGHT_ANGLE_RADIAN));
    int topRightY = (int) Math.round(center.y + radius * Math.sin(TOPRIGHT_ANGLE_RADIAN));
    graphics.drawLine(bottomLeftX, bottomLeftY, topRightX, topRightY);
    graphics.drawLine(center.x, center.y - radius, center.x, center.y + radius);
    graphics.setBackgroundColor(getLineColor());
    radius = Math.round(radius / 4.0f);
    graphics.fillOval(center.x - radius, center.y - radius, 2 * radius, 2 * radius);
    // 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 24 with Pattern

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

the class DeliverableFigure 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
    int lineWidth = 1;
    setLineWidth(graphics, lineWidth, bounds);
    int offset = 11;
    int curve_y = bounds.y + bounds.height - offset;
    graphics.setAlpha(getAlpha());
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    // Main Fill
    Path path = new Path(null);
    path.moveTo(bounds.x, bounds.y);
    path.lineTo(bounds.x, curve_y - 1);
    path.quadTo(bounds.x + (bounds.width / 4), bounds.y + bounds.height + offset, bounds.x + bounds.width / 2 + 1, curve_y);
    path.quadTo(bounds.x + bounds.width - (bounds.width / 4), curve_y - offset - 1, bounds.x + bounds.width, curve_y);
    path.lineTo(bounds.x + bounds.width, bounds.y);
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, bounds);
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    // Outline
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    float lineOffset = (float) lineWidth / 2;
    path.lineTo(bounds.x - lineOffset, bounds.y);
    graphics.drawPath(path);
    path.dispose();
    // Icon
    // drawIconImage(graphics, bounds);
    drawIconImage(graphics, bounds, 0, 0, -14, 0);
    graphics.popState();
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Example 25 with Pattern

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

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