Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==PREPROCESSOR==
- // @name "Album Art"
- // @author "Mire777"
- // @feature "v1.4"
- // @feature "watch-metadb"
- // ==/PREPROCESSOR==
- var quality = window.GetProperty(" Quality", 7.5);
- var cut_edge = window.GetProperty(" Cut Edge", 0);
- var cycle = window.GetProperty(" Auto Cycle Image", 0);
- function on_selection_changed() {
- if (cycle==1)
- a.id = 0;
- a.metadb_changed();
- p.item_focus_change();
- }
- function on_playlist_switch() {
- if (cycle==1)
- a.id = 0;
- a.metadb_changed();
- p.item_focus_change();
- }
- function on_playback_new_track() {
- if (cycle==1)
- a.id = 0;
- a.metadb_changed();
- p.item_focus_change();
- }
- function on_playback_dynamic_info_track() {
- if (cycle==1)
- a.id = 0;
- a.metadb_changed();
- p.item_focus_change();
- }
- function on_playback_stop() {
- if (cycle==1)
- a.id = 0;
- a.metadb_changed();
- p.item_focus_change();
- }
- function on_item_focus_change() {
- if (cycle==1)
- a.id = 0;
- a.metadb_changed();
- p.item_focus_change();
- }
- function on_mouse_leave() {
- if (typeof b == "object") b.leave();
- if (typeof r == "object") r.leave();
- if (typeof li == "object") li.leave();
- if (typeof s == "object") s.leave();
- }
- function on_mouse_rbtn_up(x, y) {
- p.rbtn_up(x, y);
- return true;
- }
- function panel(name, features) {
- this.item_focus_change = function() {
- switch(this.selection_mode) {
- case 0:
- this.metadb = fb.GetSelection();
- break;
- case 1:
- this.metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
- break;
- case 2:
- this.metadb = fb.GetFocusItem();
- break;
- }
- if (this.metadb && typeof on_metadb_changed == "function") on_metadb_changed();
- }
- this.colors_changed = function() {
- }
- this.font_changed = function() {
- }
- this.size = function() {
- this.w = window.Width;
- this.h = window.Height;
- }
- this.move = function(x, y) {
- this.mx = x;
- this.my = y;
- }
- this.rbtn_up = function(x, y) {
- var MF_STRING = 0x00000000;
- var _menu = window.CreatePopupMenu();
- var q = window.CreatePopupMenu();
- var MF_POPUP = 0x00000010;
- var MF_GRAYED = 0x00000001;
- var idx;
- switch(true) {
- case typeof a == "object" && a.trace(x, y):
- _menu.AppendMenuItem(MF_STRING, 1, "Refresh");
- //Auto Cycle Image(menu)
- if (cycle==1) _menu.AppendMenuItem(MF_STRING, 5001, "Auto Cycle Image");
- else
- if (cycle==0) _menu.AppendMenuItem(MF_STRING, 5002, "Auto Cycle Image");
- _menu.CheckMenuItem(5001, cycle?1:0);
- //Image Quality(menu)
- _menu.AppendMenuItem(MF_STRING | MF_POPUP, q.ID, "Image Quality");
- q.AppendMenuItem(MF_STRING, 5003, "High");
- q.AppendMenuItem(MF_STRING, 5004, "Cut");
- q.AppendMenuItem(MF_STRING, 5005, "Low");
- _menu.CheckMenuItem(5003, quality=="7" & cut_edge=="0");
- _menu.CheckMenuItem(5004, quality=="7" & cut_edge=="1");
- _menu.CheckMenuItem(5005, quality=="7.5" & cut_edge=="0");
- //Main(menu)
- _menu.AppendMenuSeparator();
- if (cycle==0) _menu.AppendMenuItem(MF_STRING, 2, "Front");
- if (cycle==1) _menu.AppendMenuItem(MF_STRING | MF_GRAYED, 2, "Front");
- if (cycle==0) _menu.AppendMenuItem(MF_STRING, 3, "Back");
- if (cycle==1) _menu.AppendMenuItem(MF_STRING | MF_GRAYED, 3, "Back");
- if (cycle==0) _menu.AppendMenuItem(MF_STRING, 4, "Disc");
- if (cycle==1) _menu.AppendMenuItem(MF_STRING | MF_GRAYED, 4, "Disc");
- if (cycle==0) _menu.AppendMenuItem(MF_STRING, 5, "Icon");
- if (cycle==1) _menu.AppendMenuItem(MF_STRING | MF_GRAYED, 5, "Icon");
- if (cycle==0) _menu.AppendMenuItem(MF_STRING, 6, "Artist");
- if (cycle==1) _menu.AppendMenuItem(MF_STRING | MF_GRAYED, 6, "Artist");
- if (cycle==0) _menu.CheckMenuRadioItem(2, 6, a.id + 2);
- _menu.AppendMenuSeparator();
- _menu.AppendMenuItem(MF_STRING, 16, "Top");
- _menu.AppendMenuItem(MF_STRING, 15, "Centre");
- _menu.AppendMenuItem(MF_STRING, 17, "Adjust");
- _menu.AppendMenuItem(MF_STRING, 18, "Stretch");
- //_menu.AppendMenuSeparator();
- _menu.AppendMenuItem(MF_STRING, 5000, "Properties");
- _menu.CheckMenuRadioItem(15, 18, a.type == "crop" ? 15 : a.type == "crop top" ? 16 : a.type == "centre" ? 17 : 18);
- //_menu.AppendMenuSeparator();
- break;
- case typeof c == "object" && (!this.check_feature("now_playing") || np_cd) && c.trace(x, y):
- _menu.AppendMenuItem(MF_STRING, 1, "Refresh");
- //_menu.AppendMenuSeparator();
- break;
- }
- _menu.AppendMenuItem(MF_STRING, 10, "Configure...");
- idx = _menu.TrackPopupMenu(x, y);
- switch(idx) {
- case 1:
- on_item_focus_change();
- break;
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- a.id = idx - 2;
- window.SetProperty("artreader_id", a.id);
- on_item_focus_change();
- break;
- case 10:
- window.ShowConfigure();
- break;
- case 15:
- case 16:
- case 17:
- case 18:
- a.type = idx == 15 ? "crop" : idx == 16 ? "crop top" : idx == 17 ? "centre" : "stretch";
- window.SetProperty("artreader_image_type", a.type);
- window.RepaintRect(a.x, a.y, a.w, a.h);
- break;
- case 5000:
- window.ShowProperties();
- break;
- case 5001:
- cycle = 0;
- window.SetProperty(" Auto Cycle Image", 0);
- break;
- case 5002:
- cycle = 1;
- window.SetProperty(" Auto Cycle Image", 1);
- break;
- case 5003:
- cut_edge = 0;
- quality = 7;
- window.SetProperty(" Cut Edge", 0);
- window.SetProperty(" Quality", 7);
- p.item_focus_change();
- break;
- case 5004:
- cut_edge = 1;
- quality = 7;
- window.SetProperty(" Cut Edge", 1);
- window.SetProperty(" Quality", 7);
- p.item_focus_change();
- break;
- case 5005:
- cut_edge = 0;
- quality = 7.5;
- window.SetProperty(" Cut Edge", 0);
- window.SetProperty(" Quality", 7.5);
- p.item_focus_change();
- break;
- }
- _menu.Dispose();
- }
- this.features_init = function() {
- for (i = 0; i < this.features.length; i++) {
- switch(this.features[i]) {
- case "metadb":
- this.selection_mode = window.GetProperty("selection_mode", 1);
- this.metadb = fb.GetFocusItem();
- break;
- }
- }
- }
- this.check_feature = function(f) {
- for (i = 0; i < this.features.length; i++) {
- if (this.features[i] == f) return true;
- }
- return false;
- }
- this.tt = function(t) {
- if (this.tooltip.Text == t) return;
- this.tooltip.Text = t;
- this.tooltip.Activate();
- }
- this.ttd = function() {
- this.tooltip.Text = "";
- this.tooltip.Deactivate();
- }
- this.draw_image = function(gr, img, pos_x, pos_y, width, height, type, border, alpha) {
- if (!img) return;
- gr.SetInterpolationMode(quality);
- switch(type) {
- case "crop":
- case "crop top":
- {
- var sr = img.Width / img.Height;
- var dr = width / height;
- if (sr < dr) {
- var r = img.Width / width;
- var ch = height * r;
- var sy = Math.round((img.Height - ch) / (type == "crop top" ? 1000 : 2));
- var cw = img.Width;
- var sx = 0;
- } else {
- var r = img.Height / height;
- var cw = width * r;
- var sx = Math.round((img.Width - cw) / 2);
- var ch = img.Height;
- var sy = 0;
- }
- if (cut_edge==0)
- {
- gr.DrawImage(img, pos_x, pos_y, width, height, sx + 5, sy + 5, cw - 10, ch - 10, 0, alpha || 255);
- if (border) gr.DrawRect(pos_x, pos_y, width - 1, height - 1, 1, border);
- }
- else
- if (cut_edge==1)
- {
- gr.DrawImage(img, pos_x, pos_y, width, height, sx + 5, sy + 5, cw - 10, ch - 10, 0, alpha || 255);
- if (border) gr.DrawRect(pos_x, pos_y, width - 1, height - 1, 1, border);
- }
- }
- break;
- case "stretch":
- //strech
- if (cut_edge==0)
- {
- gr.DrawImage(img, pos_x, pos_y, width, height, 0, 0, img.Width, img.Height, 0, alpha || 255);
- if (border) gr.DrawRect(pos_x, pos_y, width - 1, height - 1, 1, border);
- }
- else
- if (cut_edge==1)
- {
- gr.DrawImage(img, pos_x, pos_y, width, height, 5, 5, img.Width-10, img.Height-10, 0, alpha || 255);
- if (border) gr.DrawRect(pos_x, pos_y, width - 1, height - 1, 1, border);
- }
- break;
- case "centre":
- default:
- //adjust
- var s = Math.min(width / img.Width, height / img.Height);
- var nw = Math.round(img.Width * s);
- var nh = Math.round(img.Height * s);
- pos_x += Math.round((width - nw) / 2);
- pos_y += Math.round((height - nh) / 2);
- if (cut_edge==0)
- {
- gr.DrawImage(img, pos_x, pos_y, nw, nh, 0, 0, img.Width, img.Height, 0, alpha || 255);
- if (border) gr.DrawRect(pos_x, pos_y, nw - 1, nh - 1, 1, border);
- }
- else
- if (cut_edge==1)
- {
- gr.DrawImage(img, pos_x, pos_y, nw, nh, 5, 5, img.Width-10, img.Height-10, 0, alpha || 255);
- if (border) gr.DrawRect(pos_x, pos_y, nw - 1, nh - 1, 1, border);
- }
- break;
- }
- }
- this.name = name;
- this.features = features;
- this.dui = window.InstanceType;
- this.tooltip = window.CreateTooltip();
- this.w = 0;
- this.h = 0;
- this.mx = 0;
- this.my = 0;
- this.metadb = fb.GetFocusItem();
- this.vb = new ActiveXObject("ScriptControl");
- this.vb.Language = "VBScript";
- this.artist = "";
- this.artist_tf = "%artist%";
- this.list_font_size = 11;
- this.features_init();
- this.colors_changed();
- this.font_changed();
- }
- function artreader(x, y, w, h) {
- this.draw = function(gr) {
- if (!this.img) return;
- p.draw_image(gr, this.img, this.x, this.y, this.w, this.h, this.type);
- }
- this.metadb_changed = function() {
- if (!p.metadb) return;
- this.img && this.img.Dispose();
- this.path = "";
- this.img = utils.GetAlbumArtV2(p.metadb, this.id);
- //if 1+ image not found, then show front cover
- if (cycle==1)
- if (!this.img) {
- this.id++;
- if (this.id < 4) this.id = 0;
- else
- if (this.id > 4) this.id = 0;
- //p.item_focus_change();
- //this.metadb_changed();
- return;
- }
- window.RepaintRect(this.x, this.y, this.w, this.h);
- utils.GetAlbumArtAsync(window.ID, p.metadb, this.id);
- }
- this.get_album_art_done = function(ip) {
- this.path = ip;
- }
- this.trace = function(x, y) {
- return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
- }
- this.wheel = function(step) {
- if (!this.trace(p.mx, p.my)) return false;
- this.id -= step;
- if (this.id < 0) this.id = 4;
- if (this.id > 4) this.id = 0;
- window.SetProperty("artreader_id", this.id);
- this.metadb_changed();
- return true;
- }
- this.move = function(x, y) {
- if (this.trace(x, y)) {
- // next line show picture size
- //if (this.img) p.tt("Original size: " + this.img.Width + "x" + this.img.Height + "px");
- //return true;
- } else {
- p.ttd();
- return false;
- }
- }
- this.x = x;
- this.y = y;
- this.w = w;
- this.h = h;
- this.id = window.GetProperty("artreader_id", 0);
- this.img = null;
- this.path = null;
- this.type = window.GetProperty("artreader_image_type", "centre");
- }
- //Begin
- var p = new panel("Art Reader", ["metadb"]);
- var a = new artreader(0, 0, 100, 100);
- on_item_focus_change();
- function on_size() {
- p.size();
- a.w = p.w;
- a.h = p.h;
- }
- function on_paint(gr) {
- a.draw(gr);
- if (!a.img) p.centre_tex;
- }
- function on_metadb_changed() {
- a.metadb_changed();
- }
- function on_get_album_art_done(metadb, art_id, im, ip) {
- a.get_album_art_done(ip);
- }
- function on_mouse_wheel(step) {
- a.wheel(step);
- p.item_focus_change();
- }
- //next line alow you to skroll images with mouse (front,back,artist..)
- function on_mouse_move(x, y) {
- p.move(x, y);
- a.move(x, y);
- p.item_focus_change();
- }
- //Auto Cycle Image
- var timer = window.CreateTimerInterval(15000);
- function on_timer() {
- if (cycle==1)
- a.id++;
- if (a.id > 4) a.id = 0;
- a.metadb_changed();
- p.item_focus_change();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement