progressbar.monkey2 918 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. Namespace mojox
  2. #rem monkeydoc The ProgressBar class.
  3. #end
  4. Class ProgressBar Extends View
  5. #rem monkeydoc Creates a new progress bar.
  6. #end
  7. Method New( fps:Int=15,speed:Float=2 )
  8. Style=GetStyle( "ProgressBar" )
  9. Activated+=Lambda()
  10. _timer=New Timer( fps,Lambda()
  11. _scroll+=speed
  12. RequestRender()
  13. End )
  14. End
  15. Deactivated+=Lambda()
  16. _timer.Cancel()
  17. End
  18. End
  19. Protected
  20. Method OnMeasure:Vec2i() Override
  21. Local icon:=RenderStyle.Icons[0]
  22. Return icon.Rect.Size
  23. End
  24. Method OnRender( canvas:Canvas ) Override
  25. Local icon:=RenderStyle.Icons[0]
  26. Local w:=icon.Width
  27. Local h:=icon.Height
  28. Local color:=canvas.Color
  29. canvas.Color=RenderStyle.IconColor
  30. _scroll=_scroll Mod w
  31. For Local x:=_scroll-w+1 Until Width Step w
  32. canvas.DrawRect( x,0,w,Height,icon )
  33. Next
  34. canvas.Color=color
  35. End
  36. Private
  37. Field _timer:Timer
  38. Field _scroll:Float
  39. End