Search in sources :

Example 6 with Pattern

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

the class GraphicsExample method createCanvas.

void createCanvas(Composite parent) {
    int style = SWT.NO_BACKGROUND;
    if (dbItem.getSelection())
        style |= SWT.DOUBLE_BUFFERED;
    canvas = new Canvas(parent, style);
    canvas.addListener(SWT.Paint, event -> {
        GC gc = event.gc;
        Rectangle rect = canvas.getClientArea();
        Device device = gc.getDevice();
        Pattern pattern = null;
        if (background.getBgColor1() != null) {
            if (background.getBgColor2() != null) {
                // gradient
                pattern = new Pattern(device, 0, 0, rect.width, rect.height, background.getBgColor1(), background.getBgColor2());
                gc.setBackgroundPattern(pattern);
            } else {
                // solid color
                gc.setBackground(background.getBgColor1());
            }
        } else if (background.getBgImage() != null) {
            // image
            pattern = new Pattern(device, background.getBgImage());
            gc.setBackgroundPattern(pattern);
        }
        gc.fillRectangle(rect);
        GraphicsTab tab = getTab();
        if (tab != null)
            tab.paint(gc, rect.width, rect.height);
        if (pattern != null)
            pattern.dispose();
    });
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern) Device(org.eclipse.swt.graphics.Device) Canvas(org.eclipse.swt.widgets.Canvas) Rectangle(org.eclipse.swt.graphics.Rectangle) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point)

Example 7 with Pattern

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

the class Bulb method paintClientArea.

@Override
protected void paintClientArea(Graphics graphics) {
    graphics.setAntialias(SWT.ON);
    if (effect3D && GraphicsUtil.testPatternSupported(graphics)) {
        // Fills the circle with solid bulb color
        graphics.setBackgroundColor(bulbColor);
        graphics.fillOval(bounds);
        // diagonal linear gradient
        Pattern p = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), bounds.x, bounds.y, bounds.x + getWidth(), bounds.y + getHeight(), COLOR_WHITE, 255, bulbColor, 0);
        try {
            graphics.setBackgroundPattern(p);
            graphics.fillOval(bounds);
            p.dispose();
        } catch (Exception e) {
            p.dispose();
        }
    } else {
        graphics.setBackgroundColor(bulbColor);
        graphics.fillOval(bounds);
    }
    super.paintClientArea(graphics);
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern)

Example 8 with Pattern

use of org.eclipse.swt.graphics.Pattern in project nebula.widgets.nattable by eclipse.

the class BackgroundImagePainter method paintCell.

@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
    if (this.bgImage != null) {
        // Save GC settings
        Color originalBackground = gc.getBackground();
        Color originalForeground = gc.getForeground();
        Pattern pattern = new Pattern(Display.getCurrent(), this.bgImage);
        gc.setBackgroundPattern(pattern);
        gc.fillRectangle(rectangle);
        gc.setBackgroundPattern(null);
        pattern.dispose();
        if (isNotNull(this.separatorColor)) {
            gc.setForeground(this.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 9 with Pattern

use of org.eclipse.swt.graphics.Pattern in project nebula.widgets.nattable by eclipse.

the class PercentageBarDecorator method paintCell.

@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
    Pattern originalBackgroundPattern = gc.getBackgroundPattern();
    double factor = Math.min(1.0, ((Number) cell.getDataValue()).doubleValue());
    factor = Math.max(0.0, factor);
    Rectangle bar = new Rectangle(rectangle.x, rectangle.y, (int) (rectangle.width * factor), rectangle.height);
    Color color1 = CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(PERCENTAGE_BAR_COMPLETE_REGION_START_COLOR);
    Color color2 = CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(PERCENTAGE_BAR_COMPLETE_REGION_END_COLOR);
    if (color1 == null) {
        color1 = DEFAULT_COMPLETE_REGION_START_COLOR;
    }
    if (color2 == null) {
        color2 = DEFAULT_COMPLETE_REGION_END_COLOR;
    }
    Pattern pattern = new Pattern(Display.getCurrent(), rectangle.x, rectangle.y, rectangle.x + rectangle.width, rectangle.y + rectangle.height, color1, color2);
    gc.setBackgroundPattern(pattern);
    gc.fillRectangle(bar);
    gc.setBackgroundPattern(originalBackgroundPattern);
    pattern.dispose();
    Color incompleteRegionColor = CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(PERCENTAGE_BAR_INCOMPLETE_REGION_COLOR);
    if (incompleteRegionColor != null) {
        Region incompleteRegion = new Region();
        incompleteRegion.add(rectangle);
        incompleteRegion.subtract(bar);
        Color originalBackgroundColor = gc.getBackground();
        gc.setBackground(incompleteRegionColor);
        gc.fillRectangle(incompleteRegion.getBounds());
        gc.setBackground(originalBackgroundColor);
        incompleteRegion.dispose();
    }
    super.paintCell(cell, gc, rectangle, configRegistry);
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region)

Example 10 with Pattern

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

the class EllipseFigure method fillShape.

@Override
protected void fillShape(Graphics graphics) {
    if (support3D == null) {
        support3D = GraphicsUtil.testPatternSupported(graphics);
    }
    var figureBounds = getClientArea();
    if (!transparent) {
        graphics.pushState();
        if (isEnabled()) {
            graphics.setBackgroundColor(getBackgroundColor());
        }
        Pattern pattern = null;
        if (gradient && support3D && isEnabled()) {
            pattern = setGradientPattern(graphics, figureBounds, backGradientStartColor, getBackgroundColor());
        }
        graphics.fillOval(figureBounds);
        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.fillOval(figureBounds);
        if (pattern != null) {
            pattern.dispose();
        }
        graphics.popState();
    }
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

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