Advertisement
Guest User

Modified Album Art, for WSH 1.4.2 (Autor: Marc2003)

a guest
Aug 13th, 2013
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==PREPROCESSOR==
  2. // @name "Album Art"
  3. // @author "Marc2003"
  4. // @feature "v1.4"
  5. // @feature "watch-metadb"
  6. // ==/PREPROCESSOR==
  7.  
  8. function on_selection_changed() {
  9.     p.item_focus_change();
  10. }
  11.  
  12. function on_playlist_switch() {
  13.     p.item_focus_change();
  14. }
  15.  
  16. function on_playback_new_track() {
  17.     p.item_focus_change();
  18. }
  19.  
  20. function on_playback_dynamic_info_track() {
  21.     p.item_focus_change();
  22. }
  23.  
  24. function on_playback_stop() {
  25.     p.item_focus_change();
  26. }
  27.  
  28. function on_item_focus_change() {
  29.     p.item_focus_change();
  30. }
  31.  
  32. function on_mouse_leave() {
  33.     if (typeof b == "object") b.leave();
  34.     if (typeof r == "object") r.leave();
  35.     if (typeof li == "object") li.leave();
  36.     if (typeof s == "object") s.leave();
  37. }
  38.  
  39. function on_mouse_rbtn_up(x, y) {
  40.     p.rbtn_up(x, y);
  41.     return true;
  42. }
  43. function panel(name, features) {
  44.     this.item_focus_change = function() {
  45.         switch(this.selection_mode) {
  46.             case 0:
  47.                 this.metadb = fb.GetSelection();
  48.                 break;
  49.             case 1:
  50.                 this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
  51.                 break;
  52.             case 2:
  53.                 this.metadb = fb.GetFocusItem();
  54.                 break;
  55.         }
  56.         if (this.metadb && typeof on_metadb_changed == "function") on_metadb_changed();
  57.     }
  58.  
  59. this.colors_changed = function() {
  60.         }
  61.    
  62.  
  63.  
  64. this.font_changed = function() {
  65.         }
  66.    
  67.    
  68.     this.size = function() {
  69.         this.w = window.Width;
  70.         this.h = window.Height;
  71.     }
  72.    
  73.     this.move = function(x, y) {
  74.         this.mx = x;
  75.         this.my = y;
  76.     }
  77.    
  78.  
  79.     this.rbtn_up = function(x, y) {
  80.         var MF_STRING = 0x00000000;
  81.         var _menu = window.CreatePopupMenu();
  82.         var idx;
  83.         switch(true) {
  84.            
  85.             case typeof a == "object" && a.trace(x, y):
  86.                 _menu.AppendMenuItem(MF_STRING, 1, "Refresh");
  87.                 _menu.AppendMenuSeparator();
  88.                 _menu.AppendMenuItem(MF_STRING, 2, "Front");
  89.                 _menu.AppendMenuItem(MF_STRING, 3, "Back");
  90.                 _menu.AppendMenuItem(MF_STRING, 4, "Disc");
  91.                 _menu.AppendMenuItem(MF_STRING, 5, "Icon");
  92.                 _menu.AppendMenuItem(MF_STRING, 6, "Artist");
  93.                 _menu.CheckMenuRadioItem(2, 6, a.id + 2);
  94.                 _menu.AppendMenuSeparator();
  95.                 _menu.AppendMenuItem(MF_STRING, 16, "Top");
  96.                 _menu.AppendMenuItem(MF_STRING, 15, "Centre");
  97.                 _menu.AppendMenuItem(MF_STRING, 17, "Adjust");
  98.                 _menu.AppendMenuItem(MF_STRING, 18, "Stretch");
  99.                 //_menu.AppendMenuSeparator();
  100.                 //_menu.AppendMenuItem(MF_STRING, 5000, "Properties");
  101.                
  102.                
  103.                 _menu.CheckMenuRadioItem(15, 18, a.type == "crop" ? 15 : a.type == "crop top" ? 16 : a.type == "centre" ? 17 : 18);
  104.                 //_menu.AppendMenuSeparator();
  105.                 break;
  106.             case typeof c == "object" && (!this.check_feature("now_playing") || np_cd) && c.trace(x, y):
  107.                 _menu.AppendMenuItem(MF_STRING, 1, "Refresh");
  108.                 //_menu.AppendMenuSeparator();
  109.                 break;
  110.                
  111.             }
  112.        
  113.         //_menu.AppendMenuItem(MF_STRING, 10, "Configure...");
  114.         idx = _menu.TrackPopupMenu(x, y);
  115.         switch(idx) {
  116.             case 1:
  117.                 on_item_focus_change();
  118.                 break;
  119.             case 2:
  120.             case 3:
  121.             case 4:
  122.             case 5:
  123.             case 6:
  124.                 a.id = idx - 2;
  125.                 window.SetProperty("artreader_id", a.id);
  126.                 on_item_focus_change();
  127.                 break;
  128.            
  129.             case 10:
  130.                 window.ShowConfigure();
  131.                 break;
  132.            
  133.             case 15:
  134.             case 16:
  135.             case 17:
  136.             case 18:
  137.                 a.type = idx == 15 ? "crop" : idx == 16 ? "crop top" : idx == 17 ? "centre" : "stretch";
  138.                 window.SetProperty("artreader_image_type", a.type);
  139.                 window.RepaintRect(a.x, a.y, a.w, a.h);
  140.                 break;
  141.             case 5000:
  142.             window.ShowProperties();
  143.             break;
  144.         }
  145.         _menu.Dispose();
  146.        
  147.     }
  148.    
  149.     this.features_init = function() {
  150.         for (i = 0; i < this.features.length; i++) {
  151.             switch(this.features[i]) {
  152.                    
  153.                     case "metadb":
  154.                     this.selection_mode = window.GetProperty("selection_mode", 1);
  155.                     this.metadb = fb.GetFocusItem();
  156.                     break;
  157.                 }
  158.         }
  159.    
  160. }
  161. this.check_feature = function(f) {
  162.         for (i = 0; i < this.features.length; i++) {
  163.             if (this.features[i] == f) return true;
  164.         }
  165.         return false;
  166.     }
  167.     this.tt = function(t) {
  168.         if (this.tooltip.Text == t) return;
  169.         this.tooltip.Text = t;
  170.         this.tooltip.Activate();
  171. }
  172.     this.ttd = function() {
  173.         this.tooltip.Text = "";
  174.         this.tooltip.Deactivate();
  175.     }
  176.     this.draw_image = function(gr, img, pos_x, pos_y, width, height, type, border, alpha) {
  177.         if (!img) return;
  178.         gr.SetInterpolationMode(7);
  179.        
  180.             switch(type) {
  181.             case "crop":
  182.             case "crop top":
  183.                 var sr = img.Width / img.Height;
  184.                 var dr = width / height;
  185.                 if (sr < dr) {
  186.                     var r = img.Width / width;
  187.                     var ch = height * r;
  188.                     var sy = Math.round((img.Height - ch) / (type == "crop top" ? 1000 : 2));
  189.                     var cw = img.Width;
  190.                     var sx = 0;
  191.                 } else {
  192.                     var r = img.Height / height;
  193.                     var cw = width * r;
  194.                     var sx = Math.round((img.Width - cw) / 2);
  195.                     var ch = img.Height;
  196.                     var sy = 0;
  197.                 }
  198.                 gr.DrawImage(img, pos_x, pos_y, width, height, sx + 5, sy + 5, cw - 10, ch - 10, 0, alpha || 255);
  199.                 if (border) gr.DrawRect(pos_x, pos_y, width - 1, height - 1, 1, border);
  200.                 break;
  201.             case "stretch":
  202.                 gr.DrawImage(img, pos_x, pos_y, width, height, 5, 5, img.Width-10, img.Height-10, 0, alpha || 255);
  203.                 if (border) gr.DrawRect(pos_x, pos_y, width - 1, height - 1, 1, border);
  204.                 break;
  205.             case "centre":
  206.             default:
  207.                 var s = Math.min(width / img.Width, height / img.Height);
  208.                 var nw = Math.round(img.Width * s);
  209.                 var nh = Math.round(img.Height * s);
  210.                 pos_x += Math.round((width - nw) / 2);
  211.                 pos_y += Math.round((height - nh) / 2);
  212.                 //for full image, in nex line -change all on 0 or 1
  213.                 //example: gr.DrawImage(img, pos_x, pos_y-1, nw, nh, 1, -1, img.Width-1, img.Height+1, 0, alpha || 255);              
  214.                 gr.DrawImage(img, pos_x, pos_y, nw, nh, 5, 5, img.Width-10, img.Height-10, 0, alpha || 255);
  215.                 if (border) gr.DrawRect(pos_x, pos_y, nw - 1, nh - 1, 1, border);
  216.                 break;
  217.         }
  218.     }
  219.        
  220.     this.name = name;
  221.     this.features = features;
  222.     this.dui = window.InstanceType;
  223.     this.tooltip = window.CreateTooltip();
  224.     this.w = 0;
  225.     this.h = 0;
  226.     this.mx = 0;
  227.     this.my = 0;
  228.     this.metadb = fb.GetFocusItem();
  229.     this.vb = new ActiveXObject("ScriptControl");
  230.     this.vb.Language = "VBScript";
  231.     this.artist = "";
  232.     this.artist_tf = "%artist%";
  233.     this.list_font_size = 11;
  234.     this.features_init();
  235.     this.colors_changed();
  236.     this.font_changed();
  237.     }
  238.  
  239. function artreader(x, y, w, h) {
  240.     this.draw = function(gr) {
  241.         if (!this.img) return;
  242.         p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, this.type);
  243.     }
  244.     this.metadb_changed = function() {
  245.         if (!p.metadb) return;
  246.         this.img && this.img.Dispose();
  247.         this.path = "";
  248.         this.img = utils.GetAlbumArtV2(p.metadb, this.id);
  249.         window.RepaintRect(this.x, this.y, this.w, this.h);
  250.         utils.GetAlbumArtAsync(window.ID, p.metadb, this.id);
  251.     }
  252.     this.get_album_art_done = function(ip) {
  253.         this.path = ip;
  254.     }
  255.     this.trace = function(x, y) {
  256.         return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
  257.     }
  258.     this.wheel = function(step) {
  259.         if (!this.trace(p.mx, p.my)) return false;
  260.         this.id -= step;
  261.         if (this.id < 0) this.id = 4;
  262.         if (this.id > 4) this.id = 0;
  263.         window.SetProperty("artreader_id", this.id);
  264.         this.metadb_changed();
  265.         return true;
  266.     }
  267.     this.move = function(x, y) {
  268.         if (this.trace(x, y)) {
  269.             // next line show picture size
  270.             //if (this.img) p.tt("Original size: " + this.img.Width + "x" + this.img.Height + "px");
  271.             //return true;
  272.         } else {
  273.             p.ttd();
  274.             return false;
  275.         }
  276.     }
  277.     this.x = x;
  278.     this.y = y;
  279.     this.w = w;
  280.     this.h = h;
  281.     this.id = window.GetProperty("artreader_id", 0);
  282.     this.img = null;
  283.     this.path = null;
  284.     this.type = window.GetProperty("artreader_image_type", "centre");
  285. }
  286. //Begin
  287. var p = new panel("Art Reader", ["metadb"]);
  288. var a = new artreader(0, 0, 100, 100);
  289.  
  290. on_item_focus_change();
  291.  
  292. function on_size() {
  293.     p.size();
  294.     a.w = p.w;
  295.     a.h = p.h;
  296. }
  297.  
  298. function on_paint(gr) {
  299.    
  300.     a.draw(gr);
  301.     if (!a.img) p.centre_tex;
  302. }
  303.  
  304. function on_metadb_changed() {
  305.     a.metadb_changed();
  306. }
  307.  
  308. function on_get_album_art_done(metadb, art_id, im, ip) {
  309.     a.get_album_art_done(ip);
  310. }
  311. function on_mouse_wheel(step) {
  312.     a.wheel(step);
  313. }
  314. //next line alow you to skroll images with mouse (front,back,artist..)
  315. //function on_mouse_move(x, y) {
  316.     //p.move(x, y);
  317.     //a.move(x, y);
  318. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement