diff --git a/pixler.bas b/pixler.bas index 7c6b641..68a4c72 100644 --- a/pixler.bas +++ b/pixler.bas @@ -86,7 +86,7 @@ do oldheight=_height end if - cls ,backgroundcolor1 + cls,backgroundcolor1 ' Process all inputs and update offsets while _mouseinput:mw=mw+_mousewheel:wend @@ -125,7 +125,7 @@ do state.brushsize=state.brushsize+1 addcommand"brushsize ("+tst(state.brushsize)+")" case "-" - if state.brushsize>1 then + if state.brushsize>1 then state.brushsize=state.brushsize-1 addcommand"brushsize ("+tst(state.brushsize)+")" end if @@ -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" @@ -140,12 +157,12 @@ do case "l" showcommands=not showcommands 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 - 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 - redim _preserve commands(ubound(commands) + 1) as string - redraw + redim _preserve commands(ubound(commands)+1) as string + redraw end if end select