Advertisement
Guest User

DarkOne4Mod - Cover Panel (JScript Panel 2.1.6)

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