use of org.eclipse.swt.graphics.Path in project eclipse.platform.swt by eclipse.
the class GraphicAntialiasTab method paint.
@Override
public void paint(GC gc, int width, int height) {
if (!example.checkAdvancedGraphics())
return;
Device device = gc.getDevice();
if (ovalColorGB != null && ovalColorGB.getBgColor1() != null)
gc.setBackground(ovalColorGB.getBgColor1());
gc.setAntialias(aliasValues[aliasCombo.getSelectionIndex()]);
Path path = new Path(device);
float offsetX = 2 * width / 3f, offsetY = height / 3f;
for (int i = 0; i < 25; i++) {
path.addArc(offsetX - (50 * i), offsetY - (25 * i), 50 + (100 * i), 25 + (50 * i), 0, 360);
}
gc.fillPath(path);
path.dispose();
}
use of org.eclipse.swt.graphics.Path in project eclipse.platform.swt by eclipse.
the class GraphicsExample method checkAdvancedGraphics.
boolean checkAdvancedGraphics() {
if (advanceGraphicsInit)
return advanceGraphics;
advanceGraphicsInit = true;
Display display = parent.getDisplay();
try {
Path path = new Path(display);
path.dispose();
} catch (SWTException e) {
Shell shell = display.getActiveShell(), newShell = null;
if (shell == null)
shell = newShell = new Shell(display);
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();
if (newShell != null)
newShell.dispose();
return false;
}
return advanceGraphics = true;
}
use of org.eclipse.swt.graphics.Path in project eclipse.platform.swt by eclipse.
the class LineJoinTab method paint.
@Override
public void paint(GC gc, int width, int height) {
if (!example.checkAdvancedGraphics())
return;
Device device = gc.getDevice();
gc.setLineWidth(20);
gc.setLineJoin(joinValues[joinCb.getSelectionIndex()]);
// set the foreground color or pattern
Pattern pattern = null;
if (shapeColor.getBgColor1() != null) {
gc.setForeground(shapeColor.getBgColor1());
} else if (shapeColor.getBgImage() != null) {
pattern = new Pattern(device, shapeColor.getBgImage());
gc.setForegroundPattern(pattern);
}
// draw the shape
Path path = new Path(device);
path.moveTo(width / 2, 25);
path.lineTo(2 * width / 3, height / 3);
path.lineTo(width - 25, height / 2);
path.lineTo(2 * width / 3, 2 * height / 3);
path.lineTo(width / 2, height - 25);
path.lineTo(width / 3, 2 * height / 3);
path.lineTo(25, height / 2);
path.lineTo(width / 3, height / 3);
path.lineTo(width / 2, 25);
path.close();
gc.drawPath(path);
path.dispose();
if (pattern != null)
pattern.dispose();
}
use of org.eclipse.swt.graphics.Path in project eclipse.platform.swt by eclipse.
the class PathClippingAnimTab method paint.
@Override
public void paint(GC gc, int width, int height) {
if (!example.checkAdvancedGraphics())
return;
Device device = gc.getDevice();
// top triangle
Path path = new Path(device);
path.moveTo(width / 2, 0);
path.lineTo(width / 2 + 100, 173);
path.lineTo(width / 2 - 100, 173);
path.lineTo(width / 2, 0);
// bottom triangle
Path path2 = new Path(device);
path2.moveTo(width / 2, height);
path2.lineTo(width / 2 + 100, height - 173);
path2.lineTo(width / 2 - 100, height - 173);
path2.lineTo(width / 2, height);
// left triangle
Path path3 = new Path(device);
path3.moveTo(0, height / 2);
path3.lineTo(173, height / 2 - 100);
path3.lineTo(173, height / 2 + 100);
path3.lineTo(0, height / 2);
// right triangle
Path path4 = new Path(device);
path4.moveTo(width, height / 2);
path4.lineTo(width - 173, height / 2 - 100);
path4.lineTo(width - 173, height / 2 + 100);
path4.lineTo(width, height / 2);
// circle
Path path5 = new Path(device);
path5.moveTo((width - 200) / 2, (height - 200) / 2);
path5.addArc((width - 200) / 2, (height - 200) / 2, 200, 200, 0, 360);
// top rectangle
Path path6 = new Path(device);
path6.addRectangle((width - 40) / 2, 175, 40, ((height - 200) / 2) - 177);
// bottom rectangle
Path path7 = new Path(device);
path7.addRectangle((width - 40) / 2, ((height - 200) / 2) + 202, 40, (height - 175) - (((height - 200) / 2) + 202));
// left rectangle
Path path8 = new Path(device);
path8.addRectangle(175, (height - 40) / 2, ((width - 200) / 2) - 177, 40);
// right rectangle
Path path9 = new Path(device);
path9.addRectangle((width - 200) / 2 + 202, (height - 40) / 2, (width - 175) - ((width - 200) / 2 + 202), 40);
path.addPath(path2);
path.addPath(path3);
path.addPath(path4);
path.addPath(path5);
path.addPath(path6);
path.addPath(path7);
path.addPath(path8);
path.addPath(path9);
gc.setClipping(path);
Pattern pattern = null;
if (background.getBgColor1() != null) {
gc.setBackground(background.getBgColor1());
} else if (background.getBgImage() != null) {
pattern = new Pattern(device, background.getBgImage());
gc.setBackgroundPattern(pattern);
}
gc.setLineWidth(2);
gc.fillRectangle((width - rectWidth) / 2, (height - rectHeight) / 2, rectWidth, rectHeight);
gc.drawPath(path);
if (pattern != null)
pattern.dispose();
path9.dispose();
path8.dispose();
path7.dispose();
path6.dispose();
path5.dispose();
path4.dispose();
path3.dispose();
path2.dispose();
path.dispose();
}
use of org.eclipse.swt.graphics.Path in project eclipse.platform.swt by eclipse.
the class PathClippingTab method paint.
@Override
public void paint(GC gc, int width, int height) {
if (!example.checkAdvancedGraphics())
return;
Device device = gc.getDevice();
int clipping = clippingCb.getSelectionIndex();
switch(clipping) {
case // circles
0:
Path path = new Path(device);
path.addArc((width - width / 5) / 2, (height - height / 5) / 2, width / 5, height / 5, 0, 360);
path.addArc(5 * (width - width / 8) / 12, 4 * (height - height / 8) / 12, width / 8, height / 8, 0, 360);
path.addArc(7 * (width - width / 8) / 12, 8 * (height - height / 8) / 12, width / 8, height / 8, 0, 360);
path.addArc(6 * (width - width / 12) / 12, 3 * (height - height / 12) / 12, width / 12, height / 12, 0, 360);
path.addArc(6 * (width - width / 12) / 12, 9 * (height - height / 12) / 12, width / 12, height / 12, 0, 360);
path.addArc(11.5f * (width - width / 18) / 20, 5 * (height - height / 18) / 18, width / 18, height / 18, 0, 360);
path.addArc(8.5f * (width - width / 18) / 20, 13 * (height - height / 18) / 18, width / 18, height / 18, 0, 360);
gc.setClipping(path);
path.dispose();
break;
case // rectangle
1:
path = new Path(device);
path.addRectangle(100, 100, width - 200, height - 200);
path.addRectangle(120, 120, width - 240, height - 240);
path.addRectangle(140, 140, width - 280, height - 280);
gc.setClipping(path);
path.dispose();
break;
case // circle
2:
path = new Path(device);
path.addArc(100, 100, width - 200, height - 200, 0, 360);
path.addArc((width - width / 5) / 2, (height - height / 5) / 2, width / 5, height / 5, 0, 360);
path.addArc(5 * (width - width / 8) / 12, 4 * (height - height / 8) / 12, width / 8, height / 8, 0, 360);
path.addArc(7 * (width - width / 8) / 12, 8 * (height - height / 8) / 12, width / 8, height / 8, 0, 360);
path.addArc(6 * (width - width / 12) / 12, 3 * (height - height / 12) / 12, width / 12, height / 12, 0, 360);
path.addArc(6 * (width - width / 12) / 12, 9 * (height - height / 12) / 12, width / 12, height / 12, 0, 360);
path.addArc(11.5f * (width - width / 18) / 20, 5 * (height - height / 18) / 18, width / 18, height / 18, 0, 360);
path.addArc(8.5f * (width - width / 18) / 20, 13 * (height - height / 18) / 18, width / 18, height / 18, 0, 360);
gc.setClipping(path);
path.dispose();
break;
case // word
3:
path = new Path(device);
// $NON-NLS-1$
String text = GraphicsExample.getResourceString("SWT");
Font font = new Font(device, "Times", 200, SWT.NORMAL);
gc.setFont(font);
Point size = gc.stringExtent(text);
path.addString(text, (width - size.x) / 2, (height - size.y) / 2, font);
font.dispose();
gc.setClipping(path);
path.dispose();
break;
case // star
4:
path = new Path(device);
path.lineTo(width / 2, 0);
path.lineTo(5 * width / 8, height / 3);
path.lineTo(width, height / 3);
path.lineTo(3 * width / 4, 10 * height / 16);
path.lineTo(7 * width / 8, height);
path.lineTo(width / 2, 3 * height / 4);
path.lineTo(width / 8, height);
path.lineTo(width / 4, 10 * height / 16);
path.lineTo(0, height / 3);
path.lineTo(3 * width / 8, height / 3);
path.lineTo(width / 2, 0);
Path ovalPath = new Path(device);
ovalPath.addArc(90, 90, width - 180, height - 180, 0, 360);
path.addPath(ovalPath);
gc.setClipping(path);
ovalPath.dispose();
path.dispose();
break;
case // triangles
5:
path = new Path(device);
path.addRectangle(0, 0, width, height);
path.lineTo(width / 4, 0);
path.lineTo(width / 4, height / 2);
path.lineTo(0, height / 2);
path.lineTo(width / 4, 0);
Path path2 = new Path(device);
path2.lineTo(width / 2, 0);
path2.lineTo(width / 4, height / 2);
path2.lineTo(3 * width / 4, height / 2);
path2.lineTo(width / 2, 0);
Path path3 = new Path(device);
path3.lineTo(3 * width / 4, 0);
path3.lineTo(3 * width / 4, height / 2);
path3.lineTo(width, height / 2);
path3.lineTo(3 * width / 4, 0);
Path path4 = new Path(device);
path4.lineTo(0, height);
path4.lineTo(width / 4, height / 2);
path4.lineTo(width / 2, height);
path4.lineTo(0, height);
Path path5 = new Path(device);
path5.lineTo(width / 2, height);
path5.lineTo(3 * width / 4, height / 2);
path5.lineTo(width, height);
path5.lineTo(width / 2, height);
path.addPath(path2);
path.addPath(path3);
path.addPath(path4);
path.addPath(path5);
gc.setClipping(path);
path5.dispose();
path4.dispose();
path3.dispose();
path2.dispose();
path.dispose();
break;
case // default
6:
gc.setClipping(0, 0, width, height);
break;
}
Pattern pattern = null;
if (background.getBgColor1() != null) {
gc.setBackground(background.getBgColor1());
} else if (background.getBgImage() != null) {
pattern = new Pattern(device, background.getBgImage());
gc.setBackgroundPattern(pattern);
}
gc.fillRectangle(0, 0, width, height);
if (pattern != null)
pattern.dispose();
}
Aggregations