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();
}
}
Aggregations