GUI: window resizing will scale contents?

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

Is it possible using MaxGUI to program so that resizing the window will scale contents that are being drawn to it's canvas?

Local Res_W:Int = 320
local Res_H:Int = 240

SetViewport(0,0,GraphicsWidth(),GraphicsHeight())
glLoadIdentity 
glScalef(Float(GraphicsWidth())/Float(Res_W),Float(GraphicsHeight())/Float(Res_H),1)
		


That helpfull? Just stick Res_W and Res_H to the width and height you created your canvas with, and run it each time the window is resized.

The short answer is no.

The long answer is that it is possible to detect the resizing event, you will then need to resize the contents yourself using scaling factors

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


Thanks

My worries are that this approach will not be fast enough to do every frame?

This was done as standard in B+, why is it so difficult in BMX?

It is not difficult.
You simply have to change the setscale according the new canvas size, that are 2 simple calculations (width / original_width , height / original_height)
Can't see why this should be a problem as it is a regular state setting.