Search in sources :

Example 21 with AffineTransform

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

the class GAbstractControl method setRotation.

/**
	 * Set the rotation to apply when displaying this control. The center of 
	 * rotation is determined by the mode parameter parameter.
	 * 
	 * @param angle clockwise angle in radians
	 * @param mode PApplet.CORNER / CORNERS / CENTER
	 */
public void setRotation(float angle, GControlMode mode) {
    rotAngle = angle;
    AffineTransform aff = new AffineTransform();
    aff.setToRotation(angle);
    switch(mode) {
        case CORNER:
        case CORNERS:
            // Rotate about top corner
            temp[0] = halfWidth;
            temp[1] = halfHeight;
            aff.transform(temp, 0, temp, 0, 1);
            // - halfWidth;
            cx = (float) temp[0] + x;
            // - halfHeight;
            cy = (float) temp[1] + y;
            break;
        case CENTER:
        default:
            // Rotate about centre
            temp[0] = -halfWidth;
            temp[1] = -halfHeight;
            aff.transform(temp, 0, temp, 0, 1);
            x = cx + (float) temp[0];
            // should this be minus?? I don't think so
            y = cy + (float) temp[1];
            break;
    }
}
Also used : AffineTransform(java.awt.geom.AffineTransform)

Example 22 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 23 with AffineTransform

use of java.awt.geom.AffineTransform in project dbeaver by serge-rider.

the class ImageViewCanvas method syncScrollBars.

/**
	 * Synchronize the scrollbar with the image. If the transform is out
	 * of range, it will correct it. This function considers only following
	 * factors :<b> transform, image size, client area</b>.
	 */
public void syncScrollBars() {
    if (sourceImage == null) {
        redraw();
        return;
    }
    AffineTransform af = transform;
    double sx = af.getScaleX(), sy = af.getScaleY();
    double tx = af.getTranslateX(), ty = af.getTranslateY();
    if (tx > 0)
        tx = 0;
    if (ty > 0)
        ty = 0;
    ScrollBar horizontal = getHorizontalBar();
    horizontal.setIncrement(getClientArea().width / 100);
    horizontal.setPageIncrement(getClientArea().width);
    Rectangle imageBound = sourceImage.getBounds();
    int cw = getClientArea().width, ch = getClientArea().height;
    if (imageBound.width * sx > cw) {
        /* image is wider than client area */
        horizontal.setMaximum((int) (imageBound.width * sx));
        horizontal.setEnabled(true);
        if (((int) -tx) > horizontal.getMaximum() - cw)
            tx = -horizontal.getMaximum() + cw;
    } else {
        /* image is narrower than client area */
        horizontal.setEnabled(false);
        //center if too small.
        tx = (cw - imageBound.width * sx) / 2;
    }
    horizontal.setSelection((int) (-tx));
    horizontal.setThumb(getClientArea().width);
    ScrollBar vertical = getVerticalBar();
    vertical.setIncrement(getClientArea().height / 100);
    vertical.setPageIncrement(getClientArea().height);
    if (imageBound.height * sy > ch) {
        /* image is higher than client area */
        vertical.setMaximum((int) (imageBound.height * sy));
        vertical.setEnabled(true);
        if (((int) -ty) > vertical.getMaximum() - ch)
            ty = -vertical.getMaximum() + ch;
    } else {
        /* image is less higher than client area */
        vertical.setEnabled(false);
        //center if too small.
        ty = (ch - imageBound.height * sy) / 2;
    }
    vertical.setSelection((int) (-ty));
    vertical.setThumb(getClientArea().height);
    /* update transform. */
    af = AffineTransform.getScaleInstance(sx, sy);
    af.preConcatenate(AffineTransform.getTranslateInstance(tx, ty));
    transform = af;
    redraw();
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) AffineTransform(java.awt.geom.AffineTransform) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 24 with AffineTransform

use of java.awt.geom.AffineTransform in project dbeaver by serge-rider.

the class ImageViewCanvas method scrollVertically.

/* Scroll vertically */
private void scrollVertically(ScrollBar scrollBar) {
    if (sourceImage == null)
        return;
    AffineTransform af = transform;
    double ty = af.getTranslateY();
    double select = -scrollBar.getSelection();
    af.preConcatenate(AffineTransform.getTranslateInstance(0, select - ty));
    transform = af;
    syncScrollBars();
}
Also used : AffineTransform(java.awt.geom.AffineTransform)

Example 25 with AffineTransform

use of java.awt.geom.AffineTransform in project dbeaver by serge-rider.

the class ImageViewCanvas method fitCanvas.

/**
	 * Fit the image onto the canvas
	 */
public void fitCanvas() {
    if (sourceImage == null)
        return;
    Rectangle imageBound = sourceImage.getBounds();
    Rectangle destRect = getClientArea();
    double sx = (double) destRect.width / (double) imageBound.width;
    double sy = (double) destRect.height / (double) imageBound.height;
    double s = Math.min(sx, sy);
    double dx = 0.5 * destRect.width;
    double dy = 0.5 * destRect.height;
    centerZoom(dx, dy, s, new AffineTransform());
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) AffineTransform(java.awt.geom.AffineTransform)

Aggregations

AffineTransform (java.awt.geom.AffineTransform)335 BufferedImage (java.awt.image.BufferedImage)55 Graphics2D (java.awt.Graphics2D)43 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)42 Rectangle2D (java.awt.geom.Rectangle2D)38 Point2D (java.awt.geom.Point2D)26 Paint (java.awt.Paint)22 Font (java.awt.Font)21 Shape (java.awt.Shape)21 GcSnapshot (com.android.layoutlib.bridge.impl.GcSnapshot)20 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)17 PathIterator (java.awt.geom.PathIterator)16 ArrayList (java.util.ArrayList)16 FontRenderContext (java.awt.font.FontRenderContext)15 Color (java.awt.Color)14 Area (java.awt.geom.Area)14 GeneralPath (java.awt.geom.GeneralPath)14 Rectangle (java.awt.Rectangle)11 Path2D (java.awt.geom.Path2D)11 Test (org.junit.Test)11