use of org.eclipse.swt.graphics.Device in project eclipse.platform.swt by eclipse.
the class SpiralTab method paint.
@Override
public void paint(GC gc, int width, int height) {
if (!example.checkAdvancedGraphics())
return;
Device device = gc.getDevice();
// set line attributes
gc.setLineWidth(20);
// round line ends
gc.setLineCap(SWT.CAP_ROUND);
// smooth jagged edges
gc.setAntialias(SWT.ON);
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 petals for the spiral
Transform transform;
int n = petalSpinner.getSelection();
for (int i = 0; i < n; i++) {
transform = new Transform(device);
transform.translate(width / 2, height / 2);
transform.rotate(-(angle + 360 / n * i));
gc.setTransform(transform);
gc.drawArc(0, 0, width / 3, height / 6, 0, 180);
transform.dispose();
}
if (pattern != null)
pattern.dispose();
}
use of org.eclipse.swt.graphics.Device in project eclipse.platform.swt by eclipse.
the class TextAntialiasTab method paint.
@Override
public void paint(GC gc, int width, int height) {
if (!example.checkAdvancedGraphics())
return;
Device device = gc.getDevice();
if (textColor != null && textColor.getBgColor1() != null)
gc.setForeground(textColor.getBgColor1());
gc.setTextAntialias(aliasValues[aliasCombo.getSelectionIndex()]);
// column 1, row 1
Font font = new Font(device, getPlatformFontFace(0), 100, SWT.NORMAL);
gc.setFont(font);
Point size = gc.stringExtent(text);
gc.drawString(text, width / 4 - size.x / 2, height / 4 - size.y / 2, true);
font.dispose();
// column 1, row 2
font = new Font(device, getPlatformFontFace(1), 100, SWT.NORMAL);
gc.setFont(font);
size = gc.stringExtent(text);
gc.drawString(text, width / 4 - size.x / 2, 3 * height / 4 - size.y / 2, true);
font.dispose();
// column 2, row 1
font = new Font(device, getPlatformFontFace(2), 50, SWT.NORMAL);
gc.setFont(font);
size = gc.stringExtent(text);
gc.drawString(text, (width - size.x) / 2, 0, true);
font.dispose();
// column 2, row 2
font = new Font(device, getPlatformFontFace(3), 100, SWT.ITALIC);
gc.setFont(font);
size = gc.stringExtent(text);
gc.drawString(text, (width - size.x) / 2, (height - size.y) / 2, true);
font.dispose();
// column 2, row 3
font = new Font(device, getPlatformFontFace(4), 50, SWT.NORMAL);
gc.setFont(font);
size = gc.stringExtent(text);
gc.drawString(text, (width - size.x) / 2, height - size.y, true);
font.dispose();
// column 3, row 1
font = new Font(device, getPlatformFontFace(5), 100, SWT.NORMAL);
gc.setFont(font);
size = gc.stringExtent(text);
gc.drawString(text, 3 * width / 4 - size.x / 2, height / 4 - size.y / 2, true);
font.dispose();
// column 3, row 2
font = new Font(device, getPlatformFontFace(6), 100, SWT.NORMAL);
gc.setFont(font);
size = gc.stringExtent(text);
gc.drawString(text, 3 * width / 4 - size.x / 2, 3 * height / 4 - size.y / 2, true);
font.dispose();
}
use of org.eclipse.swt.graphics.Device in project eclipse.platform.text by eclipse.
the class InlinedAnnotationSupport method getFont.
/**
* Returns the font according the specified <code>style</code> that the receiver will use to
* paint textual information.
*
* @param style the style of Font widget to get.
* @return the receiver's font according the specified <code>style</code>
*/
Font getFont(int style) {
StyledText styledText = fViewer != null ? fViewer.getTextWidget() : null;
if (styledText == null) {
return null;
}
if (!styledText.getFont().equals(regularFont)) {
disposeFont();
regularFont = styledText.getFont();
}
Device device = styledText.getDisplay();
switch(style) {
case SWT.BOLD:
if (boldFont != null)
return boldFont;
return boldFont = new Font(device, getFontData(style));
case SWT.ITALIC:
if (italicFont != null)
return italicFont;
return italicFont = new Font(device, getFontData(style));
case SWT.BOLD | SWT.ITALIC:
if (boldItalicFont != null)
return boldItalicFont;
return boldItalicFont = new Font(device, getFontData(style));
default:
return regularFont;
}
}
Aggregations