buggy zoom to fit.

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

View file

@ -133,6 +133,23 @@ do
state.zoom=1
state.offsetx=(_width/2)-(_width(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"
showtoolbox=not showtoolbox
case "c"