use of org.eclipse.swt.graphics.Path in project translationstudio8 by heartsome.
the class SmileyCellRenderer method draw.
/**
* {@inheritDoc}
*/
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row, IColumn column, boolean drawFocus, boolean selected, boolean printing) {
drawBackground(gc, drawingArea, cellStyle, selected, printing);
Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
Rectangle rect = applyInsets(drect);
Object value = column.getValue(row);
if (value != null) {
saveGCAttributes(gc);
int val = ((Integer) value).intValue();
_brModel.setValue(val);
calcSmileFactor();
if (_forceCircle) {
int a = Math.min(rect.width, rect.height);
Rectangle nrect = new Rectangle(0, 0, a, a);
nrect.x = rect.x + (rect.width - a) / 2;
nrect.y = rect.y + (rect.height - a) / 2;
rect = nrect;
}
int width = rect.width;
int height = rect.height;
int offx = rect.x;
int offy = rect.y;
float foffx = (float) offx;
float foffy = (float) offy;
int lineWidth = height / 40;
if (!_colorChange) {
gc.setBackground(_neutral);
} else {
if (_currentValue >= 0) {
// positive
gc.setBackground(calcColor(_positive, printing));
} else {
// negative
gc.setBackground(calcColor(_negative, printing));
}
}
Device device = printing ? _printer : Display.getCurrent();
Path p = new Path(device);
p.addArc(foffx + 0 + lineWidth / 2, foffy + 0 + lineWidth / 2, width - 1 - lineWidth, height - 1 - lineWidth, 0, 360);
gc.fillPath(p);
gc.setForeground(_black);
gc.setLineWidth(lineWidth);
gc.drawPath(p);
p.dispose();
// eyes
int y = height / 3;
int x1 = width / 3;
int x2 = width - width / 3;
int r = width / 30;
// eyes have a minimal size
if (r == 0) {
r = 1;
}
gc.setBackground(_black);
gc.fillOval(offx + x1 - r, offy + y - r, 2 * r, 2 * r);
gc.fillOval(offx + x2 - r, offy + y - r, 2 * r, 2 * r);
// eye brows
if (_eyeBrows) {
gc.setLineWidth(lineWidth / 2);
int ebWidth = width / 10;
int yDist = height / 13;
int yOff = (int) (_currentValue * (double) height / 30);
int xShift = (int) (_currentValue * (double) width / 90);
p = new Path(device);
p.moveTo(foffx + x1 - ebWidth / 2 + xShift, foffy + y - yDist + yOff);
p.lineTo(foffx + x1 + ebWidth / 2 - xShift, foffy + y - yDist - yOff);
gc.drawPath(p);
p.dispose();
p = new Path(device);
p.moveTo(foffx + x2 - ebWidth / 2 + xShift, foffy + y - yDist - yOff);
p.lineTo(foffx + x2 + ebWidth / 2 - xShift, foffy + y - yDist + yOff);
gc.drawPath(p);
p.dispose();
}
// mouth
gc.setLineWidth(lineWidth);
x1 = (int) (width / 4.5);
x2 = width - x1;
y = height - height / 3;
int midX = width / 2;
int offset = (int) (_currentValue * (double) height / 3);
p = new Path(Display.getCurrent());
p.moveTo(foffx + x1, foffy + y);
p.quadTo(foffx + midX, foffy + y + offset, foffx + x2, foffy + y);
gc.drawPath(p);
p.dispose();
restoreGCAttributes(gc);
}
if (drawFocus) {
drawFocus(gc, drect);
}
drawSelection(gc, drawingArea, cellStyle, selected, printing);
}
use of org.eclipse.swt.graphics.Path in project archi by archimatetool.
the class AbstractDiagramConnectionFigure method paintFigure.
@Override
public void paintFigure(Graphics graphics) {
if (SHOW_TARGET_FEEDBACK) {
setForegroundColor(ColorFactory.get(0, 0, 255));
setLineWidth(getModelConnection().getLineWidth() + 1);
} else {
setLineWidth();
setForegroundColor(fLineColor);
}
// Margin around label
int labelMargin = 1;
// Save dimensions of original clipping area and label
Rectangle g = graphics.getClip(new Rectangle());
Rectangle l = fConnectionLabel.getTextBounds().expand(labelMargin, labelMargin).getIntersection(g);
// Create a Path that fills the clipping area minus the label
Path p = new Path(null);
p.addRectangle(g.x, g.y, g.width, g.height);
p.addRectangle(l.x, l.y, l.width, l.height);
graphics.setClip(p);
super.paintFigure(graphics);
p.dispose();
}
use of org.eclipse.swt.graphics.Path in project eclipse.platform.swt by eclipse.
the class PathTab method paint.
@Override
public void paint(GC gc, int width, int height) {
if (!example.checkAdvancedGraphics())
return;
Device device = gc.getDevice();
Pattern pattern = null;
if (fillColor.getBgColor1() != null) {
gc.setBackground(fillColor.getBgColor1());
} else if (fillColor.getBgImage() != null) {
pattern = new Pattern(device, fillColor.getBgImage());
gc.setBackgroundPattern(pattern);
}
gc.setLineWidth(5);
gc.setForeground(device.getSystemColor(SWT.COLOR_BLACK));
// arc
Path path = new Path(device);
path.addArc((width - 250) / 2, (height - 400) / 2, 500, 400, 90, 180);
if (closeButton.getSelection())
path.close();
if (fillButton.getSelection())
gc.fillPath(path);
if (drawButton.getSelection())
gc.drawPath(path);
path.dispose();
// shape on left
Transform transform = new Transform(device);
transform.translate((width - 250) / 4, height / 2 - 150);
gc.setTransform(transform);
transform.dispose();
path = new Path(device);
path.cubicTo(-150, 100, 150, 200, 0, 300);
if (closeButton.getSelection())
path.close();
if (fillButton.getSelection())
gc.fillPath(path);
if (drawButton.getSelection())
gc.drawPath(path);
path.dispose();
gc.setTransform(null);
// shape on right
path = new Path(device);
path.moveTo(3 * (width - 250) / 4 - 25 + 250, height / 2);
path.lineTo(3 * (width - 250) / 4 + 50 + 250, height / 2 - 200);
path.lineTo(3 * (width - 250) / 4 + 50 + 250, height / 2 + 50);
path.lineTo(3 * (width - 250) / 4 - 25 + 250, height / 2 + 150);
path.lineTo(3 * (width - 250) / 4 + 25 + 250, height / 2 + 50);
if (closeButton.getSelection())
path.close();
if (fillButton.getSelection())
gc.fillPath(path);
if (drawButton.getSelection())
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 CurvesSWTTab 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(2);
Transform transform;
// ----- letter s -----
sXPos = 4 * width / 16;
sYPos = (height - 150) / 2;
transform = new Transform(device);
transform.translate(sXPos, sYPos);
gc.setTransform(transform);
transform.dispose();
gc.setForeground(device.getSystemColor(SWT.COLOR_DARK_BLUE));
gc.drawString(GraphicsExample.getResourceString("Cubic"), 0, 175, true);
Path path = new Path(device);
path.cubicTo(-200 + sDiffX1, 50 + sDiffY1, 200 + sDiffX2, 100 + sDiffY2, 0, 150);
gc.drawPath(path);
path.dispose();
// draw the spline points
gc.setTransform(null);
gc.drawRectangle(sRect1.x + (int) sXPos, sRect1.y + (int) sYPos, sRect1.width, sRect1.height);
gc.drawRectangle(sRect2.x + (int) sXPos, sRect2.y + (int) sYPos, sRect2.width, sRect2.height);
// ----- letter w -----
wXPos = 6 * width / 16;
wYPos = (height - 150) / 2;
transform = new Transform(device);
transform.translate(wXPos, wYPos);
gc.setTransform(transform);
transform.dispose();
gc.setForeground(device.getSystemColor(SWT.COLOR_GRAY));
gc.drawString(GraphicsExample.getResourceString("Quadratic"), 0, -50, true);
gc.drawString(GraphicsExample.getResourceString("Quadratic"), 110, -50, true);
path = new Path(device);
path.quadTo(100 + wDiffX1, 300 + wDiffY1, 100, 0);
path.quadTo(100 + wDiffX2, 300 + wDiffY2, 200, 0);
gc.drawPath(path);
path.dispose();
gc.setTransform(null);
gc.drawRectangle(wRect1.x + (int) wXPos, wRect1.y + (int) wYPos, wRect1.width, wRect1.height);
gc.drawRectangle(wRect2.x + (int) wXPos, wRect2.y + (int) wYPos, wRect2.width, wRect2.height);
// ----- top of letter t -----
topTXPos = 11 * width / 16;
topTYPos = (height - 150) / 2;
transform = new Transform(device);
transform.translate(topTXPos, topTYPos);
gc.setTransform(transform);
transform.dispose();
gc.setForeground(device.getSystemColor(SWT.COLOR_YELLOW));
gc.drawString(GraphicsExample.getResourceString("Cubic"), 25, -50, true);
path = new Path(device);
path.cubicTo(33 + tTopDiffX1, -20 + tTopDiffY1, 66 + tTopDiffX2, 20 + tTopDiffY2, 100, 0);
gc.drawPath(path);
path.dispose();
gc.setTransform(null);
gc.drawRectangle(tTopRect1.x + (int) topTXPos, tTopRect1.y + (int) topTYPos, tTopRect1.width, tTopRect1.height);
gc.drawRectangle(tTopRect2.x + (int) topTXPos, tTopRect2.y + (int) topTYPos, tTopRect2.width, tTopRect2.height);
// ----- vertical bar of letter t -----
botTXPos = 12 * width / 16;
botTYPos = (height - 150) / 2;
transform = new Transform(device);
transform.translate(botTXPos, botTYPos);
gc.setTransform(transform);
transform.dispose();
gc.setForeground(device.getSystemColor(SWT.COLOR_RED));
gc.drawString(GraphicsExample.getResourceString("Cubic"), 0, 175, true);
path = new Path(device);
path.cubicTo(-33 + tBotDiffX1, 50 + tBotDiffY1, 33 + tBotDiffX2, 100 + tBotDiffY2, 0, 150);
gc.drawPath(path);
path.dispose();
gc.setTransform(null);
gc.drawRectangle(tBottomRect1.x + (int) botTXPos, tBottomRect1.y + (int) botTYPos, tBottomRect1.width, tBottomRect1.height);
gc.drawRectangle(tBottomRect2.x + (int) botTXPos, tBottomRect2.y + (int) botTYPos, tBottomRect2.width, tBottomRect2.height);
font.dispose();
}
use of org.eclipse.swt.graphics.Path in project eclipse.platform.swt by eclipse.
the class CustomAlphaTab method paint.
@Override
public void paint(GC gc, int width, int height) {
if (!example.checkAdvancedGraphics())
return;
Device device = gc.getDevice();
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.setAntialias(SWT.ON);
gc.setAlpha(alphaSpinner.getSelection());
// rotate on center
Transform transform = new Transform(device);
transform.translate(width / 2, height / 2);
transform.rotate(-angle);
transform.translate(-width / 2, -height / 2);
gc.setTransform(transform);
transform.dispose();
// choose the smallest between height and width
int diameter = (height < width) ? height : width;
Path path = new Path(device);
path.addArc((width - diameter / 5) / 2, (height - diameter / 5) / 2, diameter / 5, diameter / 5, 0, 360);
path.addArc(5 * (width - diameter / 8) / 12, 4 * (height - diameter / 8) / 12, diameter / 8, diameter / 8, 0, 360);
path.addArc(7 * (width - diameter / 8) / 12, 8 * (height - diameter / 8) / 12, diameter / 8, diameter / 8, 0, 360);
path.addArc(6 * (width - diameter / 12) / 12, 3 * (height - diameter / 12) / 12, diameter / 12, diameter / 12, 0, 360);
path.addArc(6 * (width - diameter / 12) / 12, 9 * (height - diameter / 12) / 12, diameter / 12, diameter / 12, 0, 360);
path.addArc(11.5f * (width - diameter / 18) / 20, 5 * (height - diameter / 18) / 18, diameter / 18, diameter / 18, 0, 360);
path.addArc(8.5f * (width - diameter / 18) / 20, 13 * (height - diameter / 18) / 18, diameter / 18, diameter / 18, 0, 360);
path.addArc(62f * (width - diameter / 25) / 100, 32 * (height - diameter / 25) / 100, diameter / 25, diameter / 25, 0, 360);
path.addArc(39f * (width - diameter / 25) / 100, 67 * (height - diameter / 25) / 100, diameter / 25, diameter / 25, 0, 360);
gc.fillPath(path);
path.dispose();
if (pattern != null)
pattern.dispose();
}
Aggregations