Search in sources :

Example 6 with Device

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

the class ImageTransformTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    Image image = GraphicsExample.loadImage(device, GraphicsExample.class, "ace_club.jpg");
    Transform transform = new Transform(device);
    // scale image
    transform.scale(scaleSpinnerX.getSelection() / 100f, scaleSpinnerY.getSelection() / 100f);
    // translate image
    transform.translate(translateSpinnerX.getSelection(), translateSpinnerY.getSelection());
    // rotate on center of image
    Rectangle rect = image.getBounds();
    transform.translate(rect.width / 2, rect.height / 2);
    transform.rotate(rotateSpinner.getSelection());
    transform.translate(-rect.width / 2, -rect.height / 2);
    if (invertButton.getSelection()) {
        transform.invert();
    }
    gc.setTransform(transform);
    gc.drawImage(image, 0, 0);
    transform.dispose();
    image.dispose();
}
Also used : Device(org.eclipse.swt.graphics.Device) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) Transform(org.eclipse.swt.graphics.Transform)

Example 7 with Device

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

the class MazeTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    Device device = gc.getDevice();
    if (image == null) {
        image = example.loadImage(device, "maze.bmp");
    }
    // draw maze
    Rectangle bounds = image.getBounds();
    int x = (width - bounds.width) / 2;
    int y = (height - bounds.height) / 2;
    gc.drawImage(image, x, y);
    // draw correct oval
    gc.setBackground(device.getSystemColor(SWT.COLOR_RED));
    gc.fillOval(x + xcoord, y + ycoord, 16, 16);
    gc.drawOval(x + xcoord, y + ycoord, 15, 15);
    // draw wrong oval 1
    gc.setBackground(device.getSystemColor(SWT.COLOR_BLUE));
    gc.fillOval(x + xcoord2, y + ycoord2, 16, 16);
    gc.drawOval(x + xcoord2, y + ycoord2, 15, 15);
    // draw wrong oval 2
    gc.setBackground(device.getSystemColor(SWT.COLOR_GREEN));
    gc.fillOval(x + xcoord3, y + ycoord3, 16, 16);
    gc.drawOval(x + xcoord3, y + ycoord3, 15, 15);
    if (isDone2) {
        Image helpImg = example.loadImage(device, "help.gif");
        gc.drawImage(helpImg, x + xcoord2 + 16, y + ycoord2 - 16);
        helpImg.dispose();
    }
    if (isDone3) {
        Image helpImg = example.loadImage(device, "help.gif");
        gc.drawImage(helpImg, x + xcoord3 + 16, y + ycoord3 - 16);
        helpImg.dispose();
    }
}
Also used : Device(org.eclipse.swt.graphics.Device) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image)

Example 8 with Device

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

the class PathTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    Pattern pattern = null;
    if (fillColor.getBgColor1() != null) {
        gc.setBackground(fillColor.getBgColor1());
    } else if (fillColor.getBgImage() != null) {
        pattern = new Pattern(device, fillColor.getBgImage());
        gc.setBackgroundPattern(pattern);
    }
    gc.setLineWidth(5);
    gc.setForeground(device.getSystemColor(SWT.COLOR_BLACK));
    // arc
    Path path = new Path(device);
    path.addArc((width - 250) / 2, (height - 400) / 2, 500, 400, 90, 180);
    if (closeButton.getSelection())
        path.close();
    if (fillButton.getSelection())
        gc.fillPath(path);
    if (drawButton.getSelection())
        gc.drawPath(path);
    path.dispose();
    // shape on left
    Transform transform = new Transform(device);
    transform.translate((width - 250) / 4, height / 2 - 150);
    gc.setTransform(transform);
    transform.dispose();
    path = new Path(device);
    path.cubicTo(-150, 100, 150, 200, 0, 300);
    if (closeButton.getSelection())
        path.close();
    if (fillButton.getSelection())
        gc.fillPath(path);
    if (drawButton.getSelection())
        gc.drawPath(path);
    path.dispose();
    gc.setTransform(null);
    // shape on right
    path = new Path(device);
    path.moveTo(3 * (width - 250) / 4 - 25 + 250, height / 2);
    path.lineTo(3 * (width - 250) / 4 + 50 + 250, height / 2 - 200);
    path.lineTo(3 * (width - 250) / 4 + 50 + 250, height / 2 + 50);
    path.lineTo(3 * (width - 250) / 4 - 25 + 250, height / 2 + 150);
    path.lineTo(3 * (width - 250) / 4 + 25 + 250, height / 2 + 50);
    if (closeButton.getSelection())
        path.close();
    if (fillButton.getSelection())
        gc.fillPath(path);
    if (drawButton.getSelection())
        gc.drawPath(path);
    path.dispose();
    if (pattern != null)
        pattern.dispose();
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Device(org.eclipse.swt.graphics.Device) Transform(org.eclipse.swt.graphics.Transform)

Example 9 with Device

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

the class RegionClippingTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    // array of coordinate points of polygon 1 (region 1)
    int[] polygon1 = new int[] { 10, height / 2, 9 * width / 16, 10, 9 * width / 16, height - 10 };
    Region region1 = new Region(device);
    region1.add(polygon1);
    // array of coordinate points of polygon 2 (region 2)
    int[] polygon2 = new int[] { 9 * width / 16, 10, 9 * width / 16, height / 8, 7 * width / 16, 2 * height / 8, 9 * width / 16, 3 * height / 8, 7 * width / 16, 4 * height / 8, 9 * width / 16, 5 * height / 8, 7 * width / 16, 6 * height / 8, 9 * width / 16, 7 * height / 8, 9 * width / 16, height - 10, width - 10, height / 2 };
    Region region2 = new Region(device);
    region2.add(polygon2);
    gc.setAlpha(127);
    int clippingIndex = clippingCb.getSelectionIndex();
    switch(clippingIndex) {
        case 0:
            // region 1
            gc.setClipping(region1);
            gc.setBackground(colorGB1.getBgColor1());
            gc.fillPolygon(polygon1);
            break;
        case 1:
            // region 2
            gc.setClipping(region2);
            gc.setBackground(colorGB2.getBgColor1());
            gc.fillPolygon(polygon2);
            break;
        case 2:
            // add
            region1.add(region2);
            break;
        case 3:
            // sub
            region1.subtract(region2);
            break;
        case 4:
            // intersect
            region1.intersect(region2);
            break;
    }
    if (clippingIndex > 1) {
        gc.setClipping(region1);
        gc.setBackground(colorGB1.getBgColor1());
        gc.fillPolygon(polygon1);
        gc.setBackground(colorGB2.getBgColor1());
        gc.fillPolygon(polygon2);
    }
    region1.dispose();
    region2.dispose();
}
Also used : Device(org.eclipse.swt.graphics.Device) Region(org.eclipse.swt.graphics.Region) Point(org.eclipse.swt.graphics.Point)

Example 10 with Device

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

the class CardsTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    if (ace_club == null) {
        ace_club = GraphicsExample.loadImage(device, GraphicsExample.class, "ace_club.jpg");
        ace_spade = GraphicsExample.loadImage(device, GraphicsExample.class, "ace_spade.jpg");
        ace_diamond = GraphicsExample.loadImage(device, GraphicsExample.class, "ace_diamond.jpg");
        ace_hearts = GraphicsExample.loadImage(device, GraphicsExample.class, "ace_hearts.jpg");
    }
    clubWidth = ace_club.getBounds().width;
    diamondWidth = ace_diamond.getBounds().width;
    heartWidth = ace_hearts.getBounds().width;
    spadeHeight = ace_spade.getBounds().height;
    Transform transform;
    // ace of clubs
    transform = new Transform(device);
    transform.translate((int) movClubX, (int) movClubY);
    transform.scale(scaleWidth, scaleWidth);
    // rotate on center of image
    Rectangle rect = ace_club.getBounds();
    transform.translate(rect.width / 2, rect.height / 2);
    transform.rotate(rotationAngle);
    transform.translate(-rect.width / 2, -rect.height / 2);
    gc.setTransform(transform);
    transform.dispose();
    gc.drawImage(ace_club, 0, 0);
    // ace of diamonds
    transform = new Transform(device);
    transform.translate((int) movDiamondX, (int) movDiamondY);
    transform.scale(scaleWidth, scaleWidth);
    gc.setTransform(transform);
    transform.dispose();
    gc.drawImage(ace_diamond, 0, 0);
    // ace of hearts
    transform = new Transform(device);
    transform.translate(movHeart, height / 2);
    transform.scale(heartScale, 0.5f * scale);
    gc.setTransform(transform);
    transform.dispose();
    gc.drawImage(ace_hearts, 0, 0);
    // ace of spades
    transform = new Transform(device);
    transform.translate(movSpade, movSpade);
    transform.scale(0.5f * scale, spadeScale);
    gc.setTransform(transform);
    transform.dispose();
    gc.drawImage(ace_spade, 0, 0);
}
Also used : Device(org.eclipse.swt.graphics.Device) Rectangle(org.eclipse.swt.graphics.Rectangle) Transform(org.eclipse.swt.graphics.Transform)

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