Search in sources :

Example 76 with Path

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

the class ResourceFigure method drawFigure.

@Override
protected void drawFigure(Graphics graphics) {
    if (getFigureDelegate() != null) {
        getFigureDelegate().drawFigure(graphics);
        drawIcon(graphics);
        return;
    }
    graphics.pushState();
    Rectangle rect = getBounds().getCopy();
    rect.width--;
    rect.height--;
    // Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
    setLineWidth(graphics, 1, rect);
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    graphics.setAlpha(getAlpha());
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, rect);
    Path path = getFigurePath(rect);
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    // Lines
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawPath(path);
    path.dispose();
    Dimension nubSize = new Dimension(rect.width / 10, rect.height / 3);
    graphics.drawLine(rect.x + rect.width - nubSize.width, rect.y + (rect.height - nubSize.height) / 2, rect.x + rect.width - nubSize.width, rect.y + (rect.height - nubSize.height) / 2 + nubSize.height);
    int lineTop = rect.y + rect.height / 5;
    int lineBottom = rect.y + rect.height * 4 / 5;
    int lineGap = rect.width / 6;
    graphics.drawLine(rect.x + lineGap, lineTop, rect.x + lineGap, lineBottom);
    graphics.drawLine(rect.x + lineGap * 2, lineTop, rect.x + lineGap * 2, lineBottom);
    graphics.drawLine(rect.x + lineGap * 3, lineTop, rect.x + lineGap * 3, lineBottom);
    // Image Icon
    drawIconImage(graphics, rect, 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) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point)

Example 77 with Path

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

the class ResourceFigure method drawIcon.

/**
 * Draw the icon
 */
private void drawIcon(Graphics graphics) {
    if (!isIconVisible()) {
        return;
    }
    graphics.pushState();
    graphics.setLineWidth(1);
    graphics.setForegroundColor(isEnabled() ? ColorConstants.black : ColorConstants.gray);
    Point pt = getIconOrigin();
    // main rectangle
    graphics.drawRoundRectangle(new Rectangle(pt.x, pt.y, 15, 10), 3, 3);
    // nub
    pt.translate(15, 3);
    graphics.drawRoundRectangle(new Rectangle(pt.x, pt.y, 2, 4), 1, 1);
    // lines
    pt = getIconOrigin();
    Path path = new Path(null);
    path.moveTo(pt.x + 3f, pt.y + 2);
    path.lineTo(pt.x + 3f, pt.y + 8);
    path.moveTo(pt.x + 6f, pt.y + 2);
    path.lineTo(pt.x + 6f, pt.y + 8);
    path.moveTo(pt.x + 9f, pt.y + 2);
    path.lineTo(pt.x + 9f, pt.y + 8);
    graphics.drawPath(path);
    path.dispose();
    // Alternate method of drawing lines
    // pt.translate(-12, -1);
    // graphics.drawLine(pt.x, pt.y, pt.x, pt.y + 6);
    // pt.translate(3, 0);
    // graphics.drawLine(pt.x, pt.y, pt.x, pt.y + 6);
    // pt.translate(3, 0);
    // graphics.drawLine(pt.x, pt.y, pt.x, pt.y + 6);
    graphics.popState();
}
Also used : Path(org.eclipse.swt.graphics.Path) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point)

Example 78 with Path

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

the class SystemSoftwareFigure method drawIcon.

/**
 * Draw the icon
 */
private void drawIcon(Graphics graphics) {
    if (!isIconVisible()) {
        return;
    }
    graphics.pushState();
    graphics.setLineWidth(1);
    graphics.setForegroundColor(isEnabled() ? ColorConstants.black : ColorConstants.gray);
    Point pt = getIconOrigin();
    Path path = new Path(null);
    path.addArc(pt.x, pt.y, 11, 11, 90, 360);
    path.addArc(pt.x + 2, pt.y - 2, 11, 11, -60, 210);
    graphics.drawPath(path);
    path.dispose();
    graphics.popState();
}
Also used : Path(org.eclipse.swt.graphics.Path) Point(org.eclipse.draw2d.geometry.Point)

Example 79 with Path

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

the class FigureUtils method createPathFromPoints.

/**
 * Create a Path from a points list
 * @param points The points as x,y
 * @return The Path - callers should dispose of it
 */
public static Path createPathFromPoints(int[] points) {
    Path path = new Path(null);
    path.moveTo(points[0], points[1]);
    for (int i = 2; i < points.length; i += 2) {
        path.lineTo(points[i], points[i + 1]);
    }
    path.lineTo(points[0], points[1]);
    return path;
}
Also used : Path(org.eclipse.swt.graphics.Path)

Example 80 with Path

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

the class CanvasStickyFigure method paintFigure.

@Override
protected void paintFigure(Graphics graphics) {
    graphics.pushState();
    graphics.setAntialias(SWT.ON);
    graphics.setAlpha(getAlpha());
    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);
    // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=568864
    if (PlatformUtils.isLinux() && ImageFactory.getDeviceZoom() > 100) {
        graphics.setBackgroundColor(getFillColor());
        graphics.fillRectangle(bounds);
    } else {
        graphics.setForegroundColor(getFillColor());
        graphics.setBackgroundColor(ColorFactory.getLighterColor(getFillColor(), 0.9f));
        graphics.fillGradient(bounds, false);
    }
    // Icon
    drawIconImage(graphics, bounds);
    // Border
    if (getBorderColor() != null) {
        graphics.setAlpha(getLineAlpha());
        float lineOffset = (float) lineWidth / 2;
        graphics.setForegroundColor(ColorFactory.getLighterColor(getBorderColor(), 0.82f));
        Path path = new Path(null);
        path.moveTo(bounds.x - lineOffset, bounds.y);
        path.lineTo(bounds.x + bounds.width, bounds.y);
        path.lineTo(bounds.x + bounds.width, bounds.y + bounds.height);
        graphics.drawPath(path);
        path.dispose();
        graphics.setForegroundColor(getBorderColor());
        path = new Path(null);
        path.moveTo(bounds.x, bounds.y - lineOffset);
        path.lineTo(bounds.x, bounds.y + bounds.height);
        path.lineTo(bounds.x + bounds.width + lineOffset, bounds.y + bounds.height);
        graphics.drawPath(path);
        path.dispose();
    }
    graphics.popState();
}
Also used : Path(org.eclipse.swt.graphics.Path) 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