Advertisement
Guest User

WSH seekbar

a guest
Oct 26th, 2010
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // vi:set ft=javascript ff=dos ts=4 sts=4 sw=4 et:
  2.  
  3. // This is just a demo so is buggy.
  4. var g_theme = window.CreateThemeManager("PROGRESS");
  5. var g_bar_height = 15;
  6. var g_cycles = 0;
  7. var ww = 0,
  8.     wh = 0;
  9. var top = 0;
  10. var g_pos = 0;
  11. var g_drag = false;
  12. var g_length = 1;
  13.  
  14. function clamp(x, l, h) {
  15.     return (x < l) ? l : ((x > h) ? h : x);
  16. }
  17.  
  18.  
  19. function on_size() {
  20.     ww = window.Width;
  21.     wh = window.Height;
  22.     top = (wh - g_bar_height) >> 1;
  23. }
  24.  
  25. function on_paint(gr) {
  26.     g_theme.SetPartAndStateID(1, 0);
  27.     g_theme.DrawThemeBackground(gr, 0, top, ww, g_bar_height);
  28.  
  29.     if (fb.IsPlaying && g_length > 0) {
  30.         g_theme.SetPartAndStateID(5, fb.IsPaused ? 3 : 1);
  31.         g_theme.DrawThemeBackground(gr, 0, top, g_pos, g_bar_height);
  32.     }
  33. }
  34.  
  35. function on_mouse_lbtn_down(x, y) {
  36.     if (g_length > 0) {
  37.         g_drag = true;
  38.         on_mouse_move(x, y);
  39.     }
  40. }
  41.  
  42. function on_mouse_lbtn_up(x, y) {
  43.     if (g_length > 0 && g_drag) {
  44.         g_drag = false;
  45.         fb.PlaybackTime = g_length * g_pos / ww;
  46.         on_mouse_move(x, y);
  47.     }
  48. }
  49.  
  50. function on_mouse_move(x, y) {
  51.     if (g_drag) {
  52.         g_pos = clamp(x, 0, ww);
  53.         window.Repaint();
  54.     }
  55. }
  56.  
  57. function on_mouse_wheel(delta) {
  58.     fb.PlaybackTime = fb.PlaybackTime + delta * 2;
  59. }
  60.  
  61. function on_playback_time(time) {
  62.     if (!g_drag) {
  63.         if (g_length > 0) g_pos = ww * time / g_length;
  64.         window.Repaint();
  65.     }
  66. }
  67.  
  68. function on_playback_seek() {
  69.     if (!g_drag && g_length > 0) window.Repaint();
  70. }
  71.  
  72. function on_playback_pause() {
  73.     window.Repaint();
  74. }
  75.  
  76. function on_playback_stop() {
  77.     g_length = 0;
  78.     g_pos = 0;
  79.     g_drag = false;
  80.     window.Repaint();
  81. }
  82.  
  83. function on_playback_new_track() {
  84.     g_length = fb.PlaybackLength;
  85.     g_pos = 0;
  86.     g_drag = false;
  87.     window.Repaint();
  88. }
  89.  
  90. if (fb.IsPlaying) on_playback_new_track();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement