Hey, I hope this is an appropriate place to post this but I am looking for some help as to anchoring a WSH volume slider script to a Panel Stack Splitter. It currently moves out when resizing the window and I'd like it to stay at a consistent distance away from the edge of the window when resizing. Here's what I have so far;
// ==PREPROCESSOR==
// @import "%fb2k_path%\resources\Common.h"
// @import "%fb2k_path%\resources\UI.h"
// ==/PREPROCESSOR==
// Based on human hearing curve
// 0 <= p <= 1
// return a value value: -100 <= vol <= 0
function pos2vol(p) {
return (50 * Math.log(0.99 * p + 0.01) / Math.log(10));
}
function vol2pos(v){
var p=((Math.pow(10,v/50)-0.01)/0.99);
return(p);
}
//-----------------------------------
var muted = false;
var volume = fb.Volume;
var path = fb.FoobarPath + "resources\\";
var volume_img = gdi.Image(path + "volume.png");
var mute_button_img = gdi.Image(path + "bt_volume.png");
var mute_button_img_h = gdi.Image(path + "bt_volume.png");
var knob_img = gdi.Image(path + "knob.png");
var bar_left_img = gdi.Image(path + "bar_left.png");
var bar_mid_img = gdi.Image(path + "bar_mid.png");
var bar_right_img = gdi.Image(path + "bar_right.png");
var VolumeBar = new Dragbar();
var MuteButton = new Button(5,-1,26,21,mute_button_img,mute_button_img_h,mute_button_img,"Mute");
function on_size() {
ww = window.Width;
wh = window.Height;
VolumeBar.SetSize(30,5,165,10);
}
function on_paint(gr){
//gr.FillSolidRect(0,0,ww,wh,RGBA(25,25,25,255));
var p = parseInt(vol2pos(fb.Volume) * VolumeBar.W);
VolumeBar.Pos = p>0 ? p : 0;
gr.FillSolidRect(VolumeBar.X,VolumeBar.Y + 0,VolumeBar.Pos,9,RGBA(179,179,179,255))
MuteButton.Draw(gr);
var i = 0;
var vol = fb.Volume;
if(vol == -100){
if(muted)i = 0;
else i = 1;
}
if(vol>-100 && vol<-20)i = 2;
if(vol>=-20 && vol<-8)i = 3;
if(vol>=-8)i = 4;
gr.Drawimage(volume_img,19,3,10,14,i*10,0,10,14,0);
gr.Drawimage(bar_left_img,VolumeBar.X,VolumeBar.Y+0,0,5,0,0,2,5,0);
gr.Drawimage(bar_mid_img,VolumeBar.X,VolumeBar.Y+0,VolumeBar.W,9,0,0,10,5,0);
gr.Drawimage(bar_right_img,VolumeBar.X+VolumeBar.W,VolumeBar.Y+0,0,5,0,0,2,5,0);
var knob_x = (VolumeBar.Pos<5 ? 5: VolumeBar.Pos) + VolumeBar.X - 5;
knob_x = VolumeBar.Pos+5>VolumeBar.W ? VolumeBar.W+VolumeBar.X-10 : knob_x;
gr.Drawimage(knob_img,knob_x,VolumeBar.Y,10,10,0,0,10,10,0);
}
function on_mouse_move(x,y){
if(VolumeBar.Drag(x,y)){
var p = VolumeBar.Pos/VolumeBar.W;
fb.Volume = pos2vol(p);
}
MuteButton.Activate(x,y);
}
function on_mouse_lbtn_down(x,y){
if(VolumeBar.Click(x,y)){
var p = VolumeBar.Pos/VolumeBar.W;
fb.Volume = pos2vol(p);
}
MuteButton.Down();
}
function on_mouse_lbtn_up(x,y){
VolumeBar.Reset();
if(MuteButton.Click()){
if(muted){
fb.Volume = volume;
}
else{
if(fb.Volume > -100){
volume = fb.Volume;
muted = true;
fb.RunMainMenuCommand("Playback/Volume/Mute");
}
}
}
MuteButton.Reset();
}
function on_mouse_wheel(step){
if(step>0)
fb.VolumeUp();
else
fb.VolumeDown();
}
function on_volume_change(vol){
if (vol > -100 && muted)muted = false;
if(!muted)volume = fb.Volume;
window.Repaint();
}
Any help would be greatly appreciated.