Zooms in by making the window bigger. If it can't be made bigger, then makes the source rectangle (srcRect) smaller and centers it on the position in the image where the cursor was when zooming has started. Note that sx and sy are screen coordinates.
(int sx, int sy)
| 890 | image where the cursor was when zooming has started. |
| 891 | Note that sx and sy are screen coordinates. */ |
| 892 | @AstroImageJ(reason = "increase zoom levels to 128 from 32", modified = true) |
| 893 | public void zoomIn(int sx, int sy) { |
| 894 | if (magnification>=128) return; |
| 895 | scaleToFit = false; |
| 896 | boolean mouseMoved = sqr(sx-lastZoomSX) + sqr(sy-lastZoomSY) > MAX_MOUSEMOVE_ZOOM*MAX_MOUSEMOVE_ZOOM; |
| 897 | lastZoomSX = sx; |
| 898 | lastZoomSY = sy; |
| 899 | if (mouseMoved || zoomTargetOX<0) { |
| 900 | boolean cursorInside = sx >= 0 && sy >= 0 && sx < dstWidth && sy < dstHeight; |
| 901 | zoomTargetOX = offScreenX(cursorInside ? sx : dstWidth/2); //where to zoom, offscreen (image) coordinates |
| 902 | zoomTargetOY = offScreenY(cursorInside ? sy : dstHeight/2); |
| 903 | } |
| 904 | double newMag = getHigherZoomLevel(magnification); |
| 905 | int newWidth = (int)(imageWidth*newMag); |
| 906 | int newHeight = (int)(imageHeight*newMag); |
| 907 | Dimension newSize = canEnlarge(newWidth, newHeight); |
| 908 | if (newSize!=null) { |
| 909 | setSize(newSize.width, newSize.height); |
| 910 | if (newSize.width!=newWidth || newSize.height!=newHeight) |
| 911 | adjustSourceRect(newMag, zoomTargetOX, zoomTargetOY); |
| 912 | else |
| 913 | setMagnification(newMag); |
| 914 | imp.getWindow().pack(); |
| 915 | } else // can't enlarge window |
| 916 | adjustSourceRect(newMag, zoomTargetOX, zoomTargetOY); |
| 917 | repaint(); |
| 918 | if (srcRect.width<imageWidth || srcRect.height<imageHeight) |
| 919 | resetMaxBounds(); |
| 920 | } |
| 921 | |
| 922 | /** Centers the viewable area on offscreen (image) coordinates x, y */ |
| 923 | void adjustSourceRect(double newMag, int x, int y) { |
no test coverage detected