use of org.eclipse.swt.graphics.Path in project archi by archimatetool.
the class GroupingFigure method drawFigure.
@Override
protected void drawFigure(Graphics graphics) {
graphics.pushState();
Rectangle bounds = getBounds().getCopy();
bounds.width--;
bounds.height--;
graphics.setAntialias(SWT.ON);
graphics.setAlpha(getAlpha());
if (!isEnabled()) {
setDisabledState(graphics);
}
// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
setLineWidth(graphics, 1, bounds);
// Scale line dashes below 1.0
double scale = Math.min(FigureUtils.getGraphicsScale(graphics), 1.0);
graphics.setLineDash(new float[] { (float) (8 * scale), (float) (4 * scale) });
graphics.setBackgroundColor(getFillColor());
graphics.setForegroundColor(getLineColor());
Pattern gradient = applyGradientPattern(graphics, bounds);
int[] mainRectangle;
if (getDiagramModelArchimateObject().getType() == 1) {
mainRectangle = new int[] { bounds.x, bounds.y, bounds.x + bounds.width, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height, bounds.x, bounds.y + bounds.height };
Path path = FigureUtils.createPathFromPoints(mainRectangle);
graphics.fillPath(path);
path.dispose();
// Icon
if (getIconicDelegate() != null) {
getIconicDelegate().setTopOffset(0);
drawIconImage(graphics, bounds);
}
} else {
tabWidth = (int) (bounds.width / INSET);
tabHeight = TOPBAR_HEIGHT;
if (getDiagramModelArchimateObject().getTextPosition() == ITextPosition.TEXT_POSITION_TOP) {
int textWidth = FigureUtilities.getTextExtents(getText(), getFont()).width;
tabWidth = Math.min(Math.max(tabWidth, textWidth + 8), bounds.width);
// Tab height is calculated from font height
int textHeight = FigureUtilities.getFontMetrics(getFont()).getHeight();
// Tab height is calculated from the text control height which includes all text
// int textHeight = getTextControl().getBounds().height;
tabHeight = Math.max(TOPBAR_HEIGHT, textHeight);
}
mainRectangle = new int[] { bounds.x, bounds.y + tabHeight, bounds.x + bounds.width, bounds.y + tabHeight, bounds.x + bounds.width, bounds.y + bounds.height, bounds.x, bounds.y + bounds.height };
int[] fillShape = new int[] { bounds.x, bounds.y, bounds.x + tabWidth, bounds.y, bounds.x + tabWidth, bounds.y + tabHeight, bounds.getRight().x, bounds.y + tabHeight, bounds.getRight().x, bounds.getBottom().y, bounds.x, bounds.getBottom().y };
Path path = FigureUtils.createPathFromPoints(fillShape);
graphics.fillPath(path);
path.dispose();
// Icon
if (getIconicDelegate() != null) {
getIconicDelegate().setTopOffset(tabHeight);
drawIconImage(graphics, bounds);
}
graphics.setAlpha(getLineAlpha());
graphics.drawLine(bounds.x, bounds.y, bounds.x, bounds.y + tabHeight);
graphics.drawLine(bounds.x, bounds.y, bounds.x + tabWidth, bounds.y);
graphics.drawLine(bounds.x + tabWidth, bounds.y, bounds.x + tabWidth, bounds.y + tabHeight);
}
disposeGradientPattern(graphics, gradient);
// Outlines
graphics.setAlpha(getLineAlpha());
graphics.drawPolygon(mainRectangle);
graphics.popState();
}
use of org.eclipse.swt.graphics.Path in project archi by archimatetool.
the class InteractionFigure 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);
// Should match 'FRACTION' defined in getFigurePath()
setFigurePositionFromTextPosition(rect, 1 / 0.86);
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);
// Line
graphics.setAlpha(getLineAlpha());
graphics.setForegroundColor(getLineColor());
graphics.drawPath(path);
path.dispose();
// 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 InteractionFigure method getFigurePath.
private Path getFigurePath(Rectangle rect) {
// fraction to use for diameter in landscape bounds
final float FRACTION = 0.86f;
// gap to use for diameter in landscape bounds
final float GAP = 1 - FRACTION;
float diameter;
int x1 = rect.x, x2;
// width < height or same
if (rect.width <= rect.height) {
diameter = rect.width * FRACTION;
x2 = rect.x + rect.width;
} else // height < width
{
// minimum of height or 85% of width
diameter = Math.min(rect.height, rect.width * 0.85f);
x1 += ((rect.width - diameter) / 2) - (diameter * GAP / 2);
x2 = (int) (x1 + diameter + (diameter * GAP));
}
int y = (int) (rect.y + (rect.height - diameter) / 2);
Path path = new Path(null);
path.addArc(x1, y, diameter, diameter, 90, 180);
path.close();
path.moveTo(x1 + (diameter / 2), y);
path.addArc(x2 - diameter, y, diameter, diameter, 270, 180);
path.close();
return path;
}
use of org.eclipse.swt.graphics.Path in project archi by archimatetool.
the class InteractionFigure 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);
// Start at top
Point pt = getIconOrigin();
Path path = new Path(null);
path.addArc(pt.x - 5, pt.y, 10, 12, 90, 180);
path.lineTo(pt.x, pt.y - 0.5f);
graphics.drawPath(path);
path.dispose();
path = new Path(null);
path.addArc(pt.x - 2, pt.y, 10, 12, -90, 180);
path.lineTo(pt.x + 3, pt.y + 12.5f);
graphics.drawPath(path);
path.dispose();
graphics.popState();
}
use of org.eclipse.swt.graphics.Path in project archi by archimatetool.
the class LocationFigure 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);
// Start at top
Point pt = getIconOrigin();
Path path = new Path(null);
path.addArc(pt.x - 5, pt.y - 15, 10, 10, -20, 220);
path.lineTo(pt.x, pt.y);
path.close();
graphics.drawPath(path);
path.dispose();
graphics.popState();
}
Aggregations