Search in sources :

Example 11 with Pattern

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

the class EllipseFigure 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 12 with Pattern

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

the class RoundedRectangleFigure method fillShape.

@Override
protected void fillShape(Graphics graphics) {
    var figureBounds = getClientArea();
    if (support3D == null) {
        support3D = GraphicsUtil.testPatternSupported(graphics);
    }
    if (!transparent) {
        graphics.pushState();
        if (isEnabled()) {
            graphics.setBackgroundColor(getBackgroundColor());
        }
        Pattern pattern = null;
        if (gradient && support3D && isEnabled()) {
            pattern = setGradientPattern(graphics, figureBounds, backGradientStartColor, getBackgroundColor());
        }
        graphics.fillRoundRectangle(figureBounds, corner.width, corner.height);
        if (pattern != null) {
            pattern.dispose();
        }
        graphics.popState();
    }
    if (getFill() > 0) {
        Rectangle fillRectangle;
        if (horizontalFill) {
            var newW = (int) Math.round(figureBounds.width * (getFill() / 100));
            fillRectangle = new Rectangle(figureBounds.x, figureBounds.y, newW, figureBounds.height);
        } else {
            var newH = (int) Math.round(figureBounds.height * (getFill() / 100));
            fillRectangle = new Rectangle(figureBounds.x, figureBounds.y + figureBounds.height - newH, figureBounds.width, newH);
        }
        graphics.pushState();
        graphics.setClip(fillRectangle);
        if (isEnabled()) {
            graphics.setBackgroundColor(getForegroundColor());
        }
        Pattern pattern = null;
        if (gradient && support3D && isEnabled()) {
            pattern = setGradientPattern(graphics, figureBounds, foreGradientStartColor, getForegroundColor());
        }
        graphics.fillRoundRectangle(figureBounds, corner.width, corner.height);
        if (pattern != null) {
            pattern.dispose();
        }
        graphics.popState();
    }
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern) Rectangle(org.eclipse.draw2d.geometry.Rectangle) RoundedRectangle(org.eclipse.draw2d.RoundedRectangle)

Example 13 with Pattern

use of org.eclipse.swt.graphics.Pattern in project pentaho-kettle by pentaho.

the class Sleak method refreshLabel.

void refreshLabel() {
    int colors = 0, cursors = 0, fonts = 0, gcs = 0, images = 0;
    int paths = 0, patterns = 0, regions = 0, textLayouts = 0, transforms = 0;
    for (int i = 0; i < objects.length; i++) {
        Object object = objects[i];
        if (object instanceof Color) {
            colors++;
        }
        if (object instanceof Cursor) {
            cursors++;
        }
        if (object instanceof Font) {
            fonts++;
        }
        if (object instanceof GC) {
            gcs++;
        }
        if (object instanceof Image) {
            images++;
        }
        if (object instanceof Path) {
            paths++;
        }
        if (object instanceof Pattern) {
            patterns++;
        }
        if (object instanceof Region) {
            regions++;
        }
        if (object instanceof TextLayout) {
            textLayouts++;
        }
        if (object instanceof Transform) {
            transforms++;
        }
    }
    String string = "";
    if (colors != 0) {
        string += colors + " Color(s)\n";
    }
    if (cursors != 0) {
        string += cursors + " Cursor(s)\n";
    }
    if (fonts != 0) {
        string += fonts + " Font(s)\n";
    }
    if (gcs != 0) {
        string += gcs + " GC(s)\n";
    }
    if (images != 0) {
        string += images + " Image(s)\n";
    }
    if (paths != 0) {
        string += paths + " Paths(s)\n";
    }
    if (patterns != 0) {
        string += patterns + " Pattern(s)\n";
    }
    if (regions != 0) {
        string += regions + " Region(s)\n";
    }
    if (textLayouts != 0) {
        string += textLayouts + " TextLayout(s)\n";
    }
    if (transforms != 0) {
        string += transforms + " Transform(s)\n";
    }
    if (string.length() != 0) {
        string = string.substring(0, string.length() - 1);
    }
    label.setText(string);
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Color(org.eclipse.swt.graphics.Color) Cursor(org.eclipse.swt.graphics.Cursor) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) TextLayout(org.eclipse.swt.graphics.TextLayout) Region(org.eclipse.swt.graphics.Region) GC(org.eclipse.swt.graphics.GC) Transform(org.eclipse.swt.graphics.Transform)

Example 14 with Pattern

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

the class BusinessActorFigure 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, 2 / 3.0);
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    graphics.setAlpha(getAlpha());
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, rect);
    Path path = new Path(null);
    int diameter = Math.min(rect.width / 2, rect.height / 3);
    path.addArc((rect.x + rect.width / 2 - diameter / 2), (rect.y + rect.height / 2 - diameter - diameter / 2), diameter, diameter, 0, 360);
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    // Lines
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawPath(path);
    path.dispose();
    graphics.setLineCap(SWT.CAP_ROUND);
    graphics.drawLine(rect.x + rect.width / 2, rect.y + rect.height / 2 - diameter / 2, rect.x + rect.width / 2, rect.y + rect.height / 2 - diameter / 2 + diameter);
    graphics.drawLine(rect.x + rect.width / 2, rect.y + rect.height / 2 - diameter / 2 + diameter, rect.x + rect.width / 2 - diameter, rect.y + rect.height / 2 - diameter / 2 + diameter + diameter);
    graphics.drawLine(rect.x + rect.width / 2, rect.y + rect.height / 2 - diameter / 2 + diameter, rect.x + rect.width / 2 + diameter, rect.y + rect.height / 2 - diameter / 2 + diameter + diameter);
    graphics.drawLine(rect.x + rect.width / 2 - diameter, rect.y + rect.height / 2 - diameter / 4, rect.x + rect.width / 2 + diameter, rect.y + rect.height / 2 - diameter / 4);
    // 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 15 with Pattern

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

the class CapabilityFigure 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 = new Path(null);
    // block length
    int blockLength = Math.min(rect.height / 3, rect.width / 3);
    int figureLength = blockLength * 3;
    int xMargin = (rect.width - figureLength) / 2;
    int yMargin = (rect.height - figureLength) / 2;
    path.moveTo(rect.x + xMargin, rect.y + yMargin + 3 * blockLength);
    path.lineTo(rect.x + xMargin, rect.y + yMargin + 2 * blockLength);
    path.lineTo(rect.x + xMargin + 1 * blockLength, rect.y + yMargin + 2 * blockLength);
    path.lineTo(rect.x + xMargin + 1 * blockLength, rect.y + yMargin + 1 * blockLength);
    path.lineTo(rect.x + xMargin + 2 * blockLength, rect.y + yMargin + 1 * blockLength);
    path.lineTo(rect.x + xMargin + 2 * blockLength, rect.y + yMargin);
    path.lineTo(rect.x + xMargin + 3 * blockLength, rect.y + yMargin);
    path.lineTo(rect.x + xMargin + 3 * blockLength, rect.y + yMargin + 3 * blockLength);
    path.close();
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawPath(path);
    path.dispose();
    // Inner lines
    graphics.drawLine(rect.x + xMargin + 1 * blockLength, rect.y + yMargin + 3 * blockLength, rect.x + xMargin + 1 * blockLength, rect.y + yMargin + 2 * blockLength);
    graphics.drawLine(rect.x + xMargin + 2 * blockLength, rect.y + yMargin + 3 * blockLength, rect.x + xMargin + 2 * blockLength, rect.y + yMargin + 1 * blockLength);
    graphics.drawLine(rect.x + xMargin + 1 * blockLength, rect.y + yMargin + 2 * blockLength, rect.x + xMargin + 3 * blockLength, rect.y + yMargin + 2 * blockLength);
    graphics.drawLine(rect.x + xMargin + 2 * blockLength, rect.y + yMargin + 1 * blockLength, rect.x + xMargin + 3 * blockLength, rect.y + yMargin + 1 * blockLength);
    // 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)

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