// ==PREPROCESSOR==
// @import "%fb2k_profile_path%scripts\common.js"
// @name "Album Art"
// ==/PREPROCESSOR==
var g_img;
var g_text = '';
var artist = '';
var album = '';
var title = '';
var lfm_img = gdi.Image(images_path + "lastfm_red_small.gif");
var g_tooltip = window.CreateTooltip();
g_tooltip.Text = "last.fm track page";
var g_textrender = gdi.CreateStyleTextRender();
window.GetProperty("scale", "max");
window.GetProperty("playinginfo", true);
window.GetProperty("lastfminfo", true);
window.GetProperty("id",0);
on_item_focus_change();
function on_size() {
ww = window.Width;
wh = window.Height;
}
function on_notify_data(name, data) {
if (name == "playingtrack") {
g_text = data;
window.RepaintRect(0, wh - 70, ww, 70);
}
}
function on_paint(gr) {
gr.FillSolidRect(0, 0, ww, wh, g_backcolor);
if (g_img) {
scale(gr, g_img, 0, 0, ww, wh, window.GetProperty("scale"));
} else {
gr.GdiDrawText(g_metadb ? "[no image]" : "[no selection]", g_font, g_textcolor, 0, 0, ww, wh, DT_VCENTER | DT_CENTER | DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
}
if (!fb.IsPlaying) return;
y_off = 16;
g_textrender.OutLineText(g_textcolor, g_backcolor, 3);
gr.SetTextRenderingHint(0);
gr.SetSmoothingMode(4);
gr.SetInterpolationMode(7);
if (window.GetProperty("lastfminfo")) gr.DrawImage(lfm_img, ww-60, 8, 50, 18, 0, 0, 50, 18);
if (g_text != "") {
y_off = 0;
g_textrender.RenderStringRect(gr, g_text, gdi.Font(font, 12, 1), 5, wh-22, ww-10, 14, 0x10305000);
}
if (window.GetProperty("playinginfo")) {
g_textrender.RenderStringRect(gr, title, gdi.Font(font, 12, 1), 5, wh-70+y_off, ww-10, 14, 0x10305000);
g_textrender.RenderStringRect(gr, album, gdi.Font(font, 12, 1), 5, wh-54+y_off, ww-10, 14, 0x10305000);
g_textrender.RenderStringRect(gr, artist, gdi.Font(font, 12, 1), 5, wh-38+y_off, ww-10, 14, 0x10305000);
}
}
function scale(gr, img, pos_x, pos_y, width, height, mth) {
var s = mth == "max" ? Math.max(width / img.width, height / img.height) : 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);
gr.DrawImage(img, pos_x, pos_y, nw, nh, 0, 0, img.width, img.height);
}
function on_playback_new_track() {
g_metadb && g_metadb.Dispose();
on_item_focus_change();
artist = fb.TitleFormat("%artist%").EvalWithMetadb(g_metadb);
album = fb.TitleFormat("%album%").EvalWithMetadb(g_metadb);
title = fb.TitleFormat("%title%").EvalWithMetadb(g_metadb);
if (window.GetProperty("lastfminfo")) window.NotifyOthers("getplayinginfo", [artist, title]);
update_image();
}
function on_metadb_changed() {
if(fb.IsPlaying) return;
update_image();
}
function on_playback_stop(reason) {
if (reason != 2) window.Repaint();
}
function update_image() {
if(!g_metadb) return;
is_embedded = null;
g_img && g_img.Dispose();
type = window.GetProperty("id");
g_img = utils.GetAlbumArtEmbedded(g_metadb.rawpath, type);
if(g_img) {
is_embedded = true;
window.Repaint();
} else {
utils.GetAlbumArtAsync(window.ID, g_metadb, type);
}
}
function on_get_album_art_done(metadb, art_id, im, ip) {
g_img_path = ip;
g_img = im;
window.Repaint();
}
function on_mouse_move(x,y) {
if (window.GetProperty("playinginfo") && x > ww-60 && x < ww-10 && y > 8 && y < 26) {
g_tooltip.Activate();
window.SetCursor(IDC_HAND);
} else {
g_tooltip.Deactivate();
window.SetCursor(IDC_ARROW);
}
}
function on_mouse_lbtn_up(x, y) {
if (window.GetProperty("playinginfo") && x > ww-60 && x < ww-10 && y > 8 && y < 26) {
WshShell.run("http://www.last.fm/music/" + encodeURIComponent(artist) + "/_/" + encodeURIComponent(title));
}
}
function on_mouse_lbtn_dblclk() {
if(!g_metadb || !g_img) return;
if(is_embedded) {
fb.RunContextCommandWithMetadb("Open Containing Folder", g_metadb);
} else {
try {WshShell.Run("\"" + g_img_path + "\""); } catch(e) {}
}
}
function on_mouse_rbtn_up(x, y) {
var _menu = window.CreatePopupMenu();
var idx;
_menu.AppendMenuItem(MF_STRING, 1, "Refresh");
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_STRING, 2, "Front cover");
_menu.AppendMenuItem(MF_STRING, 3, "Back cover");
_menu.AppendMenuItem(MF_STRING, 4, "Disc");
_menu.AppendMenuItem(MF_STRING, 5, "Icon");
_menu.AppendMenuItem(MF_STRING, 6, "Artist");
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_STRING, 7, "Fill");
_menu.CheckMenuItem(7, window.GetProperty("scale") == "max");
_menu.AppendMenuItem(MF_STRING, 8, "Playing track info");
_menu.CheckMenuItem(8, window.GetProperty("playinginfo"));
_menu.AppendMenuItem(MF_STRING, 9, "Last.fm track info");
_menu.CheckMenuItem(9, window.GetProperty("lastfminfo"));
if(utils.IsKeyPressed(0x10)) {
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_STRING, 99, "Properties");
_menu.AppendMenuItem(MF_STRING, 100, "Configure...");
}
_menu.CheckMenuRadioItem(2, 6, window.GetProperty("id")+2);
idx = _menu.TrackPopupMenu(x, y);
switch(idx) {
case 1:
update_image();
break;
case 2:
case 3:
case 4:
case 5:
case 6:
window.SetProperty("id", idx-2);
update_image();
break;
case 7:
window.SetProperty("scale", window.GetProperty("scale") == "max" ? "min" : "max");
window.Repaint();
break;
case 8:
window.SetProperty("playinginfo", !window.GetProperty("playinginfo"));
window.RepaintRect(0, wh - 70, ww, 70);
break;
case 9:
window.SetProperty("lastfminfo", !window.GetProperty("lastfminfo"));
if (fb.IsPlaying && window.GetProperty("lastfminfo")) window.NotifyOthers("getplayinginfo", [artist, title]);
if (!window.GetProperty("lastfminfo")) g_text = "";
window.Repaint();
break;
case 99:
window.ShowProperties();
break;
case 100:
window.ShowConfigure();
break;
}
_menu.Dispose();
return true;
}