here is the modded version with new timer api
// ==PREPROCESSOR==
// @name "Cover Panel" by Br3tt, mod by Zin-Uru, mod by TEA
// ==/PREPROCESSOR==
var g_tooltip = window.CreateTooltip();
var hover = null;
var g_img = null;
cover = function () {
this.reset = function () {
this.x = 0;
this.y = 0;
}
this.update = function () {
this.x = img_info.x;
this.y = img_info.y;
}
this.swap = function (cover_source) {
this.image = cover_source.image;
this.x = cover_source.x;
this.y = cover_source.y;
}
}
var covers = Array(new cover, new cover);
var fader = 0;
var alphamax = 255;
var fading_step = 15.0;
var g_timer = false;
var g_refresh_timer = 40;
var g_metadb;
var is_stream = false;
var is_embedded;
var is_art;
var art_path = "";
var WshShell = new ActiveXObject("WScript.Shell");
var bg_dir = fb.FoobarPath + "\\skin\\";
var id = 0;
var img_info = {x: 0, y: 0, w: 0, h: 0};
function FormatImage(image, iw, ih) {
if (!image || !iw || !ih) return image;
var scale_w = ww / image.Width;
var scale_h = wh / image.Height;
var scale = Math.min(scale_w, scale_h);
var pos_x = 0,
pos_y = 0;
img_info.w = iw;
img_info.h = ih;
if (scale_w < scale_h) pos_y = (wh - image.height * scale) / 2;
else if (scale_w > scale_h) pos_x = (ww - image.Width * scale) / 2;
var tmp_img = gdi.CreateImage(img_info.w, img_info.h);
var gp = tmp_img.GetGraphics();
gp.DrawImage(image, pos_x, pos_y, image.Width * scale, image.Height * scale, 0, 0, image.Width, image.Height);
tmp_img.ReleaseGraphics(gp);
CollectGarbage();
return tmp_img;
}
function refresh_cover() {
covers[0].swap(covers[1]);
covers[1].reset();
if (fb.PlaybackLength > 0 || !fb.IsPlaying) {
is_stream = false;
g_metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
if (!g_metadb) {
on_playback_stop(4);
return;
}
utils.GetAlbumArtAsync(window.ID, g_metadb, 0);
is_embedded = false;
if (g_metadb) {
covers[1].image = FormatImage(utils.GetAlbumArtEmbedded(g_metadb.rawpath, 0), ww, wh, 7, 1, 0);
g_img = utils.GetAlbumArtEmbedded(g_metadb.rawpath, 0);
covers[1].update();
if (covers[1].image) {
is_embedded = true;
is_art = false;
} else {
covers[1].image = FormatImage(utils.GetAlbumArtV2(g_metadb, 0), ww, wh, 7, 1, 0);
g_img = utils.GetAlbumArtV2(g_metadb, 0);
covers[1].update();
if (!covers[1].image) {
is_art = false;
covers[1].image = FormatImage(gdi.Image(bg_dir + "no_cover.jpg"), ww, wh, 7, 1, 0);
covers[1].update();
}
}
}
} else if (fb.IsPlaying && fb.TitleFormat("$right($left(%path%,2),1)").Eval() != ":") {
is_art = false;
is_stream = true;
covers[1].image = FormatImage(gdi.Image(bg_dir + "stream.jpg"), ww, wh, 7, 1, 0);
covers[1].update();
}
window.Repaint();
}
function on_playback_stop(reason) {
if (reason == 4 || (reason == 0 && !is_art)) {
covers[0].swap(covers[1]);
covers[1].image = FormatImage(gdi.Image(bg_dir + "no_cover.jpg"), ww, wh, 7, 1, 0);
covers[1].update();
fader = alphamax;
g_img = null;
g_timer && window.ClearInterval(g_timer);
g_timer = false;
g_timer = window.SetInterval(function () {
fader = (fader > 0) ? fader - fading_step : 0;
if (fader <= 0) {
g_timer && window.ClearInterval(g_timer);
g_timer = false;
}
window.Repaint();
}, g_refresh_timer);
}
if (reason == 1 || reason == 0) {
refresh_cover();
}
}
function on_playback_new_track(info) {
refresh_cover();
fader = alphamax;
g_timer && window.ClearInterval(g_timer);
g_timer = false;
g_timer = window.SetInterval(function () {
fader = (fader > 0) ? fader - fading_step : 0;
if (fader <= 0) {
g_timer && window.ClearInterval(g_timer);
g_timer = false;
}
window.Repaint();
}, g_refresh_timer);
}
function on_paint(gr) {
gr.FillSolidRect(0, 0, ww, wh, 0xFF000000);
if (fader > 0) covers[0].image && gr.DrawImage(covers[0].image, covers[0].x, covers[0].y, covers[0].image.Width, covers[0].image.Height, 0, 0, covers[0].image.Width, covers[0].image.Height, 0, fader);
covers[1].image && gr.DrawImage(covers[1].image, covers[1].x, covers[1].y, covers[1].image.Width, covers[1].image.Height, 0, 0, covers[1].image.Width, covers[1].image.Height, 0, 255 - fader);
}
function on_size() {
ww = window.Width;
wh = window.Height;
refresh_cover();
}
function on_item_focus_change() {
if (!fb.IsPlaying) {
refresh_cover();
fader = alphamax;
g_timer && window.ClearInterval(g_timer);
g_timer = false;
g_timer = window.SetInterval(function () {
fader = (fader > 0) ? fader - fading_step : 0;
if (fader <= 0) {
g_timer && window.ClearInterval(g_timer);
g_timer = false;
}
window.Repaint();
}, g_refresh_timer);
}
}
function on_playlists_changed() {
if (!fb.IsPlaying) on_item_focus_change();
}
function on_get_album_art_done(metadb, art_id, image, image_path) {
art_path = image_path;
}
function on_mouse_lbtn_down(x, y) {
var meta = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
if (!meta || !is_art) return;
switch (true) {
case(art_path == ""):
break;
default:
// WshShell.run('"JPEGView.exe"' + '"' + art_path + '"');
break;
}
}
function on_mouse_move(x, y) {
if (!hover && g_img) {
g_tooltip.Text = (is_embedded ? "Embedded - " : "External - ") + g_img.Width + " x " + g_img.Height;
g_tooltip.Activate();
hover = true;
}
}
function on_mouse_leave() {
g_tooltip.Deactivate();
hover = null;
}