r81, r82: problem checking if viewport in-bounds on right and lower edges:
I don't know if this is a bug or my inexperience with this system, but...
The intention of my capx is to create an in-browser RTS game with left-mouse click-drag for panning, and scroll-wheel zooming, and it is currently a working background with pan and zoom.
I have working zoom and pan, and with only the need to 'stay in bounds' of the layout being the problem, so when drag-panning, the view-port size/position must be compared to the bounds of the layout, and also while zooming out, the same checks must occur. For reasons explained below, this manual check for bounds must be done. (All is much clearer in the attached capx.)
RTS pan-zoom test
Zoom out code works: Since while zooming out, scrollX & scrollY are presumably in-bounds at the beginning, but as the view-port 'grows' actual scrollX (mid-point of the view-port) ends up closer to the edge of the layout, and it can be possible to see the edge of the layout at full zoom-out, so each mouse-wheel-up event checks scrollX and scrollY, and forces the view-port back in-bounds if necessary. Works.
During the scrolling, the mouse is dragging the layout left, or actually the view-port to the right. Here, I started out trying to compare the value that is 'about' to be applied to see if it is in-bounds, and then only apply values to scrollX & scrollY that are in-bounds. Works on the left and upper bounds, but not the lower and right bounds. The only workaround is to just go ahead an apply the value regardless, THEN do the checks in the same way as the zoom-out code does, comparing the actual scrollX & scrollY values to see if they have gotten out of bounds, and THEN forcing them back in again.
Finally, all attempts to use both zooming and the Unbounded scrolling : OFF feature were a failure. EVEN with the workaround in place where the code appears to keep the view-port in-bounds at all times, if Unbounded scrolling is set to NO, very weird interactions occur when zoomed out (about 0.3 to 0.1 scaling). When zoomed at 1.0 or near to it, the auto-bounds is fine.
So to recap:
With the initial method, the view-port can be dragged infinitely to the right or down, but the upper and left bounds work fine. If out of bounds to the right or bottom, the moment the zoom-out code is triggered, it is forced back in-bounds, as checking against scrollX works fine.