use of org.eclipse.swt.graphics.Device in project eclipse.platform.swt by eclipse.
the class CustomFontTab method paint.
@Override
public void paint(GC gc, int width, int height) {
if (!example.checkAdvancedGraphics())
return;
Device device = gc.getDevice();
String fontFace = fontNames.get(fontFaceCb.getSelectionIndex());
int points = fontPointSpinner.getSelection();
int style = styleValues[fontStyleCb.getSelectionIndex()];
Font font = new Font(device, fontFace, points, style);
gc.setFont(font);
gc.setTextAntialias(SWT.ON);
Point size = gc.stringExtent(text);
int textWidth = size.x;
int textHeight = size.y;
Pattern pattern = null;
if (fontForeground.getBgColor1() != null) {
gc.setForeground(fontForeground.getBgColor1());
} else if (fontForeground.getBgImage() != null) {
pattern = new Pattern(device, fontForeground.getBgImage());
gc.setForegroundPattern(pattern);
}
gc.drawString(text, (width - textWidth) / 2, (height - textHeight) / 2, true);
font.dispose();
if (pattern != null)
pattern.dispose();
}
use of org.eclipse.swt.graphics.Device in project eclipse.platform.swt by eclipse.
the class GradientTab method paint.
/**
* This method draws the gradient patterns that make up the image. The image
* consists of 4 rows, each consisting of 4 gradient patterns (total of 16).
*/
@Override
public void paint(GC gc, int width, int height) {
if (!example.checkAdvancedGraphics())
return;
Device device = gc.getDevice();
Image image = createImage(device, colorGB1.getBgColor1(), colorGB2.getBgColor1(), width, height);
Pattern p = new Pattern(device, image);
gc.setBackgroundPattern(p);
gc.fillRectangle(0, 0, width, height);
p.dispose();
image.dispose();
}
use of org.eclipse.swt.graphics.Device in project eclipse.platform.swt by eclipse.
the class GraphicAntialiasTab method paint.
@Override
public void paint(GC gc, int width, int height) {
if (!example.checkAdvancedGraphics())
return;
Device device = gc.getDevice();
if (ovalColorGB != null && ovalColorGB.getBgColor1() != null)
gc.setBackground(ovalColorGB.getBgColor1());
gc.setAntialias(aliasValues[aliasCombo.getSelectionIndex()]);
Path path = new Path(device);
float offsetX = 2 * width / 3f, offsetY = height / 3f;
for (int i = 0; i < 25; i++) {
path.addArc(offsetX - (50 * i), offsetY - (25 * i), 50 + (100 * i), 25 + (50 * i), 0, 360);
}
gc.fillPath(path);
path.dispose();
}
use of org.eclipse.swt.graphics.Device in project eclipse.platform.swt by eclipse.
the class InterpolationTab method paint.
@Override
public void paint(GC gc, int width, int height) {
if (!example.checkAdvancedGraphics())
return;
Device device = gc.getDevice();
float scaleX = 10f;
float scaleY = 10f;
Image image = null;
switch(imageCb.getSelectionIndex()) {
case 0:
image = GraphicsExample.loadImage(device, GraphicsExample.class, "home_nav.gif");
break;
case 1:
image = GraphicsExample.loadImage(device, GraphicsExample.class, "help.gif");
break;
case 2:
image = GraphicsExample.loadImage(device, GraphicsExample.class, "task.gif");
break;
case 3:
image = GraphicsExample.loadImage(device, GraphicsExample.class, "font.gif");
break;
case 4:
image = GraphicsExample.loadImage(device, GraphicsExample.class, "cube.png");
scaleX = 0.75f;
scaleY = 0.5f;
break;
case 5:
image = GraphicsExample.loadImage(device, GraphicsExample.class, "swt.png");
scaleX = 0.4f;
scaleY = 0.8f;
break;
case 6:
image = GraphicsExample.loadImage(device, GraphicsExample.class, "ovals.png");
scaleX = 1.1f;
scaleY = 0.5f;
break;
}
Rectangle bounds = image.getBounds();
// draw the original image
gc.drawImage(image, (width - bounds.width) / 2, 20);
Font font = new Font(device, getPlatformFont(), 20, SWT.NORMAL);
gc.setFont(font);
// write some text below the original image
// $NON-NLS-1$
String text = GraphicsExample.getResourceString("OriginalImg");
Point size = gc.stringExtent(text);
gc.drawString(text, (width - size.x) / 2, 25 + bounds.height, true);
Transform transform = new Transform(device);
transform.translate((width - (bounds.width * scaleX + 10) * 4) / 2, 25 + bounds.height + size.y + (height - (25 + bounds.height + size.y + bounds.height * scaleY)) / 2);
transform.scale(scaleX, scaleY);
// --- draw strings ---
float[] point = new float[2];
// $NON-NLS-1$
text = GraphicsExample.getResourceString("None");
size = gc.stringExtent(text);
point[0] = (scaleX * bounds.width + 5 - size.x) / (2 * scaleX);
point[1] = bounds.height;
transform.transform(point);
gc.drawString(text, (int) point[0], (int) point[1], true);
// $NON-NLS-1$
text = GraphicsExample.getResourceString("Low");
size = gc.stringExtent(text);
point[0] = (scaleX * bounds.width + 5 - size.x) / (2 * scaleX) + bounds.width;
point[1] = bounds.height;
transform.transform(point);
gc.drawString(text, (int) point[0], (int) point[1], true);
// $NON-NLS-1$
text = GraphicsExample.getResourceString("Default");
size = gc.stringExtent(text);
point[0] = (scaleX * bounds.width + 5 - size.x) / (2 * scaleX) + 2 * bounds.width;
point[1] = bounds.height;
transform.transform(point);
gc.drawString(text, (int) point[0], (int) point[1], true);
// $NON-NLS-1$
text = GraphicsExample.getResourceString("High");
size = gc.stringExtent(text);
point[0] = (scaleX * bounds.width + 5 - size.x) / (2 * scaleX) + 3 * bounds.width;
point[1] = bounds.height;
transform.transform(point);
gc.drawString(text, (int) point[0], (int) point[1], true);
gc.setTransform(transform);
transform.dispose();
// --- draw images ---
// no interpolation
gc.setInterpolation(SWT.NONE);
gc.drawImage(image, 0, 0);
// low interpolation
gc.setInterpolation(SWT.LOW);
gc.drawImage(image, bounds.width, 0);
// default interpolation
gc.setInterpolation(SWT.DEFAULT);
gc.drawImage(image, 2 * bounds.width, 0);
// high interpolation
gc.setInterpolation(SWT.HIGH);
gc.drawImage(image, 3 * bounds.width, 0);
font.dispose();
if (image != null)
image.dispose();
}
use of org.eclipse.swt.graphics.Device in project eclipse.platform.swt by eclipse.
the class LineCapTab method paint.
@Override
public void paint(GC gc, int width, int height) {
Device device = gc.getDevice();
// draw side lines
gc.setLineWidth(1);
gc.setLineStyle(SWT.LINE_DOT);
gc.setForeground(device.getSystemColor(SWT.COLOR_BLACK));
gc.drawLine(3 * width / 16, height / 6, 3 * width / 16, 5 * height / 6);
gc.drawLine(13 * width / 16, height / 6, 13 * width / 16, 5 * height / 6);
gc.setLineStyle(SWT.LINE_SOLID);
// draw labels
Font font = new Font(device, getPlatformFont(), 20, SWT.NORMAL);
gc.setFont(font);
// $NON-NLS-1$
String text = GraphicsExample.getResourceString("Flat");
Point size = gc.stringExtent(text);
gc.drawString(text, (width - size.x) / 2, 3 * height / 12, true);
// $NON-NLS-1$
text = GraphicsExample.getResourceString("Square");
size = gc.stringExtent(text);
gc.drawString(text, (width - size.x) / 2, 5 * height / 12, true);
// $NON-NLS-1$
text = GraphicsExample.getResourceString("Round");
size = gc.stringExtent(text);
gc.drawString(text, (width - size.x) / 2, 7 * height / 12, true);
font.dispose();
Pattern pattern = null;
if (foreground.getBgColor1() != null) {
gc.setForeground(foreground.getBgColor1());
} else if (foreground.getBgImage() != null) {
pattern = new Pattern(device, foreground.getBgImage());
gc.setForegroundPattern(pattern);
}
// draw lines with caps
gc.setLineWidth(20);
gc.setLineCap(SWT.CAP_FLAT);
gc.drawLine(3 * width / 16, 2 * height / 6, 13 * width / 16, 2 * height / 6);
gc.setLineCap(SWT.CAP_SQUARE);
gc.drawLine(3 * width / 16, 3 * height / 6, 13 * width / 16, 3 * height / 6);
gc.setLineCap(SWT.CAP_ROUND);
gc.drawLine(3 * width / 16, 4 * height / 6, 13 * width / 16, 4 * height / 6);
if (pattern != null)
pattern.dispose();
}
Aggregations