Search in sources :

Example 26 with Device

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

the class LineJoinTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    gc.setLineWidth(20);
    gc.setLineJoin(joinValues[joinCb.getSelectionIndex()]);
    // set the foreground color or pattern
    Pattern pattern = null;
    if (shapeColor.getBgColor1() != null) {
        gc.setForeground(shapeColor.getBgColor1());
    } else if (shapeColor.getBgImage() != null) {
        pattern = new Pattern(device, shapeColor.getBgImage());
        gc.setForegroundPattern(pattern);
    }
    // draw the shape
    Path path = new Path(device);
    path.moveTo(width / 2, 25);
    path.lineTo(2 * width / 3, height / 3);
    path.lineTo(width - 25, height / 2);
    path.lineTo(2 * width / 3, 2 * height / 3);
    path.lineTo(width / 2, height - 25);
    path.lineTo(width / 3, 2 * height / 3);
    path.lineTo(25, height / 2);
    path.lineTo(width / 3, height / 3);
    path.lineTo(width / 2, 25);
    path.close();
    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)

Example 27 with Device

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

the class LineStyleTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    Device device = gc.getDevice();
    Pattern pattern = null;
    if (lineColor.getBgColor1() != null) {
        gc.setForeground(lineColor.getBgColor1());
    } else if (lineColor.getBgImage() != null) {
        pattern = new Pattern(device, lineColor.getBgImage());
        gc.setForegroundPattern(pattern);
    }
    // set line width
    gc.setLineWidth(lineWidthSpinner.getSelection());
    // draw lines with caps
    gc.drawLine(3 * width / 16, 1 * height / 6, 13 * width / 16, 1 * height / 6);
    gc.setLineStyle(SWT.LINE_DASH);
    gc.drawLine(3 * width / 16, 2 * height / 6, 13 * width / 16, 2 * height / 6);
    gc.setLineStyle(SWT.LINE_DOT);
    gc.drawLine(3 * width / 16, 3 * height / 6, 13 * width / 16, 3 * height / 6);
    gc.setLineStyle(SWT.LINE_DASHDOT);
    gc.drawLine(3 * width / 16, 4 * height / 6, 13 * width / 16, 4 * height / 6);
    gc.setLineStyle(SWT.LINE_DASHDOTDOT);
    gc.drawLine(3 * width / 16, 5 * height / 6, 13 * width / 16, 5 * height / 6);
    // draw labels
    Font font = new Font(device, getPlatformFont(), 20, SWT.NORMAL);
    gc.setFont(font);
    gc.setForeground(device.getSystemColor(SWT.COLOR_BLACK));
    // $NON-NLS-1$
    String text = GraphicsExample.getResourceString("Solid");
    Point size = gc.stringExtent(text);
    gc.drawString(text, (width - size.x) / 2, 1 * height / 12, true);
    // $NON-NLS-1$
    text = GraphicsExample.getResourceString("Dash");
    size = gc.stringExtent(text);
    gc.drawString(text, (width - size.x) / 2, 3 * height / 12, true);
    // $NON-NLS-1$
    text = GraphicsExample.getResourceString("Dot");
    size = gc.stringExtent(text);
    gc.drawString(text, (width - size.x) / 2, 5 * height / 12, true);
    // $NON-NLS-1$
    text = GraphicsExample.getResourceString("DashDot");
    size = gc.stringExtent(text);
    gc.drawString(text, (width - size.x) / 2, 7 * height / 12, true);
    // $NON-NLS-1$
    text = GraphicsExample.getResourceString("DashDotDot");
    size = gc.stringExtent(text);
    gc.drawString(text, (width - size.x) / 2, 9 * height / 12, true);
    font.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)

Example 28 with Device

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

the class PathClippingAnimTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    // top triangle
    Path path = new Path(device);
    path.moveTo(width / 2, 0);
    path.lineTo(width / 2 + 100, 173);
    path.lineTo(width / 2 - 100, 173);
    path.lineTo(width / 2, 0);
    // bottom triangle
    Path path2 = new Path(device);
    path2.moveTo(width / 2, height);
    path2.lineTo(width / 2 + 100, height - 173);
    path2.lineTo(width / 2 - 100, height - 173);
    path2.lineTo(width / 2, height);
    // left triangle
    Path path3 = new Path(device);
    path3.moveTo(0, height / 2);
    path3.lineTo(173, height / 2 - 100);
    path3.lineTo(173, height / 2 + 100);
    path3.lineTo(0, height / 2);
    // right triangle
    Path path4 = new Path(device);
    path4.moveTo(width, height / 2);
    path4.lineTo(width - 173, height / 2 - 100);
    path4.lineTo(width - 173, height / 2 + 100);
    path4.lineTo(width, height / 2);
    // circle
    Path path5 = new Path(device);
    path5.moveTo((width - 200) / 2, (height - 200) / 2);
    path5.addArc((width - 200) / 2, (height - 200) / 2, 200, 200, 0, 360);
    // top rectangle
    Path path6 = new Path(device);
    path6.addRectangle((width - 40) / 2, 175, 40, ((height - 200) / 2) - 177);
    // bottom rectangle
    Path path7 = new Path(device);
    path7.addRectangle((width - 40) / 2, ((height - 200) / 2) + 202, 40, (height - 175) - (((height - 200) / 2) + 202));
    // left rectangle
    Path path8 = new Path(device);
    path8.addRectangle(175, (height - 40) / 2, ((width - 200) / 2) - 177, 40);
    // right rectangle
    Path path9 = new Path(device);
    path9.addRectangle((width - 200) / 2 + 202, (height - 40) / 2, (width - 175) - ((width - 200) / 2 + 202), 40);
    path.addPath(path2);
    path.addPath(path3);
    path.addPath(path4);
    path.addPath(path5);
    path.addPath(path6);
    path.addPath(path7);
    path.addPath(path8);
    path.addPath(path9);
    gc.setClipping(path);
    Pattern pattern = null;
    if (background.getBgColor1() != null) {
        gc.setBackground(background.getBgColor1());
    } else if (background.getBgImage() != null) {
        pattern = new Pattern(device, background.getBgImage());
        gc.setBackgroundPattern(pattern);
    }
    gc.setLineWidth(2);
    gc.fillRectangle((width - rectWidth) / 2, (height - rectHeight) / 2, rectWidth, rectHeight);
    gc.drawPath(path);
    if (pattern != null)
        pattern.dispose();
    path9.dispose();
    path8.dispose();
    path7.dispose();
    path6.dispose();
    path5.dispose();
    path4.dispose();
    path3.dispose();
    path2.dispose();
    path.dispose();
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Device(org.eclipse.swt.graphics.Device)

Example 29 with Device

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

the class PathClippingTab method paint.

@Override
public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;
    Device device = gc.getDevice();
    int clipping = clippingCb.getSelectionIndex();
    switch(clipping) {
        case // circles
        0:
            Path path = new Path(device);
            path.addArc((width - width / 5) / 2, (height - height / 5) / 2, width / 5, height / 5, 0, 360);
            path.addArc(5 * (width - width / 8) / 12, 4 * (height - height / 8) / 12, width / 8, height / 8, 0, 360);
            path.addArc(7 * (width - width / 8) / 12, 8 * (height - height / 8) / 12, width / 8, height / 8, 0, 360);
            path.addArc(6 * (width - width / 12) / 12, 3 * (height - height / 12) / 12, width / 12, height / 12, 0, 360);
            path.addArc(6 * (width - width / 12) / 12, 9 * (height - height / 12) / 12, width / 12, height / 12, 0, 360);
            path.addArc(11.5f * (width - width / 18) / 20, 5 * (height - height / 18) / 18, width / 18, height / 18, 0, 360);
            path.addArc(8.5f * (width - width / 18) / 20, 13 * (height - height / 18) / 18, width / 18, height / 18, 0, 360);
            gc.setClipping(path);
            path.dispose();
            break;
        case // rectangle
        1:
            path = new Path(device);
            path.addRectangle(100, 100, width - 200, height - 200);
            path.addRectangle(120, 120, width - 240, height - 240);
            path.addRectangle(140, 140, width - 280, height - 280);
            gc.setClipping(path);
            path.dispose();
            break;
        case // circle
        2:
            path = new Path(device);
            path.addArc(100, 100, width - 200, height - 200, 0, 360);
            path.addArc((width - width / 5) / 2, (height - height / 5) / 2, width / 5, height / 5, 0, 360);
            path.addArc(5 * (width - width / 8) / 12, 4 * (height - height / 8) / 12, width / 8, height / 8, 0, 360);
            path.addArc(7 * (width - width / 8) / 12, 8 * (height - height / 8) / 12, width / 8, height / 8, 0, 360);
            path.addArc(6 * (width - width / 12) / 12, 3 * (height - height / 12) / 12, width / 12, height / 12, 0, 360);
            path.addArc(6 * (width - width / 12) / 12, 9 * (height - height / 12) / 12, width / 12, height / 12, 0, 360);
            path.addArc(11.5f * (width - width / 18) / 20, 5 * (height - height / 18) / 18, width / 18, height / 18, 0, 360);
            path.addArc(8.5f * (width - width / 18) / 20, 13 * (height - height / 18) / 18, width / 18, height / 18, 0, 360);
            gc.setClipping(path);
            path.dispose();
            break;
        case // word
        3:
            path = new Path(device);
            // $NON-NLS-1$
            String text = GraphicsExample.getResourceString("SWT");
            Font font = new Font(device, "Times", 200, SWT.NORMAL);
            gc.setFont(font);
            Point size = gc.stringExtent(text);
            path.addString(text, (width - size.x) / 2, (height - size.y) / 2, font);
            font.dispose();
            gc.setClipping(path);
            path.dispose();
            break;
        case // star
        4:
            path = new Path(device);
            path.lineTo(width / 2, 0);
            path.lineTo(5 * width / 8, height / 3);
            path.lineTo(width, height / 3);
            path.lineTo(3 * width / 4, 10 * height / 16);
            path.lineTo(7 * width / 8, height);
            path.lineTo(width / 2, 3 * height / 4);
            path.lineTo(width / 8, height);
            path.lineTo(width / 4, 10 * height / 16);
            path.lineTo(0, height / 3);
            path.lineTo(3 * width / 8, height / 3);
            path.lineTo(width / 2, 0);
            Path ovalPath = new Path(device);
            ovalPath.addArc(90, 90, width - 180, height - 180, 0, 360);
            path.addPath(ovalPath);
            gc.setClipping(path);
            ovalPath.dispose();
            path.dispose();
            break;
        case // triangles
        5:
            path = new Path(device);
            path.addRectangle(0, 0, width, height);
            path.lineTo(width / 4, 0);
            path.lineTo(width / 4, height / 2);
            path.lineTo(0, height / 2);
            path.lineTo(width / 4, 0);
            Path path2 = new Path(device);
            path2.lineTo(width / 2, 0);
            path2.lineTo(width / 4, height / 2);
            path2.lineTo(3 * width / 4, height / 2);
            path2.lineTo(width / 2, 0);
            Path path3 = new Path(device);
            path3.lineTo(3 * width / 4, 0);
            path3.lineTo(3 * width / 4, height / 2);
            path3.lineTo(width, height / 2);
            path3.lineTo(3 * width / 4, 0);
            Path path4 = new Path(device);
            path4.lineTo(0, height);
            path4.lineTo(width / 4, height / 2);
            path4.lineTo(width / 2, height);
            path4.lineTo(0, height);
            Path path5 = new Path(device);
            path5.lineTo(width / 2, height);
            path5.lineTo(3 * width / 4, height / 2);
            path5.lineTo(width, height);
            path5.lineTo(width / 2, height);
            path.addPath(path2);
            path.addPath(path3);
            path.addPath(path4);
            path.addPath(path5);
            gc.setClipping(path);
            path5.dispose();
            path4.dispose();
            path3.dispose();
            path2.dispose();
            path.dispose();
            break;
        case // default
        6:
            gc.setClipping(0, 0, width, height);
            break;
    }
    Pattern pattern = null;
    if (background.getBgColor1() != null) {
        gc.setBackground(background.getBgColor1());
    } else if (background.getBgImage() != null) {
        pattern = new Pattern(device, background.getBgImage());
        gc.setBackgroundPattern(pattern);
    }
    gc.fillRectangle(0, 0, width, height);
    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) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font)

Example 30 with Device

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

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