Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 20th, 2010  |  syntax: JavaScript  |  size: 6.12 KB  |  views: 179  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // ==PREPROCESSOR==
  2. // @import "%fb2k_profile_path%scripts\common.js"
  3. // @name "Album Art"
  4. // ==/PREPROCESSOR==
  5.  
  6. var g_img;
  7. var g_text = '';
  8. var artist = '';
  9. var album = '';
  10. var title = '';
  11. var lfm_img = gdi.Image(images_path + "lastfm_red_small.gif");
  12. var g_tooltip = window.CreateTooltip();
  13. g_tooltip.Text = "last.fm track page";
  14. var g_textrender = gdi.CreateStyleTextRender();
  15.  
  16. window.GetProperty("scale", "max");
  17. window.GetProperty("playinginfo", true);
  18. window.GetProperty("lastfminfo", true);
  19. window.GetProperty("id",0);
  20.  
  21. on_item_focus_change();
  22.  
  23. function on_size() {
  24.         ww = window.Width;
  25.         wh = window.Height;
  26. }
  27.  
  28. function on_notify_data(name, data) {
  29.         if (name == "playingtrack") {
  30.                 g_text = data;
  31.         window.RepaintRect(0, wh - 70, ww, 70);
  32.         }
  33. }
  34.  
  35. function on_paint(gr) {
  36.         gr.FillSolidRect(0, 0, ww, wh, g_backcolor);
  37.         if (g_img) {
  38.            scale(gr, g_img, 0, 0, ww, wh, window.GetProperty("scale"));
  39.         } else {
  40.                 gr.GdiDrawText(g_metadb ? "[no image]" : "[no selection]", g_font, g_textcolor, 0, 0, ww, wh, DT_VCENTER | DT_CENTER | DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
  41.         }
  42.     if (!fb.IsPlaying) return;
  43.     y_off = 16;
  44.     g_textrender.OutLineText(g_textcolor, g_backcolor, 3);
  45.     gr.SetTextRenderingHint(0);
  46.     gr.SetSmoothingMode(4);
  47.     gr.SetInterpolationMode(7);
  48.     if (window.GetProperty("lastfminfo")) gr.DrawImage(lfm_img, ww-60, 8, 50, 18, 0, 0, 50, 18);
  49.     if (g_text != "") {
  50.         y_off = 0;
  51.         g_textrender.RenderStringRect(gr, g_text, gdi.Font(font, 12, 1), 5, wh-22, ww-10, 14, 0x10305000);
  52.     }
  53.         if (window.GetProperty("playinginfo")) {
  54.         g_textrender.RenderStringRect(gr, title, gdi.Font(font, 12, 1), 5, wh-70+y_off, ww-10, 14, 0x10305000);
  55.         g_textrender.RenderStringRect(gr, album, gdi.Font(font, 12, 1), 5, wh-54+y_off, ww-10, 14, 0x10305000);
  56.                 g_textrender.RenderStringRect(gr, artist, gdi.Font(font, 12, 1), 5, wh-38+y_off, ww-10, 14, 0x10305000);               
  57.         }
  58. }
  59.  
  60. function scale(gr, img, pos_x, pos_y, width, height, mth) {
  61.         var s = mth == "max" ? Math.max(width / img.width, height / img.height) : Math.min(width / img.width, height / img.height);
  62.         var nw = Math.round(img.width * s);
  63.         var nh = Math.round(img.height * s);
  64.         pos_x += Math.round((width - nw) / 2);
  65.         pos_y += Math.round((height - nh) / 2);
  66.         gr.DrawImage(img, pos_x, pos_y, nw, nh, 0, 0, img.width, img.height);
  67. }
  68.  
  69. function on_playback_new_track() {
  70.     g_metadb && g_metadb.Dispose();
  71.         on_item_focus_change();
  72.     artist = fb.TitleFormat("%artist%").EvalWithMetadb(g_metadb);
  73.     album = fb.TitleFormat("%album%").EvalWithMetadb(g_metadb);
  74.     title = fb.TitleFormat("%title%").EvalWithMetadb(g_metadb);
  75.     if (window.GetProperty("lastfminfo")) window.NotifyOthers("getplayinginfo", [artist, title]);
  76.         update_image();
  77. }
  78.  
  79. function on_metadb_changed() {
  80.         if(fb.IsPlaying) return;
  81.         update_image();
  82. }
  83.  
  84. function on_playback_stop(reason) {
  85.     if (reason != 2) window.Repaint();
  86. }
  87.  
  88. function update_image() {
  89.         if(!g_metadb) return;
  90.         is_embedded = null;
  91.         g_img && g_img.Dispose();
  92.         type = window.GetProperty("id");
  93.         g_img = utils.GetAlbumArtEmbedded(g_metadb.rawpath, type);
  94.         if(g_img) {
  95.                 is_embedded = true;
  96.                 window.Repaint();
  97.         } else {
  98.                 utils.GetAlbumArtAsync(window.ID, g_metadb, type);
  99.         }
  100. }
  101.  
  102. function on_get_album_art_done(metadb, art_id, im, ip) {
  103.         g_img_path = ip;
  104.         g_img = im;
  105.         window.Repaint();
  106. }
  107.  
  108. function on_mouse_move(x,y) {
  109.         if (window.GetProperty("playinginfo") && x > ww-60 && x < ww-10 && y > 8 && y < 26) {
  110.                 g_tooltip.Activate();
  111.                 window.SetCursor(IDC_HAND);
  112.         } else {
  113.                 g_tooltip.Deactivate();
  114.                 window.SetCursor(IDC_ARROW);
  115.         }
  116. }
  117.  
  118. function on_mouse_lbtn_up(x, y) {
  119.         if (window.GetProperty("playinginfo") && x > ww-60 && x < ww-10 && y > 8 && y < 26) {
  120.                 WshShell.run("http://www.last.fm/music/" + encodeURIComponent(artist) + "/_/" + encodeURIComponent(title));
  121.         }
  122. }
  123.  
  124. function on_mouse_lbtn_dblclk() {
  125.         if(!g_metadb || !g_img) return;
  126.         if(is_embedded) {
  127.                 fb.RunContextCommandWithMetadb("Open Containing Folder", g_metadb);
  128.         } else {
  129.                 try {WshShell.Run("\"" + g_img_path + "\""); } catch(e) {}
  130.         }
  131. }
  132.  
  133. function on_mouse_rbtn_up(x, y) {
  134.         var _menu = window.CreatePopupMenu();
  135.         var idx;
  136.         _menu.AppendMenuItem(MF_STRING, 1, "Refresh");
  137.         _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  138.         _menu.AppendMenuItem(MF_STRING, 2, "Front cover");
  139.         _menu.AppendMenuItem(MF_STRING, 3, "Back cover");
  140.         _menu.AppendMenuItem(MF_STRING, 4, "Disc");
  141.         _menu.AppendMenuItem(MF_STRING, 5, "Icon");
  142.         _menu.AppendMenuItem(MF_STRING, 6, "Artist");
  143.         _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  144.         _menu.AppendMenuItem(MF_STRING, 7, "Fill");
  145.         _menu.CheckMenuItem(7, window.GetProperty("scale") == "max");
  146.     _menu.AppendMenuItem(MF_STRING, 8, "Playing track info");
  147.     _menu.CheckMenuItem(8, window.GetProperty("playinginfo"));
  148.     _menu.AppendMenuItem(MF_STRING, 9, "Last.fm track info");
  149.     _menu.CheckMenuItem(9, window.GetProperty("lastfminfo"));
  150.         if(utils.IsKeyPressed(0x10)) {
  151.         _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  152.         _menu.AppendMenuItem(MF_STRING, 99, "Properties");
  153.             _menu.AppendMenuItem(MF_STRING, 100, "Configure...");
  154.     }
  155.         _menu.CheckMenuRadioItem(2, 6, window.GetProperty("id")+2);
  156.         idx = _menu.TrackPopupMenu(x, y);
  157.         switch(idx) {
  158.                 case 1:
  159.                         update_image();
  160.                         break;
  161.                 case 2:
  162.                 case 3:
  163.                 case 4:
  164.                 case 5:
  165.                 case 6:
  166.                         window.SetProperty("id", idx-2);
  167.                         update_image();
  168.                         break;
  169.                 case 7:
  170.                         window.SetProperty("scale", window.GetProperty("scale") == "max" ? "min" : "max");
  171.                         window.Repaint();
  172.                         break;
  173.         case 8:
  174.             window.SetProperty("playinginfo", !window.GetProperty("playinginfo"));
  175.             window.RepaintRect(0, wh - 70, ww, 70);
  176.             break;
  177.         case 9:
  178.             window.SetProperty("lastfminfo", !window.GetProperty("lastfminfo"));
  179.             if (fb.IsPlaying && window.GetProperty("lastfminfo")) window.NotifyOthers("getplayinginfo", [artist, title]);
  180.             if (!window.GetProperty("lastfminfo")) g_text = "";
  181.             window.Repaint();
  182.             break;
  183.                 case 99:
  184.                         window.ShowProperties();
  185.                         break;
  186.                 case 100:
  187.                         window.ShowConfigure();
  188.                         break;
  189.         }
  190.         _menu.Dispose();
  191.         return true;
  192. }