MaxGUI menu over a canvas

BlitzMax Forums/BlitzMax Beginners Area/MaxGUI menu over a canvas

Idiot(Posted 2005) [#1]
I've noticed when a menu overlaps a canvas it doesn't erase itself until no menu item is selected. For example, if you have a File and Help menu and click file, then go over to Help, the File menu isn't erased on the canvas. This is on Windows (not sure if it happens on Mac or Linux).

Is there a way to get around this?


Idiot(Posted 2005) [#2]
Example:

Const MENU_EXIT=105
Const MENU_ABOUT=109

Local win:TGadget = CreateWindow("WINDOW",300,300,700,500,0,WINDOW_TITLEBAR|WINDOW_MENU|WINDOW_STATUS|WINDOW_CLIENTCOORDS)

Local can:TGadget = CreateCanvas(0,0,700,500,win,1)
SetGadgetLayout can,1,1,1,1

' create menu
Local filemenu:TGadget = CreateMenu("&File",0,WindowMenu(win))
CreateMenu"E&xit",MENU_EXIT,filemenu

Local helpmenu:TGadget = CreateMenu("&Help",0,WindowMenu(win))
CreateMenu "&About",MENU_ABOUT,helpmenu

UpdateWindowMenu win

Local timer = CreateTimer (10)
' Main loop
While WaitEvent()
	Select EventID()
		Case EVENT_TIMERTICK
			updateCanvas(can)
		'	Print "Tick!"
		Case EVENT_WINDOWCLOSE
			'
			' Quit
			End
		
		Case EVENT_MENUACTION
			'
			' Menu stuff
			Select EventData()
				Case MENU_EXIT
					End
				Case MENU_ABOUT
					Notify "A WINDOW!~nBy IDIOT"
			End Select
		
		Default
			'
			' Uncomment this to show what other events occur
			' Print CurrentEvent.toString()
					
	EndSelect
Wend

Function updateCanvas(can:TGadget)
	'
	' Draw to the canvas
	SetGraphics CanvasGraphics(can)
				
	'
	' Make sure it has the correct dimensions
	SetViewport 0,0,GadgetWidth(can),GadgetHeight(can)
	
	SetBlend SOLIDBLEND
	
	Cls
	
	Flip
End Function




WendellM(Posted 2005) [#3]
I was able to fix this by splicing in portions of Shagwana's event hook example. It involved three changes: making Can global, putting in an AddHook before the main loop, and adding an EventHook function:


This also keeps the About box from leaving a trail when you drag it around. I guess it's time for me to start using event hooks, myself - they look mighty handy. :)


Idiot(Posted 2005) [#4]
Works perfectly, thanks!