Advertisement
Guest User

DarkOne4Mod - Display Panel - MS Sans Serif (JScript Panel 2

a guest
Jul 16th, 2018
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==PREPROCESSOR==
  2. // @name "DarkOne4Mod - Display Panel"
  3. // @version "1.0 build20160929"
  4. // @author "super-gau and tedGo, includes partial codes by fbuser, Br3tt and T.P Wang"
  5. // @import "%fb2k_path%themes\DarkOne4Mod\Others\JScripts\DarkOne4Mod - Global Script.js"
  6. // ==/PREPROCESSOR==
  7.  
  8. // ----- VARIABLES -----
  9. var t_rem = window.GetProperty("Remain Time on", false);
  10. var fileinfo, g_trackinfo, d_font, t_font, f_size, t_size;
  11. var g_timer = v_timer = null;
  12. var v_change = false;
  13. var p_backcol = RGB(31, 31, 31);
  14.  
  15. // ----- COLOURS -----
  16. var d_arr = new Array("Blue", "Green", "Light Blue", "Red", "White", "Yellow");
  17. var c_arr = new Array(RGB(41, 143, 204), RGB(6, 176, 37), RGB(191, 223, 255), RGB(255, 0, 0), RGB(255, 255, 255), RGB(255, 223, 63));
  18.  
  19. function InitColours() {
  20.     d_col = window.GetProperty("Display Colour", 0);
  21.     g_acol = c_arr[d_col];
  22.     g_bcol = combColours(p_backcol, c_arr[4], 0.02);
  23. }
  24.  
  25. InitColours();
  26.  
  27. // ----- CREATE HELPERS -----
  28. String.prototype.repeat = function(n) {
  29.     return (new Array(n + 1)).join(this);
  30. }
  31.  
  32. function pad(x, y, z) {
  33.     z || (z = ' ');
  34.     return x.length < y ? x + z.repeat(y - x.length) : x;
  35. }
  36.  
  37. function pad_right(x, y, z) {
  38.     z || (z = ' ');
  39.     return x.length < y ? z.repeat(y - x.length) + x : x
  40. }
  41.  
  42. function TimeFmt(t) {
  43.     var zpad = function(n) {
  44.         var str = n.toString();
  45.         return str.length < 2 ? "0" + str : str;
  46.     }
  47.  
  48.     var h = Math.floor(t / 3600);
  49.     t -= h * 3600;
  50.     var m = Math.floor(t / 60);
  51.     t -= m * 60;
  52.     var s = Math.floor(t);
  53.  
  54.     return zpad(h) + ":" + zpad(m) + ":" + zpad(s);
  55. }
  56.  
  57. // ----- CREATE INFO -----
  58. Info.prototype.setColours = function() {
  59.     var metadb = fb.GetNowPlaying();
  60.  
  61.     if (metadb) {
  62.         this.Colours[0] = fb.TitleFormat("[$info(encoding)]").Eval() == "lossless" ? g_acol : g_bcol;
  63.         this.Colours[1] = fb.TitleFormat("[$info(encoding)]").Eval() == "lossless" ? g_bcol : g_acol;
  64.         this.Colours[2] = fb.TitleFormat("[$info(md5)]").Eval() ? g_acol : g_bcol;
  65.         this.Colours[3] = fb.TitleFormat("[%replaygain_track_gain%]").Eval() ? g_acol : g_bcol;
  66.         this.Colours[4] = fb.TitleFormat("[%tracknumber%]").Eval() ? ui_btntxtcol : g_bcol;
  67.         this.Colours[5] = fb.TitleFormat("[%totaltracks%]").Eval() ? ui_btntxtcol : g_bcol;
  68.         this.Colours[6] = ui_btntxtcol;
  69.     } else for (var i = 0; i < this.Colours.length; i++) this.Colours[i] = g_bcol;
  70. }
  71.  
  72. Info.prototype.setTrackNo = function() {
  73.     var metadb = fb.GetNowPlaying();
  74.     var a, b, c, d;
  75.  
  76.     if (metadb) {
  77.         a = fb.TitleFormat("[$num(%tracknumber%,2)]").Eval();
  78.         b = fb.TitleFormat("[$num(%totaltracks%,2)]").Eval();
  79.         c = a ? a : "";
  80.         d = b ? b : "";
  81.         this.TrackNo = c;
  82.         this.TotalNo = d;
  83.         g_trackinfo = fb.PlaybackLength <= 0 ? 2 : metadb.RawPath.indexOf("FOO_LASTFM") == 0 ? 1 : 0;
  84.     } else {
  85.         this.TrackNo = "";
  86.         this.TotalNo = "";
  87.     }
  88. }
  89.  
  90. Info.prototype.setPBTime = function() {
  91.     this.Elapse = TimeFmt(fb.PlaybackTime);
  92.     this.Remain = fb.PlaybackLength < 0 ? "-- : -- : --" : TimeFmt(fb.PlaybackLength - fb.PlaybackTime);
  93. }
  94.  
  95. Info.prototype.setBitrate = function() {
  96.     this.Bitrate = pad_right(fb.TitleFormat("%bitrate%").Eval(), 5);
  97. }
  98.  
  99. Info.prototype.setInfo = function() {
  100.     this.setColours();
  101.     this.setTrackNo();
  102.     this.setPBTime();
  103.     this.setBitrate();
  104. }
  105.  
  106. function Info() {
  107.     this.Colours = new Array(7);
  108.     this.setInfo();
  109. }
  110.  
  111. info = new Info();
  112.  
  113. // ----- CREATE MENU -----
  114. function CustomMenu(x, y) {
  115.     var a = window.CreatePopupMenu();
  116.     var idx;
  117.  
  118.     for (var i = 0; i < d_arr.length; i++) {
  119.         a.AppendMenuItem(0, 1 + i, d_arr[i]);
  120.     }
  121.     a.CheckMenuRadioItem(1, 6, d_col + 1);
  122.  
  123.     a.AppendMenuSeparator();
  124.     a.AppendMenuItem(0, 7, "Properties");
  125.     a.AppendMenuItem(0, 8, "Configure...");
  126.  
  127.     idx = a.TrackPopupMenu(x, y);
  128.  
  129.     switch (true) {
  130.         case (idx >= 1 && idx <= 6):
  131.             window.SetProperty("Display Colour", idx - 1);
  132.             InitColours();
  133.             info.setColours();
  134.             window.Repaint();
  135.             fb.RunMainMenuCommand("DarkOne4Mod - " + d_arr[d_col]);
  136.             break;
  137.  
  138.         case (idx == 7):
  139.             window.ShowProperties();
  140.             break;
  141.  
  142.         case (idx == 8):
  143.             window.ShowConfigure();
  144.             break;
  145.     }
  146.  
  147.     a.Dispose();
  148. }
  149.  
  150. // ----- DRAW -----
  151. function on_paint(gr) {
  152.     !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, p_backcol);
  153.  
  154.     gr.SetInterpolationMode(7);
  155.  
  156.     gr.DrawRect(1, 0, ww / 4 - 2, ww / 40, ww / 400, info.Colours[0]);
  157.     gr.DrawRect(ww / 4 + 1, 0, ww / 4 - 2, ww / 40, ww / 400, info.Colours[1]);
  158.     gr.DrawRect(ww / 2 + 1, 0, ww / 4 - 2, ww / 40, ww / 400, info.Colours[2]);
  159.     gr.DrawRect(ww * 3 / 4 + 1, 0, ww / 4 - 2, ww / 40, ww / 400, info.Colours[3]);
  160.  
  161.     d_font = gdi.Font("Arial Black", f_size);
  162.  
  163.     gr.GdiDrawText("LOSSLESS", d_font, info.Colours[0], 1, 0, ww / 4 - 2, ww / 40, 5);
  164.     gr.GdiDrawText("LOSSY", d_font, info.Colours[1], ww / 4 + 1, 0, ww / 4 - 2, ww / 40, 5);
  165.     gr.GdiDrawText("AUDIO MD5", d_font, info.Colours[2], ww / 2 + 1, 0, ww / 4 - 2, ww / 40, 5);
  166.     gr.GdiDrawText("REPLAYGAIN", d_font, info.Colours[3], ww *3 / 4 + 1, 0, ww / 4 - 2, ww / 40, 5);
  167.  
  168.     gr.GdiDrawText("TRACK", d_font, info.Colours[4], 0, ww * 9 / 200, ww / 10, ww / 50, 0);
  169.     gr.GdiDrawText("TOTAL", d_font, info.Colours[5], ww * 41 / 200, ww * 9 / 200, ww / 10, ww / 50, 0);
  170.     gr.GdiDrawText("ELAPSED", d_font, v_change || t_rem ? g_bcol : info.Colours[6], ww * 41 / 100, ww * 9 / 200, ww * 9 / 100, ww / 50, 0);
  171.     gr.GdiDrawText("TIME", d_font, v_change ? g_bcol : info.Colours[6], ww * 41 / 80, ww * 9 / 200, ww / 20, ww / 50, 1);
  172.     gr.GdiDrawText("REMAINING", d_font, v_change || !t_rem ? g_bcol : info.Colours[6], ww * 229 / 400, ww * 9 / 200, ww * 23 / 200, ww / 50, 2);
  173.     gr.GdiDrawText("VOLUME", d_font, v_change ? ui_btntxtcol : g_bcol, ww * 39 / 50, ww * 9 / 200, ww / 12, ww / 50, 2);
  174.     gr.GdiDrawText("KBPS", d_font, v_change ? g_bcol : info.Colours[6], ww * 22 / 25, ww * 9 / 200, ww * 4 / 75, ww / 50, 2);
  175.  
  176.     t_font = gdi.Font("Microsoft Sans Serif", t_size);
  177.  
  178.     if (g_trackinfo == 0) {
  179.         gr.GdiDrawText(info.TrackNo, t_font, g_acol, 0, ww * 3 / 50, ww * 41 / 200, ww / 9, 0);
  180.         gr.GdiDrawText(info.TotalNo, t_font, g_acol, ww * 41 / 200, ww * 3 / 50, ww * 41 / 200, ww / 9, 0);
  181.     } else {
  182.         var noTrack = g_trackinfo == 1 ? "last.fm" : "Stream";
  183.         fb.IsPlaying && gr.GdiDrawText(noTrack, t_font, g_acol, 0, ww * 3 / 50, ww * 41 / 100, ww / 9, 0);
  184.     }
  185.  
  186.     if (v_change) gr.GdiDrawText(fb.Volume.toFixed(2) + " dB", t_font, g_acol, ww * 57 / 100, ww * 3 / 50, ww * 9 / 25, ww / 9, 2);
  187.     else {
  188.         if (fb.IsPlaying) {
  189.             var t_fmt = fb.IsPaused ? "-Paused-" : t_rem ? info.Remain : info.Elapse;
  190.             gr.GdiDrawText(t_fmt, t_font, g_acol, ww * 41 / 100, ww * 3 / 50, ww * 7 / 25, ww / 9, 1);
  191.             gr.GdiDrawText(info.Bitrate, t_font, g_acol, ww * 147 / 200, ww * 3 / 50, ww / 5, ww / 9, 2);
  192.  
  193.         }
  194.     }
  195.  
  196.     g_signs && gr.DrawImage(g_signs, Math.floor(ww - ww * 9 / 200), ww / 20, ww * 9 / 200, ww * 3 / 100, 1944, fb.StopAfterCurrent ? d_col * 66 : 264, 54, 36, 0, fb.StopAfterCurrent ? 255 : 5);
  197.     g_signs && gr.DrawImage(g_signs, Math.floor(ww - ww * 9 / 200), ww * 39 / 400, ww * 9 / 200, ww * 3 / 100, 2004 + plman.PlaybackOrder * 60, fb.IsPlaying ? d_col * 66 : 264, 54, 36, 0, fb.IsPlaying ? 255 : 5);
  198. }
  199.  
  200. // ----- MOUSE ACTIONS -----
  201. function on_mouse_rbtn_up(x, y) {
  202.     CustomMenu(x, y);
  203.     return true;
  204. }
  205.  
  206. // ----- EVENTS -----
  207. function on_size() {
  208.     ww = window.Width;
  209.     wh = window.Height;
  210.     f_size = ww * 7 / 400;
  211.     t_size = ww * 29 / 400;
  212. }
  213.  
  214. function on_volume_change(val) {
  215.     if (v_timer) {
  216.         window.ClearTimeout(v_timer);
  217.         v_timer = null;
  218.     }
  219.  
  220.     v_timer = window.SetTimeout(
  221.         function () {
  222.             window.RepaintRect(Math.floor(ww * 41 / 100), Math.floor(ww * 9 / 200), ww * 105 / 200 + 2, ww * 9 / 100 + 2);
  223.             window.ClearTimeout(v_timer);
  224.             v_timer = null;
  225.             v_change = false;
  226.         }, 3000);
  227.  
  228.     v_change = true;
  229.     window.RepaintRect(Math.floor(ww * 41 / 100), Math.floor(ww * 9 / 200), ww * 105 / 200 + 2, ww * 9 / 100 + 2);
  230. }
  231.  
  232. function on_playback_order_changed(new_order) {
  233.     window.RepaintRect(Math.floor(ww - ww * 9 / 200), Math.floor(ww * 39 / 400), ww * 9 / 200 + 2, ww * 3 / 100 + 3 );
  234. }
  235.  
  236. function on_playback_time(time) {
  237.     info.setPBTime();
  238.     window.RepaintRect(Math.floor(ww * 41 / 100), Math.floor(ww * 3 / 50), ww * 71 / 200 + 2, ww / 9 + 2);
  239. }
  240.  
  241. function on_playback_dynamic_info() {
  242.     info.setBitrate()
  243.     window.RepaintRect(Math.floor(ww * 147 / 200), Math.floor(ww * 3 / 50), ww / 5 + 2, ww / 9 + 2);
  244. }
  245.  
  246. function on_playback_edited() {
  247.     info.setInfo();
  248.     window.Repaint();
  249. }
  250.  
  251. function on_playback_new_track(metadb) {
  252.     info.setInfo();
  253.     window.Repaint();
  254. }
  255.  
  256. function on_playback_pause(state) {
  257.     window.RepaintRect(Math.floor(ww * 41 / 100), Math.floor(ww * 3 / 50), ww * 71 / 200 + 2, ww / 9 + 2);
  258. }
  259.  
  260. function on_playback_stop(reason) {
  261.     if (fileinfo) fileinfo.Dispose();
  262.  
  263.     if (reason != 2) {
  264.         info.setInfo();
  265.         fb.RunMainMenuCommand("ELPlaylist/Redraw");
  266.     }
  267.  
  268.     window.Repaint();
  269. }
  270.  
  271. function on_playlist_stop_after_current_changed(state) {
  272.     window.RepaintRect(Math.floor(ww - ww * 9 / 200), Math.floor(ww / 20), ww * 9 / 200 + 2, ww * 3 / 100 + 2);
  273. }
  274.  
  275. function on_notify_data(name, info) {
  276.     if (name == "remTime") {
  277.         window.SetProperty("Remain Time on", info == true ? true : false);
  278.         t_rem = window.GetProperty("Remain Time on");
  279.         window.RepaintRect(Math.floor(ww * 41 / 100), Math.floor(ww * 9 / 200), ww * 15 / 50 + 2, ww * 9 / 100 + 2);
  280.     }
  281. }
  282.  
  283. function on_script_unload() {
  284.     if (fileinfo) fileinfo.Dispose();
  285.     g_signs && g_signs.Dispose();
  286. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement