I was just using the built in %rating% tag and I ran into two problems.
1. It would not show the current rating (all tracks initially showed as zero)
2. When I moused over it and then moused out (without clicking), it would stay on however many stars I had highlighted, not the actual current rating
The first is because the way that TF retrieves metadata has changed ($meta(rating) instead of just %rating%). In any case, below is the modified panel code if you run into this trouble, too. Thanks go to marc2003, of course.
// ==PREPROCESSOR==
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==
//do not include %% here
var tag = "rating";
////////////////////////////////////////////////////
var r = new rating(0, 0, 24);
var ww = 0;
var wh = 0;
var metadb = fb.GetFocusItem();
on_item_focus_change();
function on_item_focus_change() {
metadb = fb.GetSelection();
if (metadb) on_metadb_changed();
}
function on_size() {
ww = window.Width;
wh = window.Height;
r.x = Math.round((ww - r.w) / 2);
r.y = Math.round((wh - r.bs) / 2);
}
function on_paint(gr) {
gr.FillSolidRect(0, 0, ww, wh, utils.GetSysColor(15));
r.draw(gr);
}
function on_metadb_changed() {
r.metadb_changed();
}
function on_mouse_move(x, y) {
r.move(x, y);
}
function on_mouse_lbtn_up(x, y) {
r.lbtn_up(x, y);
}
function rating(x, y, bs) {
this.draw = function(gr) {
if (metadb) {
this.rating = fb.TitleFormat("$meta(" + tag + ")").EvalWithMetadb(metadb);
if(this.rating == '?')
this.rating=0;
for (i = 1; i < 11; i++) {
this.img = i > (this.hover ? this.lrating : this.rating) ? this.off_img : this.on_img;
gr.DrawImage(this.img, this.x + this.bs * (i - 1), this.y, this.bs, this.bs, 0, 0, this.off_img.Width, this.off_img.Height);
}
}
}
this.metadb_changed = function() {
if (!metadb) return;
this.hover = false;
this.rating = fb.TitleFormat("$meta(" + tag + ")").EvalWithMetadb(metadb);
if(this.rating == '?')
this.rating=0;
if (this.rating == "?") this.rating = 0;
this.lrating = this.rating;
window.RepaintRect(this.x, this.y, this.w, this.bs);
}
this.trace = function(x, y) {
return x > this.x - this.bs && x < this.x + (this.bs * 10) && y > this.y && y < this.y + this.bs;
}
this.move = function(x, y) {
if (!this.trace(x, y)) {
if (this.hover) this.leave();
return false;
}
if (metadb) {
this.hover = true;
this.lrating = Math.ceil((x - this.x) / this.bs);
window.RepaintRect(this.x, this.y, this.w, this.bs);
}
return true;
}
this.lbtn_up = function(x, y) {
if (!this.trace(x, y)) return false;
if (this.lrating != this.rating && this.hover == 1) metadb.UpdateFileInfoSimple(tag, this.lrating == 0 ? "" : this.lrating);
return true;
}
this.leave = function() {
this.hover = false;
window.RepaintRect(this.x, this.y, this.w, this.bs);
}
this.x = x;
this.y = y;
this.bs = bs;
this.w = this.bs * 10;
this.hover = false;
this.rating = null;
this.lrating = null;
this.img = null;
this.off_img = gdi.Image("Z:\\home\\kevin\\.foobar2000\\images\\off.png");
this.on_img = gdi.Image("Z:\\home\\kevin\\.foobar2000\\images\\on.png");
}