use of org.apache.pivot.wtk.ImageView in project pivot by apache.
the class ImageViewSkin method layout.
@Override
public void layout() {
ImageView imageView = (ImageView) getComponent();
Image image = imageView.getImage();
if (image != null) {
int width = getWidth();
int height = getHeight();
Dimensions imageSize = image.getSize();
if (fill) {
// Scale to fit
if (preserveAspectRatio) {
float aspectRatio = (float) width / (float) height;
float imageAspectRatio = (float) imageSize.width / (float) imageSize.height;
if (aspectRatio > imageAspectRatio) {
imageY = 0;
scaleY = (float) height / (float) imageSize.height;
imageX = (int) (width - imageSize.width * scaleY) / 2;
scaleX = scaleY;
} else {
imageX = 0;
scaleX = (float) width / (float) imageSize.width;
imageY = (int) (height - imageSize.height * scaleX) / 2;
scaleY = scaleX;
}
} else {
imageX = 0;
scaleX = (float) width / (float) imageSize.width;
imageY = 0;
scaleY = (float) height / (float) imageSize.height;
}
} else {
if (horizontalAlignment == HorizontalAlignment.CENTER) {
imageX = (width - imageSize.width) / 2;
} else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
imageX = width - imageSize.width;
} else {
imageX = 0;
}
scaleX = 1.0f;
if (verticalAlignment == VerticalAlignment.CENTER) {
imageY = (height - imageSize.height) / 2;
} else if (verticalAlignment == VerticalAlignment.BOTTOM) {
imageY = height - imageSize.height;
} else {
imageY = 0;
}
scaleY = 1.0f;
}
}
}
Aggregations