use of org.eclipse.swt.graphics.Transform 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();
}
use of org.eclipse.swt.graphics.Transform in project nebula.widgets.nattable by eclipse.
the class VerticalTextPainter method paintCell.
@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
if (this.paintBg) {
super.paintCell(cell, gc, rectangle, configRegistry);
}
if (this.paintFg) {
Rectangle originalClipping = gc.getClipping();
gc.setClipping(rectangle.intersection(originalClipping));
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
setupGCFromConfig(gc, cellStyle);
int fontHeight = gc.getFontMetrics().getHeight();
String text = convertDataType(cell, configRegistry);
// Draw Text
text = getTextToDisplay(cell, gc, rectangle.height, text);
int numberOfNewLines = getNumberOfNewLines(text);
// if the content height is bigger than the available column width
// we're extending the column width (only if word wrapping is
// enabled)
int contentHeight = (fontHeight * numberOfNewLines) + (this.lineSpacing * (numberOfNewLines - 1)) + (this.spacing * 2);
int contentToCellDiff = (cell.getBounds().width - rectangle.width);
if ((contentHeight > rectangle.width) && this.calculateByTextHeight) {
ILayer layer = cell.getLayer();
layer.doCommand(new ColumnResizeCommand(layer, cell.getColumnPosition(), contentHeight + contentToCellDiff, true));
}
if (text != null && text.length() > 0) {
Transform originalTransform = new Transform(gc.getDevice());
gc.getTransform(originalTransform);
Transform transform = new Transform(gc.getDevice());
gc.getTransform(transform);
if (numberOfNewLines == 1) {
int contentWidth = Math.min(getLengthFromCache(gc, text), rectangle.height);
if (!isRotateClockwise()) {
transform.rotate(-90f);
int xOffset = -rectangle.x + (-contentWidth - rectangle.y) - CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentWidth);
int yOffset = rectangle.x + -rectangle.y + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentHeight) + this.spacing;
transform.translate(xOffset, yOffset);
} else {
transform.rotate(90f);
int horizontalPadding = CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentHeight);
if (horizontalPadding != 0) {
horizontalPadding += gc.getFontMetrics().getLeading();
}
int xOffset = rectangle.y - rectangle.x + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentWidth);
int yOffset = -contentHeight - rectangle.y - rectangle.x - horizontalPadding + this.spacing;
transform.translate(xOffset, yOffset);
}
gc.setTransform(transform);
gc.drawText(text, rectangle.x, rectangle.y, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
int length = gc.textExtent(text).x;
paintDecoration(cellStyle, gc, rectangle.x, rectangle.y, length, fontHeight);
} else {
// draw every line by itself because of the alignment,
// otherwise the whole text is always aligned right
// $NON-NLS-1$
String[] lines = text.split("\n");
boolean firstline = true;
int previousXOffset = 0;
for (String line : lines) {
int lineContentWidth = Math.min(getLengthFromCache(gc, line), rectangle.height);
if (!isRotateClockwise()) {
int xOffset = -rectangle.x + (-lineContentWidth - rectangle.y) - CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, lineContentWidth);
if (firstline) {
transform.rotate(-90f);
int yOffset = rectangle.x + -rectangle.y + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentHeight) + this.spacing;
transform.translate(xOffset, yOffset);
firstline = false;
} else {
transform.translate(xOffset - previousXOffset, fontHeight + this.lineSpacing);
}
previousXOffset = xOffset;
} else {
int xOffset = rectangle.y - rectangle.x + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, lineContentWidth);
if (firstline) {
transform.rotate(90f);
int horizontalPadding = CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentHeight);
if (horizontalPadding != 0) {
horizontalPadding += gc.getFontMetrics().getLeading();
}
int yOffset = -contentHeight - rectangle.y - rectangle.x - horizontalPadding + this.spacing + (fontHeight * (numberOfNewLines - 1)) + (this.lineSpacing * (numberOfNewLines - 1));
transform.translate(xOffset, yOffset);
firstline = false;
} else {
transform.translate(xOffset - previousXOffset, -fontHeight - this.lineSpacing);
}
previousXOffset = xOffset;
}
gc.setTransform(transform);
gc.drawText(line, rectangle.x, rectangle.y, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
int length = gc.textExtent(line).x;
paintDecoration(cellStyle, gc, rectangle.x, rectangle.y, length, fontHeight);
}
}
gc.setTransform(originalTransform);
if (originalTransform != null) {
originalTransform.dispose();
}
if (transform != null) {
transform.dispose();
}
}
gc.setClipping(originalClipping);
resetGC(gc);
}
}
use of org.eclipse.swt.graphics.Transform in project n4js by eclipse.
the class GraphUtils method drawArrowHead.
// poor man's implementation of decorators
public static void drawArrowHead(GC gc, Point referencePoint, Point p) {
final double angle = Math.atan2(p.y - referencePoint.y, p.x - referencePoint.x) * 180.0 / Math.PI;
final Transform tf = new Transform(gc.getDevice());
tf.rotate(new Double(angle).floatValue());
tf.scale(7, 3);
final float[] pnts = new float[] { -1, 1, -1, -1 };
tf.transform(pnts);
gc.drawLine(Math.round(p.x), Math.round(p.y), Math.round(p.x + pnts[0]), Math.round(p.y + pnts[1]));
gc.drawLine(Math.round(p.x), Math.round(p.y), Math.round(p.x + pnts[2]), Math.round(p.y + pnts[3]));
tf.dispose();
}
use of org.eclipse.swt.graphics.Transform in project tdq-studio-se by Talend.
the class TdColumnHeaderRenderer method setRotation.
/**
* Set the rotation of the header text. Please note that you have to call <code>redraw()</code> on the table
* yourself if you change the rotation while the table is showing.
*
* @param rotation rotation in degrees anti clockwise between 0 and 90 degrees.
*/
public void setRotation(int rotation) {
if (rotation < 0 || rotation > 90) {
throw new IllegalArgumentException("Rotation range 0..90");
}
if (_rotation != rotation) {
disposeTransformations();
_rotation = rotation;
_transform = new Transform(Display.getCurrent());
_transformInv = new Transform(Display.getCurrent());
_transform.rotate(-rotation);
_transformInv.rotate(-rotation);
_transformInv.invert();
sinRotation = Math.sin(_rotation * Math.PI / 180);
imageSpacing = (int) (10 / sinRotation);
}
}
use of org.eclipse.swt.graphics.Transform in project netxms by netxms.
the class AxisTickLabels method drawRotatedText.
/**
* Draws the rotated text.
*
* @param gc the graphics context
* @param text the text
* @param x the x coordinate
* @param y the y coordinate
* @param angle the angle
*/
private void drawRotatedText(GC gc, String text, float x, float y, int angle) {
// set transform to rotate
Transform transform = new Transform(gc.getDevice());
transform.translate(x, y);
transform.rotate(360 - angle);
gc.setTransform(transform);
gc.drawText(text, 0, 0);
transform.dispose();
gc.setTransform(null);
}
Aggregations