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;
}
}
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;
}
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();
}
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();
}
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());
}
Aggregations