Search in sources :

Example 66 with Pattern

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

the class EventFigure 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 indent = Math.min(bounds.height / 3, bounds.width / 3);
    int centre_y = bounds.y + bounds.height / 2 - 1;
    int arc_startx = bounds.x + bounds.width - indent;
    graphics.setAlpha(getAlpha());
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    // Main Fill
    Path path = new Path(null);
    path.moveTo(bounds.x, bounds.y);
    path.lineTo(bounds.x + indent, centre_y);
    path.lineTo(bounds.x, bounds.y + bounds.height);
    path.lineTo(arc_startx, bounds.y + bounds.height);
    path.addArc(arc_startx - indent, bounds.y, indent * 2, bounds.height, -90, 180);
    path.lineTo(bounds.x, bounds.y);
    path.lineTo(bounds.x + indent, centre_y);
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, bounds);
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    // Outline
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    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) Point(org.eclipse.draw2d.geometry.Point)

Example 67 with Pattern

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

the class FunctionFigure 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--;
    // 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 = getFigurePath(rect);
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    // Line
    graphics.setForegroundColor(getLineColor());
    graphics.setAlpha(getLineAlpha());
    graphics.drawPath(path);
    path.dispose();
    // Image Icon
    // drawIconImage(graphics, bounds, 0, 0, 0, 0);
    // drawIconImage(graphics, bounds, bounds.height / 5 + 1, 0, -(bounds.height / 5 + 1), 0);
    int top = 0, right = 0, left = 0, bottom = 0;
    switch(((IIconic) getDiagramModelObject()).getImagePosition()) {
        case IIconic.ICON_POSITION_TOP_LEFT:
        case IIconic.ICON_POSITION_TOP_RIGHT:
            top = rect.height / OFFSET;
            break;
        case IIconic.ICON_POSITION_BOTTOM_CENTRE:
            bottom = -(rect.height / OFFSET);
            break;
        case IIconic.ICON_POSITION_BOTTOM_LEFT:
        case IIconic.ICON_POSITION_BOTTOM_RIGHT:
            bottom = -(rect.height / OFFSET / 3);
            break;
    }
    drawIconImage(graphics, rect, top, right, bottom, left);
    graphics.popState();
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) IIconic(com.archimatetool.model.IIconic) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point)

Example 68 with Pattern

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

the class GoalFigure 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 radius = getRadius(rect);
    Point center = rect.getCenter();
    path.addArc((float) center.preciseX() - radius, (float) center.preciseY() - radius, radius * 2, radius * 2, 0, 360);
    path.close();
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    // Lines
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawPath(path);
    path.dispose();
    graphics.setBackgroundColor(getLineColor());
    radius = Math.round(radius * 2.0f / 3.0f - (graphics.getLineWidth() / 2));
    graphics.drawOval(center.x - radius, center.y - radius, 2 * radius, 2 * radius);
    radius = Math.round(radius / 3.0f - (graphics.getLineWidth() / 2));
    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 69 with Pattern

use of org.eclipse.swt.graphics.Pattern in project yamcs-studio by yamcs.

the class RoundedRectangleFigure method setGradientPattern.

protected Pattern setGradientPattern(Graphics graphics, Rectangle figureBounds, Color gradientStartColor, Color fillColor) {
    Pattern pattern;
    var tx = figureBounds.x;
    var ty = figureBounds.y + figureBounds.height;
    if (!horizontalFill) {
        tx = figureBounds.x + figureBounds.width;
        ty = figureBounds.y;
    }
    var alpha = getAlpha() == null ? 255 : getAlpha();
    // Workaround for the pattern zoom bug on ScaledGraphics:
    // The coordinates need to be scaled for ScaledGraphics.
    var scale = graphics.getAbsoluteScale();
    pattern = new Pattern(Display.getCurrent(), (int) (figureBounds.x * scale), (int) (figureBounds.y * scale), (int) (tx * scale), (int) (ty * scale), gradientStartColor, alpha, fillColor, alpha);
    graphics.setBackgroundPattern(pattern);
    return pattern;
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern)

Example 70 with Pattern

use of org.eclipse.swt.graphics.Pattern in project yamcs-studio by yamcs.

the class RoundScaledRamp method paintClientArea.

@Override
protected void paintClientArea(Graphics graphics) {
    updateThresholdPosition();
    graphics.setAntialias(SWT.ON);
    graphics.setLineWidth(rampWidth);
    graphics.pushState();
    var overlap = 0;
    Pattern pattern = null;
    var support3D = GraphicsUtil.testPatternSupported(graphics);
    // draw lolo part
    if (lolo.visible) {
        graphics.setBackgroundColor(lolo.color);
        graphics.fillArc(bounds, lolo.absolutePosition, min.relativePosition - lolo.relativePosition);
    }
    // draw lo part
    if (lo.visible) {
        if (support3D && gradient && lolo.visible) {
            try {
                pattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), lolo.leftPoint.x, lolo.leftPoint.y, lo.rightPoint.x, lo.rightPoint.y, lolo.color, lo.color);
                graphics.setBackgroundPattern(pattern);
                overlap = OVERLAP_DEGREE / 2;
            } catch (Exception e) {
                support3D = false;
                pattern.dispose();
                graphics.setBackgroundColor(lo.color);
                overlap = 0;
            }
        } else {
            graphics.setBackgroundColor(lo.color);
            overlap = 0;
        }
        if (lolo.visible) {
            graphics.fillArc(bounds, lo.absolutePosition, lolo.relativePosition - lo.relativePosition + overlap);
        } else {
            graphics.fillArc(bounds, lo.absolutePosition, min.relativePosition - lo.relativePosition);
        }
        if (gradient && lolo.visible && support3D) {
            pattern.dispose();
        }
    }
    // draw left normal part
    // get the left marker
    var leftMarkerVisible = false;
    ThresholdMarker leftMarker = null;
    if (lo.visible) {
        leftMarkerVisible = true;
        leftMarker = lo;
    } else if (lolo.visible) {
        leftMarkerVisible = true;
        leftMarker = lolo;
    } else {
        leftMarkerVisible = false;
    }
    if (gradient && leftMarkerVisible && support3D) {
        pattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), leftMarker.leftPoint.x, leftMarker.leftPoint.y, normal.rightPoint.x, normal.rightPoint.y, leftMarker.color, normal.color);
        graphics.setBackgroundPattern(pattern);
        overlap = OVERLAP_DEGREE / 2;
    } else {
        graphics.setBackgroundColor(normal.color);
        overlap = 0;
    }
    if (leftMarkerVisible) {
        graphics.fillArc(bounds, normal.absolutePosition, leftMarker.relativePosition - normal.relativePosition + overlap);
    } else {
        graphics.fillArc(bounds, normal.absolutePosition, min.relativePosition - normal.relativePosition);
    }
    if (gradient && leftMarkerVisible && support3D) {
        pattern.dispose();
    }
    // draw right normal part
    // get the right marker
    var rightMarkerVisible = false;
    ThresholdMarker rightMarker = null;
    if (hi.visible) {
        rightMarkerVisible = true;
        rightMarker = hi;
    } else if (hihi.visible) {
        rightMarkerVisible = true;
        rightMarker = hihi;
    } else {
        rightMarkerVisible = false;
    }
    if (gradient && rightMarkerVisible && support3D) {
        pattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), rightMarker.rightPoint.x, rightMarker.rightPoint.y, normal.leftPoint.x, normal.leftPoint.y, rightMarker.color, normal.color);
        graphics.setBackgroundPattern(pattern);
        overlap = OVERLAP_DEGREE / 2;
    } else {
        graphics.setBackgroundColor(normal.color);
        overlap = 0;
    }
    if (rightMarkerVisible) {
        graphics.fillArc(bounds, rightMarker.absolutePosition, normal.relativePosition - rightMarker.relativePosition + overlap + 1);
    } else {
        graphics.fillArc(bounds, max.absolutePosition, normal.relativePosition - max.relativePosition + 1);
    }
    if (gradient && rightMarkerVisible && support3D) {
        pattern.dispose();
    }
    // draw hi part
    if (hi.visible) {
        if (hihi.visible) {
            rightMarkerVisible = true;
            rightMarker = hihi;
        } else {
            rightMarkerVisible = false;
        }
        if (gradient && rightMarkerVisible && support3D) {
            pattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), rightMarker.rightPoint.x, rightMarker.rightPoint.y, hi.leftPoint.x, hi.leftPoint.y, rightMarker.color, hi.color);
            graphics.setBackgroundPattern(pattern);
            overlap = OVERLAP_DEGREE / 2;
        } else {
            graphics.setBackgroundColor(hi.color);
            overlap = 0;
        }
        if (rightMarkerVisible) {
            graphics.fillArc(bounds, rightMarker.absolutePosition, hi.relativePosition - rightMarker.relativePosition + overlap);
        } else {
            graphics.fillArc(bounds, max.absolutePosition, hi.relativePosition - max.relativePosition);
        }
        if (gradient && rightMarkerVisible && support3D) {
            pattern.dispose();
        }
    }
    // draw hihi part
    if (hihi.visible) {
        if (gradient && support3D) {
            overlap = OVERLAP_DEGREE / 2;
        } else {
            overlap = 0;
        }
        graphics.setBackgroundColor(hihi.color);
        graphics.fillArc(bounds, max.absolutePosition, hihi.relativePosition - max.relativePosition + overlap);
    }
    graphics.popState();
    graphics.fillOval(bounds.x + rampWidth, bounds.y + rampWidth, bounds.width - 2 * rampWidth, bounds.height - 2 * rampWidth);
    super.paintClientArea(graphics);
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern)

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