Search in sources :

Example 46 with Pattern

use of org.eclipse.swt.graphics.Pattern in project eclipse.platform.swt by eclipse.

the class PathClippingTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    int clipping = clippingCb.getSelectionIndex();
    switch(clipping) {
        case // circles
        0:
            Path path = new Path(device);
            path.addArc((width - width / 5) / 2, (height - height / 5) / 2, width / 5, height / 5, 0, 360);
            path.addArc(5 * (width - width / 8) / 12, 4 * (height - height / 8) / 12, width / 8, height / 8, 0, 360);
            path.addArc(7 * (width - width / 8) / 12, 8 * (height - height / 8) / 12, width / 8, height / 8, 0, 360);
            path.addArc(6 * (width - width / 12) / 12, 3 * (height - height / 12) / 12, width / 12, height / 12, 0, 360);
            path.addArc(6 * (width - width / 12) / 12, 9 * (height - height / 12) / 12, width / 12, height / 12, 0, 360);
            path.addArc(11.5f * (width - width / 18) / 20, 5 * (height - height / 18) / 18, width / 18, height / 18, 0, 360);
            path.addArc(8.5f * (width - width / 18) / 20, 13 * (height - height / 18) / 18, width / 18, height / 18, 0, 360);
            gc.setClipping(path);
            path.dispose();
            break;
        case // rectangle
        1:
            path = new Path(device);
            path.addRectangle(100, 100, width - 200, height - 200);
            path.addRectangle(120, 120, width - 240, height - 240);
            path.addRectangle(140, 140, width - 280, height - 280);
            gc.setClipping(path);
            path.dispose();
            break;
        case // circle
        2:
            path = new Path(device);
            path.addArc(100, 100, width - 200, height - 200, 0, 360);
            path.addArc((width - width / 5) / 2, (height - height / 5) / 2, width / 5, height / 5, 0, 360);
            path.addArc(5 * (width - width / 8) / 12, 4 * (height - height / 8) / 12, width / 8, height / 8, 0, 360);
            path.addArc(7 * (width - width / 8) / 12, 8 * (height - height / 8) / 12, width / 8, height / 8, 0, 360);
            path.addArc(6 * (width - width / 12) / 12, 3 * (height - height / 12) / 12, width / 12, height / 12, 0, 360);
            path.addArc(6 * (width - width / 12) / 12, 9 * (height - height / 12) / 12, width / 12, height / 12, 0, 360);
            path.addArc(11.5f * (width - width / 18) / 20, 5 * (height - height / 18) / 18, width / 18, height / 18, 0, 360);
            path.addArc(8.5f * (width - width / 18) / 20, 13 * (height - height / 18) / 18, width / 18, height / 18, 0, 360);
            gc.setClipping(path);
            path.dispose();
            break;
        case // word
        3:
            path = new Path(device);
            // $NON-NLS-1$
            String text = GraphicsExample.getResourceString("SWT");
            Font font = new Font(device, "Times", 200, SWT.NORMAL);
            gc.setFont(font);
            Point size = gc.stringExtent(text);
            path.addString(text, (width - size.x) / 2, (height - size.y) / 2, font);
            font.dispose();
            gc.setClipping(path);
            path.dispose();
            break;
        case // star
        4:
            path = new Path(device);
            path.lineTo(width / 2, 0);
            path.lineTo(5 * width / 8, height / 3);
            path.lineTo(width, height / 3);
            path.lineTo(3 * width / 4, 10 * height / 16);
            path.lineTo(7 * width / 8, height);
            path.lineTo(width / 2, 3 * height / 4);
            path.lineTo(width / 8, height);
            path.lineTo(width / 4, 10 * height / 16);
            path.lineTo(0, height / 3);
            path.lineTo(3 * width / 8, height / 3);
            path.lineTo(width / 2, 0);
            Path ovalPath = new Path(device);
            ovalPath.addArc(90, 90, width - 180, height - 180, 0, 360);
            path.addPath(ovalPath);
            gc.setClipping(path);
            ovalPath.dispose();
            path.dispose();
            break;
        case // triangles
        5:
            path = new Path(device);
            path.addRectangle(0, 0, width, height);
            path.lineTo(width / 4, 0);
            path.lineTo(width / 4, height / 2);
            path.lineTo(0, height / 2);
            path.lineTo(width / 4, 0);
            Path path2 = new Path(device);
            path2.lineTo(width / 2, 0);
            path2.lineTo(width / 4, height / 2);
            path2.lineTo(3 * width / 4, height / 2);
            path2.lineTo(width / 2, 0);
            Path path3 = new Path(device);
            path3.lineTo(3 * width / 4, 0);
            path3.lineTo(3 * width / 4, height / 2);
            path3.lineTo(width, height / 2);
            path3.lineTo(3 * width / 4, 0);
            Path path4 = new Path(device);
            path4.lineTo(0, height);
            path4.lineTo(width / 4, height / 2);
            path4.lineTo(width / 2, height);
            path4.lineTo(0, height);
            Path path5 = new Path(device);
            path5.lineTo(width / 2, height);
            path5.lineTo(3 * width / 4, height / 2);
            path5.lineTo(width, height);
            path5.lineTo(width / 2, height);
            path.addPath(path2);
            path.addPath(path3);
            path.addPath(path4);
            path.addPath(path5);
            gc.setClipping(path);
            path5.dispose();
            path4.dispose();
            path3.dispose();
            path2.dispose();
            path.dispose();
            break;
        case // default
        6:
            gc.setClipping(0, 0, width, height);
            break;
    }
    Pattern pattern = null;
    if (background.getBgColor1() != null) {
        gc.setBackground(background.getBgColor1());
    } else if (background.getBgImage() != null) {
        pattern = new Pattern(device, background.getBgImage());
        gc.setBackgroundPattern(pattern);
    }
    gc.fillRectangle(0, 0, width, height);
    if (pattern != null)
        pattern.dispose();
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Device(org.eclipse.swt.graphics.Device) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font)

Example 47 with Pattern

use of org.eclipse.swt.graphics.Pattern in project eclipse.platform.swt by eclipse.

the class RGBTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    // horizontal rectangle
    Transform transform = new Transform(device);
    transform.translate(0, translateY);
    gc.setTransform(transform);
    transform.dispose();
    Path path = new Path(device);
    path.addRectangle(0, 0, width, 50);
    Pattern pattern = new Pattern(device, 0, 0, width, 50, device.getSystemColor(SWT.COLOR_BLUE), 0x7f, device.getSystemColor(SWT.COLOR_RED), 0x7f);
    gc.setBackgroundPattern(pattern);
    gc.fillPath(path);
    gc.drawPath(path);
    path.dispose();
    // vertical rectangle
    transform = new Transform(device);
    transform.translate(translateX, 0);
    gc.setTransform(transform);
    transform.dispose();
    path = new Path(device);
    path.addRectangle(0, 0, 50, height);
    pattern.dispose();
    pattern = new Pattern(device, 0, 0, 50, height, device.getSystemColor(SWT.COLOR_DARK_CYAN), 0x7f, device.getSystemColor(SWT.COLOR_WHITE), 0x7f);
    gc.setBackgroundPattern(pattern);
    gc.fillPath(path);
    gc.drawPath(path);
    path.dispose();
    // diagonal rectangle from bottom right corner
    Rectangle rect = new Rectangle(0, 0, 50, height);
    transform = new Transform(device);
    transform.translate(width - diagTranslateX1, (height / 2) - diagTranslateY1);
    // rotate on center of rectangle
    transform.translate(rect.width / 2, rect.height / 2);
    transform.rotate(45);
    transform.translate(-rect.width / 2, -rect.height / 2);
    gc.setTransform(transform);
    transform.dispose();
    path = new Path(device);
    path.addRectangle(rect.x, rect.y, rect.width, rect.height);
    pattern.dispose();
    pattern = new Pattern(device, rect.x, rect.y, rect.width, rect.height, device.getSystemColor(SWT.COLOR_DARK_GREEN), 0x7f, device.getSystemColor(SWT.COLOR_DARK_MAGENTA), 0x7f);
    gc.setBackgroundPattern(pattern);
    gc.fillPath(path);
    gc.drawPath(path);
    path.dispose();
    // diagonal rectangle from top right corner
    transform = new Transform(device);
    transform.translate(width - diagTranslateX2, (height / 2) - diagTranslateY2);
    // rotate on center of rectangle
    transform.translate(rect.width / 2, rect.height / 2);
    transform.rotate(-45);
    transform.translate(-rect.width / 2, -rect.height / 2);
    gc.setTransform(transform);
    transform.dispose();
    path = new Path(device);
    path.addRectangle(rect.x, rect.y, rect.width, rect.height);
    pattern.dispose();
    pattern = new Pattern(device, rect.x, rect.y, rect.width, rect.height, device.getSystemColor(SWT.COLOR_DARK_RED), 0x7f, device.getSystemColor(SWT.COLOR_YELLOW), 0x7f);
    gc.setBackgroundPattern(pattern);
    gc.fillPath(path);
    gc.drawPath(path);
    pattern.dispose();
    path.dispose();
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Device(org.eclipse.swt.graphics.Device) Rectangle(org.eclipse.swt.graphics.Rectangle) Transform(org.eclipse.swt.graphics.Transform)

Example 48 with Pattern

use of org.eclipse.swt.graphics.Pattern in project eclipse.platform.swt by eclipse.

the class SpiralTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    // set line attributes
    gc.setLineWidth(20);
    // round line ends
    gc.setLineCap(SWT.CAP_ROUND);
    // smooth jagged edges
    gc.setAntialias(SWT.ON);
    Pattern pattern = null;
    if (foreground.getBgColor1() != null) {
        gc.setForeground(foreground.getBgColor1());
    } else if (foreground.getBgImage() != null) {
        pattern = new Pattern(device, foreground.getBgImage());
        gc.setForegroundPattern(pattern);
    }
    // draw petals for the spiral
    Transform transform;
    int n = petalSpinner.getSelection();
    for (int i = 0; i < n; i++) {
        transform = new Transform(device);
        transform.translate(width / 2, height / 2);
        transform.rotate(-(angle + 360 / n * i));
        gc.setTransform(transform);
        gc.drawArc(0, 0, width / 3, height / 6, 0, 180);
        transform.dispose();
    }
    if (pattern != null)
        pattern.dispose();
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern) Device(org.eclipse.swt.graphics.Device) Transform(org.eclipse.swt.graphics.Transform) Point(org.eclipse.swt.graphics.Point)

Example 49 with Pattern

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

the class Sleak method paintCanvas.

void paintCanvas(Event event) {
    canvas.setCursor(null);
    int index = list.getSelectionIndex();
    if (index == -1) {
        return;
    }
    GC gc = event.gc;
    Object object = objects[index];
    if (object instanceof Color) {
        if (((Color) object).isDisposed()) {
            return;
        }
        gc.setBackground((Color) object);
        gc.fillRectangle(canvas.getClientArea());
        return;
    }
    if (object instanceof Cursor) {
        if (((Cursor) object).isDisposed()) {
            return;
        }
        canvas.setCursor((Cursor) object);
        return;
    }
    if (object instanceof Font) {
        if (((Font) object).isDisposed()) {
            return;
        }
        gc.setFont((Font) object);
        FontData[] array = gc.getFont().getFontData();
        String string = "";
        String lf = text.getLineDelimiter();
        for (int i = 0; i < array.length; i++) {
            FontData data = array[i];
            String style = "NORMAL";
            int bits = data.getStyle();
            if (bits != 0) {
                if ((bits & SWT.BOLD) != 0) {
                    style = "BOLD ";
                }
                if ((bits & SWT.ITALIC) != 0) {
                    style += "ITALIC";
                }
            }
            string += data.getName() + " " + data.getHeight() + " " + style + lf;
        }
        gc.drawString(string, 0, 0);
        return;
    }
    // }
    if (object instanceof Image) {
        if (((Image) object).isDisposed()) {
            return;
        }
        gc.drawImage((Image) object, 0, 0);
        return;
    }
    if (object instanceof Path) {
        if (((Path) object).isDisposed()) {
            return;
        }
        gc.drawPath((Path) object);
        return;
    }
    if (object instanceof Pattern) {
        if (((Pattern) object).isDisposed()) {
            return;
        }
        gc.setBackgroundPattern((Pattern) object);
        gc.fillRectangle(canvas.getClientArea());
        gc.setBackgroundPattern(null);
        return;
    }
    if (object instanceof Region) {
        if (((Region) object).isDisposed()) {
            return;
        }
        String string = ((Region) object).getBounds().toString();
        gc.drawString(string, 0, 0);
        return;
    }
    if (object instanceof TextLayout) {
        if (((TextLayout) object).isDisposed()) {
            return;
        }
        ((TextLayout) object).draw(gc, 0, 0);
        return;
    }
    if (object instanceof Transform) {
        if (((Transform) object).isDisposed()) {
            return;
        }
        String string = ((Transform) object).toString();
        gc.drawString(string, 0, 0);
        return;
    }
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Color(org.eclipse.swt.graphics.Color) FontData(org.eclipse.swt.graphics.FontData) 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 50 with Pattern

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

the class OutcomeFigure 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 = getCenter(rect);
    path.addArc((float) center.preciseX() - radius, (float) center.preciseY() - radius, (radius * 2), (radius * 2), 0, 360);
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    // Lines
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawPath(path);
    path.dispose();
    graphics.setBackgroundColor(getLineColor());
    int radius2 = Math.round(radius * 2.0f / 3.0f - (graphics.getLineWidth() / 2));
    graphics.drawOval(center.x - radius2, center.y - radius2, 2 * radius2, 2 * radius2);
    int radius3 = Math.round(radius / 3.0f - (graphics.getLineWidth() / 2));
    graphics.drawOval(center.x - radius3, center.y - radius3, 2 * radius3, 2 * radius3);
    // int arrowLineWidth = Math.round(graphics.getLineWidth() * 1.2f);
    // graphics.setLineWidth(arrowLineWidth);
    int arrowLength = (int) (radius3 * 0.8f);
    // calculate this now but don't set it in graphics
    int arrowLineWidth = Math.max(2, arrowLength / 6);
    // Small adjustment for the arrow head
    Rectangle rectTemp = rect.getCopy();
    rectTemp.width--;
    Point centerTemp = getCenter(rectTemp);
    graphics.fillPolygon(new int[] { centerTemp.x - arrowLineWidth, centerTemp.y + arrowLineWidth, centerTemp.x + arrowLength, centerTemp.y, centerTemp.x, centerTemp.y - arrowLength });
    // Now set this
    graphics.setLineWidth(arrowLineWidth);
    double ratio = 1.2d;
    graphics.drawLine(center.x, center.y, (int) (center.x + radius * ratio - 0.5d * arrowLength), (int) (center.y - radius * ratio + 0.5d * arrowLength));
    graphics.drawLine((int) (center.x + ratio * (radius - arrowLength * 1.2d)), (int) (center.y + ratio * (arrowLength * 1.2d - radius)), (int) (center.x + radius * ratio), (int) (center.y - radius * ratio) + arrowLength + arrowLineWidth);
    graphics.drawLine((int) (center.x + ratio * (radius - arrowLength * 1.2d)), (int) (center.y + ratio * (arrowLength * 1.2d - radius)), (int) (center.x + radius * ratio) - arrowLength - arrowLineWidth, (int) (center.y - radius * ratio));
    // 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) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

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