Search in sources :

Example 71 with Pattern

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

the class GaugeFigure method paintClientArea.

@Override
protected void paintClientArea(Graphics graphics) {
    graphics.setAntialias(SWT.ON);
    var area = getClientArea();
    area.width = Math.min(area.width, area.height);
    area.height = area.width;
    Pattern pattern = null;
    graphics.pushState();
    graphics.setBackgroundColor(GRAY_COLOR);
    if (support3D == null) {
        support3D = GraphicsUtil.testPatternSupported(graphics);
    }
    if (effect3D && support3D) {
        // add this to eliminate the repaint bug on Mac
        // Who added this? this will cause problem in zoom.
        // graphics.fillOval(new Rectangle());
        pattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), area.x, area.y, area.x + area.width, area.y + area.height, BORDER_COLOR, WHITE_COLOR);
        graphics.setBackgroundPattern(pattern);
    }
    graphics.fillOval(area);
    if (effect3D && support3D) {
        pattern.dispose();
        area.shrink(BORDER_WIDTH, BORDER_WIDTH);
    } else {
        area.shrink(1, 1);
    }
    graphics.popState();
    graphics.fillOval(area);
    super.paintClientArea(graphics);
    // glossy effect
    if (effect3D && support3D) {
        graphics.pushState();
        graphics.setAntialias(SWT.ON);
        var R = area.width / 2.0d;
        var UD_FILL_PART = 9.5d / 10d;
        var UP_DOWN_RATIO = 1d / 2d;
        var LR_FILL_PART = 8.5d / 10d;
        var UP_ANGLE = 0d * Math.PI / 180d;
        var DOWN_ANGLE = 35d * Math.PI / 180d;
        // add this to eliminate the repaint bug on Mac
        // graphics.fillOval(new Rectangle());
        var glossyPattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), area.x + area.width / 2, (float) (area.y + area.height / 2 - R * UD_FILL_PART), area.x + area.width / 2, (float) (area.y + area.height / 2 + R * UP_DOWN_RATIO), WHITE_COLOR, 90, WHITE_COLOR, 0);
        graphics.setBackgroundPattern(glossyPattern);
        var rectangle = new Rectangle((int) (area.x + area.width / 2 - R * LR_FILL_PART * Math.cos(UP_ANGLE)), (int) (area.y + area.height / 2 - R * UD_FILL_PART), (int) (2 * R * LR_FILL_PART * Math.cos(UP_ANGLE)), (int) (R * UD_FILL_PART + R * UP_DOWN_RATIO));
        graphics.fillOval(rectangle);
        glossyPattern.dispose();
        glossyPattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), area.x + area.width / 2, (float) (area.y + area.height / 2 + R * UP_DOWN_RATIO - 1), area.x + area.width / 2, (float) (area.y + area.height / 2 + R * UD_FILL_PART + 1), WHITE_COLOR, 0, WHITE_COLOR, 40);
        graphics.setBackgroundPattern(glossyPattern);
        rectangle = new Rectangle((int) (area.x + area.width / 2 - R * LR_FILL_PART * Math.sin(DOWN_ANGLE)), (int) Math.ceil(area.y + area.height / 2 + R * UP_DOWN_RATIO), (int) (2 * R * LR_FILL_PART * Math.sin(DOWN_ANGLE)), (int) Math.ceil(R * UD_FILL_PART - R * UP_DOWN_RATIO));
        graphics.fillOval(rectangle);
        glossyPattern.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