Advertisement
D-Gj

Album art display

Apr 2nd, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==PREPROCESSOR==
  2. // @name "Album art display"
  3. // ==/PREPROCESSOR==
  4.  
  5. window.MinWidth = window.MinHeight = window.MaxWidth = window.MaxHeight = 333;
  6.  
  7. var Artwork =
  8. {
  9.     Image: null,
  10.     Path: ""
  11. }
  12.  
  13. var Info =
  14. {
  15.     Tooltip: window.CreateTooltip(),
  16.     Active: false
  17. }
  18.  
  19. function on_paint(graphics)
  20. {
  21.     graphics.SetSmoothingMode(4); // Use anti-aliasing
  22.     graphics.FillSolidRect(0, 0, window.Width, window.Height, 0xFFFFFFFF); // Fill the background
  23.    
  24.     if (Artwork.Image)
  25.     {
  26.         graphics.SetInterpolationMode(7); // Use high-quality bicubic interpolation
  27.         graphics.DrawImage(Artwork.Image, 0, 0, window.Width, window.Height, 0, 0, Artwork.Image.Width, Artwork.Image.Height);
  28.        
  29.         if (Info.Active)
  30.         {
  31.             Info.Tooltip.Deactivate();
  32.             Info.Tooltip.Text = "Original size: " + Artwork.Image.Width + "×" + Artwork.Image.Height + " pixels.";
  33.             Info.Tooltip.Activate();
  34.         }
  35.         else
  36.         {
  37.             Info.Tooltip.Text = "Original size: " + Artwork.Image.Width + "×" + Artwork.Image.Height + " pixels.";
  38.         }
  39.     }
  40.     else
  41.     {
  42.         graphics.SetTextRenderingHint(4); // Use anti-aliased text
  43.         graphics.GdiDrawText("No image was found to be displayed.", gdi.Font(window.GetFontDUI(0).Name, 19), 0x00000000, 0, 0, window.Width, window.Height, 3077);
  44.     }
  45.     /*
  46.         DT_CENTER   = 0x00000001
  47.         DT_VCENTER  = 0x00000004
  48.         DT_CALCRECT = 0x00000400
  49.         DT_NOPREFIX = 0x00000800
  50.        
  51.         DT_CENTER | DT_VCENTER | DT_CALCRECT | DT_NOPREFIX = 3077
  52.     */
  53. }
  54.  
  55. function on_get_album_art_done(whichTrack, coverType, coverImage, coverPath)
  56. {
  57.     if (coverPath != Artwork.Path)
  58.     {
  59.         Artwork.Image && Artwork.Image.Dispose();
  60.        
  61.         Artwork.Image = coverImage;
  62.         Artwork.Path  = coverPath;
  63.        
  64.         window.Repaint();
  65.     }
  66. }
  67.  
  68. function on_playback_new_track(whichTrack)
  69. {
  70.     if (whichTrack)
  71.     {
  72.         utils.GetAlbumArtAsync(window.ID, whichTrack, 0, false, false, false);
  73.         whichTrack.Dispose();
  74.     }
  75.     /*
  76.         Do not load a stub image if no cover art is found.
  77.         Check for external as well as for embedded images.
  78.         Load the image into the memory and use it within the callback.
  79.     */
  80. }
  81.  
  82. function on_mouse_move(x, y)
  83. {
  84.     if (!Info.Active && Artwork.Image)
  85.     {
  86.         Info.Tooltip.Activate();
  87.         Info.Active = true;
  88.     }
  89. }
  90.  
  91. function on_mouse_leave()
  92. {
  93.     if (Info.Active)
  94.     {
  95.         Info.Tooltip.Deactivate();
  96.         Info.Active = false;
  97.     }
  98. }
  99.  
  100. on_playback_new_track(fb.GetNowPlaying());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement