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();
}
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();
}
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();
}
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;
}
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();
}
Aggregations