Root cause of the scrolling issue when the image is zoomed in. There are two main problems:
Problem 1: Fixed scroll step sizes
The scroll step values (::nVStep and ::nHStep) are initialized to 1 and never scale with the zoom level. When you zoom in (e.g., nZoom = 2 or 3), the image dimensions increase proportionally, but the scroll step remains at 1 pixel, making scrolling extremely slow.
Problem 2: Incorrect bounds in scroll handlers
In the VScroll() and HScroll() methods, the SB_BOTTOM case sets ::nX = ::nXExtra() and ::nY = ::nYExtra(), but everywhere else in the code treats the lower bound as negative (-::nXExtra() and -::nYExtra()). This sign inconsistency prevents reaching the true end of the image.
Solution:
You need to make three changes in bitmap.prg:
1. Scale scroll steps with zoom - Modify the ScrollAdjust() method (around line 1072) to set the step sizes based on zoom:
METHOD ScrollAdjust() CLASS TBitmap
local nVisHeight, nVisWidth
local lHor := .f., lVer := .f.
nVisHeight = ::Super:nHeight()
nVisWidth = ::Super:nWidth()
// Add these lines to scale steps with zoom:
::nVStep := Max( 1, Int( ::nZoom ) )
::nHStep := Max( 1, Int( ::nZoom ) )
if ::lScroll .and. ! Empty( ::hBitmap ) .and. ::oVScroll != nil
// ... rest of the method unchanged
2. Fix the vertical scroll end position - In the VScroll() method (around line 1008), change:
case nScrollCode == SB_BOTTOM
::nX := -::nXExtra() // Changed from ::nX = ::nXExtra()
::oVScroll:GoBottom()
::Refresh( .f. )
3. Fix the horizontal scroll end position - In the HScroll() method (around line 1054), change:
case nScrollCode == SB_BOTTOM
::nY := -::nYExtra() // Changed from ::nY = ::nYExtra()
::oHScroll:GoBottom()
::Refresh( .f. )
Optional Enhancement:
For even smoother scrolling, you could make the step size proportional to the visible area instead of just the zoom factor:
::nVStep := Max( 1, Int( ::Super:nHeight() / 10 ) )
::nHStep := Max( 1, Int( ::Super:nWidth() / 10 ) )
This would make each scroll step move approximately 10% of the visible area, which provides a better user experience regardless of zoom level.
These changes will allow the image to scroll properly to the end when zoomed in, with scroll steps that scale appropriately with the zoom level.