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