maxgui canvas refresh rate.

BlitzMax Forums/MaxGUI Module/maxgui canvas refresh rate.

hub(Posted 2009) [#1]
Hi !
Is there a way to fix the canvas refresh rate to 60 fps (for example). When the canvas is included into a maxgui window. (in my case inside a panel).

Thanks !


Brucey(Posted 2009) [#2]
Create a timer (on 60 FPS) and repaint the canvas on each tick.


hub(Posted 2009) [#3]
could you post a pseudo-code sample. i've already a timer in my code but not work as i want !


hub(Posted 2009) [#4]
i've this :



Local My_timer:TTimer=CreateTimer(60)

While WaitEvent()
	
	Select EventID()

	Case EVENT_TIMERTICK
		
	
		If EventSource() = Mon_timer Then
			RedrawGadget(Canvas_parametres_ennemi)
		End If
		
	Case EVENT_GADGETPAINT
	
		SetGraphics CanvasGraphics(Canvas_parametres_ennemi)
		...
		SetColor 255,255,255
		DrawText mx + "," + my, mx, my
		DrawOval mx-2, my-2,2,2					
		Flip
		RedrawGadget Canvas_parametres_ennemi

					

	End Select

Wend



Brucey(Posted 2009) [#5]
Something like this :

	Select EventID()
		Case EVENT_TIMERTICK
			RedrawGadget canvas

		Case EVENT_GADGETPAINT
			SetGraphics CanvasGraphics(canvas)
			SetOrigin 160,120
			SetLineWidth 5
			Cls
			Local t=MilliSecs()
			DrawLine 0,0,120*Cos(t),120*Sin(t)
			DrawLine 0,0,80*Cos(t/60),80*Sin(t/60)
			Flip



SebHoll(Posted 2009) [#6]
Does using an event hook for the EVENT_TIMERTICK event help?

Global tmrRepaint:TTimer = CreateTimer(60)

AddHook EmitEventHook, eventHook

While WaitEvent()
	Select EventID()
		Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE
			End
	EndSelect
Wend

Function eventHook:Object( pID:Int, pData:Object, pContext:Object )
	
	Local pEvent:TEvent = TEvent(pData)
	
	If pEvent Then
		
		Select pEvent.id
			Case EVENT_TIMERTICK
				If pEvent.source = tmrRepaint Then
					RedrawGadget(gadCanvas)
					Return Null
				EndIf
			Case EVENT_GADGETPAINT 'Blatant copy and pasting (thanks Brucey)
				SetGraphics CanvasGraphics(gadCanvas)
				SetOrigin 160,120
				SetLineWidth 5
				Cls
				Local t=MilliSecs()
				DrawLine 0,0,120*Cos(t),120*Sin(t)
				DrawLine 0,0,80*Cos(t/60),80*Sin(t/60)
				Flip
		EndSelect
		
	EndIf
	
	Return pData
	
EndFunction



hub(Posted 2009) [#7]
Thanks !