I have got an working code from tedgo and i want to add
Costum Database Rating %RATING_CD%
and if it is possible love and unlove for LastFM
(I use the LastFM script from marc2003)
Could anyone help me please?
that's my foobar skin Silent Night for fb2k v.1+
Global Button Script.js
// Global Button Script
// Code by T.P Wang and tedGo
var ButtonStates = {normal: 0, hover: 1, down: 2, hide: 3};
var Buttons = {};
var g_down = false;
// ----- CREATE BUTTON OBJECT --------------------------------------
var g_tooltip;
function Button(x, y, w, h, img_src, func, tiptext) {
this.left = x;
this.top = y;
this.w = w;
this.h = h;
this.right = x + w;
this.bottom = y + h;
this.func = func;
this.tiptext = tiptext;
this.state = ButtonStates.normal;
this.img_normal = img_src && img_src.normal ? gdi.Image(img_src.normal) : null;
this.img_hover = img_src && img_src.hover ? gdi.Image(img_src.hover) : this.img_normal;
this.img_down = img_src && img_src.down ? gdi.Image(img_src.down) : this.img_hover;
this.img = this.img_normal;
this.alterImage = function(img_src) {
this.img_normal = img_src && img_src.normal ? gdi.Image(img_src.normal) : null;
this.img_hover = img_src && img_src.hover ? gdi.Image(img_src.hover) : this.img_normal;
this.img_down = img_src && img_src.down ? gdi.Image(img_src.down) : this.img_hover;
this.changeState(this.state);
}
this.traceMouse = function(x, y) {
if (this.state == ButtonStates.hide) return false;
var b = (this.left < x) && (x < this.right) && (this.top < y) && (y < this.bottom);
if (b)
g_down ? this.changeState(ButtonStates.down) : this.changeState(ButtonStates.hover);
else
this.changeState(ButtonStates.normal);
return b;
}
this.changeState = function(newstate) {
newstate != this.state && window.RepaintRect(this.left, this.top, this.w, this.h);
this.state = newstate;
switch (this.state) {
case ButtonStates.normal:
this.img = this.img_normal;
break;
case ButtonStates.hover:
this.img = this.img_hover;
break;
case ButtonStates.down:
this.img = this.img_down;
break;
default:
this.img = null;
}
}
this.changePos = function(x, y, w, h) {
this.left = x;
this.top = y;
this.w = w;
this.h = h;
this.right = x + w;
this.bottom = y + h;
}
this.draw = function(gr) {
this.img && gr.DrawImage(this.img, this.left, this.top, this.w, this.h, 0, 0, this.w, this.h);
}
this.repaint = function() {
window.RepaintRect(this.left, this.top, this.w, this.h);
}
this.onClick = function() {
this.func && this.func();
}
this.onMouseIn = function() {
g_tooltip = window.CreateTooltip();
g_tooltip.Text = this.tiptext;
g_tooltip.Activate();
}
this.onMouseOut = function() {
g_tooltip.Deactivate();
g_tooltip.Dispose();
}
}
function buttonsDraw(gr) {
for (var i in Buttons) {
Buttons[i].draw(gr);
}
}
function buttonsTraceMouse(x, y) {
var btn = null;
for (var i in Buttons) {
if (Buttons[i].traceMouse(x, y) && !btn)
btn = Buttons[i];
}
return btn;
}
// ----- MOUSE ACTIONS ---------------------------------------------
var cur_btn = null;
var btn_down;
function on_mouse_move(x, y) {
var btn = buttonsTraceMouse(x, y);
if (btn != cur_btn) {
cur_btn && cur_btn.onMouseOut();
btn && btn.onMouseIn();
}
cur_btn = btn;
}
function on_mouse_lbtn_down(x, y) {
g_down = true;
(btn_down = cur_btn) && cur_btn.changeState(ButtonStates.down);
}
function on_mouse_lbtn_up(x, y) {
if (cur_btn) {
cur_btn.changeState(ButtonStates.hover);
btn_down == cur_btn && cur_btn.onClick(x, y);
}
g_down = false;
}
function on_mouse_leave() {
cur_btn && cur_btn.changeState(ButtonStates.normal);
}
Popup-Rating Menu
// Popup-Rating Menu
// Code by tedGo
// ==PREPROCESSOR==
// @import "%fb2k_path%Silent Night\scripts\Global Button Script.js"
// ==/PREPROCESSOR==
var ww = 0; wh = 0;
// ----- CREATE BUTTON ---------------------------------------------
var imgPath = fb.FoobarPath + "Silent Night\\images\\";
Buttons.RAT = new Button(0, 0, 39, 20, {normal: imgPath + "Rate.png", hover: imgPath + "Rate1.png"}, getRatingMenu);
// ----- CREATE MENU -----------------------------------------------
function RateMode() {
rm = window.GetProperty("Rating Mode", 0);
if (typeof rm < 0 || rm > 1) rm = 0;
return rm;
}
RateMode();
function getRatingMenu(x, y) {
x = Buttons.RAT.left;
y = Buttons.RAT.top;
var a = window.CreatePopupMenu();
var g_metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
var isRating = fb.TitleFormat("$if2(%rating%,0)").EvalWithMetadb(g_metadb);
var delRating = isRating > 0 ? 0 : 1;
var idx;
a.CheckMenuRadioItem(101, 102, rm + 101);
a.AppendMenuItem(0, 101, "Database Rating");
a.AppendMenuItem(0, 102, "Tag Rating");
a.CheckMenuRadioItem(101, 102, rm + 101);
a.AppendMenuItem(2048, 0, 0);
a.AppendMenuItem(0, 1, "Rating 1 - ★");
a.AppendMenuItem(0, 2, "Rating 2 - ★★");
a.AppendMenuItem(0, 3, "Rating 3 - ★★★");
a.AppendMenuItem(0, 4, "Rating 4 - ★★★★");
a.AppendMenuItem(0, 5, "Rating 5 - ★★★★★");
a.CheckMenuRadioItem(1, 5, isRating);
a.AppendMenuItem(delRating, 6, "Remove Rating");
idx = a.TrackPopupMenu(x, y);
switch (true) {
case (idx >= 101 && idx <= 102):
window.SetProperty("Rating Mode", idx - 101);
RateMode();
break;
case (idx >= 1 && idx <= 5):
rm == 0 ? fb.RunContextCommandWithMetadb("Rating/" + idx, g_metadb) : g_metadb.UpdateFileInfoSimple("Rating", idx);
break;
case (idx == 6):
fb.IsMetadbInMediaLibrary(g_metadb) ? fb.RunContextCommandWithMetadb("Rating/<not set>", g_metadb) : g_metadb.UpdateFileInfoSimple("Rating", "");
break;
}
a.Dispose();
}
//Fixed coords for menu
function on_mouse_rbtn_down(x, y) {
}function on_mouse_rbtn_down(x, y, vkey){
rbtnDown = vkey==6 ? true : false;
}
function on_mouse_rbtn_up(x, y, vkey){
if (rbtnDown) {
rbtnDown=false;
return vkey==4 ? false : true;
} else
return true;
}
// ----- DRAW ------------------------------------------------------
function on_paint(gr) {
buttonsDraw(gr);
}
// ----- EVENTS ----------------------------------------------------
function on_size() {
ww = window.Width;
wh = window.Height;
Buttons.RAT.changePos(0, 0, 39, 20);
}