use of org.eclipse.swt.graphics.Path in project eclipse.platform.swt by eclipse.
the class RGBTab method paint.
@Override
public void paint(GC gc, int width, int height) {
if (!example.checkAdvancedGraphics())
return;
Device device = gc.getDevice();
// horizontal rectangle
Transform transform = new Transform(device);
transform.translate(0, translateY);
gc.setTransform(transform);
transform.dispose();
Path path = new Path(device);
path.addRectangle(0, 0, width, 50);
Pattern pattern = new Pattern(device, 0, 0, width, 50, device.getSystemColor(SWT.COLOR_BLUE), 0x7f, device.getSystemColor(SWT.COLOR_RED), 0x7f);
gc.setBackgroundPattern(pattern);
gc.fillPath(path);
gc.drawPath(path);
path.dispose();
// vertical rectangle
transform = new Transform(device);
transform.translate(translateX, 0);
gc.setTransform(transform);
transform.dispose();
path = new Path(device);
path.addRectangle(0, 0, 50, height);
pattern.dispose();
pattern = new Pattern(device, 0, 0, 50, height, device.getSystemColor(SWT.COLOR_DARK_CYAN), 0x7f, device.getSystemColor(SWT.COLOR_WHITE), 0x7f);
gc.setBackgroundPattern(pattern);
gc.fillPath(path);
gc.drawPath(path);
path.dispose();
// diagonal rectangle from bottom right corner
Rectangle rect = new Rectangle(0, 0, 50, height);
transform = new Transform(device);
transform.translate(width - diagTranslateX1, (height / 2) - diagTranslateY1);
// rotate on center of rectangle
transform.translate(rect.width / 2, rect.height / 2);
transform.rotate(45);
transform.translate(-rect.width / 2, -rect.height / 2);
gc.setTransform(transform);
transform.dispose();
path = new Path(device);
path.addRectangle(rect.x, rect.y, rect.width, rect.height);
pattern.dispose();
pattern = new Pattern(device, rect.x, rect.y, rect.width, rect.height, device.getSystemColor(SWT.COLOR_DARK_GREEN), 0x7f, device.getSystemColor(SWT.COLOR_DARK_MAGENTA), 0x7f);
gc.setBackgroundPattern(pattern);
gc.fillPath(path);
gc.drawPath(path);
path.dispose();
// diagonal rectangle from top right corner
transform = new Transform(device);
transform.translate(width - diagTranslateX2, (height / 2) - diagTranslateY2);
// rotate on center of rectangle
transform.translate(rect.width / 2, rect.height / 2);
transform.rotate(-45);
transform.translate(-rect.width / 2, -rect.height / 2);
gc.setTransform(transform);
transform.dispose();
path = new Path(device);
path.addRectangle(rect.x, rect.y, rect.width, rect.height);
pattern.dispose();
pattern = new Pattern(device, rect.x, rect.y, rect.width, rect.height, device.getSystemColor(SWT.COLOR_DARK_RED), 0x7f, device.getSystemColor(SWT.COLOR_YELLOW), 0x7f);
gc.setBackgroundPattern(pattern);
gc.fillPath(path);
gc.drawPath(path);
pattern.dispose();
path.dispose();
}
use of org.eclipse.swt.graphics.Path in project n4js by eclipse.
the class GraphUtils method arcSelf.
/**
* Paints an looping arc from scr to tgt.
* <p/>
* <b>Assumption:</b> The tgt is located right/below of the src.
*/
public static float[] arcSelf(GC gc, Point src, Point tgt) {
Path path = new Path(gc.getDevice());
int diffH = 10;
int diff = diffH * 3;
path.moveTo((int) src.x, (int) src.y);
path.cubicTo((int) src.x + diff, (int) src.y - diffH, (int) tgt.x, (int) tgt.y - diff, (int) tgt.x, (int) tgt.y);
gc.drawPath(path);
float[] pp = path.getPathData().points;
return pp;
}
use of org.eclipse.swt.graphics.Path in project liferay-ide by liferay.
the class GearControl method _drawGear.
private Path _drawGear(GC gc, Display display, double cx, double cy, double outerR, double innerR, float angleOffset) {
double radian2 = _teethAngle / 2 * _radian;
double radian3 = .06;
Path path = new Path(display);
for (int i = 0; i < _teeth; i++) {
double radian = (i * _teethAngle + angleOffset) * _radian;
double x = cx + outerR * Math.cos(radian);
double y = cy - outerR * Math.sin(radian);
if (i == 0) {
path.moveTo((int) x, (int) y);
}
double r1 = radian + radian3;
double r3 = radian + radian2;
double r2 = r3 - radian3;
double r4 = r3 + radian2;
x = cx + innerR * Math.cos(r1);
y = cy - innerR * Math.sin(r1);
path.lineTo((int) x, (int) y);
x = cx + innerR * Math.cos(r2);
y = cy - innerR * Math.sin(r2);
path.lineTo((int) x, (int) y);
x = cx + outerR * Math.cos(r3);
y = cy - outerR * Math.sin(r3);
path.lineTo((int) x, (int) y);
x = cx + outerR * Math.cos(r4);
y = cy - outerR * Math.sin(r4);
path.lineTo((int) x, (int) y);
}
path.close();
gc.fillPath(path);
gc.drawPath(path);
return path;
}
use of org.eclipse.swt.graphics.Path in project SIMVA-SoS by SESoS.
the class SWTGraphics2D method draw.
/**
* Draws the outline of the specified shape using the current stroke and
* paint settings.
*
* @param shape the shape (<code>null</code> not permitted).
*
* @see #getPaint()
* @see #getStroke()
* @see #fill(Shape)
*/
public void draw(Shape shape) {
Path path = toSwtPath(shape);
this.gc.drawPath(path);
path.dispose();
}
use of org.eclipse.swt.graphics.Path in project SIMVA-SoS by SESoS.
the class SWTGraphics2D method toSwtPath.
/**
* Converts an AWT <code>Shape</code> into a SWT <code>Path</code>.
*
* @param shape the shape (<code>null</code> not permitted).
*
* @return The path.
*/
private Path toSwtPath(Shape shape) {
int type;
float[] coords = new float[6];
Path path = new Path(this.gc.getDevice());
PathIterator pit = shape.getPathIterator(null);
while (!pit.isDone()) {
type = pit.currentSegment(coords);
switch(type) {
case (PathIterator.SEG_MOVETO):
path.moveTo(coords[0], coords[1]);
break;
case (PathIterator.SEG_LINETO):
path.lineTo(coords[0], coords[1]);
break;
case (PathIterator.SEG_QUADTO):
path.quadTo(coords[0], coords[1], coords[2], coords[3]);
break;
case (PathIterator.SEG_CUBICTO):
path.cubicTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
break;
case (PathIterator.SEG_CLOSE):
path.close();
break;
default:
break;
}
pit.next();
}
return path;
}
Aggregations