Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions CodenameOne/src/com/codename1/components/ImageViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,26 @@ private void updatePositions() {
imageDrawHeight = prefH;
imageX = prefX;
imageY = prefY;
cropBox.set(-imageY/(double)imageDrawHeight, (imageX + imageDrawWidth - getWidth())/(double)imageDrawWidth, (imageY + imageDrawHeight - getHeight())/(double)imageDrawHeight, -imageX/(double)imageDrawWidth);

// Apply the same constraints used in paint() method to ensure cropBox matches what's actually visible
int constrainedImageX = imageX;
int constrainedImageY = imageY;

if (imageDrawWidth > getInnerWidth()) {
constrainedImageX = Math.max(
Math.min(0, imageX),
-imageDrawWidth + getInnerWidth()
);
}

if (imageDrawHeight > getInnerHeight()) {
constrainedImageY = Math.max(
Math.min(0, imageY),
-imageDrawHeight + getInnerHeight()
);
}

cropBox.set(-constrainedImageY/(double)imageDrawHeight, (constrainedImageX + imageDrawWidth - getWidth())/(double)imageDrawWidth, (constrainedImageY + imageDrawHeight - getHeight())/(double)imageDrawHeight, -constrainedImageX/(double)imageDrawWidth);
return;
}
int iW = image.getWidth();
Expand All @@ -529,7 +548,26 @@ private void updatePositions() {

imageY += (getInnerHeight() - imageDrawHeight)/2;
}
cropBox.set(-imageY/(double)imageDrawHeight, (imageX + imageDrawWidth - getWidth())/(double)imageDrawWidth, (imageY + imageDrawHeight - getHeight())/(double)imageDrawHeight, -imageX/(double)imageDrawWidth);

// Apply the same constraints used in paint() method to ensure cropBox matches what's actually visible
int constrainedImageX = imageX;
int constrainedImageY = imageY;

if (imageDrawWidth > getInnerWidth()) {
constrainedImageX = Math.max(
Math.min(0, imageX),
-imageDrawWidth + getInnerWidth()
);
}

if (imageDrawHeight > getInnerHeight()) {
constrainedImageY = Math.max(
Math.min(0, imageY),
-imageDrawHeight + getInnerHeight()
);
}

cropBox.set(-constrainedImageY/(double)imageDrawHeight, (constrainedImageX + imageDrawWidth - getWidth())/(double)imageDrawWidth, (constrainedImageY + imageDrawHeight - getHeight())/(double)imageDrawHeight, -constrainedImageX/(double)imageDrawWidth);
}

/**
Expand Down