Search in sources :

Example 31 with Device

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();
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern) Device(org.eclipse.swt.graphics.Device) Transform(org.eclipse.swt.graphics.Transform) Point(org.eclipse.swt.graphics.Point)

Example 32 with Device

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();
}
Also used : Device(org.eclipse.swt.graphics.Device) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font)

Example 33 with Device

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;
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Device(org.eclipse.swt.graphics.Device) Font(org.eclipse.swt.graphics.Font)

Aggregations

Device (org.eclipse.swt.graphics.Device)33 Path (org.eclipse.swt.graphics.Path)13 Point (org.eclipse.swt.graphics.Point)13 Font (org.eclipse.swt.graphics.Font)12 Pattern (org.eclipse.swt.graphics.Pattern)12 Transform (org.eclipse.swt.graphics.Transform)11 Rectangle (org.eclipse.swt.graphics.Rectangle)8 Color (org.eclipse.swt.graphics.Color)6 Image (org.eclipse.swt.graphics.Image)4 ColorManager (de.jaret.util.swt.ColorManager)3 RGB (org.eclipse.swt.graphics.RGB)3 GC (org.eclipse.swt.graphics.GC)2 FontManager (de.jaret.util.swt.FontManager)1 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)1 IMatchViewPart (net.heartsome.cat.ts.ui.view.IMatchViewPart)1 StyledText (org.eclipse.swt.custom.StyledText)1 Region (org.eclipse.swt.graphics.Region)1 Canvas (org.eclipse.swt.widgets.Canvas)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IViewPart (org.eclipse.ui.IViewPart)1