Redrawing during window move/size?

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

It would be nice to be able to do stuff while a window is being resized or moved, so that I can re-draw viewports while they are being sized. Is this possible?

Yes, see the RedrawGadget example and if you haven't done so please read Help->Tutorials->MaxGUIOverview.

Is it possible to make panel gadgets detect a GADGET_PAINT event?

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



Nice! It works perfectly with an OpenGL viewport created on a panel.

What if the viewport gets corrupted by dragging something over it? Panels don't produce gadgetpaint events. Detecting a WindowMove event won't work for this.

In PureBasic, I had to do something like this:
Procedure SubclassProc(hWnd,Mesg,wParam,lParam)
If mesg=#WM_PAINT
;Repaint the window
EndIf
AddMessage(mess,hWnd,wParam,lParam)
ProcedureReturn CallWindowProc_(oldProc,hWnd,Mesg,wParam,lParam)
EndProcedure




If I understood your problem right you could do it this way:

SuperStrict

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

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
		ElseIf EventID() = EVENT_MOUSEDOWN
			Sus=True
			RequestFile("Load")
			Sus=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 Or Sus=True
		SetViewport 0, 0, ClientWidth(Canvas), ClientHeight(Canvas)
		Draw()
	End If
	
	Event=Null
	Return data
End Function


To get the file requester just click on the canvas.

I just added a Sus variable and also set the if statement in the hook function to run if Sus = True. If you set Sus to true before you open the requestor and set it to false afterwards it works. There might be a better way but this seems to work fine for me.

Use a Canvas not a Panel.

I'll try a canvas. In BlitzPlus, canvases were not good for OpenGL viewports.

I also found the solution for panels. This is really nice because I don't have to have a bunch of extra render calls in every waitevent() loop:

Extern "Win32"
	Function SetWindowLong(hwnd:Int,index:Int,newlong:Int) = "SetWindowLongA@12"
	Function CallWindowProc:Int(prevwndfunc:Int,hwnd:Int,msg:Int,wparam:Byte Ptr,lparam:Byte Ptr) = "CallWindowProcA@20"
EndExtern

Const GWL_WNDPROC=-4
Const WM_PAINT=15

hwnd=QueryGadget(Viewport.panel,QUERY_HWND)
Global OldWindowCallback=SetWindowLong(hwnd,GWL_WNDPROC,Int(Byte Ptr(WindowCallback)))

Function WindowCallback(hwnd,msg,wparam:Byte Ptr,lparam:Byte Ptr) "win32"
	Select msg
		Case WM_PAINT
			renderworld
			sync
	EndSelect
	Return CallWindowProc(OldWindowCallback,hwnd,msg,wparam,lparam)
End Function


Well, BlitzMax canvases don't seem to have the problems BlitzPlus canvases did, so it looks like they are fine for OpenGL viewports.

Thanks for the tips. This is the greatest programming language ever.