Search in sources :

Example 81 with AffineTransform

use of java.awt.geom.AffineTransform in project limelight by slagyr.

the class ImagePanelLayoutTest method getRotationTransformWhenDimensionsAreAuto.

@Test
public void getRotationTransformWhenDimensionsAreAuto() throws Exception {
    panel.setFilename(TestUtil.DATA_DIR + "/star.gif");
    panel.setRotation(45);
    Layouts.on(panel, panel.getDefaultLayout());
    AffineTransform tranform = panel.getTransform();
    // No good way to test rotation....
    assertEquals(141.0, tranform.getTranslateX(), 0.5);
    assertEquals(0.0, tranform.getTranslateY(), 0.5);
}
Also used : AffineTransform(java.awt.geom.AffineTransform) Test(org.junit.Test)

Example 82 with AffineTransform

use of java.awt.geom.AffineTransform in project limelight by slagyr.

the class PropPanelTest method hasChangesWhenTextIsChanged.

@Test
public void hasChangesWhenTextIsChanged() throws Exception {
    TextPanel.staticFontRenderingContext = new FontRenderContext(new AffineTransform(), true, true);
    Layouts.on(panel, panel.getDefaultLayout());
    panel.resetNeededLayout();
    panel.setText("blah");
    assertEquals(true, panel.needsLayout());
    panel.resetNeededLayout();
    panel.setText("blah");
    assertEquals(false, panel.needsLayout());
    panel.setText("new text");
    assertEquals(true, panel.needsLayout());
}
Also used : AffineTransform(java.awt.geom.AffineTransform) FontRenderContext(java.awt.font.FontRenderContext) Test(org.junit.Test)

Example 83 with AffineTransform

use of java.awt.geom.AffineTransform in project scriptographer by scriptographer.

the class TransformStackElement method matrixMultiply.

/**
     *  Multiplies two 2x3 matrices of double precision values
     */
private double[] matrixMultiply(double[] matrix1, double[] matrix2) {
    double[] product = new double[6];
    AffineTransform transform1 = new AffineTransform(matrix1);
    transform1.concatenate(new AffineTransform(matrix2));
    transform1.getMatrix(product);
    return product;
}
Also used : AffineTransform(java.awt.geom.AffineTransform)

Example 84 with AffineTransform

use of java.awt.geom.AffineTransform in project hid-serial by rayshobby.

the class GAbstractControl method calcTransformedOrigin.

/**
	 * This method takes a position px, py and calculates the equivalent
	 * position [ox,oy] as if no transformations have taken place and
	 * the origin is the top-left corner of the control.
	 * @param px
	 * @param py
	 */
protected void calcTransformedOrigin(float px, float py) {
    AffineTransform aff = new AffineTransform();
    aff = getTransform(aff);
    temp[0] = px;
    temp[1] = py;
    try {
        aff.inverseTransform(temp, 0, temp, 0, 1);
        ox = (float) temp[0] + halfWidth;
        oy = (float) temp[1] + halfHeight;
    } catch (NoninvertibleTransformException e) {
    }
}
Also used : NoninvertibleTransformException(java.awt.geom.NoninvertibleTransformException) AffineTransform(java.awt.geom.AffineTransform)

Example 85 with AffineTransform

use of java.awt.geom.AffineTransform in project hid-serial by rayshobby.

the class GAbstractControl method addControl.

/**
	 * This will set the rotation of the control to angle overwriting
	 * any previous rotation set. Then it calculates the centre position
	 * so that the original top left corner of the control will be the 
	 * position indicated by x,y with respect to the top left corner of
	 * parent. <br>
	 * 
	 * The added control will have its position calculated relative to the 
	 * centre of the parent control. <br>
	 * 
	 * All overloaded methods call this one. <br>
	 * 
	 * @param c the control to add.
	 * @param x the leftmost or centre position depending on controlMode
	 * @param y the topmost or centre position depending on controlMode
	 * @param angle the rotation angle (replaces any the angle specified in control)
	 */
public void addControl(GAbstractControl c, float x, float y, float angle) {
    // Ignore if children are not allowed.
    if (children == null)
        return;
    c.rotAngle = angle;
    // In child control reset the control so it centred about the origin
    AffineTransform aff = new AffineTransform();
    aff.setToRotation(angle);
    /*
		 * The following code should result in the x,y and cx,cy coordinates of
		 * the added control (c) added being measured relative to the centre of  
		 * this control.
		 */
    switch(G4P.control_mode) {
        case CORNER:
        case CORNERS:
            // Rotate about top corner
            c.x = x;
            c.y = y;
            c.temp[0] = c.halfWidth;
            c.temp[1] = c.halfHeight;
            aff.transform(c.temp, 0, c.temp, 0, 1);
            c.cx = (float) c.temp[0] + x - halfWidth;
            c.cy = (float) c.temp[1] + y - halfHeight;
            c.x = c.cx - c.halfWidth;
            c.y = c.cy - c.halfHeight;
            break;
        case CENTER:
            // Rotate about centre
            c.cx = x;
            c.cy = y;
            c.temp[0] = -c.halfWidth;
            c.temp[1] = -c.halfHeight;
            aff.transform(c.temp, 0, c.temp, 0, 1);
            c.x = c.cx + (float) c.temp[0] - halfWidth;
            c.y = c.cy - (float) c.temp[1] - halfHeight;
            c.cx -= halfWidth;
            c.cy -= halfHeight;
            break;
    }
    c.rotAngle = angle;
    // Add to parent
    c.parent = this;
    c.setZ(z);
    // Parent will now be responsible for drawing
    c.registeredMethods &= (ALL_METHOD - DRAW_METHOD);
    if (children == null)
        children = new LinkedList<GAbstractControl>();
    children.addLast(c);
    Collections.sort(children, new Z_Order());
    // Does the control being added have to do anything extra
    c.addToParent(this);
}
Also used : AffineTransform(java.awt.geom.AffineTransform) LinkedList(java.util.LinkedList)

Aggregations

AffineTransform (java.awt.geom.AffineTransform)370 BufferedImage (java.awt.image.BufferedImage)60 Graphics2D (java.awt.Graphics2D)54 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)42 Rectangle2D (java.awt.geom.Rectangle2D)40 Point2D (java.awt.geom.Point2D)28 Shape (java.awt.Shape)24 Font (java.awt.Font)23 Paint (java.awt.Paint)23 GcSnapshot (com.android.layoutlib.bridge.impl.GcSnapshot)20 ArrayList (java.util.ArrayList)18 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)17 Rectangle (java.awt.Rectangle)16 PathIterator (java.awt.geom.PathIterator)16 Color (java.awt.Color)15 Point (java.awt.Point)15 FontRenderContext (java.awt.font.FontRenderContext)15 Area (java.awt.geom.Area)14 GeneralPath (java.awt.geom.GeneralPath)14 AffineTransformOp (java.awt.image.AffineTransformOp)13