Search in sources :

Example 21 with Device

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

Example 22 with Device

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

Example 23 with Device

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

Example 24 with Device

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

Example 25 with Device

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