3
Good to know you got it working, but if I'm not mistaken, all changes made in the JS Sample directories would be overwritten upon update.
Anyway, here's my newbie attempt at a text reader with album art blur code.
We could change the blur radius and the overlay shade here.
// ==PREPROCESSOR==
// @name "Text Display + Album Art Blur"
// @author "marc2003"
// @import "%fb2k_component_path%helpers.txt"
// @import "%fb2k_component_path%samples\js\lodash.min.js"
// @import "%fb2k_component_path%samples\js\common.js"
// @import "%fb2k_component_path%samples\js\panel.js"
// @import "%fb2k_component_path%samples\js\albumart.js"
// @import "%fb2k_component_path%samples\js\text_display.js"
// ==/PREPROCESSOR==
// https://jscript-panel.github.io/gallery/text-display/
var radius = 50;
var overlay = 180;
var g_img = null;
var g_metadb = null;
var g_info = '';
var panel = new _panel({ custom_background : true });
var albumart = new _albumart(0, 0, 0, 0);
var text = new _text_display(LM, 0, 0, 0);
var blur_img = null;
var ww = 0, wh = 0;
update_album_art();
StackBlur(radius);
panel.item_focus_change();
function update_album_art() {
if (g_img) g_img.Dispose();
g_img = null;
g_info = '';
g_metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
if (g_metadb) {
g_img = g_metadb.GetAlbumArt(); // omitting the type defaults to front
if (g_img) {
blur_img = g_img.Clone();
blur_img.StackBlur(radius);
}
}
window.Repaint();
}
//
function StackBlur(radius) {
if (blur_img) blur_img.Dispose();
blur_img = g_img.Clone();
g_img.StackBlur(radius);
}
//
function on_colours_changed() {
panel.colours_changed();
text.refresh(true);
//
window.Repaint();
}
function on_font_changed() {
panel.font_changed();
text.refresh(true);
}
function on_item_focus_change() {
panel.item_focus_change();
//
if (!fb.IsPlaying) update_album_art();
}
function on_metadb_changed() {
albumart.metadb_changed();
text.metadb_changed();
}
function on_mouse_lbtn_dblclk() {
if (g_metadb) g_metadb.ShowAlbumArtViewer(0);
}
function on_mouse_lbtn_up(x, y) {
text.lbtn_up(x, y);
}
function on_mouse_move(x, y) {
text.move(x, y);
}
function on_mouse_rbtn_up(x, y) {
return panel.rbtn_up(x, y, text);
}
function on_mouse_wheel(s) {
text.wheel(s);
}
function on_paint(gr) {
panel.paint(gr);
var bg = window.IsDefaultUI ? window.GetColourDUI(1) : window.GetColourCUI(3);
gr.Clear(bg);
if (g_img) {
_drawImage(gr, blur_img, 0, 0, panel.w, panel.h, image.crop);
}
_drawOverlay(gr, 0, 0, panel.w, panel.h, overlay);
text.paint(gr);
}
// get notified of album art changes when listening to a supported stream
function on_playback_dynamic_info_track(type) {
if (type == 1) update_album_art();
// type 0 is metadata which we're not interested in
}
function on_playback_new_track() {
panel.item_focus_change();
//
update_album_art();
}
function on_playback_pause() {
text.refresh();
}
function on_playback_stop(reason) {
text.refresh();
//
if (reason != 2) {
update_album_art();
}
}
function on_playback_time() {
text.playback_time();
}
function on_playlist_items_added() {
panel.item_focus_change();
}
function on_playlist_items_removed() {
panel.item_focus_change();
}
function on_playlist_items_reordered() {
text.refresh();
}
function on_playlist_switch() {
panel.item_focus_change();
//
if (!fb.IsPlaying) update_album_art();
}
function on_size() {
panel.size();
text.w = panel.w - (LM * 2);
text.h = panel.h;
text.size();
ww = window.Width;
wh = window.Height;
}
Preview
5
It worked!
I added the new line to the JS file,
but as I am using multiple JScript panels that also displays the album cover,
they're all using that same "albumart" JS script file,
so obviously, (almost) all of the album covers got blurry.
So, to fix that,
I simply duplicated the JS file with a new name ("albumart+blur.js"), added in the StackBlur to it
and in the code for my "Text Display" panel, in the Preprocessor area,
I just changed the import path for the old "albumart" to reflect the new name for the new script just like so!
// @import "%fb2k_component_path%samples\js\albumart+blur.js"
After saving the script, it only applied the blur here, which is perfectly what I wanted!
Thanks for the help!