Search in sources :

Example 16 with Transform

use of org.eclipse.swt.graphics.Transform in project pentaho-kettle by pentaho.

the class SwtUniversalImageBitmap method renderRotated.

@Override
protected Image renderRotated(Device device, int width, int height, double angleRadians) {
    Image result = new Image(device, width * 2, height * 2);
    GC gc = new GC(result);
    int bw = bitmap.getBounds().width;
    int bh = bitmap.getBounds().height;
    Transform affineTransform = new Transform(device);
    affineTransform.translate(width, height);
    affineTransform.rotate((float) Math.toDegrees(angleRadians));
    affineTransform.scale((float) 1.0 * width / bw, (float) 1.0 * height / bh);
    gc.setTransform(affineTransform);
    gc.drawImage(bitmap, 0, 0, bw, bh, -bw / 2, -bh / 2, bw, bh);
    gc.dispose();
    return result;
}
Also used : Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC) Transform(org.eclipse.swt.graphics.Transform)

Example 17 with Transform

use of org.eclipse.swt.graphics.Transform in project pentaho-kettle by pentaho.

the class Sleak method refreshLabel.

void refreshLabel() {
    int colors = 0, cursors = 0, fonts = 0, gcs = 0, images = 0;
    int paths = 0, patterns = 0, regions = 0, textLayouts = 0, transforms = 0;
    for (int i = 0; i < objects.length; i++) {
        Object object = objects[i];
        if (object instanceof Color) {
            colors++;
        }
        if (object instanceof Cursor) {
            cursors++;
        }
        if (object instanceof Font) {
            fonts++;
        }
        if (object instanceof GC) {
            gcs++;
        }
        if (object instanceof Image) {
            images++;
        }
        if (object instanceof Path) {
            paths++;
        }
        if (object instanceof Pattern) {
            patterns++;
        }
        if (object instanceof Region) {
            regions++;
        }
        if (object instanceof TextLayout) {
            textLayouts++;
        }
        if (object instanceof Transform) {
            transforms++;
        }
    }
    String string = "";
    if (colors != 0) {
        string += colors + " Color(s)\n";
    }
    if (cursors != 0) {
        string += cursors + " Cursor(s)\n";
    }
    if (fonts != 0) {
        string += fonts + " Font(s)\n";
    }
    if (gcs != 0) {
        string += gcs + " GC(s)\n";
    }
    if (images != 0) {
        string += images + " Image(s)\n";
    }
    if (paths != 0) {
        string += paths + " Paths(s)\n";
    }
    if (patterns != 0) {
        string += patterns + " Pattern(s)\n";
    }
    if (regions != 0) {
        string += regions + " Region(s)\n";
    }
    if (textLayouts != 0) {
        string += textLayouts + " TextLayout(s)\n";
    }
    if (transforms != 0) {
        string += transforms + " Transform(s)\n";
    }
    if (string.length() != 0) {
        string = string.substring(0, string.length() - 1);
    }
    label.setText(string);
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Color(org.eclipse.swt.graphics.Color) Cursor(org.eclipse.swt.graphics.Cursor) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) TextLayout(org.eclipse.swt.graphics.TextLayout) Region(org.eclipse.swt.graphics.Region) GC(org.eclipse.swt.graphics.GC) Transform(org.eclipse.swt.graphics.Transform)

Example 18 with Transform

use of org.eclipse.swt.graphics.Transform in project translationstudio8 by heartsome.

the class DefaultTableHeaderRenderer method setRotation.

/**
     * Set the rotation of the header text. Please note that you have to call <code>redraw()</code> on the table
     * yourself if you change the rotation while the table is showing.
     * 
     * @param rotation rotation in degrees anti clockwise between 0 and 90 degrees.
     */
public void setRotation(int rotation) {
    if (rotation < 0 || rotation > 90) {
        throw new IllegalArgumentException("Rotation range 0..90");
    }
    if (_rotation != rotation) {
        disposeTransformations();
        _rotation = rotation;
        _transform = new Transform(Display.getCurrent());
        _transformInv = new Transform(Display.getCurrent());
        _transform.rotate(-rotation);
        _transformInv.rotate(-rotation);
        _transformInv.invert();
    }
}
Also used : Transform(org.eclipse.swt.graphics.Transform)

Example 19 with Transform

use of org.eclipse.swt.graphics.Transform in project eclipse.platform.swt by eclipse.

the class AdvancedGraphics method open.

public Shell open(final Display display) {
    final Shell shell = new Shell(display);
    // $NON-NLS-1$
    shell.setText(RESOURCE_BUNDLE.getString("AdvancedGraphics"));
    try {
        Path path = new Path(display);
        path.dispose();
    } catch (SWTException e) {
        MessageBox dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
        // $NON-NLS-1$
        dialog.setText(RESOURCE_BUNDLE.getString("Warning"));
        // $NON-NLS-1$
        dialog.setMessage(RESOURCE_BUNDLE.getString("LibNotFound"));
        dialog.open();
        shell.dispose();
        return null;
    }
    FontData fd = shell.getFont().getFontData()[0];
    final Font font = new Font(display, fd.getName(), 96, SWT.BOLD | SWT.ITALIC);
    final Image image = loadImage(display, AdvancedGraphics.class, "irmaos.jpg");
    final Rectangle rect = image.getBounds();
    shell.addListener(SWT.Paint, event -> {
        GC gc = event.gc;
        Transform tr = new Transform(display);
        tr.translate(rect.width / 4, rect.height / 2);
        tr.rotate(-30);
        if (image != null) {
            gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width, rect.height);
        }
        gc.setAlpha(100);
        gc.setTransform(tr);
        Path path = new Path(display);
        path.addString("SWT", 0, 0, font);
        gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
        gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
        gc.fillPath(path);
        gc.drawPath(path);
        tr.dispose();
        path.dispose();
    });
    shell.setSize(shell.computeSize(rect.width, rect.height));
    shell.open();
    shell.addListener(SWT.Dispose, event -> {
        if (image != null)
            image.dispose();
        font.dispose();
    });
    return shell;
}
Also used : Path(org.eclipse.swt.graphics.Path) Shell(org.eclipse.swt.widgets.Shell) SWTException(org.eclipse.swt.SWTException) FontData(org.eclipse.swt.graphics.FontData) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC) Transform(org.eclipse.swt.graphics.Transform) Font(org.eclipse.swt.graphics.Font) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 20 with Transform

use of org.eclipse.swt.graphics.Transform in project eclipse.platform.swt by eclipse.

the class BallTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    if (bc[0] == null) {
        bc[0] = new BallCollection(0, 0, 5, 5, 20, 20, new Color[] { device.getSystemColor(SWT.COLOR_GREEN) });
        bc[1] = new BallCollection(50, 300, 10, -5, 50, 10, new Color[] { device.getSystemColor(SWT.COLOR_BLUE) });
        bc[2] = new BallCollection(250, 100, -5, 8, 25, 12, new Color[] { device.getSystemColor(SWT.COLOR_RED) });
        bc[3] = new BallCollection(150, 400, 5, 8, 35, 14, new Color[] { device.getSystemColor(SWT.COLOR_BLACK) });
        bc[4] = new BallCollection(100, 250, -5, -18, 100, 5, new Color[] { device.getSystemColor(SWT.COLOR_MAGENTA) });
    }
    for (BallCollection ballCollection : bc) {
        for (int i = 0; i < ballCollection.prevx.size(); i++) {
            Transform transform = new Transform(device);
            transform.translate(ballCollection.prevx.get(ballCollection.prevx.size() - (i + 1)).floatValue(), ballCollection.prevy.get(ballCollection.prevy.size() - (i + 1)).floatValue());
            gc.setTransform(transform);
            transform.dispose();
            Path path = new Path(device);
            path.addArc(0, 0, ballCollection.ball_size, ballCollection.ball_size, 0, 360);
            gc.setAlpha(255 - i * (255 / ballCollection.capacity));
            gc.setBackground(ballCollection.colors[0]);
            gc.fillPath(path);
            gc.drawPath(path);
            path.dispose();
        }
    }
}
Also used : Path(org.eclipse.swt.graphics.Path) Device(org.eclipse.swt.graphics.Device) Color(org.eclipse.swt.graphics.Color) Transform(org.eclipse.swt.graphics.Transform)

Aggregations

Transform (org.eclipse.swt.graphics.Transform)34 Device (org.eclipse.swt.graphics.Device)11 Path (org.eclipse.swt.graphics.Path)10 Point (org.eclipse.swt.graphics.Point)9 Font (org.eclipse.swt.graphics.Font)7 Image (org.eclipse.swt.graphics.Image)7 Rectangle (org.eclipse.swt.graphics.Rectangle)7 AffineTransform (java.awt.geom.AffineTransform)6 GC (org.eclipse.swt.graphics.GC)6 Pattern (org.eclipse.swt.graphics.Pattern)6 Color (org.eclipse.swt.graphics.Color)3 Cursor (org.eclipse.swt.graphics.Cursor)2 FontData (org.eclipse.swt.graphics.FontData)2 Region (org.eclipse.swt.graphics.Region)2 TextLayout (org.eclipse.swt.graphics.TextLayout)2 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)1 ColumnResizeCommand (org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand)1 IStyle (org.eclipse.nebula.widgets.nattable.style.IStyle)1 SWTException (org.eclipse.swt.SWTException)1 Printer (org.eclipse.swt.printing.Printer)1