canvas & menu & animation not cooperating.

BlitzMax Forums/BlitzMax GUI Programming/canvas & menu & animation not cooperating.

Is ther a way to have canvas, working correctly while animating.

I am trying to adopt the code from this thread:
http://www.blitzmax.com/Community/posts.php?topic=78597#881924
it doesn't seem to work with animation.
If I change the hook to a timer it does not update the menu properly as in the mentioned thread. Is there a way to solve this problem? I did a forum search and I couldn't find anything to help me.
Any help would be appreciated.


this is the original code with animation included:
Import MaxGui.Drivers
SuperStrict
Local Style:Int = WINDOW_TITLEBAR | WINDOW_MENU  | WINDOW_CLIENTCOORDS

Local MyWindow:TGadget
Local filemenu:TGadget
Local editmenu:TGadget
Local helpmenu:TGadget

Global canvas:TGadget

MyWindow=CreateWindow("Max GUI App.", 112,84,800,600,Null,Style)

filemenu=CreateMenu("&File          ",0,WindowMenu(MyWindow))
CreateMenu "&New",101,filemenu,KEY_N,MODIFIER_COMMAND
CreateMenu "&Open file",102,filemenu,KEY_O,MODIFIER_COMMAND
CreateMenu "&Close file",103,filemenu,KEY_C,MODIFIER_COMMAND
CreateMenu"",0,filemenu
CreateMenu "&Save",104,filemenu,KEY_S,MODIFIER_COMMAND
CreateMenu"",0,filemenu
CreateMenu "&Open bitmap image",105,filemenu,KEY_I,MODIFIER_COMMAND
CreateMenu"",0,filemenu
CreateMenu "&Exit",106,fileMenu,KEY_F4,MODIFIER_COMMAND

editmenu=CreateMenu("&Edit          ",0,WindowMenu(MyWindow))
CreateMenu "Cu&t",107,editmenu,KEY_X,MODIFIER_COMMAND
CreateMenu "&Copy",108,editmenu,KEY_C,MODIFIER_COMMAND
CreateMenu "&Paste",109,editmenu,KEY_V,MODIFIER_COMMAND

helpmenu=CreateMenu("&Help          ",0,WindowMenu(MyWindow))
CreateMenu "&About",110,helpmenu

canvas=CreateCanvas(0,0,800,640,MyWindow)

UpdateWindowMenu MyWindow

AddHook EmitEventHook , MyHook

While True
	WaitEvent 
	Select EventID()
		Case EVENT_MENUACTION
			Select EventData()
			
				Case 106
					End

				Case 110
					Notify "About stuff here"
			End Select
	End Select
Wend

Function MyHook:Object(iId:Int,tData:Object,tContext:Object)
	Local Event:TEvent=TEvent(tData)
  	If event = Null Return Null
	
	If (Event.ID = EVENT_GADGETPAINT) Or (Event.ID = EVENT_WINDOWSIZE) Or (Event.ID = EVENT_WINDOWMOVE) Or (Event.ID = Event_AppResume) Then 
		'ReDraw the canvas when requested (GadgetPaint) or when the window was moved, sized, resumed..
		ReDraw()
	End If
	
	Return tData
End Function

Function ReDraw() 
	'Call the ReDraw every time you want to update the canvas
	SetGraphics CanvasGraphics (canvas)
	SetViewport 0,0,GadgetWidth(canvas),GadgetHeight(canvas)
	Cls
	Local t:Long=MilliSecs()/100
	DrawLine 400,300,400+120*Cos(t),300+120*Sin(t)
	DrawLine 400,300,400+80*Cos(t/60),300+80*Sin(t/60)
	Flip
End Function


but does not work

If I add the timer, and include EVENT_TIMERTICK in the event-hook processing, then everything seems to work fine over here...

SuperStrict
Import MaxGui.Drivers

AppTitle = "MaxGUI Application"

Local MyWindow:TGadget = CreateWindow(AppTitle,112,84,800,600,Null,WINDOW_TITLEBAR|WINDOW_MENU|WINDOW_CLIENTCOORDS)

Local filemenu:TGadget = CreateMenu("&File",0,WindowMenu(MyWindow))
CreateMenu "&New",101,filemenu,KEY_N,MODIFIER_COMMAND
CreateMenu "&Open file",102,filemenu,KEY_O,MODIFIER_COMMAND
CreateMenu "&Close file",103,filemenu,KEY_C,MODIFIER_COMMAND
CreateMenu "",0,filemenu
CreateMenu "&Save",104,filemenu,KEY_S,MODIFIER_COMMAND
CreateMenu "",0,filemenu
CreateMenu "&Open bitmap image",105,filemenu,KEY_I,MODIFIER_COMMAND
CreateMenu "",0,filemenu
CreateMenu "&Exit",106,fileMenu,KEY_F4,MODIFIER_COMMAND

Local editmenu:TGadget = CreateMenu("&Edit",0,WindowMenu(MyWindow))
CreateMenu "Cu&t",107,editmenu,KEY_X,MODIFIER_COMMAND
CreateMenu "&Copy",108,editmenu,KEY_C,MODIFIER_COMMAND
CreateMenu "&Paste",109,editmenu,KEY_V,MODIFIER_COMMAND

Local helpmenu:TGadget = CreateMenu("&Help",0,WindowMenu(MyWindow))
CreateMenu "&About",110,helpmenu

UpdateWindowMenu MyWindow

Global canvas:TGadget = CreateCanvas(0,0,800,640,MyWindow)
SetGraphics CanvasGraphics (canvas)

AddHook EmitEventHook, MyHook

CreateTimer(100)

Repeat
	Select WaitEvent()
		Case EVENT_MENUACTION
			Select EventData()
				Case 106
					End
				Case 110
					Notify "About stuff here"
			End Select
	End Select
Forever

Function MyHook:Object(iId:Int,tData:Object,tContext:Object)
	Local Event:TEvent=TEvent(tData)
  	If event = Null Return Null
	
	Select event.id
		Case EVENT_TIMERTICK, EVENT_GADGETPAINT, EVENT_WINDOWMOVE, EVENT_APPRESUME
		'ReDraw the canvas when requested (GadgetPaint) or when the window was moved, sized, resumed..
			ReDraw()
		Case EVENT_WINDOWSIZE
			SetViewport 0,0,ClientWidth(canvas),ClientHeight(canvas)
			ReDraw()
	EndSelect
	
	Return tData
End Function

Function ReDraw() 
	'Call ReDraw() every time you want to update the canvas
	Cls
	Local t:Long=MilliSecs()/100
	DrawLine 400,300,400+120*Cos(t),300+120*Sin(t)
	DrawLine 400,300,400+80*Cos(t/60),300+80*Sin(t/60)
	Flip
End Function


What OS are you on?

Thanks!, that did it!,
I don't know why but I can't figure this stuff out. I tried like crazy to figure it out on my own but I ended up posting about something simple yet unintuitive to me. The whole gui concept is new to me and has become a real challenge to learn. The real challeng to me is making the whole thing work together. I can use all of the functions sintax properly but I can't seem to figure out the hooks and timer thing. I went through Assari tutorials and I thought I understood them well But as he said on the canvas lesson:

This gadget actually deserves a whole series of tutorial by itself as it actually brings the whole power of Max2D with it.


Thanks Again, much appreciated.

By the way, I am using WIN XP SP2