Canvas Redraw - Menus/Requesters

BlitzMax Forums/BlitzMax GUI Programming/Canvas Redraw - Menus/Requesters

** Only tested on Win32 (and Max with latest gubbings) **


Issue
___________________________________________
Canvas does not redraw leaving menu and requester data visible


Reproducing the issue
___________________________________________
Run the code example
Open a menu and move across to different menus
The individual menus do not clear from the canvas area

Select a menu item
Move the Notify() requester around
Again, the canvas does not redraw to clear dialog



Other observations
___________________________________________
The menu/canvas redraw seems to work second time around
That is, the menus are cleared from the canvas after opening them again

The dialog box clears first time around when dragged. After that, the redraw issue kicks in

Same problems under Dx7/GL



' canvas redraw issues with requesters and menus

SuperStrict
Framework BRL.Win32MaxGUI
Import BRL.EventQueue


Import BRL.GLMax2D
SetGraphicsDriver GLMax2DDriver()
'Import BRL.D3D7Max2D
'SetGraphicsDriver D3D7Max2DDriver()


Global win:TGadget=CreateWindow("Canvas - menus/requesters",250,150,512,400,Null,15)
Global can:TGadget=CreateCanvas(10,10,win.Width-40,win.Height-40,win)

' create menus
Global MainMenu:TGadget=WindowMenu(win)
Global FileMenu:TGadget = CreateMenu("&File",  100, MainMenu)
Global EditMenu:TGadget = CreateMenu("&Edit",  200, MainMenu)
Global ToolMenu:TGadget = CreateMenu("&Tools", 300, MainMenu)
CreateMenu("New",					101, FileMenu)
CreateMenu("",						000, FileMenu)
CreateMenu("Open",					102, FileMenu)
CreateMenu("Save",					103, FileMenu)
CreateMenu("", 						000, FileMenu)
CreateMenu("Exit", 					105, FileMenu)
CreateMenu("Copy",					201, EditMenu)
CreateMenu("Paste",					202, EditMenu)
CreateMenu("Tool 1",				301, ToolMenu)
CreateMenu("Tool 2",				302, ToolMenu)
CreateMenu("Tool 3",				303, ToolMenu)
CreateMenu("Tool 4",				304, ToolMenu)
UpdateWindowMenu win

' ___________________________________________________
Repeat
	DebugLog CurrentEvent.ToString()
	Select WaitEvent()
		Case EVENT_WINDOWCLOSE , EVENT_APPTERMINATE
		Exit
		Case EVENT_MENUACTION
		Notify "Drag me around the canvas"
		Case EVENT_GADGETPAINT
		DrawCanvas
	End Select
Forever
End
' ___________________________________________________

Function DrawCanvas()
	SetGraphics CanvasGraphics(can)
	SetViewport 0,0,GraphicsWidth(),GraphicsHeight()
	Cls
	DrawLine 0,0,can.width,can.height
	DrawLine can.width,0,0,can.height
	Flip
End Function


You need to use an eventhook to manage events when windows sends your your program into a modal loop (menu selection, window dragging, scrollbar dragging etc.)

' canvas redraw issues with requesters and menus

SuperStrict
Framework BRL.Win32MaxGUI
Import BRL.EventQueue


Import BRL.GLMax2D
SetGraphicsDriver GLMax2DDriver()
'Import BRL.D3D7Max2D
'SetGraphicsDriver D3D7Max2DDriver()


Global win:TGadget=CreateWindow("Canvas - menus/requesters",250,150,512,400,Null,15)
Global can:TGadget=CreateCanvas(10,10,win.Width-40,win.Height-40,win)

' create menus
Global MainMenu:TGadget=WindowMenu(win)
Global FileMenu:TGadget = CreateMenu("&File",  100, MainMenu)
Global EditMenu:TGadget = CreateMenu("&Edit",  200, MainMenu)
Global ToolMenu:TGadget = CreateMenu("&Tools", 300, MainMenu)
CreateMenu("New",					101, FileMenu)
CreateMenu("",						000, FileMenu)
CreateMenu("Open",					102, FileMenu)
CreateMenu("Save",					103, FileMenu)
CreateMenu("", 						000, FileMenu)
CreateMenu("Exit", 					105, FileMenu)
CreateMenu("Copy",					201, EditMenu)
CreateMenu("Paste",					202, EditMenu)
CreateMenu("Tool 1",				301, ToolMenu)
CreateMenu("Tool 2",				302, ToolMenu)
CreateMenu("Tool 3",				303, ToolMenu)
CreateMenu("Tool 4",				304, ToolMenu)
UpdateWindowMenu win


AddHook EmitEventHook,myhook
While True
WaitEvent
Wend

' ___________________________________________________

Function myhook:Object(id%,data:Object,context:Object)
	Local event:TEvent
	event=TEvent(data)
	
	Select event.id
		Case EVENT_WINDOWCLOSE , EVENT_APPTERMINATE
			End
		Case EVENT_MENUACTION
			Notify "Drag me around the canvas"
		Case EVENT_GADGETPAINT
			DrawCanvas
	End Select
End Function

' ___________________________________________________

Function DrawCanvas()
	SetGraphics CanvasGraphics(can)
	SetViewport 0,0,GraphicsWidth(),GraphicsHeight()
	Cls
	DrawLine 0,0,can.width,can.height
	DrawLine can.width,0,0,can.height
	Flip
End Function


Thanks for the quick repsonse skid. I'll update my code to suit.