Search in sources :

Example 71 with Path

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

the class Sleak method paintCanvas.

void paintCanvas(Event event) {
    canvas.setCursor(null);
    int index = list.getSelectionIndex();
    if (index == -1) {
        return;
    }
    GC gc = event.gc;
    Object object = objects[index];
    if (object instanceof Color) {
        if (((Color) object).isDisposed()) {
            return;
        }
        gc.setBackground((Color) object);
        gc.fillRectangle(canvas.getClientArea());
        return;
    }
    if (object instanceof Cursor) {
        if (((Cursor) object).isDisposed()) {
            return;
        }
        canvas.setCursor((Cursor) object);
        return;
    }
    if (object instanceof Font) {
        if (((Font) object).isDisposed()) {
            return;
        }
        gc.setFont((Font) object);
        FontData[] array = gc.getFont().getFontData();
        String string = "";
        String lf = text.getLineDelimiter();
        for (int i = 0; i < array.length; i++) {
            FontData data = array[i];
            String style = "NORMAL";
            int bits = data.getStyle();
            if (bits != 0) {
                if ((bits & SWT.BOLD) != 0) {
                    style = "BOLD ";
                }
                if ((bits & SWT.ITALIC) != 0) {
                    style += "ITALIC";
                }
            }
            string += data.getName() + " " + data.getHeight() + " " + style + lf;
        }
        gc.drawString(string, 0, 0);
        return;
    }
    // }
    if (object instanceof Image) {
        if (((Image) object).isDisposed()) {
            return;
        }
        gc.drawImage((Image) object, 0, 0);
        return;
    }
    if (object instanceof Path) {
        if (((Path) object).isDisposed()) {
            return;
        }
        gc.drawPath((Path) object);
        return;
    }
    if (object instanceof Pattern) {
        if (((Pattern) object).isDisposed()) {
            return;
        }
        gc.setBackgroundPattern((Pattern) object);
        gc.fillRectangle(canvas.getClientArea());
        gc.setBackgroundPattern(null);
        return;
    }
    if (object instanceof Region) {
        if (((Region) object).isDisposed()) {
            return;
        }
        String string = ((Region) object).getBounds().toString();
        gc.drawString(string, 0, 0);
        return;
    }
    if (object instanceof TextLayout) {
        if (((TextLayout) object).isDisposed()) {
            return;
        }
        ((TextLayout) object).draw(gc, 0, 0);
        return;
    }
    if (object instanceof Transform) {
        if (((Transform) object).isDisposed()) {
            return;
        }
        String string = ((Transform) object).toString();
        gc.drawString(string, 0, 0);
        return;
    }
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Color(org.eclipse.swt.graphics.Color) FontData(org.eclipse.swt.graphics.FontData) 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 72 with Path

use of org.eclipse.swt.graphics.Path in project archi by archimatetool.

the class SketchModelGraphicsIcon method drawIcon.

@Override
public void drawIcon(Graphics graphics, Point origin) {
    graphics.pushState();
    graphics.setLineWidth(1);
    graphics.setForegroundColor(ColorConstants.darkGray);
    // rectangles
    graphics.setBackgroundColor(color1);
    graphics.fillRectangle(origin.x, origin.y, 8, 5);
    graphics.drawRectangle(origin.x, origin.y, 8, 5);
    graphics.setBackgroundColor(color2);
    graphics.fillRectangle(origin.x + 4, origin.y + 8, 8, 5);
    graphics.drawRectangle(origin.x + 4, origin.y + 8, 8, 5);
    // line
    Path path = new Path(null);
    path.moveTo(origin.x + 2, origin.y + 5);
    path.lineTo(origin.x + 2, origin.y + 11);
    path.lineTo(origin.x + 4, origin.y + 11);
    graphics.drawPath(path);
    path.dispose();
    graphics.popState();
}
Also used : Path(org.eclipse.swt.graphics.Path)

Example 73 with Path

use of org.eclipse.swt.graphics.Path in project archi by archimatetool.

the class OutcomeFigure method drawFigure.

@Override
protected void drawFigure(Graphics graphics) {
    if (getDiagramModelArchimateObject().getType() == 0) {
        super.drawFigure(graphics);
        drawIcon(graphics);
        return;
    }
    graphics.pushState();
    Rectangle rect = getBounds().getCopy();
    rect.width--;
    rect.height--;
    Rectangle imageBounds = rect.getCopy();
    // Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
    setLineWidth(graphics, 1, rect);
    setFigurePositionFromTextPosition(rect);
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    // Fill
    graphics.setAlpha(getAlpha());
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, rect);
    Path path = new Path(null);
    int radius = getRadius(rect);
    Point center = getCenter(rect);
    path.addArc((float) center.preciseX() - radius, (float) center.preciseY() - radius, (radius * 2), (radius * 2), 0, 360);
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    // Lines
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawPath(path);
    path.dispose();
    graphics.setBackgroundColor(getLineColor());
    int radius2 = Math.round(radius * 2.0f / 3.0f - (graphics.getLineWidth() / 2));
    graphics.drawOval(center.x - radius2, center.y - radius2, 2 * radius2, 2 * radius2);
    int radius3 = Math.round(radius / 3.0f - (graphics.getLineWidth() / 2));
    graphics.drawOval(center.x - radius3, center.y - radius3, 2 * radius3, 2 * radius3);
    // int arrowLineWidth = Math.round(graphics.getLineWidth() * 1.2f);
    // graphics.setLineWidth(arrowLineWidth);
    int arrowLength = (int) (radius3 * 0.8f);
    // calculate this now but don't set it in graphics
    int arrowLineWidth = Math.max(2, arrowLength / 6);
    // Small adjustment for the arrow head
    Rectangle rectTemp = rect.getCopy();
    rectTemp.width--;
    Point centerTemp = getCenter(rectTemp);
    graphics.fillPolygon(new int[] { centerTemp.x - arrowLineWidth, centerTemp.y + arrowLineWidth, centerTemp.x + arrowLength, centerTemp.y, centerTemp.x, centerTemp.y - arrowLength });
    // Now set this
    graphics.setLineWidth(arrowLineWidth);
    double ratio = 1.2d;
    graphics.drawLine(center.x, center.y, (int) (center.x + radius * ratio - 0.5d * arrowLength), (int) (center.y - radius * ratio + 0.5d * arrowLength));
    graphics.drawLine((int) (center.x + ratio * (radius - arrowLength * 1.2d)), (int) (center.y + ratio * (arrowLength * 1.2d - radius)), (int) (center.x + radius * ratio), (int) (center.y - radius * ratio) + arrowLength + arrowLineWidth);
    graphics.drawLine((int) (center.x + ratio * (radius - arrowLength * 1.2d)), (int) (center.y + ratio * (arrowLength * 1.2d - radius)), (int) (center.x + radius * ratio) - arrowLength - arrowLineWidth, (int) (center.y - radius * ratio));
    // Image Icon
    drawIconImage(graphics, imageBounds, 0, 0, 0, 0);
    graphics.popState();
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 74 with Path

use of org.eclipse.swt.graphics.Path in project archi by archimatetool.

the class ProcessFigureDelegate method drawFigure.

@Override
public void drawFigure(Graphics graphics) {
    graphics.pushState();
    graphics.setAlpha(getAlpha());
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    graphics.setBackgroundColor(getFillColor());
    Rectangle bounds = getBounds();
    bounds.width--;
    bounds.height--;
    // Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
    int lineWidth = 1;
    setLineWidth(graphics, lineWidth, bounds);
    Pattern gradient = applyGradientPattern(graphics, bounds);
    Path path = new Path(null);
    float x1 = bounds.x + (bounds.width * 0.7f);
    float y1 = bounds.y + (bounds.height / 5);
    float y2 = bounds.y + bounds.height - (bounds.height / 5);
    float lineOffset = (float) lineWidth / 2;
    path.moveTo(bounds.x, y1);
    path.lineTo(x1, y1);
    path.lineTo(x1, bounds.y);
    path.lineTo(bounds.x + bounds.width, bounds.y + (bounds.height / 2));
    path.lineTo(x1, bounds.y + bounds.height);
    path.lineTo(x1, y2);
    path.lineTo(bounds.x, y2);
    path.lineTo(bounds.x, y1 - lineOffset);
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    // Line
    graphics.setForegroundColor(getLineColor());
    graphics.setAlpha(getLineAlpha());
    graphics.drawPath(path);
    path.dispose();
    // Icon
    // getOwner().drawIconImage(graphics, bounds);
    getOwner().drawIconImage(graphics, bounds, bounds.height / 5 + 1, (int) -(bounds.width * 0.2f), -(bounds.height / 5 + 1), 0);
    graphics.popState();
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Example 75 with Path

use of org.eclipse.swt.graphics.Path in project archi by archimatetool.

the class RepresentationFigure method drawFigure.

@Override
public void drawFigure(Graphics graphics) {
    graphics.pushState();
    Rectangle bounds = getBounds().getCopy();
    bounds.width--;
    bounds.height--;
    // Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
    int lineWidth = 1;
    setLineWidth(graphics, lineWidth, bounds);
    int offset = 6;
    int curve_y = bounds.y + bounds.height - offset;
    graphics.setAlpha(getAlpha());
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    // Main Fill
    Path path = new Path(null);
    path.moveTo(bounds.x, bounds.y);
    path.lineTo(bounds.x, curve_y - 1);
    path.quadTo(bounds.x + (bounds.width / 4), bounds.y + bounds.height + offset, bounds.x + bounds.width / 2 + 1, curve_y);
    path.quadTo(bounds.x + bounds.width - (bounds.width / 4), curve_y - offset - 1, bounds.x + bounds.width, curve_y);
    path.lineTo(bounds.x + bounds.width, bounds.y);
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, bounds);
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    // Outline
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    float lineOffset = (float) lineWidth / 2;
    path.lineTo(bounds.x - lineOffset, bounds.y);
    graphics.drawPath(path);
    path.dispose();
    // Line
    graphics.drawLine(bounds.x, bounds.y + TOP_MARGIN, bounds.x + bounds.width, bounds.y + TOP_MARGIN);
    // Icon
    // drawIconImage(graphics, bounds);
    drawIconImage(graphics, bounds, TOP_MARGIN, 0, -TOP_MARGIN, 0);
    graphics.popState();
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

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