Advertisement
ExtremeHunter

Spinning Disc Image Viewer (Jan 24, 2013)

Jan 24th, 2013
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ================================================== //
  2. // @name "Spinning Disc Image Viewer  (Jan 24, 2013)"
  3. // @author "eXtremeHunter"
  4. // ================================================== //
  5. function RGB(r, g, b) {
  6.     return (0xff000000 | (r << 16) | (g << 8) | (b));
  7. }
  8. window.DlgCode = 0x0001; // arrow keys for DUI
  9.  
  10. var defaultDisc = gdi.Image(fb.FoobarPath + "images\\disc.jpg");
  11. var margin = window.GetProperty("Margin", 50);
  12. var zoomStep = window.GetProperty("Zoom Step", 30);
  13. var useDiscMask = window.GetProperty("Use Disc Mask", true);
  14.  
  15. var angle = 0;
  16. var minSize = 20;
  17. var disc = defaultDisc;
  18. var rotationInterval = 50;
  19. var rotationTimer;
  20. var rotationTimerStarted = false;
  21. // ============================== //
  22. function on_paint(gr) {
  23.  
  24.     gr.FillGradRect(0, 0, ww, wh, 65, RGB(50, 50, 50), RGB(105, 105, 105), 0.5);
  25.  
  26.     disc && gr.DrawImage(resizedDisc, discX, discY, discW, discH, 0, 0, resizedDisc.Width, resizedDisc.Height, angle);
  27.  
  28. }
  29. // ============================== //
  30. function on_mouse_wheel(step) {
  31.  
  32.     if (utils.IsKeyPressed(16)) {
  33.  
  34.         if (step == -1 && discW <= minSize) return;
  35.  
  36.         var s = step * zoomStep;
  37.         margin = margin -= s;
  38.         window.SetProperty("Margin", margin);
  39.         on_size();
  40.  
  41.         window.Repaint();
  42.  
  43.     }
  44.  
  45. }
  46. // ============================== //
  47. function on_key_down(vkey) {
  48.  
  49.     if (vkey == 38) on_mouse_wheel(1) //UP ARROW
  50.     if (vkey == 40) on_mouse_wheel(-1); //DOWN ARROW
  51.  
  52. }
  53. // ============================== //
  54. function on_size() {
  55.  
  56.     ww = window.Width;
  57.     wh = window.Height;
  58.  
  59.     discW = Math.max(minSize, ww - margin);
  60.     discH = Math.max(minSize, wh - margin);
  61.  
  62.     if (discH < discW) discW = discH;
  63.     else if (discW < discH) discH = discW;
  64.  
  65.     discX = ww / 2 - discW / 2;
  66.     discY = wh / 2 - discH / 2;
  67.  
  68.     resizedDisc = disc.resize(discW, discH);
  69.  
  70.     if (useDiscMask) {
  71.  
  72.         var discMask = gdi.CreateImage(discW, discH);
  73.         var g = discMask.GetGraphics();
  74.         g.FillSolidRect(0, 0, discW, discH, 0xffffffff);
  75.         g.SetSmoothingMode(2);
  76.         g.FillEllipse(1, 1, discW - 2, discH - 2, 0xff000000);
  77.         discMask.ReleaseGraphics(g);
  78.         resizedDisc.ApplyMask(discMask);
  79.         discMask.Dispose();
  80.  
  81.     }
  82.  
  83. }
  84. // ============================== //
  85. (function onRotationTimer() {
  86.  
  87.     getDiscImage();
  88.  
  89.     if (!fb.IsPlaying || fb.IsPaused) {
  90.         return;
  91.     }
  92.  
  93.     if (!rotationTimerStarted) {
  94.  
  95.         rotationTimer = window.SetInterval(function () {
  96.  
  97.             if (angle >= 360) angle = 0;
  98.             angle += 10;
  99.             (discW >= ww || discH >= wh) ? window.Repaint() : window.RepaintRect(discX, discY, discW, discH);
  100.  
  101.         }, rotationInterval);
  102.  
  103.         rotationTimerStarted = true;
  104.     }
  105.  
  106. })();
  107. // ============================== //
  108. function stopRotationTimer() {
  109.  
  110.     window.ClearInterval(rotationTimer);
  111.     rotationTimerStarted = false;
  112.  
  113. }
  114. // ============================== //
  115. function on_playback_stop(reason) {
  116.  
  117.     if (reason != 2) {
  118.         stopRotationTimer();
  119.         getDiscImage();
  120.     }
  121. }
  122. // ============================== //
  123. function on_playback_pause(state) {
  124.  
  125.     state ? stopRotationTimer() : onRotationTimer();
  126.  
  127. }
  128. // ============================== //
  129. function on_playback_new_track() {
  130.  
  131.     onRotationTimer();
  132.  
  133. }
  134. // ============================== //
  135. var tempAlbum;
  136.  
  137. function getDiscImage() {
  138.  
  139.     if (!plman.PlaylistItemCount(plman.ActivePlaylist)) return;
  140.  
  141.     var nowPlayingDisc;
  142.  
  143.     var metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
  144.    
  145.     if(!metadb) return;
  146.  
  147.     var currentAlbum = fb.TitleFormat("%album%").EvalWithMetadb(metadb);
  148.  
  149.     if (currentAlbum == tempAlbum) return;
  150.  
  151.         nowPlayingDisc = utils.GetAlbumArtV2(metadb, 2);
  152.  
  153.         nowPlayingDisc ? disc = nowPlayingDisc : disc = defaultDisc;
  154.  
  155.         tempAlbum = currentAlbum;
  156.  
  157.     on_size();
  158.     window.Repaint();
  159.  
  160. }
  161. // ============================== //
  162. function on_selection_changed(metadb) {
  163.     if (!fb.IsPlaying) getDiscImage();
  164. }
  165. // ============================== //
  166. function on_playlist_items_removed() {
  167.  
  168.     if (!plman.PlaylistItemCount(plman.ActivePlaylist)) disc = defaultDisc;
  169.     on_size();
  170.     window.Repaint();
  171.  
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement