Redrawing during window move/size?

BlitzMax Forums/BlitzMax Programming/Redrawing during window move/size?

I had to do this in something I was making. Event Hooks have to be used. Here's a little example:

SuperStrict

Global Window:TGadget, Canvas:TGadget, Run:Byte=True

Window = CreateWindow("Test",100,100,300,300,Null)
Canvas = CreateCanvas(0,0,300,300,Window)
SetGadgetLayout Canvas, EDGE_RELATIVE, EDGE_ALIGNED, EDGE_RELATIVE, EDGE_ALIGNED

SetGraphics CanvasGraphics(Canvas)
SetClsColor 0,0,255

AddHook EmitEventHook, ResizeWindow


While Run
	
	If PollEvent()
		If EventID() = EVENT_WINDOWCLOSE
			Run=False
		End If
	End If
	
	Draw()
	
Wend

Function Draw()
	SetGraphics CanvasGraphics(Canvas)
	
	Cls
	
	SetColor 255,0,0
	DrawRect 10,20,50,70
	
	SetColor 0,255,0
	DrawOval 50,40,80,90
	
	Flip
	
End Function

Function ResizeWindow:Object(id:Int,data:Object,context:Object)
	Local Event:TEvent = TEvent(data)
	If Event.id = EVENT_WINDOWSIZE
		SetViewport 0, 0, ClientWidth(Canvas), ClientHeight(Canvas)
		Draw()
	End If
	Event=Null
	Return data
End Function