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: Buttons in WSH Panel mod (Read 2749 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Buttons in WSH Panel mod

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??

Code: [Select]
// 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

Buttons in WSH Panel mod

Reply #1
I cleaned up my code so far, but still no result

Code: [Select]
// 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));
}

var g_font = gdi.Font("AvantGarde LT Medium", 8, 0);
var g_fontbutton = gdi.Font("AvantGarde LT Medium", 8, 0);
var ww = window.Width;
var wh = 24;
 
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.draw = function(gr) {
        this.txt &&  gr.DrawString(this.text, 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 drawAllButtons(gr) {
    for (var i in $buttons) {
        $buttons[i].draw(gr);
    }
}

var Volume = {
    VolumeDown: 0,
    VolumeUp: 1
}
 
$buttons = {
VolumeDOWN: new SimpleButton(-16, 10, ww, wh,"-", function() {
        fb.VolumeDown()
        Volume.VolumeDown
    }),
   
VolumeUP: new SimpleButton(-6, 10, ww, wh,"+", function() {
        fb.VolumeUp()
        Volume.VolumeUp
    })
}

function on_paint(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), -12, 2, ww, wh, 0x21005000);
    drawAllButtons(gr);
}

function on_volume_change(val) {
    window.Repaint();
}
//EOF

Buttons in WSH Panel mod

Reply #2
Try adding this.txt=txt to function SimpleButton. Also change this.text to this.txt in the respective drawing function.

Buttons in WSH Panel mod

Reply #3
Thanks that worked, only the next problem I run into is that the buttons don't respond so the volume isn't going up

Quote
// 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));
}

var g_font = gdi.Font("AvantGarde LT Medium", 8, 0);
var g_fontbutton = gdi.Font("AvantGarde LT Medium", 8, 0);
var ww = window.Width;
var wh = 24;

function SimpleButton(x, y, w, h, txt, func_onClick) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.txt  = txt;
this.func_onClick = func_onClick;
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 drawAllButtons(gr) {
for (var i in $buttons) {
$buttons.draw(gr);
}
}

$buttons = {
VolumeDOWN: new SimpleButton(-4, 10, ww, wh,"-", function() {
fb.VolumeDown();
}),

VolumeUP: new SimpleButton(6, 10, ww, wh,"+", function() {
fb.VolumeUp()
;})
}

function on_paint(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);
drawAllButtons(gr);
}

function on_volume_change(val) {
window.Repaint();
}
//EOF

 

Buttons in WSH Panel mod

Reply #4
I have solved the problem, I was missing a little bit of script

Quote
// 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));
}

var g_font = gdi.Font("AvantGarde LT Medium", 8, 0);
var g_fontbutton = gdi.Font("AvantGarde LT Medium", 8, 0);
var ww = window.Width;
var wh = 24;
var cur_btn = null;

function SimpleButton(x, y, w, h, txt, func_onClick) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.txt  = txt;
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 drawAllButtons(gr) {
for (var i in $buttons) {
$buttons.draw(gr);
}
}

function chooseButton(x, y) {
    for (var i in $buttons) {
        if ($buttons.containXY(x, y)) return $buttons;
    }

    return null;
}

$buttons = {
VolumeDOWN: new SimpleButton(0, 10,8, 8,"-", function() {
fb.VolumeDown();
}),

VolumeUP: new SimpleButton(10, 10, 8, 8,"+", function() {
fb.VolumeUp()
;})
}

function on_paint(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, 20, 8, 0x11005000);
drawAllButtons(gr);
}

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