Advertisement
soKindly

Damask buttons panel 1.0

Dec 25th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==PREPROCESSOR==
  2. // @name "Damask Buttons Panel"
  3. // @version "1.0"
  4. // @author "so_kindly"
  5. // ==/PREPROCESSOR==
  6.  
  7.  
  8. // Variables {{
  9. // Flags, used with GdiDrawText
  10. // For more information, see: http://msdn.microsoft.com/en-us/library/dd162498(VS.85).aspx
  11. var DT_TOP = 0x00000000;
  12. var DT_LEFT = 0x00000000;
  13. var DT_CENTER = 0x00000001;
  14. var DT_RIGHT = 0x00000002;
  15. var DT_VCENTER = 0x00000004;
  16. var DT_BOTTOM = 0x00000008;
  17. var DT_WORDBREAK = 0x00000010;
  18. var DT_SINGLELINE = 0x00000020;
  19. var DT_EXPANDTABS = 0x00000040;
  20. var DT_TABSTOP = 0x00000080;
  21. var DT_NOCLIP = 0x00000100;
  22. var DT_EXTERNALLEADING = 0x00000200;
  23. var DT_CALCRECT = 0x00000400;
  24. var DT_NOPREFIX = 0x00000800;
  25. var DT_INTERNAL = 0x00001000;
  26. var DT_EDITCONTROL = 0x00002000;
  27. var DT_PATH_ELLIPSIS = 0x00004000;
  28. var DT_END_ELLIPSIS = 0x00008000;
  29. var DT_MODIFYSTRING = 0x00010000;
  30. var DT_RTLREADING = 0x00020000;
  31. var DT_WORD_ELLIPSIS = 0x00040000;
  32. var DT_NOFULLWIDTHCHARBREAK = 0x00080000;
  33. var DT_HIDEPREFIX = 0x00100000;
  34. var DT_PREFIXONLY = 0x00200000;
  35.  
  36. // menu flags
  37. var MF_SEPARATOR = 0x00000800;
  38. var MF_ENABLED = 0x00000000;
  39. var MF_GRAYED = 0x00000001;
  40. var MF_DISABLED = 0x00000002;
  41. var MF_UNCHECKED = 0x00000000;
  42. var MF_CHECKED = 0x00000008;
  43. var MF_STRING = 0x00000000;
  44. var MF_POPUP = 0x00000010;
  45. var MF_RIGHTJUSTIFY = 0x00004000;
  46.  
  47. var MK_SHIFT = 0x0004;
  48.  
  49. var CursorFollowMode = {
  50.     OnlyStopped: 1,
  51.     Always: 2
  52. }
  53.  
  54. // globals
  55. var ww = 0;
  56. var wh = 0;
  57. var Properties = new GetProperties();
  58. var MetaDB;
  59. var MetaDB_type;
  60.  
  61. // margins (left,right,top,bottom)
  62. var lm = 5;
  63. var rm = 5;
  64. var tm = 5;
  65. var bm = 5;
  66. var border_size = 10;
  67.  
  68. // buttons vars
  69. var Buttons;
  70. var MaxRange;
  71. var Tooltip = window.CreateTooltip();
  72. var EnableTooltip = true;
  73.  
  74. var hbtn; // hover button
  75. var dbtn; // pressed down button
  76. var dbtnBackup;
  77. var rbtnDown;
  78.  
  79. // rating vars
  80. var tf_rating = fb.TitleFormat("$if2(%rating%,0)");
  81. var rating;
  82. var h_rating;
  83.  
  84. rating_rect = {
  85.     x: 0,
  86.     y: 0,
  87.     width: 110,
  88.     height: 22
  89. }
  90.  
  91.  
  92. // images {{
  93. var imgPath = fb.FoobarPath + "skins\\Damask\\images\\";
  94. var ButtonsPath = fb.FoobarPath + "skins\\Damask\\images\\buttons\\";
  95.  
  96. // buttons
  97. var img_stop = gdi.Image(ButtonsPath + "stop20.png");
  98. var img_play = gdi.Image(ButtonsPath + "play20.png");
  99. var img_pause = gdi.Image(ButtonsPath + "pause20.png");
  100. var img_prev = gdi.Image(ButtonsPath + "prev20.png");
  101. var img_next = gdi.Image(ButtonsPath + "next20.png");
  102. var img_random = gdi.Image(ButtonsPath + "playrandom20.png");
  103. var img_folder = gdi.Image(ButtonsPath + "folder20.png");
  104. var img_library = gdi.Image(ButtonsPath + "library20.png");
  105.  
  106. // rating
  107. var star_normal = gdi.Image(ButtonsPath + "star_normal.png");
  108. var star_empty = gdi.Image(ButtonsPath + "star_empty.png");
  109. var star_hover = gdi.Image(ButtonsPath + "star_hover.png");
  110. var star_x = gdi.Image(ButtonsPath + "star_x.png");
  111.  
  112. // bg images
  113. var img_bg_bmp;
  114. var img_main_wallpaper = gdi.Image(imgPath + "DamaskBotBGSmall.png").CreateRawBitmap();
  115. borders_img = {
  116.     left_top: gdi.Image(imgPath + "borders\\top-bot\\left_top.png"),
  117.     top_line: gdi.Image(imgPath + "borders\\top-bot\\top_line.png"),
  118.     right_top: gdi.Image(imgPath + "borders\\top-bot\\right_top.png"),
  119.     left_line: gdi.Image(imgPath + "borders\\top-bot\\left_line.png"),
  120.     right_line: gdi.Image(imgPath + "borders\\top-bot\\right_line.png"),
  121.     left_bot: gdi.Image(imgPath + "borders\\top-bot\\left_bot.png"),
  122.     bot_line: gdi.Image(imgPath + "borders\\top-bot\\bot_line.png"),
  123.     right_bot: gdi.Image(imgPath + "borders\\top-bot\\right_bot.png")
  124. };
  125. var img_rating_container = gdi.Image(ButtonsPath + "rating_container.png");
  126.  
  127. // }}
  128. // others
  129. var ButtonAnimationTimerID;
  130. var ButtonWaitTimerID;
  131. var ButtonAnimationTimer;
  132. var ButtonWaitTimer;
  133.  
  134. // Variables}}
  135. //===================================================================================================================================================
  136.  
  137. function RGB(r, g, b) {
  138.     return (0xff000000 | (r << 16) | (g << 8) | (b));
  139. }
  140.  
  141. function TrackType(trkpath) {
  142.     var taggable;
  143.     var type;
  144.     switch (trkpath) {
  145.         case "file":
  146.             taggable = 1;
  147.             type = 0;
  148.             break;
  149.         case "cdda":
  150.             taggable = 1;
  151.             type = 1;
  152.             break;
  153.         case "FOO_":
  154.             taggable = 0;
  155.             type = 2;
  156.             break;
  157.         case "http":
  158.             taggable = 0;
  159.             type = 3;
  160.             break;
  161.         case "mms:":
  162.             taggable = 0;
  163.             type = 3;
  164.             break;
  165.         case "unpa":
  166.             taggable = 0;
  167.             type = 4;
  168.             break;
  169.         default:
  170.             taggable = 0;
  171.             type = 5;
  172.     }
  173.     return type;
  174. }
  175.  
  176. // Generate background image.
  177. function GenerateBG() {
  178.     var img_bg = gdi.CreateImage(ww, wh);
  179.     var g = img_bg.GetGraphics();
  180.     // wallpaper
  181.     g.GdiDrawBitmap(img_main_wallpaper, border_size, border_size, img_bg.width - (border_size * 2), img_bg.height - (border_size * 2), 0, 0, img_bg.width - (border_size * 2), img_bg.height - (border_size * 2));
  182.     // borders
  183.     g.DrawImage(borders_img.left_top, 0, 0, border_size, border_size, 0, 0, 10, 10);
  184.     g.DrawImage(borders_img.top_line, border_size, 0, img_bg.width - (border_size * 2), border_size, 0, 0, img_bg.width - (border_size * 2), 10);
  185.     g.DrawImage(borders_img.right_top, img_bg.width - border_size, 0, border_size, border_size, 0, 0, 10, 10);
  186.  
  187.     g.DrawImage(borders_img.left_line, 0, border_size, border_size, img_bg.height - (border_size * 2), 0, 0, border_size, img_bg.height - (border_size * 2));
  188.     g.DrawImage(borders_img.right_line, img_bg.width - border_size, border_size, border_size, img_bg.height - (border_size * 2), 0, 0, border_size, img_bg.height - (border_size * 2));
  189.  
  190.     g.DrawImage(borders_img.left_bot, 0, img_bg.height - border_size, border_size, border_size, 0, 0, 10, 10);
  191.     g.DrawImage(borders_img.bot_line, border_size, img_bg.height - border_size, img_bg.width - (border_size * 2), border_size, 0, 0, img_bg.width - (border_size * 2), 10);
  192.     g.DrawImage(borders_img.right_bot, img_bg.width - border_size, img_bg.height - border_size, border_size, border_size, 0, 0, 10, 10);
  193.     //rating container
  194.     g.DrawImage(img_rating_container, img_bg.width - border_size - rm - 118 - 4, Math.round((img_bg.height - 28) / 2), 119, 29, 0, 0, 119, 29);
  195.     img_bg_bmp = img_bg.CreateRawBitmap();
  196.     img_bg.ReleaseGraphics(g);
  197. }
  198.  
  199. //Properties
  200. function GetProperties() {
  201.     this.Panel = {
  202.         CursorFollowMode: window.GetProperty("A01.Panel.CursorFollowMode", CursorFollowMode.OnlyStopped),
  203.     }
  204.  
  205.     this.Panel.CursorFollowMode = Math.max(this.Panel.CursorFollowMode, CursorFollowMode.OnlyStopped);
  206.     this.Panel.CursorFollowMode = Math.min(this.Panel.CursorFollowMode, CursorFollowMode.Always);
  207.     window.SetProperty("A01.Panel.CursorFollowMode", this.Panel.CursorFollowMode);
  208. }
  209.  
  210. // context menu
  211. function ShowContextMenu(x, y) {
  212.     var menu = window.CreatePopupMenu();
  213.     var FollowModeChild = window.CreatePopupMenu();
  214.     var ret;
  215.  
  216.     FollowModeChild.AppendMenuItem(MF_STRING, 1, "Only Stopped");
  217.     FollowModeChild.AppendMenuItem(MF_STRING, 2, "Always");
  218.     FollowModeChild.CheckMenuRadioItem(1, 2, Properties.Panel.CursorFollowMode);
  219.     FollowModeChild.AppendTo(menu, MF_STRING, "Cursor follow mode");
  220.     menu.AppendMenuItem(MF_STRING, 3, "Properties");
  221.     ret = menu.TrackPopupMenu(x, y);
  222.     switch (ret) {
  223.         case 1:
  224.             SetCursorFollowMode(CursorFollowMode.OnlyStopped);
  225.             break;
  226.         case 2:
  227.             SetCursorFollowMode(CursorFollowMode.Always);
  228.             break;
  229.         case 3:
  230.             window.ShowProperties();
  231.             break;
  232.     }
  233. }
  234.  
  235. // Cursor follow tools {{
  236. function SetCursorFollowMode(FollowMode) {
  237.     if (FollowMode != Properties.Panel.CursorFollowMode) {
  238.         Properties.Panel.CursorFollowMode = FollowMode;
  239.         window.SetProperty("A01.Panel.CursorFollowMode", FollowMode);
  240.         CursorFollow(FollowMode);
  241.     }
  242. }
  243.  
  244. function CursorFollow(FollowMode) {
  245.     switch (FollowMode) {
  246.         case CursorFollowMode.OnlyStopped:
  247.             if (fb.IsPlaying) on_playback_new_track();
  248.             else on_item_focus_change();
  249.             break;
  250.         case CursorFollowMode.Always:
  251.             on_item_focus_change();
  252.             break;
  253.     }
  254. }
  255.  
  256. // Cursor follow tools }}
  257.  
  258. //===================================================================================================================================================
  259. // Buttons {{
  260.  
  261. // button class
  262. function Button(x, y, width, height, c_width, c_height, img, fn_onclick, tiptext) {
  263.     this.x = x;
  264.     this.y = y;
  265.     this.width = width;
  266.     this.height = height;
  267.     this.c_width = c_width;
  268.     this.c_height = c_height;
  269.     this.tiptext = tiptext;
  270.     this.NeedRefresh = 0;
  271.     this.img = img;
  272.     this.oldstate = 0; // 0=normal, 1=hover, 2=down.
  273.     this.state = 0;
  274.     this.opacity = 0; // Opacity of new state image.
  275.     this.step = 0;
  276.  
  277.     this.OnClick = fn_onclick;
  278.  
  279.     this.ChangeState = function (s) {
  280.         this.oldstate = this.state;
  281.         this.state = s;
  282.         this.opacity = 0;
  283.         this.NeedRefresh = 1;
  284.         switch (s) {
  285.             case 0:
  286.                 this.step = 40; // Step of changing to normal state.
  287.                 Tooltip.Deactivate();
  288.                 Tooltip.Text = "";
  289.                 break;
  290.             case 1:
  291.                 this.step = 75; // hover state.
  292.                 if (EnableTooltip) {
  293.                     Tooltip.Text = this.tiptext;
  294.                     Tooltip.Activate();
  295.                 }
  296.                 break;
  297.             case 2:
  298.                 this.step = 85; // down state.
  299.                 Tooltip.Deactivate();
  300.                 Tooltip.Text = "";
  301.                 break;
  302.         }
  303.  
  304.         if (!ButtonAnimationTimerID) // start animation
  305.         ButtonAnimationTimer.Start();
  306.     }
  307.  
  308.     this.isXYok = function (x2, y2) {
  309.         return (x2 >= this.x && y2 >= this.y && x2 <= this.x + width && y2 <= this.y + height) ? true : false;
  310.     }
  311.  
  312.     this.Draw = function (x2, y2, gr) {
  313.         x2 = this.x;
  314.         y2 = this.y;
  315.         if (this.opacity < 255) this.img && gr.DrawImage(this.img, x2, y2, width, height, this.oldstate * c_width, 0, c_width, c_height, 0, 255);
  316.         if (this.opacity) this.img && gr.DrawImage(this.img, x2, y2, width, height, this.state * c_width, 0, c_width, c_height, 0, this.opacity);
  317.     }
  318.  
  319.     this.RefreshOpacity = function (fn) {
  320.         if (this.opacity < 255) this.opacity = Math.min(this.opacity + this.step, 255);
  321.         else {
  322.             this.oldstate = this.state;
  323.             this.opacity = 0;
  324.             this.NeedRefresh = 0;
  325.         }
  326.     }
  327. }
  328.  
  329. function GetCoordinates() {
  330.     for (var i = 0; i < Buttons.length; i++) {
  331.         Buttons[i].y = Math.round((wh - Buttons[i].height) / 2);
  332.     }
  333.     rating_rect.x = ww - border_size - rm - 118;
  334.     rating_rect.y = Math.round((wh - 28) / 2) + 3;
  335.  
  336.     // Calculate the max range of buttons, for increasing refresh speed.
  337.     MaxRange = {
  338.         x: Buttons[0].x,
  339.         y: Buttons[0].y,
  340.         width: Buttons[0].width,
  341.         height: Buttons[0].height
  342.     }
  343.  
  344.     for (var i = 1; i < Buttons.length; i++) {
  345.         MaxRange.x = Math.min(Buttons[i].x, MaxRange.x);
  346.         MaxRange.y = Math.min(Buttons[i].y, MaxRange.y);
  347.         MaxRange.width = Math.max(Buttons[i].x + Buttons[i].width - MaxRange.x, MaxRange.width);
  348.         MaxRange.height = Math.max(Buttons[i].y + Buttons[i].height - MaxRange.y, MaxRange.height);
  349.     }
  350. }
  351.  
  352. // Buttons init }}
  353. //===================================================================================================================================================
  354. // Timers {{
  355.  
  356. function c_ButtonAnimationTimer() {
  357.     this.Stop = function () {
  358.         if (ButtonAnimationTimerID) {
  359.             window.ClearInterval(ButtonAnimationTimerID);
  360.             ButtonAnimationTimerID = null;
  361.         }
  362.     }
  363.  
  364.     this.Start = function () {
  365.         ButtonAnimationTimerID = window.SetInterval(function () {
  366.             var NeedRepaint = 0;
  367.             for (var i = 0; i < Buttons.length; i++) {
  368.                 if (Buttons[i].NeedRefresh) {
  369.                     Buttons[i].RefreshOpacity();
  370.                     NeedRepaint += 1;
  371.                     Onlybtn = Buttons[i]; // If only one button need to be repainted.
  372.                 }
  373.             }
  374.  
  375.             if (NeedRepaint) {
  376.                 if (NeedRepaint == 1) window.RepaintRect(Onlybtn.x, Onlybtn.y, Onlybtn.width, Onlybtn.height);
  377.                 else window.RepaintRect(MaxRange.x, MaxRange.y, MaxRange.width, MaxRange.height); // This is range of buttons.
  378.             } else {
  379.                 ButtonAnimationTimer.Stop();
  380.             }
  381.         }, 50)
  382.     }
  383. }
  384.  
  385. function c_ButtonWaitTimer() {
  386.     this.Stop = function () {
  387.         if (ButtonWaitTimerID) {
  388.             window.ClearTimeout(ButtonWaitTimerID);
  389.             ButtonWaitTimerID = null;
  390.         }
  391.     }
  392.  
  393.     this.Start = function () {
  394.         ButtonWaitTimerID = window.SetTimeout(function () {
  395.             ButtonWaitTimerID = null;
  396.             dbtnBackup.ChangeState(0);
  397.             dbtnBackup = null;
  398.         }, 200)
  399.     }
  400. }
  401.  
  402. // Timers }}
  403. //===================================================================================================================================================
  404. //===================================================================================================================================================
  405.  
  406. function on_init() {
  407.     // creating buttons array
  408.     Buttons = new Array(
  409.     b1 = new Button(lm + border_size, 0, 58, 58, 58, 58, img_stop, function () {
  410.         fb.Stop()
  411.     }, "Stop"),
  412.     b2 = new Button(5 + lm + border_size + b1.width, 0, 58, 58, 58, 58, fb.IsPaused || !fb.IsPlaying ? img_play : img_pause, function () {
  413.         fb.PlayOrPause();
  414.     }, "Play or pause"),
  415.     b3 = new Button(10 + lm + border_size + b1.width + b2.width, 0, 58, 58, 58, 58, img_prev, function () {
  416.         fb.Prev()
  417.     }, "Previous"),
  418.     b4 = new Button(15 + lm + border_size + b1.width + b2.width + b3.width, 0, 58, 58, 58, 58, img_next, function () {
  419.         fb.Next()
  420.     }, "Next"),
  421.     b5 = new Button(20 + lm + border_size + b1.width + b2.width + b3.width + b4.width, 0, 58, 58, 58, 58, img_random, function () {
  422.         fb.RunMainMenuCommand("Playback/Random")
  423.     }, "Play random track"),
  424.     b6 = new Button(25 + lm + border_size + b1.width + b2.width + b3.width + b4.width + b5.width, 0, 58, 58, 58, 58, img_folder, function () {
  425.         if (MetaDB) fb.RunContextCommandWithMetadb("Open containing folder", MetaDB)
  426.     }, "Open folder"),
  427.     b7 = new Button(30 + lm + border_size + b1.width + b2.width + b3.width + b4.width + b5.width + b6.width, 0, 58, 58, 58, 58, img_library, function () {
  428.         fb.RunMainMenuCommand("Library/Facets")
  429.     }, "Library browser"));
  430.  
  431.     // init timers
  432.     ButtonAnimationTimer = new c_ButtonAnimationTimer();
  433.     ButtonWaitTimer = new c_ButtonWaitTimer();
  434.  
  435. }
  436. on_init();
  437.  
  438. function on_size() {
  439.     if (!window.Width || !window.Height) return;
  440.     ww = window.Width;
  441.     wh = window.Height;
  442.  
  443.     GetCoordinates();
  444.     CursorFollow(Properties.Panel.CursorFollowMode);
  445.     GenerateBG(); // Generate background image
  446. }
  447.  
  448. function on_paint(gr) {
  449.  
  450.     // Draw background image.
  451.     if (img_bg_bmp) gr.GdiDrawBitmap(img_bg_bmp, 0, 0, ww, wh, 0, 0, img_bg_bmp.width, img_bg_bmp.height);
  452.  
  453.     // Draw buttons
  454.     for (var i = 0; i < Buttons.length; i++)
  455.     Buttons[i].Draw(Buttons[i].x, Buttons[i].y, gr);
  456.  
  457.     // Rating
  458.     if (h_rating) {
  459.         for (var i = 0; i < 5; i++) {
  460.             gr.DrawImage(i + 1 <= h_rating ? (h_rating == rating ? star_x : star_hover) : star_empty, rating_rect.x + i * 22, rating_rect.y, 22, 22, 0, 0, 22, 22);
  461.         }
  462.     } else {
  463.         for (var i = 0; i < 5; i++) {
  464.             gr.DrawImage(i + 1 <= rating ? star_normal : star_empty, rating_rect.x + i * 22, rating_rect.y, 22, 22, 0, 0, 22, 22);
  465.         }
  466.     }
  467. }
  468.  
  469. //===================================================================================================================================================
  470. // Mouse callbacks {{
  471.  
  472. function on_mouse_move(x, y) {
  473.     if (dbtn) {
  474.         if (dbtn.isXYok(x, y)) {
  475.             if (dbtn.state != 2) dbtn.ChangeState(2);
  476.         } else if (dbtn.state != 1) dbtn.ChangeState(1);
  477.     } else {
  478.         for (var i = 0; i < Buttons.length; i++)
  479.         if (Buttons[i].isXYok(x, y)) {
  480.             if (hbtn != Buttons[i] && Buttons[i] != dbtnBackup) {
  481.                 if (hbtn) hbtn.ChangeState(0);
  482.                 hbtn = Buttons[i];
  483.                 hbtn.ChangeState(1);
  484.             };
  485.             break;
  486.         };
  487.         if (i == Buttons.length) {
  488.  
  489.             if (hbtn) {
  490.                 if (hbtn && hbtn != dbtnBackup) hbtn.ChangeState(0);
  491.                 hbtn = undefined;
  492.             };
  493.         };
  494.     };
  495.  
  496.     // rating
  497.     if (MetaDB) {
  498.         if (MetaDB_type < 2) {
  499.             if (x > ww - border_size - rm - 122 && y > Math.round((wh - 29) / 2) && x < 110 + ww - border_size - rm - 122 && y < Math.round((wh - 29) / 2) + 29) {
  500.                 h_rating = Math.ceil((x - rating_rect.x) / 22);
  501.                 window.RepaintRect(ww - border_size - rm - 131, Math.round((wh - 29) / 2), 131, 29); //repaint rating  
  502.             } else {
  503.                 h_rating = 0;
  504.                 window.RepaintRect(ww - border_size - rm - 131, Math.round((wh - 29) / 2), 131, 29); //repaint rating
  505.             }
  506.         }
  507.     }
  508. }
  509.  
  510. function on_mouse_lbtn_down(x, y) {
  511.     if (hbtn && !ButtonWaitTimerID && !dbtn) {
  512.         dbtn = hbtn;
  513.         dbtn.ChangeState(2);
  514.     };
  515. }
  516.  
  517. function on_mouse_lbtn_up(x, y) {
  518.     if (dbtn) {
  519.         if (dbtn.state == 2 && dbtn != dbtnBackup) {
  520.             dbtn.OnClick(x, y);
  521.             if (!ButtonWaitTimerID) {
  522.                 dbtnBackup = dbtn;
  523.                 ButtonWaitTimer.Start();
  524.             }
  525.         };
  526.         dbtn = undefined;
  527.         on_mouse_move(x, y);
  528.     };
  529.  
  530.     if (MetaDB_type < 2 && h_rating) {
  531.         if (h_rating != rating) {
  532.             if (MetaDB) {
  533.                 fb.RunContextCommandWithMetadb("Rating/" + ((h_rating == 0) ? "<not set>" : h_rating), MetaDB);
  534.             }
  535.         } else {
  536.             fb.RunContextCommandWithMetadb("Rating/<not set>", MetaDB);
  537.         }
  538.     }
  539. }
  540.  
  541. function on_mouse_rbtn_down(x, y, vkey) {
  542.     rbtnDown = true;
  543. }
  544.  
  545. function on_mouse_rbtn_up(x, y, vkey) {
  546.     if (rbtnDown) {
  547.         rbtnDown = false;
  548.         if (vkey == MK_SHIFT) {
  549.             return false; // if shift button pressed, show default context menu.
  550.         } else {
  551.             ShowContextMenu(x, y);
  552.             return true;
  553.         }
  554.     }
  555. }
  556.  
  557. function on_mouse_leave() {
  558.     if (hbtn && !ButtonWaitTimerID) {
  559.         hbtn.ChangeState(0);
  560.         hbtn = undefined;
  561.     }
  562.     Tooltip.Text = "";
  563.  
  564.     if (h_rating) {
  565.         h_rating = 0;
  566.         window.RepaintRect(ww - border_size - rm - 131, Math.round((wh - 29) / 2), 131, 29); //repaint rating
  567.     }
  568. }
  569.  
  570. // Mouse callbacks }}
  571. //===================================================================================================================================================
  572. // Playback callbacks {{
  573.  
  574. function on_playback_new_track() {
  575.     Buttons[1].img = fb.IsPaused || !fb.IsPlaying ? img_play : img_pause;
  576.     window.RepaintRect(Buttons[1].x,Buttons[1].y,Buttons[1].width,Buttons[1].height);
  577.    
  578.     if(Properties.Panel.CursorFollowMode == CursorFollowMode.OnlyStopped){
  579.         if (MetaDB) {
  580.             window.UnwatchMetadb();
  581.         }
  582.        
  583.         MetaDB = fb.GetNowPlaying();
  584.        
  585.         if (MetaDB) {
  586.             on_metadb_changed();
  587.             window.WatchMetadb(MetaDB);
  588.         }
  589.     }
  590. }
  591.  
  592. function on_playback_stop(reason) {
  593.     if (!reason || reason == 1) {
  594.         Buttons[1].img = fb.IsPaused || !fb.IsPlaying ? img_play : img_pause;
  595.         window.RepaintRect(Buttons[1].x,Buttons[1].y,Buttons[1].width,Buttons[1].height);
  596.        
  597.         if(Properties.Panel.CursorFollowMode == CursorFollowMode.OnlyStopped){
  598.             if (MetaDB) {
  599.                 window.UnwatchMetadb();
  600.             }
  601.            
  602.             MetaDB = fb.GetFocusItem();
  603.            
  604.             if (MetaDB) {
  605.                 on_metadb_changed();
  606.                 window.WatchMetadb(MetaDB);
  607.             }
  608.         }
  609.     }
  610. }
  611.  
  612. // Playback callbacks }}
  613. //===================================================================================================================================================
  614. // Other events
  615.  
  616.  
  617. function on_playback_pause(state) {
  618.     Buttons[1].img = state ? img_play : img_pause;
  619.     window.RepaintRect(Buttons[1].x,Buttons[1].y,Buttons[1].width,Buttons[1].height);
  620. }
  621.  
  622. function on_item_focus_change() {
  623.     if (Properties.Panel.CursorFollowMode == CursorFollowMode.Always || (Properties.Panel.CursorFollowMode == CursorFollowMode.OnlyStopped && !fb.IsPlaying && !fb.IsPaused)) {
  624.         if (MetaDB) {
  625.             window.UnwatchMetadb();
  626.         }
  627.        
  628.         MetaDB = fb.GetFocusItem();
  629.        
  630.         if (MetaDB) {
  631.             on_metadb_changed();
  632.             window.WatchMetadb(MetaDB);
  633.         }
  634.     }
  635. }
  636.  
  637. function on_metadb_changed() {
  638.     MetaDB_type = TrackType(MetaDB.RawPath.substring(0, 4));
  639.     if (MetaDB_type < 2) rating = tf_rating.EvalWithMetadb(MetaDB);
  640.  
  641.     window.RepaintRect(ww - border_size - rm - 131, Math.round((wh - 29) / 2), 131, 29); //repaint rating
  642.     window.RepaintRect(Buttons[1].x, Buttons[1].y, Buttons[1].width, Buttons[1].height); // repaint play/pause btn
  643. }
  644.  
  645.  
  646. function on_playlist_switch() {
  647.     on_playlists_changed();
  648. }
  649.  
  650. function on_playlist_items_removed(playlist, new_count) {
  651.     on_playlists_changed();
  652. }
  653.  
  654. function on_playlists_changed() {
  655.     on_item_focus_change();
  656.     if (!fb.IsPlaying && fb.PlaylistItemCount(fb.ActivePlaylist) == 0) {
  657.         MetaDB = false;
  658.     }
  659. }
  660.  
  661.  
  662.  
  663. //EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement