Java Code Examples for org.eclipse.swt.graphics.Transform#rotate()

The following examples show how to use org.eclipse.swt.graphics.Transform#rotate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwtUniversalImageBitmap.java    From hop with Apache License 2.0 6 votes vote down vote up
@Override
protected Image renderRotated( Device device, int width, int height, double angleRadians ) {
  Image result = new Image( device, width * 2, height * 2 );

  GC gc = new GC( result );

  int bw = bitmap.getBounds().width;
  int bh = bitmap.getBounds().height;
  Transform affineTransform = new Transform( device );
  affineTransform.translate( width, height );
  affineTransform.rotate( (float) Math.toDegrees( angleRadians ) );
  affineTransform.scale( (float) zoomFactor * width / bw, (float) zoomFactor * height / bh );
  gc.setTransform( affineTransform );

  gc.drawImage( bitmap, 0, 0, bw, bh, -bw / 2, -bh / 2, bw, bh );

  gc.dispose();

  return result;
}
 
Example 2
Source File: RotatePiece.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private void rotateTransform(Transform transform) {
	switch (angle) {
	case 90:
		transform.translate(0, size.y);
		break;
	case 180:
		transform.translate(size.x, size.y);
		break;
	case 270:
		transform.translate(size.x, 0);
		break;
	default:
		PaperClips.error(SWT.ERROR_INVALID_ARGUMENT,
				"Rotation angle must be 90, 180 or 270."); //$NON-NLS-1$
	}
	transform.rotate(-angle); // reverse the angle since Transform.rotate
	// goes clockwise
}
 
Example 3
Source File: SwtUniversalImageBitmap.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
protected Image renderRotated( Device device, int width, int height, double angleRadians ) {
  Image result = new Image( device, width * 2, height * 2 );

  GC gc = new GC( result );

  int bw = bitmap.getBounds().width;
  int bh = bitmap.getBounds().height;
  Transform affineTransform = new Transform( device );
  affineTransform.translate( width, height );
  affineTransform.rotate( (float) Math.toDegrees( angleRadians ) );
  affineTransform.scale( (float) 1.0 * width / bw, (float) 1.0 * height / bh );
  gc.setTransform( affineTransform );

  gc.drawImage( bitmap, 0, 0, bw, bh, -bw / 2, -bh / 2, bw, bh );

  gc.dispose();

  return result;
}
 
Example 4
Source File: AnalogClockPainter.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void setTransform(Event e, float angle, boolean shadow) {
	Transform t = new Transform(e.display);
	int x = picker.dialCenter.x;
	int y = picker.dialCenter.y;
	if (shadow) {
		x += 4;
		y += 4;
	}
	t.translate(x, y);
	t.rotate(angle - 90);
	e.gc.setTransform(t);
	t.dispose();
}
 
Example 5
Source File: GraphUtils.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
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(Double.valueOf(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();
}
 
Example 6
Source File: TagCloud.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private ImageData createImageData(final Word word, Font font, Point stringExtent, final double sin,
		final double cos, int x, int y, Color color) {
	Image img = new Image(null, x, y);
	word.width = x;
	word.height = y;
	word.stringExtent = stringExtent;
	GC g = new GC(img);
	g.setAntialias(antialias);
	g.setForeground(color);
	Transform t = new Transform(img.getDevice());
	if (word.angle < 0) {
		t.translate(0, img.getBounds().height - (int) (cos * stringExtent.y));
	} else {
		t.translate((int) (sin * stringExtent.y), 0);
	}
	t.rotate(word.angle);
	g.setTransform(t);
	g.setFont(font);
	// Why is drawString so slow? between 30 and 90 percent of the whole
	// draw time...
	g.drawString(word.string, 0, 0, false);
	int max = Math.max(x, y);
	int tmp = maxSize;
	while (max < tmp) {
		tmp = tmp / 2;
	}
	tmp = tmp * 2;
	SmallRect root = new SmallRect(0, 0, tmp, tmp);
	word.tree = new RectTree(root, accuracy);
	final ImageData id = img.getImageData();
	g.dispose();
	img.dispose();
	return id;
}
 
Example 7
Source File: StatechartDefinitionSection.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void paintControl(PaintEvent e) {
	int w = e.width;
	int h = e.height;
	Transform tr = new Transform(e.display);
	tr.translate(w / 2, h / 2);
	tr.rotate(rotationAngle);
	e.gc.setTransform(tr);
	tr.dispose();
	int drawHeight = -w + 2;
	e.gc.drawString(sectionExpanded ? "" : text, 0, drawHeight % 2 != 0 ? drawHeight + 1 : drawHeight - 1);
}
 
Example 8
Source File: DefaultTableHeaderRenderer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
    }
}
 
Example 9
Source File: SWTGraphics2D.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies a rotation transform.
 *
 * @param theta  the angle of rotation.
 */
public void rotate(double theta) {
    Transform swtTransform = new Transform(this.gc.getDevice());
    this.gc.getTransform(swtTransform);
    swtTransform.rotate((float) (theta * 180 / Math.PI));
    this.gc.setTransform(swtTransform);
    swtTransform.dispose();
}
 
Example 10
Source File: SWTGraphics2D.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void rotate(double theta) {
    Transform swtTransform = new Transform(this.gc.getDevice()); 
    this.gc.getTransform(swtTransform);
    swtTransform.rotate( (float) (theta * 180 / Math.PI));
    this.gc.setTransform(swtTransform);
    swtTransform.dispose();
}
 
Example 11
Source File: DefaultTableHeaderRenderer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
    }
}
 
Example 12
Source File: SwtTextRenderer.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @param ipr
 * @param lo
 * @param la
 * @param b
 */
private void showTopValue( IPrimitiveRenderer ipr, Location lo, Label la,
		boolean b )
{
	GC gc = (GC) ( (IDeviceRenderer) ipr ).getGraphicsContext( );
	IChartComputation cComp = ( (IDeviceRenderer) ipr ).getChartComputation( );
	double dX = lo.getX( ), dY = lo.getY( );
	final FontDefinition fd = la.getCaption( ).getFont( );

	final int dAngleInDegrees = (int)fd.getRotation( );

	final Color clrBackground = (Color) _sxs.getColor( la.getShadowColor( ) );

	final ITextMetrics itm = cComp.getTextMetrics( _sxs, la, 0 );
	final double dFW = itm.getFullWidth( );
	final double dFH = itm.getFullHeight( );
	cComp.recycleTextMetrics( itm );

	double scaledThickness = SHADOW_THICKNESS
			* _sxs.getDpiResolution( )
			/ 72d;

	gc.setBackground( clrBackground );

	R31Enhance.setAlpha( gc, la.getShadowColor( ) );

	// HORIZONTAL TEXT
	if ( dAngleInDegrees == 0 )
	{
		gc.fillRectangle( (int) ( dX + scaledThickness ),
				(int) ( dY + scaledThickness ),
				(int) dFW,
				(int) dFH );
	}
	// TEXT AT POSITIVE 90 (TOP RIGHT HIGHER THAN TOP LEFT CORNER)
	else if ( dAngleInDegrees == 90 )
	{
		gc.fillRectangle( (int) ( dX + scaledThickness ),
				(int) ( dY - dFW - scaledThickness ),
				(int) dFH,
				(int) dFW );
	}
	// TEXT AT NEGATIVE 90 (TOP RIGHT LOWER THAN TOP LEFT CORNER)
	else if ( dAngleInDegrees == -90 )
	{
		gc.fillRectangle( (int) ( dX - dFH - scaledThickness ),
				(int) ( dY + scaledThickness ),
				(int) dFH,
				(int) dFW );
	}
	else
	{
		Transform transform = new Transform( getDevice( ) );
		transform.translate( (float) dX, (float) dY );
		transform.rotate( -dAngleInDegrees );
		gc.setTransform( transform );
		gc.fillRectangle( (int) scaledThickness,
				(int) scaledThickness,
				(int) dFW,
				(int) dFH );
		transform.dispose( );
		gc.setTransform( null );
	}
}
 
Example 13
Source File: VerticalLabel.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Fix the issues in the ImageUtilities where the size of the image is the
 * ascent of the font instead of being its height.
 * 
 * Also uses the GC for the rotation.
 * 
 * The biggest issue is the very idea of using an image. The size of the
 * font should be given by the mapmode, not in absolute device pixel as it
 * does look ugly when zooming in.
 * 
 * 
 * @param string
 *            the String to be rendered
 * @param font
 *            the font
 * @param foreground
 *            the text's color
 * @param background
 *            the background color
 * @param useGCTransform
 *            true to use the Transform on the GC object.
 *            false to rely on the homemade algorithm. Transform seems to
 *            not be supported in eclipse-3.2 except on windows.
 *            It is working on macos-3.3M3.
 * @return an Image which must be disposed
 */
public Image createRotatedImageOfString(Graphics g, String string,
        Font font, Color foreground, Color background,
        boolean useGCTransform) {
    Display display = Display.getCurrent();
    if (display == null) {
        SWT.error(SWT.ERROR_THREAD_INVALID_ACCESS);
    }

    List<FontData> fontDatas = new ArrayList<FontData>();
    // take all font datas, mac and linux specific
    for (FontData data : font.getFontData()) {
        FontData data2 = new FontData(data.getName(),
                (int) (data.getHeight() * g.getAbsoluteScale()), data.getStyle());
        fontDatas.add(data2);
    }
    // create the new font
    Font zoomedFont = new Font(display, fontDatas.toArray(new FontData[fontDatas.size()]));
    // get the dimension in this font
    Dimension strDim = FigureUtilities
            .getTextExtents(string, zoomedFont);
    if (strDim.width == 0 || strDim.height == 0) {
        strDim = FigureUtilities
                .getTextExtents(string, font);
    }
    Image srcImage = useGCTransform ?
            new Image(display, strDim.height, strDim.width) :
            new Image(display, strDim.width, strDim.height);
    GC gc = new GC(srcImage);
    if (useGCTransform) {
        Transform transform = new Transform(display);
        transform.rotate(-90);

        gc.setTransform(transform);
    }
    gc.setFont(zoomedFont);
    gc.setForeground(foreground);
    gc.setBackground(background);
    gc.fillRectangle(gc.getClipping());
    gc.drawText(string, gc.getClipping().x, gc.getClipping().y
            // - metrics.getLeading()
            );
    gc.dispose();
    if (useGCTransform) {
        srcImage.dispose();
        zoomedFont.dispose();
        return srcImage;
    }
    disposeImage();
    Image rotated = ImageUtilities.createRotatedImage(srcImage);
    srcImage.dispose();
    zoomedFont.dispose();
    return rotated;
}