use of org.eclipse.swt.graphics.Path in project archi by archimatetool.
the class EquipmentFigure method drawCog.
/**
* Draw a Cog with choosen number of "segments"
*/
protected void drawCog(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 eclipse.platform.swt by eclipse.
the class AdvancedGraphics method open.
public Shell open(final Display display) {
final Shell shell = new Shell(display);
// $NON-NLS-1$
shell.setText(RESOURCE_BUNDLE.getString("AdvancedGraphics"));
try {
Path path = new Path(display);
path.dispose();
} catch (SWTException e) {
MessageBox dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
// $NON-NLS-1$
dialog.setText(RESOURCE_BUNDLE.getString("Warning"));
// $NON-NLS-1$
dialog.setMessage(RESOURCE_BUNDLE.getString("LibNotFound"));
dialog.open();
shell.dispose();
return null;
}
FontData fd = shell.getFont().getFontData()[0];
final Font font = new Font(display, fd.getName(), 96, SWT.BOLD | SWT.ITALIC);
final Image image = loadImage(display, AdvancedGraphics.class, "irmaos.jpg");
final Rectangle rect = image.getBounds();
shell.addListener(SWT.Paint, event -> {
GC gc = event.gc;
Transform tr = new Transform(display);
tr.translate(rect.width / 4, rect.height / 2);
tr.rotate(-30);
if (image != null) {
gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width, rect.height);
}
gc.setAlpha(100);
gc.setTransform(tr);
Path path = new Path(display);
path.addString("SWT", 0, 0, font);
gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
gc.fillPath(path);
gc.drawPath(path);
tr.dispose();
path.dispose();
});
shell.setSize(shell.computeSize(rect.width, rect.height));
shell.open();
shell.addListener(SWT.Dispose, event -> {
if (image != null)
image.dispose();
font.dispose();
});
return shell;
}
use of org.eclipse.swt.graphics.Path in project eclipse.platform.swt by eclipse.
the class BallTab method paint.
@Override
public void paint(GC gc, int width, int height) {
if (!example.checkAdvancedGraphics())
return;
Device device = gc.getDevice();
if (bc[0] == null) {
bc[0] = new BallCollection(0, 0, 5, 5, 20, 20, new Color[] { device.getSystemColor(SWT.COLOR_GREEN) });
bc[1] = new BallCollection(50, 300, 10, -5, 50, 10, new Color[] { device.getSystemColor(SWT.COLOR_BLUE) });
bc[2] = new BallCollection(250, 100, -5, 8, 25, 12, new Color[] { device.getSystemColor(SWT.COLOR_RED) });
bc[3] = new BallCollection(150, 400, 5, 8, 35, 14, new Color[] { device.getSystemColor(SWT.COLOR_BLACK) });
bc[4] = new BallCollection(100, 250, -5, -18, 100, 5, new Color[] { device.getSystemColor(SWT.COLOR_MAGENTA) });
}
for (BallCollection ballCollection : bc) {
for (int i = 0; i < ballCollection.prevx.size(); i++) {
Transform transform = new Transform(device);
transform.translate(ballCollection.prevx.get(ballCollection.prevx.size() - (i + 1)).floatValue(), ballCollection.prevy.get(ballCollection.prevy.size() - (i + 1)).floatValue());
gc.setTransform(transform);
transform.dispose();
Path path = new Path(device);
path.addArc(0, 0, ballCollection.ball_size, ballCollection.ball_size, 0, 360);
gc.setAlpha(255 - i * (255 / ballCollection.capacity));
gc.setBackground(ballCollection.colors[0]);
gc.fillPath(path);
gc.drawPath(path);
path.dispose();
}
}
}
use of org.eclipse.swt.graphics.Path in project eclipse.platform.swt by eclipse.
the class CountDownTab method paint.
@Override
public void paint(GC gc, int width, int height) {
if (!example.checkAdvancedGraphics())
return;
Device device = gc.getDevice();
// diameter of the circle in pixels
int diameter = ((width < height) ? width - 25 : height - 25);
if (!getAnimation() && nextNumber == 0) {
Font font = new Font(device, getPlatformFontFace(1), diameter / 2, SWT.NONE);
gc.setFont(font);
// display "SWT"
gc.setForeground(device.getSystemColor(SWT.COLOR_DARK_BLUE));
gc.setTextAntialias(SWT.ON);
// determine the dimensions of the word
String text = GraphicsExample.getResourceString("SWT");
Point point = gc.stringExtent(text);
int textWidth = point.x;
int textHeight = point.y;
gc.drawString(text, (width - textWidth) / 2, (height - textHeight) / 2, true);
font.dispose();
} else {
Font font = new Font(device, getPlatformFontFace(0), 6 * diameter / 10, SWT.NONE);
gc.setFont(font);
// set attributes from controls
gc.setLineWidth(lineWidthSpinner.getSelection());
// round line ends
gc.setLineCap(lineCap);
// smooth jagged edges
gc.setAntialias(antialias);
// smooth jagged edges
gc.setTextAntialias(antialias);
// draw the circles
Path path = new Path(device);
path.addArc((width - diameter) / 2, (height - diameter) / 2, diameter, diameter, 0, 360);
path.addArc((width - diameter + 50) / 2, (height - diameter + 50) / 2, diameter - 50, diameter - 50, 0, 360);
gc.drawPath(path);
gc.setBackground(device.getSystemColor(SWT.COLOR_RED));
gc.fillPath(path);
path.dispose();
Point point = gc.stringExtent(Integer.valueOf(nextNumber).toString());
int textWidth = point.x;
int textHeight = point.y;
// draw the number
gc.drawString(Integer.valueOf(nextNumber).toString(), (width - textWidth) / 2, (height - textHeight) / 2, true);
// draw the rotating arm
Transform transform = new Transform(device);
transform.translate(width / 2, height / 2);
transform.rotate(angle);
gc.setTransform(transform);
gc.setForeground(device.getSystemColor(SWT.COLOR_RED));
gc.drawLine(0, 0, diameter / 2, 0);
transform.dispose();
font.dispose();
}
}
use of org.eclipse.swt.graphics.Path in project eclipse.platform.swt by eclipse.
the class CurvesTab method paint.
@Override
public void paint(GC gc, int width, int height) {
if (!example.checkAdvancedGraphics())
return;
Device device = gc.getDevice();
Font font = new Font(device, getPlatformFont(), 16, SWT.ITALIC);
gc.setFont(font);
gc.setLineWidth(5);
Transform transform;
// ----- cubic curve -----
cubXPos = width / 5;
cubYPos = height / 3;
transform = new Transform(device);
transform.translate(cubXPos, cubYPos);
gc.setTransform(transform);
transform.dispose();
gc.setForeground(device.getSystemColor(SWT.COLOR_RED));
gc.drawString(GraphicsExample.getResourceString("Cubic"), 25, -70, true);
Path path = new Path(device);
path.cubicTo(133 + cubDiffX1, -60 + cubDiffY1, 266 + cubDiffX2, 60 + cubDiffY2, 400 + cubEndDiffX, 0 + cubEndDiffY);
gc.drawPath(path);
path.dispose();
gc.setTransform(null);
gc.setForeground(device.getSystemColor(SWT.COLOR_DARK_BLUE));
gc.drawRectangle(cubHndl1.x + (int) cubXPos, cubHndl1.y + (int) cubYPos, cubHndl1.width, cubHndl1.height);
gc.drawRectangle(cubHndl2.x + (int) cubXPos, cubHndl2.y + (int) cubYPos, cubHndl2.width, cubHndl2.height);
gc.drawRectangle(cubEndHndl.x + (int) cubXPos, cubEndHndl.y + (int) cubYPos, cubEndHndl.width, cubEndHndl.height);
// ----- quadratic curve -----
quadXPos = width / 5;
quadYPos = 2 * height / 3;
transform = new Transform(device);
transform.translate(quadXPos, quadYPos);
gc.setTransform(transform);
transform.dispose();
gc.setForeground(device.getSystemColor(SWT.COLOR_GREEN));
gc.drawString(GraphicsExample.getResourceString("Quadratic"), 0, -50, true);
path = new Path(device);
path.quadTo(200 + quadDiffX, 150 + quadDiffY, 400 + quadEndDiffX, 0 + quadEndDiffY);
gc.drawPath(path);
path.dispose();
gc.setTransform(null);
gc.setForeground(device.getSystemColor(SWT.COLOR_GRAY));
gc.drawRectangle(quadHndl.x + (int) quadXPos, quadHndl.y + (int) quadYPos, quadHndl.width, quadHndl.height);
gc.drawRectangle(quadEndHndl.x + (int) quadXPos, quadEndHndl.y + (int) quadYPos, quadEndHndl.width, quadEndHndl.height);
font.dispose();
}
Aggregations