Search in sources :

Example 21 with Transform

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

the class CountDownTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    // diameter of the circle in pixels
    int diameter = ((width < height) ? width - 25 : height - 25);
    if (!getAnimation() && nextNumber == 0) {
        Font font = new Font(device, getPlatformFontFace(1), diameter / 2, SWT.NONE);
        gc.setFont(font);
        // display "SWT"
        gc.setForeground(device.getSystemColor(SWT.COLOR_DARK_BLUE));
        gc.setTextAntialias(SWT.ON);
        // determine the dimensions of the word
        String text = GraphicsExample.getResourceString("SWT");
        Point point = gc.stringExtent(text);
        int textWidth = point.x;
        int textHeight = point.y;
        gc.drawString(text, (width - textWidth) / 2, (height - textHeight) / 2, true);
        font.dispose();
    } else {
        Font font = new Font(device, getPlatformFontFace(0), 6 * diameter / 10, SWT.NONE);
        gc.setFont(font);
        // set attributes from controls
        gc.setLineWidth(lineWidthSpinner.getSelection());
        // round line ends
        gc.setLineCap(lineCap);
        // smooth jagged edges
        gc.setAntialias(antialias);
        // smooth jagged edges
        gc.setTextAntialias(antialias);
        // draw the circles
        Path path = new Path(device);
        path.addArc((width - diameter) / 2, (height - diameter) / 2, diameter, diameter, 0, 360);
        path.addArc((width - diameter + 50) / 2, (height - diameter + 50) / 2, diameter - 50, diameter - 50, 0, 360);
        gc.drawPath(path);
        gc.setBackground(device.getSystemColor(SWT.COLOR_RED));
        gc.fillPath(path);
        path.dispose();
        Point point = gc.stringExtent(Integer.valueOf(nextNumber).toString());
        int textWidth = point.x;
        int textHeight = point.y;
        // draw the number
        gc.drawString(Integer.valueOf(nextNumber).toString(), (width - textWidth) / 2, (height - textHeight) / 2, true);
        // draw the rotating arm
        Transform transform = new Transform(device);
        transform.translate(width / 2, height / 2);
        transform.rotate(angle);
        gc.setTransform(transform);
        gc.setForeground(device.getSystemColor(SWT.COLOR_RED));
        gc.drawLine(0, 0, diameter / 2, 0);
        transform.dispose();
        font.dispose();
    }
}
Also used : Path(org.eclipse.swt.graphics.Path) Device(org.eclipse.swt.graphics.Device) Point(org.eclipse.swt.graphics.Point) Transform(org.eclipse.swt.graphics.Transform) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font)

Example 22 with Transform

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

the class CurvesTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    Font font = new Font(device, getPlatformFont(), 16, SWT.ITALIC);
    gc.setFont(font);
    gc.setLineWidth(5);
    Transform transform;
    // ----- cubic curve -----
    cubXPos = width / 5;
    cubYPos = height / 3;
    transform = new Transform(device);
    transform.translate(cubXPos, cubYPos);
    gc.setTransform(transform);
    transform.dispose();
    gc.setForeground(device.getSystemColor(SWT.COLOR_RED));
    gc.drawString(GraphicsExample.getResourceString("Cubic"), 25, -70, true);
    Path path = new Path(device);
    path.cubicTo(133 + cubDiffX1, -60 + cubDiffY1, 266 + cubDiffX2, 60 + cubDiffY2, 400 + cubEndDiffX, 0 + cubEndDiffY);
    gc.drawPath(path);
    path.dispose();
    gc.setTransform(null);
    gc.setForeground(device.getSystemColor(SWT.COLOR_DARK_BLUE));
    gc.drawRectangle(cubHndl1.x + (int) cubXPos, cubHndl1.y + (int) cubYPos, cubHndl1.width, cubHndl1.height);
    gc.drawRectangle(cubHndl2.x + (int) cubXPos, cubHndl2.y + (int) cubYPos, cubHndl2.width, cubHndl2.height);
    gc.drawRectangle(cubEndHndl.x + (int) cubXPos, cubEndHndl.y + (int) cubYPos, cubEndHndl.width, cubEndHndl.height);
    // ----- quadratic curve -----
    quadXPos = width / 5;
    quadYPos = 2 * height / 3;
    transform = new Transform(device);
    transform.translate(quadXPos, quadYPos);
    gc.setTransform(transform);
    transform.dispose();
    gc.setForeground(device.getSystemColor(SWT.COLOR_GREEN));
    gc.drawString(GraphicsExample.getResourceString("Quadratic"), 0, -50, true);
    path = new Path(device);
    path.quadTo(200 + quadDiffX, 150 + quadDiffY, 400 + quadEndDiffX, 0 + quadEndDiffY);
    gc.drawPath(path);
    path.dispose();
    gc.setTransform(null);
    gc.setForeground(device.getSystemColor(SWT.COLOR_GRAY));
    gc.drawRectangle(quadHndl.x + (int) quadXPos, quadHndl.y + (int) quadYPos, quadHndl.width, quadHndl.height);
    gc.drawRectangle(quadEndHndl.x + (int) quadXPos, quadEndHndl.y + (int) quadYPos, quadEndHndl.width, quadEndHndl.height);
    font.dispose();
}
Also used : Path(org.eclipse.swt.graphics.Path) Device(org.eclipse.swt.graphics.Device) Transform(org.eclipse.swt.graphics.Transform) Font(org.eclipse.swt.graphics.Font)

Example 23 with Transform

use of org.eclipse.swt.graphics.Transform 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 24 with Transform

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

the class RGBTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    // horizontal rectangle
    Transform transform = new Transform(device);
    transform.translate(0, translateY);
    gc.setTransform(transform);
    transform.dispose();
    Path path = new Path(device);
    path.addRectangle(0, 0, width, 50);
    Pattern pattern = new Pattern(device, 0, 0, width, 50, device.getSystemColor(SWT.COLOR_BLUE), 0x7f, device.getSystemColor(SWT.COLOR_RED), 0x7f);
    gc.setBackgroundPattern(pattern);
    gc.fillPath(path);
    gc.drawPath(path);
    path.dispose();
    // vertical rectangle
    transform = new Transform(device);
    transform.translate(translateX, 0);
    gc.setTransform(transform);
    transform.dispose();
    path = new Path(device);
    path.addRectangle(0, 0, 50, height);
    pattern.dispose();
    pattern = new Pattern(device, 0, 0, 50, height, device.getSystemColor(SWT.COLOR_DARK_CYAN), 0x7f, device.getSystemColor(SWT.COLOR_WHITE), 0x7f);
    gc.setBackgroundPattern(pattern);
    gc.fillPath(path);
    gc.drawPath(path);
    path.dispose();
    // diagonal rectangle from bottom right corner
    Rectangle rect = new Rectangle(0, 0, 50, height);
    transform = new Transform(device);
    transform.translate(width - diagTranslateX1, (height / 2) - diagTranslateY1);
    // rotate on center of rectangle
    transform.translate(rect.width / 2, rect.height / 2);
    transform.rotate(45);
    transform.translate(-rect.width / 2, -rect.height / 2);
    gc.setTransform(transform);
    transform.dispose();
    path = new Path(device);
    path.addRectangle(rect.x, rect.y, rect.width, rect.height);
    pattern.dispose();
    pattern = new Pattern(device, rect.x, rect.y, rect.width, rect.height, device.getSystemColor(SWT.COLOR_DARK_GREEN), 0x7f, device.getSystemColor(SWT.COLOR_DARK_MAGENTA), 0x7f);
    gc.setBackgroundPattern(pattern);
    gc.fillPath(path);
    gc.drawPath(path);
    path.dispose();
    // diagonal rectangle from top right corner
    transform = new Transform(device);
    transform.translate(width - diagTranslateX2, (height / 2) - diagTranslateY2);
    // rotate on center of rectangle
    transform.translate(rect.width / 2, rect.height / 2);
    transform.rotate(-45);
    transform.translate(-rect.width / 2, -rect.height / 2);
    gc.setTransform(transform);
    transform.dispose();
    path = new Path(device);
    path.addRectangle(rect.x, rect.y, rect.width, rect.height);
    pattern.dispose();
    pattern = new Pattern(device, rect.x, rect.y, rect.width, rect.height, device.getSystemColor(SWT.COLOR_DARK_RED), 0x7f, device.getSystemColor(SWT.COLOR_YELLOW), 0x7f);
    gc.setBackgroundPattern(pattern);
    gc.fillPath(path);
    gc.drawPath(path);
    pattern.dispose();
    path.dispose();
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Device(org.eclipse.swt.graphics.Device) Rectangle(org.eclipse.swt.graphics.Rectangle) Transform(org.eclipse.swt.graphics.Transform)

Example 25 with Transform

use of org.eclipse.swt.graphics.Transform 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)

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