Last active
September 5, 2022 23:52
-
-
Save marc2k3/1d449cc5bbb2fcfdb51157e49d679ad6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==PREPROCESSOR== | |
// @name "Spinny Album Art Nonsense" | |
// @author "marc2003" | |
// @import "%fb2k_component_path%helpers.txt" | |
// ==/PREPROCESSOR== | |
var angle = 0; | |
window.SetInterval(function () { | |
if (!fb.IsPlaying || fb.IsPaused) return; | |
angle +=5; | |
window.Repaint(); | |
}, 20); | |
var g_img = null; | |
var g_metadb = null; | |
var g_tooltip = window.CreateTooltip('Segoe UI', 16); | |
g_tooltip.SetMaxWidth(600); | |
g_tooltip.Text = ''; | |
var g_info = ''; | |
var ww = 0, wh = 0; | |
var temp_gr; | |
var circular_mask = utils.CreateImage(512, 512); | |
temp_gr = circular_mask.GetGraphics(); | |
temp_gr.FillEllipse(256, 256, 256, 256, RGB(0, 0, 0)); | |
circular_mask.ReleaseGraphics(); | |
temp_gr = null; | |
update_album_art(); | |
function update_album_art() { | |
angle = 0; | |
if (g_img) g_img.Dispose(); | |
g_img = null; | |
g_info = ''; | |
g_metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem(); | |
if (g_metadb) { | |
var tmp = g_metadb.GetAlbumArt(2) // type 2 = disc art | |
if (!tmp) tmp = g_metadb.GetAlbumArt(0); // if disc art not found, use front cover | |
if (tmp) { | |
var path = tmp.Path; | |
g_info = 'Original dimensions: ' + tmp.Width + 'x' + tmp.Height; | |
if (path.length) g_info += '\nPath: ' + path; | |
var size = Math.min(tmp.Width, tmp.Height); | |
g_img = utils.CreateImage(size, size); | |
temp_gr = g_img.GetGraphics(); | |
temp_gr.DrawImageWithMask(make_square(tmp, size), circular_mask, 0, 0, size, size); | |
g_img.ReleaseGraphics(); | |
temp_gr = null; | |
tmp.Dispose(); | |
} | |
} | |
window.Repaint(); | |
} | |
function make_square(img, size) { | |
if (!img) return null; | |
if (img.Width < img.Height) { | |
var src_x = 0; | |
var src_w = img.Width; | |
var src_h = img.Width; | |
var src_y = Math.round((img.Height - src_h) / 4); | |
} else { | |
var src_y = 0; | |
var src_w = img.Height; | |
var src_h = img.Height; | |
var src_x = Math.round((img.Width - src_w) / 2); | |
} | |
var square = utils.CreateImage(size, size); | |
var temp_gr = square.GetGraphics(); | |
temp_gr.DrawImage(img, 0, 0, size, size, src_x, src_y, src_w, src_h); | |
square.ReleaseGraphics(); | |
return square; | |
} | |
function on_colours_changed() { | |
window.Repaint(); | |
} | |
function on_item_focus_change() { | |
if (!fb.IsPlaying) update_album_art(); | |
} | |
function on_mouse_move(x, y) { | |
if (g_info.length && g_tooltip.Text != g_info) { | |
g_tooltip.Text = g_info; | |
g_tooltip.Activate(); | |
} | |
} | |
function on_paint(gr) { | |
var bg = window.IsDefaultUI ? window.GetColourDUI(1) : window.GetColourCUI(3); | |
gr.FillRectangle(0, 0, ww, wh, bg); | |
if (g_img) { | |
var scale_w = ww / g_img.Width; | |
var scale_h = wh / g_img.Height; | |
var scale = Math.min(scale_w, scale_h); | |
var pos_x = 0, pos_y = 0; | |
if (scale_w < scale_h) | |
pos_y = (wh - g_img.height * scale) / 2; | |
else if (scale_w > scale_h) | |
pos_x = (ww - g_img.Width * scale) / 2; | |
gr.DrawImage(g_img, pos_x, pos_y, g_img.Width * scale, g_img.Height * scale, 0, 0, g_img.Width, g_img.Height, 1, angle); | |
} | |
} | |
function on_size() { | |
ww = window.Width; | |
wh = window.Height; | |
} | |
function on_playback_dynamic_info_track(type) { | |
if (type == 1) update_album_art(); | |
} | |
function on_playback_new_track() { | |
update_album_art(); | |
} | |
function on_playback_stop(reason) { | |
if (reason != 2) { | |
update_album_art(); | |
} | |
} | |
function on_playlist_switch() { | |
if (!fb.IsPlaying) update_album_art(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment