Search in sources :

Example 26 with Pattern

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

the class RectangleFigureDelegate 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);
    graphics.setAlpha(getAlpha());
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    // Fill
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, bounds);
    graphics.fillRectangle(bounds);
    disposeGradientPattern(graphics, gradient);
    // Outline
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawRectangle(bounds);
    // Icon
    // getOwner().drawIconImage(graphics, bounds);
    getOwner().drawIconImage(graphics, bounds, 0, 0, 0, 0);
    graphics.popState();
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Example 27 with Pattern

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

the class RoundedRectangleFigureDelegate 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);
    graphics.setAlpha(getAlpha());
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    // Fill
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, bounds);
    graphics.fillRoundRectangle(bounds, fArc.width, fArc.height);
    disposeGradientPattern(graphics, gradient);
    // Outline
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawRoundRectangle(bounds, fArc.width, fArc.height);
    // Image Icon
    Rectangle imageArea = new Rectangle(bounds.x + 2, bounds.y + 2, bounds.width - 4, bounds.height - 4);
    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)

Example 28 with Pattern

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

the class AbstractDiagramModelObjectFigure method applyGradientPattern.

/**
 * Apply a gradient pattern to the given Graphics instance and bounds using the current fill color, alpha and gradient setting
 * If a gradient is applied the alpha of graphics will be set to 255 so callers should set it back if needed after
 * calling {@link #disposeGradientPattern(Graphics, Pattern)}
 * @return the Pattern if a gradient should be applied or null if not
 */
protected Pattern applyGradientPattern(Graphics graphics, Rectangle bounds) {
    Pattern gradient = null;
    // Apply gradient
    if (getGradient() != IDiagramModelObject.GRADIENT_NONE) {
        // Ensure graphics#alpha is 255
        // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=575778
        graphics.setAlpha(255);
        gradient = FigureUtils.createGradient(graphics, bounds, getFillColor(), getAlpha(), Direction.get(getGradient()));
        graphics.setBackgroundPattern(gradient);
    }
    return gradient;
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern)

Example 29 with Pattern

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

the class StickyFigure method drawFigure.

@Override
protected void drawFigure(Graphics graphics) {
    graphics.pushState();
    graphics.setAlpha(getAlpha());
    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.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, bounds);
    graphics.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
    disposeGradientPattern(graphics, gradient);
    // Icon
    drawIconImage(graphics, bounds);
    // Outline
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
    graphics.popState();
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Example 30 with Pattern

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

the class ValueStreamFigure method drawFigure.

@Override
protected 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 / 2, bounds.width / 2);
    int centre_y = bounds.y + bounds.height / 2;
    int point_startx = bounds.x + bounds.width - indent;
    graphics.setAlpha(getAlpha());
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    // Shape
    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(point_startx, bounds.y + bounds.height);
    path.lineTo(bounds.x + bounds.width, centre_y);
    path.lineTo(point_startx, bounds.y);
    path.lineTo(bounds.x, bounds.y);
    path.lineTo(bounds.x + indent, centre_y);
    // Fill
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, bounds);
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    // Outline
    graphics.setForegroundColor(getLineColor());
    graphics.drawPath(path);
    path.dispose();
    // Icon
    // drawIconImage(graphics, bounds);
    int top = 0, right = 0, left = 0, bottom = 0;
    switch(((IIconic) getDiagramModelObject()).getImagePosition()) {
        case IIconic.ICON_POSITION_TOP_LEFT:
        case IIconic.ICON_POSITION_BOTTOM_LEFT:
            left = 10;
            break;
        case IIconic.ICON_POSITION_TOP_RIGHT:
        case IIconic.ICON_POSITION_BOTTOM_RIGHT:
            right = -indent;
            break;
        case IIconic.ICON_POSITION_MIDDLE_LEFT:
            left = indent;
            break;
        case IIconic.ICON_POSITION_MIDDLE_RIGHT:
            right = -10;
            break;
    }
    drawIconImage(graphics, bounds, 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)

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