GUI: window resizing will scale contents?

BlitzMax Forums/BlitzMax Programming/GUI: window resizing will scale contents?

Here's an example which scales a single image to fill the canvas area.
It uses SetViewport and SetScale so you need to ensure you reset these if you have other drawing operations:
AppTitle$="Canvas - Scale image to window"

Const winstyle%=WINDOW_TITLEBAR|WINDOW_RESIZABLE
Global win:TGadget=CreateWindow(AppTitle$, 80, 50, 256, 256 ,Null,winstyle)
Global can:TGadget=CreateCanvas(0,0,win.ClientWidth(),win.ClientHeight(),win)
SetGadgetLayout can,1,1,1,1
SetMinWindowSize win,96,96
RedrawGadget can

Global img:TImage=LoadImage("testimage.png")
If Not img End

Repeat
'	DebugLog currentevent.ToString()
	Select WaitEvent()
		Case EVENT_GADGETPAINT
		DrawImageToCanvas img,can
		Case EVENT_WINDOWCLOSE
		Exit
	End Select
Forever

End

' draw an image scaled to fill the canvas
Function DrawImageToCanvas(i:TImage,c:TGadget)
	SetGraphics CanvasGraphics(c)
	SetViewport 0,0,c.Width,c.Height
	Local sx#=Float(c.ClientWidth())/Float(i.Width)
	Local sy#=Float(c.ClientHeight())/Float(i.Height)
	Cls
	SetScale sx,sy
	DrawImage i,0,0
	Flip
End Function