Search in sources :

Example 1 with Pattern

use of org.eclipse.swt.graphics.Pattern in project translationstudio8 by heartsome.

the class BackgroundImagePainter method paintCell.

@Override
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
    // Save GC settings
    Color originalBackground = gc.getBackground();
    Color originalForeground = gc.getForeground();
    gc.setBackgroundPattern(new Pattern(Display.getCurrent(), bgImage));
    gc.fillRectangle(rectangle);
    gc.setBackgroundPattern(null);
    if (isNotNull(separatorColor)) {
        gc.setForeground(separatorColor);
        gc.drawLine(rectangle.x - 1, rectangle.y, rectangle.x - 1, rectangle.y + rectangle.height);
        gc.drawLine(rectangle.x - 1 + rectangle.width, rectangle.y, rectangle.x - 1 + rectangle.width, rectangle.y + rectangle.height);
    }
    // Restore original GC settings
    gc.setBackground(originalBackground);
    gc.setForeground(originalForeground);
    // Draw interior
    Rectangle interiorBounds = new Rectangle(rectangle.x + 2, rectangle.y + 2, rectangle.width - 4, rectangle.height - 4);
    super.paintCell(cell, gc, interiorBounds, configRegistry);
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle)

Example 2 with Pattern

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

the class GraphicsExample method createImage.

/**
 * Creates an image based on a gradient pattern made up of two colors.
 *
 * @param device - The Device
 * @param color1 - The first color used to create the image
 * @param color2 - The second color used to create the image
 */
static Image createImage(Device device, Color color1, Color color2, int width, int height) {
    Image image = new Image(device, width, height);
    GC gc = new GC(image);
    Rectangle rect = image.getBounds();
    Pattern pattern = new Pattern(device, rect.x, rect.y, rect.width - 1, rect.height - 1, color1, color2);
    gc.setBackgroundPattern(pattern);
    gc.fillRectangle(rect);
    gc.drawRectangle(rect.x, rect.y, rect.width - 1, rect.height - 1);
    gc.dispose();
    pattern.dispose();
    return image;
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC)

Example 3 with Pattern

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

the class PathTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    Pattern pattern = null;
    if (fillColor.getBgColor1() != null) {
        gc.setBackground(fillColor.getBgColor1());
    } else if (fillColor.getBgImage() != null) {
        pattern = new Pattern(device, fillColor.getBgImage());
        gc.setBackgroundPattern(pattern);
    }
    gc.setLineWidth(5);
    gc.setForeground(device.getSystemColor(SWT.COLOR_BLACK));
    // arc
    Path path = new Path(device);
    path.addArc((width - 250) / 2, (height - 400) / 2, 500, 400, 90, 180);
    if (closeButton.getSelection())
        path.close();
    if (fillButton.getSelection())
        gc.fillPath(path);
    if (drawButton.getSelection())
        gc.drawPath(path);
    path.dispose();
    // shape on left
    Transform transform = new Transform(device);
    transform.translate((width - 250) / 4, height / 2 - 150);
    gc.setTransform(transform);
    transform.dispose();
    path = new Path(device);
    path.cubicTo(-150, 100, 150, 200, 0, 300);
    if (closeButton.getSelection())
        path.close();
    if (fillButton.getSelection())
        gc.fillPath(path);
    if (drawButton.getSelection())
        gc.drawPath(path);
    path.dispose();
    gc.setTransform(null);
    // shape on right
    path = new Path(device);
    path.moveTo(3 * (width - 250) / 4 - 25 + 250, height / 2);
    path.lineTo(3 * (width - 250) / 4 + 50 + 250, height / 2 - 200);
    path.lineTo(3 * (width - 250) / 4 + 50 + 250, height / 2 + 50);
    path.lineTo(3 * (width - 250) / 4 - 25 + 250, height / 2 + 150);
    path.lineTo(3 * (width - 250) / 4 + 25 + 250, height / 2 + 50);
    if (closeButton.getSelection())
        path.close();
    if (fillButton.getSelection())
        gc.fillPath(path);
    if (drawButton.getSelection())
        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) Transform(org.eclipse.swt.graphics.Transform)

Example 4 with Pattern

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

the class CustomAlphaTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    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.setAntialias(SWT.ON);
    gc.setAlpha(alphaSpinner.getSelection());
    // rotate on center
    Transform transform = new Transform(device);
    transform.translate(width / 2, height / 2);
    transform.rotate(-angle);
    transform.translate(-width / 2, -height / 2);
    gc.setTransform(transform);
    transform.dispose();
    // choose the smallest between height and width
    int diameter = (height < width) ? height : width;
    Path path = new Path(device);
    path.addArc((width - diameter / 5) / 2, (height - diameter / 5) / 2, diameter / 5, diameter / 5, 0, 360);
    path.addArc(5 * (width - diameter / 8) / 12, 4 * (height - diameter / 8) / 12, diameter / 8, diameter / 8, 0, 360);
    path.addArc(7 * (width - diameter / 8) / 12, 8 * (height - diameter / 8) / 12, diameter / 8, diameter / 8, 0, 360);
    path.addArc(6 * (width - diameter / 12) / 12, 3 * (height - diameter / 12) / 12, diameter / 12, diameter / 12, 0, 360);
    path.addArc(6 * (width - diameter / 12) / 12, 9 * (height - diameter / 12) / 12, diameter / 12, diameter / 12, 0, 360);
    path.addArc(11.5f * (width - diameter / 18) / 20, 5 * (height - diameter / 18) / 18, diameter / 18, diameter / 18, 0, 360);
    path.addArc(8.5f * (width - diameter / 18) / 20, 13 * (height - diameter / 18) / 18, diameter / 18, diameter / 18, 0, 360);
    path.addArc(62f * (width - diameter / 25) / 100, 32 * (height - diameter / 25) / 100, diameter / 25, diameter / 25, 0, 360);
    path.addArc(39f * (width - diameter / 25) / 100, 67 * (height - diameter / 25) / 100, diameter / 25, diameter / 25, 0, 360);
    gc.fillPath(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) Transform(org.eclipse.swt.graphics.Transform) Point(org.eclipse.swt.graphics.Point)

Example 5 with Pattern

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

the class GradientTab method createImage.

/**
 * Creates and returns an image made up of gradient patterns. The image takes up
 * a quarter of the area of the total drawing surface.
 *
 * @param device
 *            A Device
 * @param color1
 *            A Color
 * @param color2
 *            A Color
 * @param width
 *            Width of the drawing surface
 * @param height
 *            Height of the drawing surface
 */
Image createImage(Device device, Color color1, Color color2, int width, int height) {
    Image image = new Image(device, width / 2, height / 2);
    GC gc = new GC(image);
    Rectangle rect = image.getBounds();
    Pattern pattern1 = new Pattern(device, rect.x, rect.y, rect.width / 2f, rect.height / 2f, color1, color2);
    gc.setBackgroundPattern(pattern1);
    Path path = new Path(device);
    path.addRectangle(0, 0, width / 4f, height / 4f);
    path.addRectangle(width / 4f, height / 4f, width / 4f, height / 4f);
    gc.fillPath(path);
    path.dispose();
    Pattern pattern2 = new Pattern(device, rect.width, 0, rect.width / 2f, rect.height / 2f, color1, color2);
    gc.setBackgroundPattern(pattern2);
    path = new Path(device);
    path.addRectangle(width / 4f, 0, width / 4f, height / 4f);
    path.addRectangle(0, height / 4f, width / 4f, height / 4f);
    gc.fillPath(path);
    path.dispose();
    gc.dispose();
    pattern1.dispose();
    pattern2.dispose();
    return image;
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC)

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