Search in sources :

Example 41 with Pattern

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

the class GradientTab method paint.

/**
 * This method draws the gradient patterns that make up the image. The image
 * consists of 4 rows, each consisting of 4 gradient patterns (total of 16).
 */
@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    Image image = createImage(device, colorGB1.getBgColor1(), colorGB2.getBgColor1(), width, height);
    Pattern p = new Pattern(device, image);
    gc.setBackgroundPattern(p);
    gc.fillRectangle(0, 0, width, height);
    p.dispose();
    image.dispose();
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern) Device(org.eclipse.swt.graphics.Device) Image(org.eclipse.swt.graphics.Image)

Example 42 with Pattern

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

the class LineCapTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    Device device = gc.getDevice();
    // draw side lines
    gc.setLineWidth(1);
    gc.setLineStyle(SWT.LINE_DOT);
    gc.setForeground(device.getSystemColor(SWT.COLOR_BLACK));
    gc.drawLine(3 * width / 16, height / 6, 3 * width / 16, 5 * height / 6);
    gc.drawLine(13 * width / 16, height / 6, 13 * width / 16, 5 * height / 6);
    gc.setLineStyle(SWT.LINE_SOLID);
    // draw labels
    Font font = new Font(device, getPlatformFont(), 20, SWT.NORMAL);
    gc.setFont(font);
    // $NON-NLS-1$
    String text = GraphicsExample.getResourceString("Flat");
    Point size = gc.stringExtent(text);
    gc.drawString(text, (width - size.x) / 2, 3 * height / 12, true);
    // $NON-NLS-1$
    text = GraphicsExample.getResourceString("Square");
    size = gc.stringExtent(text);
    gc.drawString(text, (width - size.x) / 2, 5 * height / 12, true);
    // $NON-NLS-1$
    text = GraphicsExample.getResourceString("Round");
    size = gc.stringExtent(text);
    gc.drawString(text, (width - size.x) / 2, 7 * height / 12, true);
    font.dispose();
    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 lines with caps
    gc.setLineWidth(20);
    gc.setLineCap(SWT.CAP_FLAT);
    gc.drawLine(3 * width / 16, 2 * height / 6, 13 * width / 16, 2 * height / 6);
    gc.setLineCap(SWT.CAP_SQUARE);
    gc.drawLine(3 * width / 16, 3 * height / 6, 13 * width / 16, 3 * height / 6);
    gc.setLineCap(SWT.CAP_ROUND);
    gc.drawLine(3 * width / 16, 4 * height / 6, 13 * width / 16, 4 * height / 6);
    if (pattern != null)
        pattern.dispose();
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern) Device(org.eclipse.swt.graphics.Device) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font)

Example 43 with Pattern

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

the class LineJoinTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    gc.setLineWidth(20);
    gc.setLineJoin(joinValues[joinCb.getSelectionIndex()]);
    // set the foreground color or pattern
    Pattern pattern = null;
    if (shapeColor.getBgColor1() != null) {
        gc.setForeground(shapeColor.getBgColor1());
    } else if (shapeColor.getBgImage() != null) {
        pattern = new Pattern(device, shapeColor.getBgImage());
        gc.setForegroundPattern(pattern);
    }
    // draw the shape
    Path path = new Path(device);
    path.moveTo(width / 2, 25);
    path.lineTo(2 * width / 3, height / 3);
    path.lineTo(width - 25, height / 2);
    path.lineTo(2 * width / 3, 2 * height / 3);
    path.lineTo(width / 2, height - 25);
    path.lineTo(width / 3, 2 * height / 3);
    path.lineTo(25, height / 2);
    path.lineTo(width / 3, height / 3);
    path.lineTo(width / 2, 25);
    path.close();
    gc.drawPath(path);
    path.dispose();
    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)

Example 44 with Pattern

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

the class LineStyleTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    Device device = gc.getDevice();
    Pattern pattern = null;
    if (lineColor.getBgColor1() != null) {
        gc.setForeground(lineColor.getBgColor1());
    } else if (lineColor.getBgImage() != null) {
        pattern = new Pattern(device, lineColor.getBgImage());
        gc.setForegroundPattern(pattern);
    }
    // set line width
    gc.setLineWidth(lineWidthSpinner.getSelection());
    // draw lines with caps
    gc.drawLine(3 * width / 16, 1 * height / 6, 13 * width / 16, 1 * height / 6);
    gc.setLineStyle(SWT.LINE_DASH);
    gc.drawLine(3 * width / 16, 2 * height / 6, 13 * width / 16, 2 * height / 6);
    gc.setLineStyle(SWT.LINE_DOT);
    gc.drawLine(3 * width / 16, 3 * height / 6, 13 * width / 16, 3 * height / 6);
    gc.setLineStyle(SWT.LINE_DASHDOT);
    gc.drawLine(3 * width / 16, 4 * height / 6, 13 * width / 16, 4 * height / 6);
    gc.setLineStyle(SWT.LINE_DASHDOTDOT);
    gc.drawLine(3 * width / 16, 5 * height / 6, 13 * width / 16, 5 * height / 6);
    // draw labels
    Font font = new Font(device, getPlatformFont(), 20, SWT.NORMAL);
    gc.setFont(font);
    gc.setForeground(device.getSystemColor(SWT.COLOR_BLACK));
    // $NON-NLS-1$
    String text = GraphicsExample.getResourceString("Solid");
    Point size = gc.stringExtent(text);
    gc.drawString(text, (width - size.x) / 2, 1 * height / 12, true);
    // $NON-NLS-1$
    text = GraphicsExample.getResourceString("Dash");
    size = gc.stringExtent(text);
    gc.drawString(text, (width - size.x) / 2, 3 * height / 12, true);
    // $NON-NLS-1$
    text = GraphicsExample.getResourceString("Dot");
    size = gc.stringExtent(text);
    gc.drawString(text, (width - size.x) / 2, 5 * height / 12, true);
    // $NON-NLS-1$
    text = GraphicsExample.getResourceString("DashDot");
    size = gc.stringExtent(text);
    gc.drawString(text, (width - size.x) / 2, 7 * height / 12, true);
    // $NON-NLS-1$
    text = GraphicsExample.getResourceString("DashDotDot");
    size = gc.stringExtent(text);
    gc.drawString(text, (width - size.x) / 2, 9 * height / 12, true);
    font.dispose();
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern) Device(org.eclipse.swt.graphics.Device) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font)

Example 45 with Pattern

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

the class PathClippingAnimTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    // top triangle
    Path path = new Path(device);
    path.moveTo(width / 2, 0);
    path.lineTo(width / 2 + 100, 173);
    path.lineTo(width / 2 - 100, 173);
    path.lineTo(width / 2, 0);
    // bottom triangle
    Path path2 = new Path(device);
    path2.moveTo(width / 2, height);
    path2.lineTo(width / 2 + 100, height - 173);
    path2.lineTo(width / 2 - 100, height - 173);
    path2.lineTo(width / 2, height);
    // left triangle
    Path path3 = new Path(device);
    path3.moveTo(0, height / 2);
    path3.lineTo(173, height / 2 - 100);
    path3.lineTo(173, height / 2 + 100);
    path3.lineTo(0, height / 2);
    // right triangle
    Path path4 = new Path(device);
    path4.moveTo(width, height / 2);
    path4.lineTo(width - 173, height / 2 - 100);
    path4.lineTo(width - 173, height / 2 + 100);
    path4.lineTo(width, height / 2);
    // circle
    Path path5 = new Path(device);
    path5.moveTo((width - 200) / 2, (height - 200) / 2);
    path5.addArc((width - 200) / 2, (height - 200) / 2, 200, 200, 0, 360);
    // top rectangle
    Path path6 = new Path(device);
    path6.addRectangle((width - 40) / 2, 175, 40, ((height - 200) / 2) - 177);
    // bottom rectangle
    Path path7 = new Path(device);
    path7.addRectangle((width - 40) / 2, ((height - 200) / 2) + 202, 40, (height - 175) - (((height - 200) / 2) + 202));
    // left rectangle
    Path path8 = new Path(device);
    path8.addRectangle(175, (height - 40) / 2, ((width - 200) / 2) - 177, 40);
    // right rectangle
    Path path9 = new Path(device);
    path9.addRectangle((width - 200) / 2 + 202, (height - 40) / 2, (width - 175) - ((width - 200) / 2 + 202), 40);
    path.addPath(path2);
    path.addPath(path3);
    path.addPath(path4);
    path.addPath(path5);
    path.addPath(path6);
    path.addPath(path7);
    path.addPath(path8);
    path.addPath(path9);
    gc.setClipping(path);
    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.setLineWidth(2);
    gc.fillRectangle((width - rectWidth) / 2, (height - rectHeight) / 2, rectWidth, rectHeight);
    gc.drawPath(path);
    if (pattern != null)
        pattern.dispose();
    path9.dispose();
    path8.dispose();
    path7.dispose();
    path6.dispose();
    path5.dispose();
    path4.dispose();
    path3.dispose();
    path2.dispose();
    path.dispose();
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Device(org.eclipse.swt.graphics.Device)

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