use of org.eclipse.swt.graphics.Pattern in project archi by archimatetool.
the class FacilityFigure 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);
Path path = getFigurePath(rect);
graphics.fillPath(path);
disposeGradientPattern(graphics, gradient);
// Lines
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.Pattern in project archi by archimatetool.
the class GapFigure 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);
// Should match 'widthFraction' formula
setFigurePositionFromTextPosition(rect, 5 / 3.0);
if (!isEnabled()) {
setDisabledState(graphics);
}
graphics.setAlpha(getAlpha());
graphics.setBackgroundColor(getFillColor());
Pattern gradient = applyGradientPattern(graphics, rect);
// 3/10ths of width
int widthFraction = 3 * (rect.width / 10);
int circleRadius = widthFraction;
// height < width
if (rect.height < rect.width) {
// half height or 3/10ths
circleRadius = Math.min(rect.height / 2, widthFraction);
}
int xCenter = rect.x + rect.width / 2;
int yCenter = rect.y + rect.height / 2;
Path path = new Path(null);
path.addArc(xCenter - circleRadius, yCenter - circleRadius, circleRadius * 2, circleRadius * 2, 0, 360);
graphics.fillPath(path);
disposeGradientPattern(graphics, gradient);
graphics.setAlpha(getLineAlpha());
graphics.setForegroundColor(getLineColor());
graphics.drawPath(path);
path.dispose();
graphics.drawLine(xCenter - (circleRadius + circleRadius / 2), yCenter - circleRadius / 4, xCenter + (circleRadius + circleRadius / 2), yCenter - circleRadius / 4);
graphics.drawLine(xCenter - (circleRadius + circleRadius / 2), yCenter + circleRadius / 4, xCenter + (circleRadius + circleRadius / 2), yCenter + circleRadius / 4);
// Image Icon
drawIconImage(graphics, imageBounds, 0, 0, 0, 0);
graphics.popState();
}
use of org.eclipse.swt.graphics.Pattern 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.Pattern 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.Pattern in project archi by archimatetool.
the class InterfaceFigure 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 diameter;
int x = rect.x, y = rect.y;
// width < height or same
if (rect.width <= rect.height) {
diameter = rect.width;
// 'x' is unchanged
y += (rect.height - diameter) / 2;
} else // height < width
{
diameter = rect.height;
x += (rect.width - diameter) / 2;
// 'y' is unchanged
}
graphics.fillOval(x, y, diameter, diameter);
disposeGradientPattern(graphics, gradient);
// Line
graphics.setAlpha(getLineAlpha());
graphics.setForegroundColor(getLineColor());
graphics.drawOval(x, y, diameter, diameter);
// Image Icon
drawIconImage(graphics, imageBounds, 0, 0, 0, 0);
graphics.popState();
}
Aggregations