use of org.eclipse.swt.graphics.Path in project archi by archimatetool.
the class EquipmentFigure method drawIconCog.
/**
* Draw a Cog with choosen number of "segments"
*/
private void drawIconCog(Graphics graphics, Point center, int segments, int r1, int r2, int r3) {
// Draw outer Cog
PointList outer = new PointList();
final double halfSeg = Math.PI / (2 * segments);
final double delta = halfSeg / 4;
for (int i = 0; i < segments; i++) {
outer.addPoint(new PolarPoint(r2, 2 * Math.PI * i / segments - halfSeg).toAbsolutePoint(center));
outer.addPoint(new PolarPoint(r3, 2 * Math.PI * i / segments - halfSeg + delta).toAbsolutePoint(center));
outer.addPoint(new PolarPoint(r3, 2 * Math.PI * i / segments + halfSeg - delta).toAbsolutePoint(center));
outer.addPoint(new PolarPoint(r2, 2 * Math.PI * i / segments + halfSeg).toAbsolutePoint(center));
}
graphics.drawPolygon(outer);
// Draw inner circle
Path path = new Path(null);
path.addArc(center.x - r1, center.y - r1, 2 * r1, 2 * r1, 0, 360);
graphics.drawPath(path);
path.dispose();
}
use of org.eclipse.swt.graphics.Path in project archi by archimatetool.
the class EquipmentFigure 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--;
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);
}
graphics.setAlpha(getAlpha());
graphics.setBackgroundColor(getFillColor());
Pattern gradient = applyGradientPattern(graphics, rect);
int xCenter = rect.x + rect.width / 2;
int yCenter = rect.y + rect.height / 2;
int width1 = Math.min(rect.width, rect.height) * 2 / 3;
Rectangle rect1 = new Rectangle(xCenter - width1 * 2 / 3, (yCenter - width1 / 2) + (width1 / 4), width1, width1);
Path path1 = getPathShape(rect1);
graphics.fillPath(path1);
int width2 = Math.min(rect.width, rect.height) * 1 / 2;
Rectangle rect2 = new Rectangle(xCenter, (int) (yCenter - (width2 * 0.96f)), width2, width2);
Path path2 = getPathShape(rect2);
graphics.fillPath(path2);
disposeGradientPattern(graphics, gradient);
// Lines
graphics.setAlpha(getLineAlpha());
graphics.setForegroundColor(getLineColor());
graphics.drawPath(path1);
graphics.drawPath(path2);
path1.dispose();
path2.dispose();
drawCircle(graphics, rect1);
drawCircle(graphics, rect2);
// Image Icon
drawIconImage(graphics, imageBounds, 0, 0, 0, 0);
graphics.popState();
}
use of org.eclipse.swt.graphics.Path in project archi by archimatetool.
the class FacilityFigure method getFigurePath.
private Path getFigurePath(Rectangle rect) {
final float buildingHeightFactor = 2f;
Path path = new Path(null);
int figureWidth = 0;
int figureHeight = 0;
// width < height or same
if (rect.width <= rect.height) {
figureWidth = rect.width;
figureHeight = rect.width;
} else // height < width
{
figureHeight = rect.height;
figureWidth = rect.height;
}
int xMargin = (rect.width - figureWidth) / 2;
int yMargin = (rect.height - figureHeight) / 2;
int xTooth = figureWidth / 4 + figureWidth / 20;
int yTooth = figureHeight / 5;
path.moveTo(rect.x + xMargin, rect.y + yMargin);
path.lineTo(rect.x + xMargin, rect.y + yMargin + figureHeight);
path.lineTo(rect.x + xMargin + figureWidth, rect.y + yMargin + figureHeight);
path.lineTo(rect.x + xMargin + figureWidth, rect.y + yMargin + figureHeight / buildingHeightFactor);
path.lineTo(rect.x + xMargin + figureWidth - xTooth, rect.y + yMargin + figureHeight / buildingHeightFactor + yTooth);
path.lineTo(rect.x + xMargin + figureWidth - xTooth, rect.y + yMargin + figureHeight / buildingHeightFactor);
path.lineTo(rect.x + xMargin + figureWidth - 2 * xTooth, rect.y + yMargin + figureHeight / buildingHeightFactor + yTooth);
path.lineTo(rect.x + xMargin + figureWidth - 2 * xTooth, rect.y + yMargin + figureHeight / buildingHeightFactor);
path.lineTo(rect.x + xMargin + figureWidth - 3 * xTooth, rect.y + yMargin + figureHeight / buildingHeightFactor + yTooth);
path.lineTo(rect.x + xMargin + figureWidth - 3 * xTooth, rect.y + yMargin);
path.close();
return path;
}
use of org.eclipse.swt.graphics.Path in project archi by archimatetool.
the class AbstractDiagramConnectionFigure method clipTextLabel.
/**
* Clip the text label so it doesn't draw on the connection
*/
protected void clipTextLabel(Graphics graphics) {
// Margin around label
final int labelMargin = 1;
// Save dimensions of original clipping area and label
Rectangle g = graphics.getClip(new Rectangle());
Rectangle l = getFlowPage().getBounds().getCopy();
// Label margin
l.expand(labelMargin, labelMargin);
// Create a Path that fills the clipping area minus the label
Path path = new Path(null);
path.moveTo(g.x, g.y);
path.lineTo(l.x, l.y);
path.lineTo(l.x + l.width, l.y);
path.lineTo(l.x + l.width, l.y + l.height);
path.lineTo(l.x, l.y + l.height);
path.lineTo(l.x, l.y);
path.lineTo(g.x, g.y);
path.lineTo(g.x, g.y + g.height);
path.lineTo(g.x + g.width, g.y + g.height);
path.lineTo(g.x + g.width, g.y);
path.lineTo(g.x, g.y);
graphics.clipPath(path);
super.paintFigure(graphics);
path.dispose();
}
use of org.eclipse.swt.graphics.Path in project archi by archimatetool.
the class LocationFigure method getFigurePath.
private Path getFigurePath(Rectangle rect) {
int figureWidth = 0;
int figureHeight = 0;
// width < height or same
if (rect.width <= rect.height) {
figureWidth = rect.width;
figureHeight = rect.width;
} else // height < width
{
figureHeight = rect.height;
figureWidth = rect.height;
}
int yMargin = (rect.height - figureHeight) / 2;
int xCenter = rect.x + rect.width / 2;
float diameter = (figureWidth / 4) * 3;
Path path = new Path(null);
path.addArc(xCenter - diameter / 2, rect.y + yMargin, diameter, diameter, -35, 250);
path.lineTo(xCenter, rect.y + rect.height - yMargin);
path.close();
return path;
}
Aggregations