Search in sources :

Example 66 with Path

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

use of org.eclipse.swt.graphics.Path in project n4js by eclipse.

the class GraphUtils method arcSelf.

/**
 * Paints an looping arc from scr to tgt.
 * <p/>
 * <b>Assumption:</b> The tgt is located right/below of the src.
 */
public static float[] arcSelf(GC gc, Point src, Point tgt) {
    Path path = new Path(gc.getDevice());
    int diffH = 10;
    int diff = diffH * 3;
    path.moveTo((int) src.x, (int) src.y);
    path.cubicTo((int) src.x + diff, (int) src.y - diffH, (int) tgt.x, (int) tgt.y - diff, (int) tgt.x, (int) tgt.y);
    gc.drawPath(path);
    float[] pp = path.getPathData().points;
    return pp;
}
Also used : Path(org.eclipse.swt.graphics.Path)

Example 68 with Path

use of org.eclipse.swt.graphics.Path in project liferay-ide by liferay.

the class GearControl method _drawGear.

private Path _drawGear(GC gc, Display display, double cx, double cy, double outerR, double innerR, float angleOffset) {
    double radian2 = _teethAngle / 2 * _radian;
    double radian3 = .06;
    Path path = new Path(display);
    for (int i = 0; i < _teeth; i++) {
        double radian = (i * _teethAngle + angleOffset) * _radian;
        double x = cx + outerR * Math.cos(radian);
        double y = cy - outerR * Math.sin(radian);
        if (i == 0) {
            path.moveTo((int) x, (int) y);
        }
        double r1 = radian + radian3;
        double r3 = radian + radian2;
        double r2 = r3 - radian3;
        double r4 = r3 + radian2;
        x = cx + innerR * Math.cos(r1);
        y = cy - innerR * Math.sin(r1);
        path.lineTo((int) x, (int) y);
        x = cx + innerR * Math.cos(r2);
        y = cy - innerR * Math.sin(r2);
        path.lineTo((int) x, (int) y);
        x = cx + outerR * Math.cos(r3);
        y = cy - outerR * Math.sin(r3);
        path.lineTo((int) x, (int) y);
        x = cx + outerR * Math.cos(r4);
        y = cy - outerR * Math.sin(r4);
        path.lineTo((int) x, (int) y);
    }
    path.close();
    gc.fillPath(path);
    gc.drawPath(path);
    return path;
}
Also used : Path(org.eclipse.swt.graphics.Path) Point(org.eclipse.swt.graphics.Point)

Example 69 with Path

use of org.eclipse.swt.graphics.Path in project SIMVA-SoS by SESoS.

the class SWTGraphics2D method draw.

/**
 * Draws the outline of the specified shape using the current stroke and
 * paint settings.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @see #getPaint()
 * @see #getStroke()
 * @see #fill(Shape)
 */
public void draw(Shape shape) {
    Path path = toSwtPath(shape);
    this.gc.drawPath(path);
    path.dispose();
}
Also used : Path(org.eclipse.swt.graphics.Path)

Example 70 with Path

use of org.eclipse.swt.graphics.Path in project SIMVA-SoS by SESoS.

the class SWTGraphics2D method toSwtPath.

/**
 * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @return The path.
 */
private Path toSwtPath(Shape shape) {
    int type;
    float[] coords = new float[6];
    Path path = new Path(this.gc.getDevice());
    PathIterator pit = shape.getPathIterator(null);
    while (!pit.isDone()) {
        type = pit.currentSegment(coords);
        switch(type) {
            case (PathIterator.SEG_MOVETO):
                path.moveTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_LINETO):
                path.lineTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_QUADTO):
                path.quadTo(coords[0], coords[1], coords[2], coords[3]);
                break;
            case (PathIterator.SEG_CUBICTO):
                path.cubicTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
                break;
            case (PathIterator.SEG_CLOSE):
                path.close();
                break;
            default:
                break;
        }
        pit.next();
    }
    return path;
}
Also used : Path(org.eclipse.swt.graphics.Path) PathIterator(java.awt.geom.PathIterator) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint)

Aggregations

Path (org.eclipse.swt.graphics.Path)103 Point (org.eclipse.draw2d.geometry.Point)49 Pattern (org.eclipse.swt.graphics.Pattern)40 Rectangle (org.eclipse.draw2d.geometry.Rectangle)37 Device (org.eclipse.swt.graphics.Device)13 Point (org.eclipse.swt.graphics.Point)11 Transform (org.eclipse.swt.graphics.Transform)10 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)8 Font (org.eclipse.swt.graphics.Font)8 Rectangle (org.eclipse.swt.graphics.Rectangle)7 PointList (org.eclipse.draw2d.geometry.PointList)6 GC (org.eclipse.swt.graphics.GC)6 PolarPoint (com.archimatetool.editor.diagram.figures.PolarPoint)4 Color (org.eclipse.swt.graphics.Color)4 Image (org.eclipse.swt.graphics.Image)4 Region (org.eclipse.swt.graphics.Region)4 IIconic (com.archimatetool.model.IIconic)3 Dimension (org.eclipse.draw2d.geometry.Dimension)2 SWTException (org.eclipse.swt.SWTException)2 Cursor (org.eclipse.swt.graphics.Cursor)2