#Import "<std>"
#Import "<mojo>"
 
Using std..
Using mojo..
 
 
Class AppWindow Extends Window
	Field UpdateTimer:Timer
	Field DisplayStatistics:Bool
	Field TakeScreenshot:Bool
	
	Method New()
		SwapInterval=0
		ClearColor = Color.Black
	End Method
	
	Method OnUpdate()
		If Keyboard.KeyReleased(Key.Escape) Then App.Terminate()
		If Keyboard.KeyDown(Key.LeftControl) Then
			If Keyboard.KeyPressed(Key.F) Then DisplayStatistics = Not DisplayStatistics
			If Keyboard.KeyPressed(Key.P) Then TakeScreenshot = True
		Endif
		App.RequestRender()
	End Method
		
	Method OnRender(Canvas:Canvas) Override
		OnUpdate()
		
		If (DisplayStatistics = True) Then
			Canvas.Color = Color.White
			Canvas.DrawText("FPS :"+App.FPS,0,0)
		Endif
		
		If (TakeScreenshot = True) Then
			TakeScreenshot = False
			Local Screenshot:Pixmap = Canvas.CopyPixmap(New Recti(0, 0, 640, 480))'Rect)
			Print SavePixmap(Screenshot, "test.png")
		Endif
	End Method	
	
End	Class
 
Function Main()
	New AppInstance	
	New AppWindow
	App.Run()
End Function