buggy zoom to fit.

This commit is contained in:
visionmercer 2026-05-27 22:43:07 +02:00
commit b5227d3af6

View file

@ -86,7 +86,7 @@ do
oldheight=_height oldheight=_height
end if end if
cls ,backgroundcolor1 cls,backgroundcolor1
' Process all inputs and update offsets ' Process all inputs and update offsets
while _mouseinput:mw=mw+_mousewheel:wend while _mouseinput:mw=mw+_mousewheel:wend
@ -133,6 +133,23 @@ do
state.zoom=1 state.zoom=1
state.offsetx=(_width/2)-(_width(layers(0).ihandle)/2) state.offsetx=(_width/2)-(_width(layers(0).ihandle)/2)
state.offsety=(_height/2)-(_height(layers(0).ihandle)/2) state.offsety=(_height/2)-(_height(layers(0).ihandle)/2)
case "f","F"
' --- ZOOM TO FIT ("f") OR OVERFLOW SHORTEST SIDE ("F") ---
' 1. Calculate and choose the fitting ratio based on the lowercase/uppercase state
if (((_width-(showtoolbox and 70)-(showcommands and 250)) \ _width(layers(0).ihandle))<((_height-(showcolorpicker and 20)) \ _height(layers(0).ihandle)) xor (keyin="F")) then
state.zoom=((_width-(showtoolbox and 70)-(showcommands and 250)) \ _width(layers(0).ihandle))
else
state.zoom=((_height-(showcolorpicker and 20)) \ _height(layers(0).ihandle))
end if
' 2. Clamp the zoom factor within safe limits (1 to 20)
if state.zoom<1 then state.zoom=1 else if state.zoom>20 then state.zoom=20
' 3. Center the canvas inside the viewport (overflowing sides will center-clip perfectly)
state.offsetx=(showtoolbox and 70)+(((_width-(showtoolbox and 70)-(showcommands and 250)) \ 2)-((_width(layers(0).ihandle)*state.zoom) \ 2))
state.offsety=(((_height-(showcolorpicker and 20)) \ 2)-((_height(layers(0).ihandle)*state.zoom) \ 2))
case "t" case "t"
showtoolbox=not showtoolbox showtoolbox=not showtoolbox
case "c" case "c"
@ -140,11 +157,11 @@ do
case "l" case "l"
showcommands=not showcommands showcommands=not showcommands
case chr$(26) ' Ctrl+Z case chr$(26) ' Ctrl+Z
if ubound(commands) > 3 then if ubound(commands)>3 then
' Drop the trailing empty slot and the last valid command ' Drop the trailing empty slot and the last valid command
redim _preserve commands(ubound(commands) - 2) as string redim _preserve commands(ubound(commands)-2) as string
' Re-create the empty trailing slot required by addcommand ' Re-create the empty trailing slot required by addcommand
redim _preserve commands(ubound(commands) + 1) as string redim _preserve commands(ubound(commands)+1) as string
redraw redraw
end if end if
end select end select