@Bryter, here's the volume script from my foobar2000:
(Notes: Read the code comments)
(Settings: Script Engine: JScript | Edge Style: None | Grab Focus: checked)
function RGB(r,g,b){ return (0xff000000|(r<<16)|(g<<8)|(b)); }
// gdi.Font is changed, the last paramter is style flags
// FontStyleRegular = 0,
// FontStyleBold = 1,
// FontStyleItalic = 2,
// FontStyleBoldItalic = 3,
// FontStyleUnderline = 4,
// FontStyleStrikeout = 8
// Here is 0, means FontStyleRegular
var g_font = gdi.Font("Verdana", 10, 0);
var g_drag = 0;
function on_paint(gr){
gr.SetTextRenderingHint(5);
var ww = window.Width;
var wh = window.Height;
var volume = fb.Volume;
// var pos = window.Width * ((100+volume)/100); // <--------- Old linear calculation
var pos = window.Width * Math.exp(0.04*volume); // <--------- Logarithmic calculation (as used in default volume slider)
var txt = "volume " + (Math.ceil(volume)) + " dB";
gr.FillGradRect(0, 0, pos, wh, 0, RGB(40,42,57), RGB(204,0,0));
gr.FillGradRect(pos, 0, ww-pos, wh, 10, RGB(102,102,102), RGB(40,42,57));
gr.DrawString(txt, g_font, RGB(128,192,255), 0, 0, ww, wh, 0x11005000);
gr.DrawRect(0,0,ww-0, wh-0, 0.0, RGB(46,48,63));
}
function on_mouse_lbtn_down(x,y){
g_drag = 1;
}
function on_mouse_lbtn_up(x,y){
on_mouse_move(x,y);
g_drag = 0;
}
function on_mouse_move(x,y){
if(g_drag){
var v = x / window.Width;
v = (v<0) ? 0 : (v<1) ? v : 1;
// v = -100 * (1-v); // <--------- Old linear scaling
v = 25 *Math.log(v+0.00001); // <--------- Logarithmic scaling (as used in default volume slider)
if(fb.Volume != v)
fb.Volume = v;
}
}
function on_mouse_wheel(delta){
if(delta>0)
fb.VolumeUp();
else
fb.VolumeDown();
}
function on_volume_change(val){
window.Repaint();
}
//EOF