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

Tom

By: a guest on Jan 16th, 2010  |  syntax: JavaScript  |  size: 5.69 KB  |  views: 314  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // ==PREPROCESSOR==
  2. // @import "%fb2k_path%scripts\getColoursFonts.js"
  3. // ==/PREPROCESSOR==
  4.  
  5. // args: h_align, v_align, trimming, flags
  6. function StringFormat()
  7. {
  8.         var h_align = 0, v_align = 0, trimming = 0, flags = 0;
  9.         switch (arguments.length)
  10.         {
  11.         // fall-thru
  12.         case 4:
  13.                 flags = arguments[3];
  14.         case 3:
  15.                 trimming = arguments[2];
  16.         case 2:
  17.                 v_align = arguments[1];
  18.         case 1:
  19.                 h_align = arguments[0];
  20.                 break;
  21.         default:
  22.                 return 0;
  23.         }
  24.         return ((h_align << 28) | (v_align << 24) | (trimming << 20) | flags);
  25. }
  26. // h_align/v_align:
  27. StringAlignment = {
  28.         Near: 0,
  29.         Center: 1,
  30.         Far: 2
  31. };
  32. //Colour funcs
  33. function RGB(r, g, b)
  34. {       return (0xff000000 | (r << 16) | (g << 8) | (b)); }
  35.  
  36. var fontname = "Segoe UI";
  37.  
  38. text = {
  39.         metadata: fb.TitleFormat("$if2(%STREAM_NAME%,[%artist%][ $char(8226) %conductor%][ $char(8226) %performer%]$crlf()[$num(%tracknumber%,0). ][%title%])$crlf()$if(%STREAM_NAME%,[%artist% - ][%title%],[%album%[ $char(8226) %set subtitle%]])"),
  40.         font: gdi.Font(fontname, 18, 1)
  41. };
  42. lyrics = {
  43.         metadata: fb.TitleFormat("[$if2(%unsynched lyrics%,%lyrics%)]"),
  44.         font: gdi.Font(fontname, 13, 0)
  45. };
  46. indfnt = gdi.Font(fontname, 9, 1);    
  47. indfmt = StringFormat(1, 0);
  48. lyr_stringformat = StringFormat(StringAlignment.Center);
  49. var ww, wh;
  50. //Stuff for text
  51. var textsize;
  52. var lyricsize = 0;
  53. var txtx=2;
  54. var lyry=0;
  55. var scroll=0;
  56. var txty;
  57. var txtwid;
  58. var img_x,img_y,img_w,img_h;
  59. var imgr_x,imgr_y;
  60. var fcstrk = false;
  61. var showlyrics = false;
  62. var padh = 2;
  63. var padt = 2;
  64. var textrender = gdi.CreateStyleTextRender();
  65. var txtev = evaldata(text.metadata);
  66. var lyrev = evaldata(lyrics.metadata);
  67. //Art
  68. var arttype = 0;
  69. var g_img = utils.GetAlbumArtV2((fb.IsPlaying&&!fcstrk)?fb.GetNowPlaying():fb.GetFocusItem(), arttype);
  70. AlbumArtName = new Array("Front","Back","Disc","Icon","Artist");
  71.  
  72. function on_paint(gr)
  73. {
  74.     gr.FillSolidRect(0,0,ww,wh,bg);
  75.         gr.SetInterpolationMode(3);
  76.     textsize = gr.MeasureString(txtev, text.font, 0, 0, ww, wh).Height;
  77.         //Draw front cover
  78.         if(g_img && !(showlyrics && lyrev))
  79.         {
  80.                 //Normal
  81.                 gr.DrawImage(g_img, img_x, img_y, img_w, img_h, 0, 0, g_img.Width, g_img.Height);
  82.                 //Rotated
  83.                 gr.DrawImage(g_img, imgr_x, imgr_y, -img_w, img_h/2, 0, g_img.Height/2, g_img.Width, g_img.Height/2,180,220);
  84.                 //Mirror mask
  85.                 gr.FillGradRect(img_x-1, imgr_y-1, img_w+2, img_h/2+2,91,bg-0x80000000,bg);
  86.     }
  87.         //Draw lyrics
  88.         if(showlyrics && lyrev)
  89.         {
  90.                 lyricsize = gr.MeasureString(lyrev, lyrics.font, 0, 0, txtwid, 9999999999).Height;
  91.                 gr.SetTextRenderingHint(5);
  92.                 gr.DrawString(lyrev, lyrics.font, txtcol, txtx, 12+textsize+lyry+scroll, txtwid, lyricsize, lyr_stringformat);
  93.                 gr.FillSolidRect(0,0,ww,textsize+8,bg);
  94.                 gr.FillSolidRect(0,wh-18,ww,18,bg);
  95.         }
  96.     //Draw track info
  97.         gr.SetSmoothingMode(4);
  98.     gr.SetTextRenderingHint(5);
  99.         textrender.OutlineText(txtcol, bg, 3);
  100.         textrender.RenderStringRect(gr, txtev, text.font, 0, (showlyrics && lyrev)?0:Math.min(wh-12-textsize,img_y+img_h), ww, Math.max(textsize,wh-img_y-img_h), (showlyrics && lyrev)?0x10000000:0x11000000);
  101.     //draw state indicator
  102.     gr.DrawString((fcstrk?"Prefer Focused Track":"Prefer Now Playing")+" | "+(showlyrics?"Prefer Lyrics":"Prefer Art")+" | Art Type: "+AlbumArtName[arttype], indfnt, RGB(0,200,0),0,wh-12,ww,12,indfmt);
  103. }
  104.  
  105. function on_size()
  106. {
  107.         ww = window.Width;
  108.         wh = window.Height;
  109.         txtwid = ww-2*txtx;
  110.         if(g_img && !(showlyrics && lyrev))
  111.         {
  112.                 img_w = Math.min(ww-2*padh,(4/5)*(wh*g_img.Width/g_img.Height));
  113.                 img_h = Math.min((ww-2*padh)*g_img.Height/g_img.Width,(4/5)*(wh-2*padh));
  114.                 img_x = (img_w==ww-2*padh)?padh:(ww-(4/5)*(wh*g_img.Width/g_img.Height))/2;
  115.                 img_y = padt;
  116.                 imgr_x = img_x+img_w;
  117.                 imgr_y = img_y+img_h-1;
  118.         }
  119. }
  120. function evaldata(txt)
  121. {
  122.         return (fb.IsPlaying&&!fcstrk)?txt.Eval():txt.EvalWithMetadb(fb.GetFocusItem());
  123. }
  124. /////Update display
  125. function on_playback_new_track(metadb)
  126. {
  127.         if(!fcstrk)
  128.         {
  129.                 lyry = 0;
  130.                 scroll=0;
  131.                 g_img = utils.GetAlbumArtV2(metadb, arttype);
  132.                 txtev = evaldata(text.metadata);
  133.                 lyrev = evaldata(lyrics.metadata);
  134.                 on_size();
  135.                 window.Repaint();
  136.         }
  137. }
  138.  
  139. function on_item_focus_change()
  140. {
  141.         if(!fb.IsPlaying||fcstrk&&fb.GetFocusItem())
  142.         {
  143.                 lyry = 0;
  144.                 scroll=0;
  145.                 g_img = utils.GetAlbumArtV2(fb.GetFocusItem(), arttype);
  146.                 txtev = evaldata(text.metadata);
  147.                 lyrev = evaldata(lyrics.metadata);
  148.                 on_size();
  149.                 window.Repaint();
  150.         }
  151. }
  152.  
  153. function on_playlist_switch()
  154. {
  155.     on_item_focus_change();
  156. }
  157.  
  158. function on_playback_dynamic_info_track()
  159. {
  160.     txtev = evaldata(text.metadata);
  161.         window.Repaint();
  162. }
  163.  
  164. function on_playback_stop()
  165. {
  166.         window.Repaint();
  167. }
  168.  
  169. function on_playback_time(time)
  170. {
  171.         if(showlyrics && lyrev && !fcstrk)
  172.         {
  173.                 lyry = (wh-textsize-32)>lyricsize?0:(wh-textsize-32-lyricsize)*fb.PlaybackTime/fb.PlaybackLength;
  174.                 window.Repaint();
  175.         }
  176. }
  177.  
  178. ////////Interaction
  179. function on_mouse_lbtn_dblclk(x, y)
  180. {
  181.         fcstrk = !fcstrk;
  182.         if(fcstrk){on_item_focus_change()}
  183.         else if(fb.IsPlaying){on_playback_new_track(fb.GetNowPlaying());}
  184.         window.Repaint();
  185. }
  186. function on_mouse_mbtn_up(x, y)
  187. {
  188.         lyrev = evaldata(lyrics.metadata);
  189.         showlyrics = !showlyrics;
  190.         if(fcstrk||!fb.IsPlaying){on_item_focus_change()}
  191.         else if(fb.IsPlaying){on_playback_new_track(fb.GetNowPlaying());}
  192.         window.repaint();
  193. }
  194. function on_mouse_wheel(step)
  195. {
  196.         if(showlyrics && lyrev)
  197.         {
  198.                 if(step>0)
  199.                 {              
  200.                         if(lyry+scroll < 0)
  201.                         {
  202.                                 scroll = scroll+60;
  203.                         }
  204.                 }
  205.                 else
  206.                 {
  207.                         if( wh-(42+textsize+lyry+scroll) < lyricsize)
  208.                         {
  209.                                 scroll = scroll-60;
  210.                         }
  211.                 }
  212.         }
  213.     else
  214.     {
  215.         arttype=((arttype+step)%5+5)%5;
  216.         if(fcstrk||!fb.IsPlaying){on_item_focus_change()}
  217.         else if(fb.IsPlaying){on_playback_new_track(fb.GetNowPlaying());}
  218.     }
  219.     window.Repaint();
  220. }