fwh_20.03\source\classes\bitmap.prg

Post Reply
yunbg1
Posts: 109
Joined: Sun Nov 13, 2005 12:40 am
Location: Winnipeg Canada

fwh_20.03\source\classes\bitmap.prg

Post by yunbg1 »

Hi everyone, I have a question.
And respected Antonio Linares

fwh_20.03\source\classes\bitmap.prg
::ScrollDown()
::ScrollUp()
::PageUp()
::PageDown()

When executing the above functions while the image is zoomed in,
they only move a small amount.
What should I change to allow the image to scroll to the end ?
Or, what is the solution?

FWH User
FWPPC User
FWLinux User
User avatar
Antonio Linares
Site Admin
Posts: 44515
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: fwh_20.03\source\classes\bitmap.prg

Post by Antonio Linares »

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:

Code: Select all | Expand

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:

Code: Select all | Expand

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:

Code: Select all | Expand

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:

Code: Select all | Expand

::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.

regards, saludos

Antonio Linares
www.fivetechsoft.com
yunbg1
Posts: 109
Joined: Sun Nov 13, 2005 12:40 am
Location: Winnipeg Canada

Re: fwh_20.03\source\classes\bitmap.prg

Post by yunbg1 »

Thank you so much, it was really helpful

FWH User
FWPPC User
FWLinux User
Post Reply