Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: help with wsh panel and volume control (Read 5286 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

help with wsh panel and volume control

Hi, i am using wsh panel like slidebar of the volume control.

All work, but the steps of the slidebar are linear, in this way when i move the bar i do not feel null until the 3/4 and after the volume it is raised of blow.

I don't know nothing of javascript and i not have the minimal idea how to modify the script which control this  behavior.

This is the code:

Code: [Select]
function RGB(r,g,b){ return (0xff000000|(r<<16)|(g<<8)|(b)); }

var g_font = gdi.Font(-12, 400, 1, 0, "MeiryoKe_PGothic");
var g_drag = 0;

function on_paint(gr){
var ww = window.Width;
var wh = window.Height;
var volume = fb.Volume;
var pos = window.Width * ((50+volume)/100);
var txt = (Math.ceil(volume)) + "dB";

gr.FillGradRect(  0, 0,    pos, wh, 90, RGB(0,0,0), RGB(255,167,47));
gr.FillGradRect(pos, 0, ww-pos, wh, 90, RGB(0,0,0), RGB(0,0,0));

gr.DrawString(txt, g_font, RGB(0,255,0), 0, 0, ww, wh, 0x11005000);
gr.DrawRect(0,0, ww-1, wh-1, 1.0, RGB(255,167,47));
}
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);
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

someone can help me?

help with wsh panel and volume control

Reply #1
You want to change this line:
Code: [Select]
v = -100 * (1-v);
I'm guessing that you want it so that the "low" end has larger increments than the "high" end. Thus you want to SquareRoot the v like so:
Code: [Select]
v = -100 * (1- sqrt(v) );
I'm not sure if sqrt if the right command though, look it up if it doesn't work.
If you want the reverse then Square v:
Code: [Select]
v = -100 * (1-(v*v));

help with wsh panel and volume control

Reply #2
I see your answerback only now. Thanks.    
Meantime I have resolved in an other way, I do not know if mathematically it is corrected but it works similarly of the original foobar's volume. I use the logarithmic function.

This is the whole code:
 
Code: [Select]
function RGB(r,g,b){ return (0xff000000|(r<<16)|(g<<8)|(b)); }

var g_font = gdi.Font(-12, 400, 1, 0, "MeiryoKe_PGothic");
var g_drag = 0;
function on_paint(gr){
var ww = window.Width;
var wh = window.Height;
var volume =-fb.Volume;
var pos =Math.exp((-(volume-100)*Math.log(100))/100);
var x = pos * ww /100
var txt = (Math.ceil(volume)) + "dB";
gr.FillGradRect(  0, 0, x, wh, 90, RGB(0,0,0), RGB(255,167,47)); //avanzamento volume arancione
gr.FillGradRect(x, 0, ww-x, wh, 90, RGB(0,0,0), RGB(0,0,0)); //ritorno volume nero
gr.DrawString(txt, g_font, RGB(0,255,0), 0, 0, ww, wh, 0x11005000); //scritta
gr.DrawRect(0,0, ww-1, wh-1, 1.0, RGB(255,167,47)); //bordo esterno




}
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 pos = x * 100 / window.Width;
var v =100-(Math.log(pos)*100)/Math.log(100);
v = (v<0) ? 0 : (v<100) ? v : 100;
v = -v
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