Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
1,171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==PREPROCESSOR==
  2. // @name "DarkOne4Mod - Cover Panel"
  3. // @version "1.0 build20160929"
  4. // @author "tedGo, includes partial code by T.P Wang"
  5. // @import "%fb2k_path%themes\DarkOne4Mod\Others\JScripts\DarkOne4Mod - Global Script.js"
  6. // ==/PREPROCESSOR==
  7.  
  8. // ----- VARIABLES -----
  9. var g_font = gdi.Font("Segoe UI", 50, 0);
  10. var g_img = descr_timer = cycle_timer = null;
  11. var g_active = false;
  12. var g_fade = 255;
  13. var g_state = 0;
  14. var metadb;
  15.  
  16. // ----- CREATE OPTIONS -----
  17. var a_arr = new Array("Picture 1", "Picture 2", "Picture 3", "Picture 4", "Picture 5");
  18. var b_arr = new Array("Front cover", "Back cover", "Disc", "Icon", "Artist");
  19.  
  20. function artType() {
  21.     at = window.GetProperty("Enable Custom Pictures", false);
  22.     c_arr = at ? a_arr : b_arr;
  23. }
  24.  
  25. artType();
  26.  
  27. function aspectRatio() {
  28.     ar = window.GetProperty("Aspect ratio", 0);
  29.     if (typeof ar < 0 || ar > 2) ar = 0;
  30.     return ar;
  31. }
  32.  
  33. aspectRatio();
  34.  
  35. // ----- GET PICTURE -----
  36. var a_img = gdi.Image(imgPath + "DarkOne.png");
  37. var b_img = gdi.Image(imgPath + "Radio.png");
  38. var c_img = gdi.Image(imgPath + "AudioCD.png");
  39. var d_img = gdi.Image(imgPath + "NoImage.png");
  40.  
  41. var e_arr = [];
  42. e_arr[0] = gdi.Image(imgPath + "NoFront.png");
  43. e_arr[1] = gdi.Image(imgPath + "NoBack.png");
  44. e_arr[2] = gdi.Image(imgPath + "NoDisc.png");
  45. e_arr[3] = gdi.Image(imgPath + "NoIcon.png");
  46. e_arr[4] = gdi.Image(imgPath + "NoArtist.png");
  47.  
  48. var f_arr = [];
  49. f_arr[0] = window.GetProperty(a_arr[0],"");
  50. f_arr[1] = window.GetProperty(a_arr[1],"");
  51. f_arr[2] = window.GetProperty(a_arr[2],"");
  52. f_arr[3] = window.GetProperty(a_arr[3],"");
  53. f_arr[4] = window.GetProperty(a_arr[4],"");
  54.  
  55. var g_ext = window.GetProperty("File extension order", "jpg|png|gif|bmp|tif");
  56. var g_arr = g_ext.split("|");
  57.  
  58. var g_art = null;
  59.  
  60. function getRightImage(switchstate) {
  61.     metadb = fb.GetNowPlaying();
  62.  
  63.     if (g_art) {
  64.         g_img.Dispose();
  65.         g_art = null;
  66.     }
  67.  
  68.     if (metadb) {
  69.         var f_img = null;
  70.         if (fb.PlaybackLength <= 0) {
  71.             f_img = b_img;
  72.             g_active = false;
  73.         } else if (metadb.RawPath.indexOf("cdda://") == 0) {
  74.             f_img = c_img;
  75.             g_active = false;
  76.         } else {
  77.             var old_state = g_state;
  78.             do {
  79.                 switchstate && switchState();
  80.                 if (at) {
  81.                     var arr = utils.Glob(fb.TitleFormat(f_arr[g_state]).Eval() + ".*").toArray();
  82.                     var g_break = false;
  83.                     for (var n = 0; n < g_arr.length && !g_break; n++) {
  84.                         for (var i = 0; i < arr.length; i++) {
  85.                             var re = new RegExp("\." + g_arr[n] + "$", "i");
  86.                             if (arr[i].match(re)) {
  87.                                 g_art = gdi.Image(arr[i]);
  88.                                 g_break = true;
  89.                                 break;
  90.                             }
  91.                         }
  92.                     }
  93.                     f_img = g_art;
  94.                 } else {
  95.                     g_art = utils.GetAlbumArtV2(metadb, g_state);
  96.                     f_img = g_art;
  97.                 }
  98.             }
  99.             while (switchstate && old_state != g_state && !f_img);
  100.             g_active = true;
  101.         }
  102.     } else {
  103.         f_img = a_img;
  104.         g_active = false;
  105.     }
  106.  
  107.     if (f_img) g_img = f_img;
  108.     else if (!switchstate) g_img = at ? d_img : e_arr[g_state];
  109.  
  110.     return g_img ? true : false;
  111. }
  112.  
  113. getRightImage(false);
  114.  
  115. // ----- CREATE ACTIONS -----
  116. function getTimer() {
  117.     if (descr_timer) {
  118.         window.ClearTimeout(descr_timer);
  119.         descr_timer = null;
  120.     }
  121.  
  122.     descr_timer = window.SetTimeout(
  123.         function () {
  124.             window.Repaint();
  125.             window.ClearTimeout(descr_timer);
  126.             descr_timer = null;
  127.         }, 1500);
  128.  
  129.     window.Repaint();
  130. }
  131.  
  132. function switchState() {
  133.     if (g_state == 4) g_state = 0;
  134.     else g_state++;
  135. }
  136.  
  137. function switchType() {
  138.     window.SetProperty("Enable Custom Pictures", at ? false : true);
  139.     artType();
  140.     g_state = 0;
  141.     getRightImage(false);
  142.     if (g_active && !g_art) getRightImage(true);
  143.     getTimer();
  144. }
  145.  
  146. // ----- CREATE MENU -----
  147. function CustomMenu(x, y) {
  148.     var a = window.CreatePopupMenu();
  149.     var b = window.CreatePopupMenu();
  150.     var idx;
  151.  
  152.     for (var i = 0; i < c_arr.length; i++) {
  153.         b.AppendMenuItem(0, 101 + i, c_arr[i]);
  154.     }
  155.     b.CheckMenuRadioItem(101, 105, g_state + 101);
  156.  
  157.     a.AppendMenuItem(0, 1, "Keep aspect ratio");
  158.     a.AppendMenuItem(0, 2, "Noexpansion");
  159.     a.AppendMenuItem(0, 3, "Stretch");
  160.     a.CheckMenuRadioItem(1, 3, ar + 1);
  161.     a.AppendMenuSeparator();
  162.     a.AppendMenuItem(0, 4, at ? "Album art" : "Custom pictures");
  163.     a.AppendMenuSeparator();
  164.     !ac && b.AppendTo(a, 0 | 16, at ? "Pictures" : "Artwork type");
  165.     !ac && a.AppendMenuSeparator();
  166.     a.AppendMenuItem(ac ? 8 : 0, 5, "Auto cycle image");
  167.     ac && a.AppendMenuItem(ct ? 8 : 0, 6, "Faded transition");
  168.     a.AppendMenuSeparator();
  169.     a.AppendMenuItem(0, 7, "Manage attached pictures");
  170.     a.AppendMenuItem(0, 8, "Remove all pictures");
  171.     a.AppendMenuSeparator();
  172.     a.AppendMenuItem(0, 9, "Properties");
  173.     a.AppendMenuItem(0, 10, "Configure...");
  174.  
  175.     idx = a.TrackPopupMenu(x, y);
  176.  
  177.     switch (true) {
  178.         case (idx >= 101 && idx <= 105):
  179.             g_state = idx - 101;
  180.             getRightImage(false);
  181.             getTimer();
  182.             break;
  183.  
  184.         case (idx >= 1 && idx <= 3):
  185.             window.SetProperty("Aspect ratio", idx - 1);
  186.             aspectRatio();
  187.             window.Repaint();
  188.             break;
  189.  
  190.         case (idx == 4):
  191.             switchType();
  192.             break;
  193.  
  194.         case (idx == 5):
  195.             window.SetProperty("Auto Cycle Image", ac ? false : true);
  196.             ac = window.GetProperty("Auto Cycle Image");
  197.             ac && !g_art && getRightImage(true);
  198.             ac && window.Repaint();
  199.             break;
  200.  
  201.         case (idx == 6):
  202.             window.SetProperty("Auto Cycle Transition Fader on", ct ? false : true);
  203.             ct = window.GetProperty("Auto Cycle Transition Fader on");
  204.             break;
  205.  
  206.         case (idx == 7):
  207.             fb.RunContextCommand("Manage attached pictures");
  208.             break;
  209.  
  210.         case (idx == 8):
  211.             fb.RunContextCommand("Remove all pictures");
  212.             break;
  213.  
  214.         case (idx == 9):
  215.             window.ShowProperties();
  216.             break;
  217.  
  218.         case (idx == 10):
  219.             window.ShowConfigure();
  220.             break;
  221.     }
  222.  
  223.     a.Dispose();
  224. }
  225.  
  226. // ----- DRAW -----
  227. var overlay_active = window.GetProperty("Back Overlay: Activate", true);
  228. var overlay_colour = window.GetProperty("Back Overlay: Colour", "0-61-98-255");
  229. var g_acol = CustomColour(overlay_colour);
  230.  
  231. var descr_tcolour = window.GetProperty("Description: Text Colour", "41-143-204-255");
  232. var g_bcol = CustomColour(descr_tcolour);
  233.  
  234. var descr_bcolour = window.GetProperty("Description: Back Colour", "10-36-51-255");
  235. var g_ccol = CustomColour(descr_bcolour);
  236.  
  237. function on_paint(gr) {
  238.     !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, ui_backcol);
  239.     fb.IsPlaying && overlay_active && gr.FillSolidRect(0, 0, ww, wh, g_acol);
  240.  
  241.     if (g_img) {
  242.         var w, h, x, y;
  243.         if (ar == 0 || ar == 1 && (g_img.Width > ww || g_img.Height > wh)) {
  244.             var img_scale = Math.min(ww / g_img.Width, wh / g_img.Height);
  245.             w = g_img.Width * img_scale;
  246.             h = g_img.Height * img_scale;
  247.             x = (ww - w) / 2;
  248.             y = (wh - h) / 2;
  249.         } else if (ar == 1) {
  250.             w = g_img.Width;
  251.             h = g_img.Height;
  252.             x = (ww - w) / 2;
  253.             y = (wh - h) / 2;
  254.         } else {
  255.             w = ww;
  256.             h = wh;
  257.             x = y = 0;
  258.         }
  259.         gr.DrawImage(g_img, x, y, w, h, 0, 0, g_img.Width, g_img.Height, 0, Math.abs(g_fade));
  260.     }
  261. }
  262.  
  263. // ----- MOUSE ACTIONS -----
  264. function on_mouse_move(x, y) {
  265.     !ac && g_active && window.SetCursor(32649);
  266. }
  267.  
  268. function on_mouse_lbtn_down(x, y) {
  269.     if (!ac && g_active) {
  270.         getRightImage(true);
  271.         getTimer();
  272.     }
  273. }
  274.  
  275. function on_mouse_mbtn_down(x, y) {
  276.     g_active && switchType();
  277. }
  278.  
  279. function on_mouse_rbtn_up(x, y) {
  280.     if (g_active) {
  281.         CustomMenu(x, y);
  282.         return true;
  283.     }
  284. }
  285.  
  286. function on_mouse_wheel(step) {
  287.     if (!ac && g_active) {
  288.         g_state -= step;
  289.         if (g_state < 0 ) g_state = 4;
  290.         else if (g_state > 4) g_state = 0;
  291.         getRightImage(false);
  292.         getTimer();
  293.     }
  294. }
  295.  
  296. // ----- EVENTS -----
  297. var ac = window.GetProperty("Auto Cycle Image", false);
  298. var ci = window.GetProperty("Auto Cycle Interval in s", 15);
  299. var ct = window.GetProperty("Auto Cycle Transition Fader on", false);
  300.  
  301. function on_size() {
  302.     ww = window.Width;
  303.     wh = window.Height;
  304. }
  305.  
  306. function on_playback_new_track(metadb) {
  307.     getRightImage(false);
  308.     if (ac && g_active && !g_art) getRightImage(true);
  309.     window.Repaint();
  310. }
  311.  
  312. function on_playback_time(time) {
  313.     if (ac && g_active && g_art && time > 1 && Math.round(time % ci) == 1) {
  314.         if (ct) {
  315.             if (cycle_timer) {
  316.                 window.ClearInterval(cycle_timer);
  317.                 cycle_timer = null;
  318.             }
  319.             cycle_timer = window.SetInterval(
  320.                 function () {
  321.                     g_fade -= 51;
  322.                     if (g_fade <= -255) {
  323.                         g_fade = 255;
  324.                         window.ClearInterval(cycle_timer);
  325.                         cycle_timer = null;
  326.                     }
  327.                     if (g_fade == 0) getRightImage(true);
  328.                     window.Repaint();
  329.                 }, 50);            
  330.         } else {
  331.             getRightImage(true);
  332.             window.Repaint();
  333.         }
  334.     }
  335. }
  336.  
  337. function on_playback_stop(reason) {
  338.     if (cycle_timer) {
  339.         window.ClearInterval(cycle_timer);
  340.         cycle_timer = null;
  341.         g_fade = 255;
  342.     }
  343.  
  344.     if (descr_timer) {
  345.         window.ClearTimeout(descr_timer);
  346.         descr_timer = null;
  347.     }
  348.  
  349.     if (reason != 2) {
  350.         getRightImage(false);
  351.         window.Repaint();
  352.     }
  353. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement