Guest User

Progress Bar

a guest
Jan 31st, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. function RGB(r,g,b){ return (0xff000000|(r<<16)|(g<<8)|(b)); }
  2.  
  3. var font = gdi.Font("ProggyTinyTTSZ", 16, 0);
  4. var g_drag = 0;
  5.  
  6. var color =
  7. {
  8. background: RGB(34, 34, 34),
  9. frame: RGB(27, 27, 27),
  10. //progress: RGB(143, 99, 153), // DARK.COLOR.1
  11. progress: RGB(26,187,201),
  12. //proghead: RGB(9, 226, 229) // LIGHT.COLOR.2
  13. proghead: RGB(221, 221, 221)
  14. };
  15.  
  16. var barChar =
  17. {
  18. back: "▓",
  19. body: "█",
  20. head: "▌"
  21. };
  22.  
  23. function on_paint(e)
  24. {
  25. e.SetTextRenderingHint(1);
  26.  
  27. var ww = window.Width,
  28. wh = window.Height,
  29. pos = ww * fb.PlaybackTime / (fb.PlaybackLength == 0 ? 1 : fb.PlaybackLength),
  30. background = barChar.back,
  31. progress = barChar.body,
  32. bgWidth = e.MeasureString(barChar.back, font, 0, 0, ww, wh).Width,
  33. bodyWidth = e.MeasureString(barChar.body, font, 0, 0, ww, wh).Width;
  34. headWidth = e.MeasureString(barChar.head, font, 0, 0, ww, wh).Width;
  35.  
  36. // generate background string
  37. for (var i = 0, MAX = Math.ceil(ww / bgWidth); i < MAX; i++)
  38. background += barChar.back;
  39.  
  40. // generate progress string
  41. if (pos > 10)
  42. for (var i = 0, MAX = Math.floor((pos - headWidth) / bodyWidth); i < MAX; i++)
  43. progress += barChar.body;
  44. else
  45. progress = "";
  46.  
  47. // Draw frame background
  48. e.FillSolidRect(0, 0, ww, wh, color.frame);
  49.  
  50. // Draw the background
  51. e.DrawString(background, font, color.background, 0, 2, ww+10, wh);
  52.  
  53. // Draw the progress head
  54. if (pos > 0)
  55. e.DrawString(barChar.head, font, color.proghead,Math.floor((pos - headWidth) / bodyWidth) * bodyWidth + (headWidth - 4), 2, ww, wh);
  56.  
  57. // Draw the progress
  58. e.DrawString(progress, font, color.progress, 0, 2, ww, wh);
  59. }
  60.  
  61. function on_mouse_lbtn_down(x, y)
  62. {
  63. g_drag = 1;
  64. }
  65.  
  66. function on_mouse_lbtn_up(x, y)
  67. {
  68. on_mouse_move(x,y);
  69. g_drag = 0;
  70. }
  71.  
  72. function on_mouse_move(x, y)
  73. {
  74. if (g_drag)
  75. fb.PlaybackTime = x / window.Width * fb.PlaybackLength;
  76. }
  77.  
  78. function on_mouse_wheel(delta)
  79. {
  80. fb.PlaybackTime += delta;
  81. }
  82.  
  83. function on_mouse_mbtn_down(x, y) {
  84. fb.PlayOrPause();
  85. }
  86.  
  87. function on_playback_seek()
  88. {
  89. window.Repaint();
  90. }
  91.  
  92. function on_playback_time()
  93. {
  94. window.Repaint();
  95. }
  96.  
  97. function on_playback_stop()
  98. {
  99. window.Repaint();
  100. }
Advertisement
Add Comment
Please, Sign In to add comment