Hello,
I'm trying to make buttons in the WSH panel mod, but it seems they are not drawn. These two buttons need to change the volume of Foobar
The console gives me no errors, so I'm guessing the code should be right.
Could you help me??
// vi:set ft=javascript ff=dos ts=4 sts=4 sw=4 et:
function RGB(r, g, b) {
return (0xff000000 | (r << 16) | (g << 8) | (b));
}
ButtonStates = {
normal: 0,
hover: 1
}
var g_font = gdi.Font("AvantGarde LT Medium", 8, 0);
var g_fontbutton = gdi.Font("AvantGarde LT Medium", 9, 0);
var g_drag = 0;
var ww = window.Width;
var wh = window.Height;
function SimpleButton(x, y, w, h, txt, func_onClick,state) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.func_onClick = func_onClick;
this.containXY = function(x, y) {
return (this.x <= x) && (x <= this.x + this.w) && (this.y <= y) && (y <= this.y + this.h);
}
this.draw = function(gr) {
this.txt && gr.DrawString(this.txt, g_fontbutton, RGB(104, 104, 104), this.x, this.y, this.w,this.h, 0x11005000);
}
this.onClick = function() {
this.func_onClick && this.func_onClick();
}
}
function chooseButton(x, y) {
for (var i in $buttons) {
if ($buttons[i].containXY(x, y) && $buttons[i].state != ButtonStates.hide) return $buttons[i];
}
return null;
}
function drawAllButtons(gr) {
for (var i in $buttons) {
$buttons[i].draw(gr);
}
}
$buttons = {
VolumeDOWN: new SimpleButton(-4, 10, ww, wh,"-", function() {
fb.VolumeDown();
},0),
VolumeUP: new SimpleButton(6, 10, ww, wh,"+", function() {
fb.VolumeUp();
},0)
}
function on_paint(gr) {
drawAllButtons(gr);
gr.SetTextRenderingHint(4);
var volume = fb.Volume;
var pos = window.Width * ((100 + volume) / 100);
var txt = (Math.ceil(volume)) + "dB";
gr.DrawString(txt, g_font, RGB(104, 104, 104), 0, 0, ww, wh, 0x11005000);
//gr.DrawString("-", g_fontbutton, RGB(104, 104, 104), -4, 10, ww, wh, 0x11005000);
//gr.DrawString("+", g_fontbutton, RGB(104, 104, 104), 6, 10, ww, wh, 0x11005000);
}
var cur_btn = null;
function on_mouse_move(x, y) {
cur_btn = chooseButton(x, y);
window.Repaint();
}
function on_mouse_move(x, y) {
cur_btn = chooseButton(x, y);
window.Repaint();
}
function on_mouse_lbtn_up(x, y) {
if (cur_btn) {
cur_btn.onClick();
}
window.Repaint();
}
function on_volume_change(val) {
window.Repaint();
}
//EOF
Thanks in advance,
r03l