resizewindow.monkey2 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #rem
  2. Use enter to toggle fullscreen, arrow keys to move window, +shift to size!
  3. #end
  4. Namespace myapp
  5. #Import "<std>"
  6. #Import "<mojo>"
  7. Using std..
  8. Using mojo..
  9. Class MyWindow Extends Window
  10. Field _ticks:=0
  11. Field _time:Double
  12. Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )
  13. Super.New( title,width,height,flags|WindowFlags.Resizable|WindowFlags.HighDPI )
  14. End
  15. Method OnRender( canvas:Canvas ) Override
  16. RequestRender()
  17. If Keyboard.KeyHit( Key.Enter )
  18. If Fullscreen EndFullscreen() Else BeginFullscreen()
  19. Else If Keyboard.KeyDown( Key.LeftShift )
  20. If Keyboard.KeyDown( Key.Left )
  21. ResizeWindow( Frame.X-1,Frame.Y,Frame.Width+2,Frame.Height )
  22. Else If Keyboard.KeyDown( Key.Right )
  23. ResizeWindow( Frame.X+1,Frame.Y,Frame.Width-2,Frame.Height )
  24. Else If Keyboard.KeyDown( Key.Up )
  25. ResizeWindow( Frame.X,Frame.Y-1,Frame.Width,Frame.Height+2 )
  26. Else If Keyboard.KeyDown( Key.Down )
  27. ResizeWindow( Frame.X,Frame.Y+1,Frame.Width,Frame.Height-2 )
  28. Endif
  29. Else
  30. If Keyboard.KeyDown( Key.Left )
  31. ResizeWindow( Frame.X-1,Frame.Y,Frame.Width,Frame.Height )
  32. Else If Keyboard.KeyDown( Key.Right )
  33. ResizeWindow( Frame.X+1,Frame.Y,Frame.Width,Frame.Height )
  34. Else If Keyboard.KeyDown( Key.Up )
  35. ResizeWindow( Frame.X,Frame.Y-1,Frame.Width,Frame.Height )
  36. Else If Keyboard.KeyDown( Key.Down )
  37. ResizeWindow( Frame.X,Frame.Y+1,Frame.Width,Frame.Height )
  38. Endif
  39. Endif
  40. canvas.DrawText( "Hello World! Ticks="+_ticks+" FPS="+App.FPS,Width/2,Height/2,.5,.5 )
  41. End
  42. End
  43. Function Main()
  44. New AppInstance
  45. New MyWindow
  46. App.Run()
  47. End