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: WSH Panel Mod script discussion/help (Read 1401718 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

WSH Panel Mod script discussion/help

Reply #700
Wait, has a script already been written for these?

the possibility to make buttons for them is provided by component "foo_uie_ptb" (i have version 0.2)

so i don't know about scripts for those 2 items, but i have JScript for "stop after current" (taken from this site)

WSH Panel Mod script discussion/help

Reply #701
Wait, has a script already been written for these?

the possibility to make buttons for them is provided by component "foo_uie_ptb" (i have version 0.2)

so i don't know about scripts for those 2 items, but i have JScript for "stop after current" (taken from this site)


Mind directing me to that?

WSH Panel Mod script discussion/help

Reply #702
it's easier for me to post the script than to search for it. JScript for "stop after current":

Code: [Select]
function RGB(r,g,b){ return (0xff000000|(r<<16)|(g<<8)|(b)); }
var g_drag = 0;
var imgname;
var img;
function on_init(bool) {
imgname =bool ? "stop-after-current-on.png" : "stop-after-current-off.png";
img = gdi.image(fb.FoobarPath + "Images\\" + imgname);
window.Repaint();
};

on_init(fb.StopAfterCurrent);

function on_paint(gr){

gr.DrawImage(img, 0, 3, 20, 16, 0, 0, 20, 16);
}

function on_mouse_leave() {
if (g_drag==1) {

on_init(fb.StopAfterCurrent);
g_drag = 0;
}
}
function on_mouse_lbtn_up(x,y){

fb.StopAfterCurrent = !fb.StopAfterCurrent;
window.Repaint();

// g_drag = 0;
}


function on_playlist_stop_after_current_changed(state) {on_init(fb.StopAfterCurrent);}

//EOF


WSH Panel Mod script discussion/help

Reply #704
i only have 2 very unpretentious images (both - 21x20) that i drew myself:

1) stop-after-current-off.png - contains nothing but a grey background (my aim was to draw exactly the same grey colour as we can see, for example, around standard buttons like play, pause...)

2) stop-after-current-on.png - there is merely a simple thin black cross here (thus, when i see it, i immediately understand that "stop after current" is enabled; and when i don't see this cross near to my standard buttons, it is clear that "stop after current" is disabled)

WSH Panel Mod script discussion/help

Reply #705
Yeah, I just made some myself... So what's preventing this sort of script from working with "remove track after playback" and the like? Would it also work with "Stop After Current Album?" Isn't it just a matter of rewriting the commands?

WSH Panel Mod script discussion/help

Reply #706
Are all usermade content for WSH Panels Mod now following the new guidelines with regards to where components and associated files should be place? I.e in the foobar2000 user profile folder.
I would hate having to put junk in c:\program files\foobar2000 again.

WSH Panel Mod script discussion/help

Reply #707
Not all I think, mine is. IMO, profile path should be used because that would be the foobar folder for portable install anyway.

WSH Panel Mod script discussion/help

Reply #708
Just my mediainfo panel.
Needs Safe mode turned off I guess since it calls new ActiveXObject();
Also requires the wonderful scrollbar.js library.

Code: [Select]
// scrollbar_demo.js: totally useless and stupid demo of my scrollbar.
// written by r0lZ September 2003
//
// ==PREPROCESSOR==
// @import "%fb2k_profile_path%\wsh_scripts\scrollbar.js"
// ==/PREPROCESSOR==

// Our own global variables

// the text that we display in the viewport
var g_text = "Shit";

//var g_font = g_dui == 1 ? window.GetFontDUI(0) : window.GetFontCUI(0);
var g_font = gdi.Font("Consolas", 12, 0);

// the bitmap that will be displayed in the viewport
var g_bitmap = null;

// flag set to true when the window size changes, as we will need to compute
// a new viewport size and redraw the bitmap.
var g_need_vp_refresh = true;


// font flags
DT_TOP = 0x00000000;
DT_LEFT = 0x00000000;
DT_CENTER = 0x00000001;
DT_RIGHT = 0x00000002;
DT_VCENTER = 0x00000004;
DT_BOTTOM = 0x00000008;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;
DT_END_ELLIPSIS = 0x00008000;


// Configuration options for the scrollbar and the viewport

// foreground color of the scrollbar (alpha supported)
var sb_fg = window.InstanceType == 1 ? window.GetColorDUI(0) : window.GetColorCUI(0);

// background color of the scrollbar (alpha supported)
var sb_bg = 0x40FFFFFF; // transluscent white background

// scroll increment, in pixels, for the scrollbar arrows, the mouse wheel and the Up/Down keys
var sb_small_inc = g_font.Height * 3;

// allow drag the viewport with the mouse?
var sb_drag_enabled = true;

// allow scroll with the mouse wheel?
var sb_mouse_wheel_enabled = true;

// allow scroll with PageUp/Down and Cursor Up/Down?
var sb_keyboard_enabled = true;

// hide the scrollbar when the whole bitmap fits in the viewport?
var sb_hide_useless_scrollbar = true;

// hide the scrollbar when the mouse is not over it?
var sb_auto_hide_scrollbar = true;

// place the scrollbar at the left side of the viewport?
var sb_scrollbar_at_left_side = false;

// draw a 1 pixel border using the sb_fg color in the viewport?
var sb_draw_border = true;



////////////////// Example code ///////////////

function on_size()
{
    // sets the flag telling that the viewport and bitmap must be reinitialized.
    g_need_vp_refresh = true;
}

function on_paint(gr)
{
    // compute the dimentions of our viewport
    var x = 2;
    var y = 2;
    var w = window.Width-4;
    var h = window.Height-4;

    // draw elements that are outside the viewport
    var bg = window.InstanceType == 1 ? window.GetColorDUI(1) : window.GetColorCUI(3);
    gr.FillSolidRect(0,0, window.Width,window.Height, bg);

    if (g_need_vp_refresh) {
        // if necessary, create the bitmap and init the viewport
        g_bitmap = draw_bitmap(x, y, w, h);
        sb_init_viewport(x, y, w, h, g_bitmap);
    }
    // paint the viewport (without the scrollbar)
    sb_paint_viewport(gr);

    // and finally, draw the scrollbar
    sb_paint_scrollbar(gr);
}

function getmediainfo(filename) {
    //var fso = new ActiveXObject("Scripting.FileSystemObject");
    var wsh = new ActiveXObject("WScript.Shell");
    var pp = "cmd.exe /C\"\"H:\\codecs and players\\mediainfo_cli\\MediaInfo.exe\" \""+filename+"\" > h:\\out.txt\"";
    //fb.trace(pp);
    var app = wsh.Run(pp, 0, 1);
    return utils.ReadTextFile("h:\\out.txt");
}

function on_selection_changed(metadb) {
    if (metadb) {
    g_text = getmediainfo(metadb.Path);
    g_need_vp_refresh = true;
    window.Repaint();
    }
}

function init() {
    var mdb = fb.GetSelection();
    if (mdb) {
        g_text = getmediainfo(mdb.Path);
        g_need_vp_refresh = true;
        window.Repaint();
    }
}

// create and draw in the bitmap
function draw_bitmap(x, y, w, h)
{
    var bg = window.InstanceType == 1 ? window.GetColorDUI(1) : window.GetColorCUI(3);
    g_need_vp_refresh = false;
    // compute the height of the bitmap that will be scrolled through the viewport
    var bitmapheight = sb_MeasureStringHeight(g_text, g_font, w)+8;
    if (bitmapheight == -1) return;
    if (bitmapheight < h) bitmapheight = h;

    // create the bitmap
    g_bitmap && g_bitmap.Dispose();
    g_bitmap = gdi.CreateImage(w, bitmapheight);

    // (the bitmap may be null when foobar starts, so we need to check it)
    if (g_bitmap) {
        // fill the bitmap with some colourful graphics
        var bitmap_gr = g_bitmap.GetGraphics();
        bitmap_gr.FillGradRect(x,y, w, bitmapheight, 0, 0xFFFFFFFF, 0xFF808080);

        bitmap_gr.DrawString(g_text, g_font, 0xFF000000, 4, 4, w-8, DT_NOPREFIX);

        // Do not forget to release the graphics!
      g_bitmap.ReleaseGraphics(bitmap_gr);
    }
    return(g_bitmap);
}

// Page Down with middle mouse button
// Demonstrates how to use sb_set_bitmap_pos() and sb_set_bitmap_pos_percent()
function on_mouse_mbtn_down(x, y, mask)
{
    if (! sb_bitmap) return;
    var curpos = sb_offset/(g_bitmap.Height-sb_vp_h);
    if (curpos > 0.999) {
        sb_set_bitmap_pos(0, 1);
    } else {
        sb_set_bitmap_pos_percent(curpos + sb_vp_h / g_bitmap.Height * 0.8, 1);
    }
}

// clean exit
function on_script_unload()
{
    g_bitmap && g_bitmap.Dispose();  // Is it really necessary?

}
init();

Scrollbar.js (put in profile folder\wsh_scripts):
Code: [Select]
// scrollbar.js v0.1
// WSH script for foobar2000, written by r0lZ, september 2010.
// Requires foobar v1.0 with WSH Panel Mod v1.3.6 or greater.
//
// Define a viewport in your WSH window and a larger bitmap.  This script generates a
// vertical scrollbar that you can draw in the viewport, and automatically scrolls the bitmap
// in the viewport according to the user actions.
// Additionnaly, the viewport can also be dragged with the mouse, and scrolled with the mouse
// wheel or the keyboard.  Horizontal scrolling is not supported.
//
//
// Functions that you should use:
//
// function sb_init_viewport(x, y, width, height, bitmap, reset_scrollbar_position)
// Initialize the internal variables.  You should call it each time you need to refresh the
// bitmap that is drawn in the viewport, or if you need to change the viewport position or size.
// The x, y, width and height parameters define the viewport window.
// The height of the viewport must be >= 30, or the slider is not drawn.
// The width of the bitmap should be identical (or greater but that's useless) than the width
// of the viewport.
// The height of the bitmap is normally greater than the height of the viewport (as otherwise
// the scrollbar is useless).
// If reset_scrollbar_position is true, the top of the bitmap will be shown.  Otherwise,
// the previous position will be kept.
// The function returns true if the bitmap is not null.
//
// function sb_paint_viewport(gr)
// Paint the viewport.  This function should be called from the on_paint() callback.
// sb_init_viewport() should have been called BEFORE this function.
//
// function sb_paint_scrollbar(gr)
// Paint the scrollbar (if it is currently visible)
// This function should be called from the on_paint() callback, after sb_paint_viewport().
//
// function sb_set_bitmap_pos(y_position, mode)
// change the Y position of the bitmap in the viewport
// y_position (in pixels): 0 = top, bitmap.Height-1 = bottom
// mode: 1=place specified bitmap position on top of the viewport,
// -1=on bottom, 0=center
// Return true if the bitmap has been moved.
//
// function sb_set_bitmap_pos_percent(y_percent, mode)
// same as sb_set_bitmap_pos(), but here the position is a float
// between 0 (top) and 1 (bottom)
//
// function sb_CenterStringHorizontally(gr, str, font, color, x, y, maxwidth, fontflags)
// Simple helper function, to draw multi-line text with word wrapping centered in the bitmap.
// It is necessary to use that function, as strings written with GdiDrawText() look horrible
// when they are drawn in a bitmap.
// The function returns the latest Y position, so you can use the return value to draw another
// string.
//
// function sb_MeasureStringHeight(str, font, maxwidth)
// This is a simple helper function that returns the height of a string to draw with the previous
// function.  It can be used to compute the height of the bitmap.
//
//
// Callback functions used by this script:
//
// Several standard callback functions are used by this script, and are therefore not available
// directly in your own script.  However, you can still use them (with some minor limitations),
// but you have to replace "on_" with "on_sb_" in the function name.  For example, if you need
// to be notified when the mouse moves, you should define the function on_sb_mouse_move(x, y)
// instead of on_mouse_move(x, y).
//
// on_sb_mouse_lbtn_down(x, y, mask)    // You will not recieve the mouse clicks on the scrollbar
//                                      // (and on the viewport if sb_drag_enabled == true)
// on_sb_mouse_lbtn_up(x, y, mask)      // No limitations
// on_sb_mouse_move(x, y)              // No limitation, except when the user scrolls the bitmap
// on_sb_mouse_leave()                  // No limitation
// on_sb_mouse_wheel(offset)            // Available only if sb_mouse_wheel_enabled == false
// on_sb_key_down(vkey)                // The Up, Down, PgUp, PgDown, Home and End keys are not
//                                      // available when sb_keyboard_enabled == true
// on_sb_timer(timerid)                // No limitations
//
// It is your responsibility to rebuild the bitmap when needed.  In most cases, it is sufficient
// to rebuild it when you have to change its content and when the WSH window size changes.
// Then, you should call sb_init_viewport().  Call sb_paint_viewport() and sb_paint_scrollbar()
// from on_paint() to draw the viewport and the slider.
//
// Notes:
//
// - The behavior of the scrollbar is determined by global variables.  See below.
//
// - All functions and global variables defined in this script begin with "sb_".
//
// - The width of the scrollbar is 16 pixels.  If you do not use the option to hide it automatically,
//  You should not draw important things in the area occupied by the scrollbar.
//
// - You can define only one viewport and scrollbar per WSH window.
//
// - Unfortunately, GdiDrawText() doesn't work well when it writes in a bitmap.  Use DrawString() or
//  the helper functions above.


////// configuration variables that you can overwrite in your script (Do not modify them here!):

// foreground color of the scrollbar (alpha supported)
var sb_fg = window.InstanceType == 1 ? window.GetColorDUI(0) : window.GetColorCUI(0);

// background color of the scrollbar (alpha supported)
var sb_bg = window.InstanceType == 1 ? window.GetColorDUI(1) : window.GetColorCUI(3);

// scroll increment, in pixels, for the scrollbar arrows, the mouse wheel and the Up/Down keys
var sb_small_inc = 40;

// allow drag the viewport with the mouse?
var sb_drag_enabled = true;

// allow scroll with the mouse wheel?
var sb_mouse_wheel_enabled = true;

// allow scroll with Up, Down, PgUp, PgDown, Home and End keys?
var sb_keyboard_enabled = true;

// hide the scrollbar when the whole bitmap fits in the viewport?
var sb_hide_useless_scrollbar = true;

// hide the scrollbar when the mouse is not over it?
var sb_auto_hide_scrollbar = true;

// place the scrollbar at the left side of the viewport?
var sb_scrollbar_at_left_side = false;

// draw a 1 pixel border using the sb_fg color in the viewport?
var sb_draw_border = false;

// if the bitmap is smaller than the viewport, center it
var sb_center_small_bitmaps = true;

////// end of configuration variables section


// Read-only global variables that you can examine.  Do NOT overwrite them directly!

var sb_bitmap = null;  // the bitmap
var sb_offset = 0;  // Height of the bitmap zone that is above the top border of the viewport.
var sb_vp_x = 0;    // Position of the viewport in the WSH window
var sb_vp_y = 0;
var sb_vp_w = window.Width;    // Size of the viewport
var sb_vp_h = window.Height;
var sb_sb_x = window.Width-16;    // X position of the scrollbar in the WSH window.


/////////////////////////////////////////////////////////////////////////////////////////////

// Other global variables.  You should not need them.
var sb_slider_y = sb_slider_h = 0;
var sb_drag_slider = sb_drag_bitmap = false;
var sb_drag_y = sb_mouse_y = 0;
var sb_is_hidden = sb_mouse_is_outside = true;
var sb_timer = null;
var sb_timer_increment = 0;
var sb_timer_big_jumps = false;


/////////////////////// main scrollbar functions ////////////////////////

// initialize the internal variables
function sb_init_viewport(x, y, width, height, bitmap, reset_scrollbar_position)
{
    sb_bitmap = bitmap;
    sb_vp_x = x;
    sb_vp_y = y;
    sb_vp_w = width;
    sb_vp_h = height;
    if (sb_scrollbar_at_left_side) {
        sb_sb_x = sb_vp_x;
    } else {
        sb_sb_x = sb_vp_x+sb_vp_w-15;
    }
    if (sb_bitmap && (sb_bitmap.Height == 0 || sb_bitmap.Width == 0)) sb_bitmap = null;
    if (reset_scrollbar_position || ! bitmap) {
        sb_offset = 0;
    } else if (sb_offset > sb_bitmap.Height-sb_vp_h) {
        sb_offset = sb_bitmap.Height-sb_vp_h;
        if (sb_offset < 0) {
            if  (sb_center_small_bitmaps) {
                sb_offset = Math.floor(sb_offset/2);
            } else {
                sb_offset = 0;
            }
        }
    }
    return sb_bitmap ? true : false;
}

// paint the content of the viewport
function sb_paint_viewport(gr)
{
    //gr.FillSolidRect(sb_vp_x,sb_vp_y, sb_vp_w,sb_vp_h, sb_bg);
    if (sb_bitmap) {
        var x = sb_vp_x;
        var sbw = (sb_hide_useless_scrollbar && sb_bitmap.Height <= sb_vp_h) || sb_auto_hide_scrollbar ? 0:16;
        if (sb_bitmap.Width < sb_vp_w-sbw && sb_center_small_bitmaps) {
            x += Math.round((sb_vp_w-sbw - sb_bitmap.Width)/2);
        }
    gr.DrawImage(sb_bitmap, x,sb_vp_y, sb_vp_w,sb_vp_h, 0,sb_offset, sb_vp_w,sb_vp_h, 0, 255);
    }
    if (sb_draw_border) {
        gr.DrawRect(sb_vp_x,sb_vp_y, sb_vp_w-1,sb_vp_h-1, 1,sb_fg);
    }
}

// paint the scrollbar (if it is currently visible)
function sb_paint_scrollbar(gr)
{
    var arrow;
    if (!sb_bitmap || (sb_hide_useless_scrollbar && sb_bitmap.Height <= sb_vp_h) || (sb_auto_hide_scrollbar && sb_mouse_is_outside) || sb_vp_h <= 30) {
        sb_is_hidden = true;
        return;
    }
    sb_is_hidden = false;
    gr.FillSolidRect(sb_sb_x,sb_vp_y, 14,sb_vp_h, sb_bg);
    gr.DrawRect(sb_sb_x,sb_vp_y, 14,sb_vp_h-1, 1,sb_fg);
    gr.DrawLine(sb_sb_x,sb_vp_y+12, sb_sb_x+13,sb_vp_y+12, 1,sb_fg);
    gr.DrawLine(sb_sb_x,sb_vp_y+sb_vp_h-13, sb_sb_x+14,sb_vp_y+sb_vp_h-13, 1,sb_fg);
    arrow = new Array(sb_sb_x+2,sb_vp_y+9, sb_sb_x+12,sb_vp_y+9, sb_sb_x+7,sb_vp_y+3);
    gr.FillPolygon(sb_fg,0,arrow);
    arrow = new Array(sb_sb_x+3,sb_vp_y+sb_vp_h-9, sb_sb_x+12,sb_vp_y+sb_vp_h-9, sb_sb_x+7,sb_vp_y+sb_vp_h-4);
    gr.FillPolygon(sb_fg,0,arrow);
    sb_draw_slider(gr);
}

// change y position of the bitmap in the viewport
function sb_set_bitmap_pos(y_position, mode)
{
    if (!sb_bitmap) return(false);
    if (mode == -1) {
        y_position -= sb_vp_h-1;
    } else if (mode == 0) {
        y_position -= Math.round(sb_vp_h/2);
    }
    if (y_position < 0) {
        y_position = 0;
    } else if (y_position > sb_bitmap.Height-sb_vp_h) {
        y_position = sb_bitmap.Height-sb_vp_h;
    }
    if (y_position != sb_offset) {
        sb_offset = y_position;
        window.Repaint();
        return(true);
    }
    return(false);
}

// same as sb_set_bitmap_pos(), in percent
function sb_set_bitmap_pos_percent(y_percent, mode)
{
    if (!sb_bitmap) return(false);
    return(sb_set_bitmap_pos(Math.round(sb_bitmap.Height*y_percent), mode));
}

//////////////// the functions below should not be called directly

// scroll the bitmap by big increrment
function sb_big_increment(dir)
{
    if (! sb_bitmap) return;
    var incr;
    var pc_shown = sb_vp_h/sb_bitmap.Height;
    if (pc_shown >= 1) {
        return;
    } else {
        incr = dir*sb_slider_h*1/pc_shown*Math.abs(sb_vp_h/(sb_vp_h-32));
        if (incr > 0 && incr > sb_small_inc) incr -= sb_small_inc;
        if (incr < 0 && incr < sb_small_inc) incr += sb_small_inc;
        sb_increment_bitmap_pos(incr);

        sb_timer_increment = incr;
        sb_timer_big_jumps = true;
        sb_timer = window.CreateTimerTimeout(500);
    }
}

// scroll the bitmap by any number of pixels
function sb_increment_bitmap_pos(increment)
{
    if (!sb_bitmap) return(false);
    var tmp = sb_offset + Math.round(increment) * -1;
    if (tmp < 0) {
        tmp = 0;
    } else if (tmp > sb_bitmap.Height-sb_vp_h) {
        tmp = sb_bitmap.Height-sb_vp_h;
    }
    if (tmp != sb_offset) {
        sb_offset = tmp;
        window.Repaint();
        return(true);
    }
    return(false);
}

// Called when the user moves the scrollbar slider
function sb_apply_scroll(y)
{
    if (! sb_bitmap) return;
    var pc_shown = sb_vp_h/sb_bitmap.Height;
    if (pc_shown >= 1) {
        return;
    } else {
        delta = y - sb_drag_y;
        if (sb_increment_bitmap_pos(delta*-1/pc_shown*Math.abs(sb_vp_h/(sb_vp_h-32)))) {
            sb_drag_y = y;
        }
    }
}

// draw the slider in the scrollbar
function sb_draw_slider(gr)
{
    if (!sb_bitmap || sb_is_hidden || (sb_hide_useless_scrollbar && sb_bitmap.Height <= sb_vp_h)) return;
    var pc_shown, pc_offset;
    var s_max = sb_vp_h-32;

    pc_shown = sb_vp_h/sb_bitmap.Height;
    if (pc_shown >= 1) {
        pc_shown = 1;
        pc_offset = 0;
    } else {
        pc_offset = sb_offset/sb_bitmap.Height;
        if (pc_offset < 0) {pc_offset = 0};  // not necessary?
    }
    sb_slider_y = sb_vp_y + s_max * pc_offset + 14;
    sb_slider_h = s_max * pc_shown + 4;
    if (sb_vp_h > 50) {
        gr.FillSolidRect(sb_sb_x+2,sb_slider_y, 11,sb_slider_h, sb_fg);
    }
}

/////////////////////////// callbacks //////////////////////

function on_mouse_lbtn_down(x, y, mask)
{
    sb_timer && window.KillTimer(sb_timer);
    if (! sb_is_hidden && sb_bitmap && sb_bitmap.Height > sb_vp_h && x > sb_sb_x && x < sb_sb_x+15 && y > sb_vp_y && y < sb_vp_y+sb_vp_h) {
        if (y < sb_vp_y+12) {
            sb_timer_increment = sb_small_inc;
            sb_timer_big_jumps = false;
            sb_increment_bitmap_pos(sb_timer_increment);
            sb_timer = window.CreateTimerTimeout(500);
            return;
        }
        if (y >= sb_vp_y+sb_vp_h-12) {
            sb_timer_increment = sb_small_inc*-1;
            sb_timer_big_jumps = false;
            sb_increment_bitmap_pos(sb_timer_increment);
            sb_timer = window.CreateTimerTimeout(500);
            return;
        }
        if (sb_vp_h > 50) {
            if (y >= sb_slider_y && y < sb_slider_y+sb_slider_h) {
                sb_drag_slider = true;
                sb_drag_y = y;
                return;
            }
            if (y >= sb_vp_y+12 && y < sb_slider_y) {
                sb_big_increment(1);
                return;
            }
            if (y < sb_vp_y+sb_vp_h-12 && y > sb_slider_y + sb_slider_h) {
                sb_big_increment(-1);
                return;
            }
        } else {
            sb_timer_increment = sb_vp_h * -0.9;
            sb_timer_big_jumps = false;
            if (sb_offset + sb_vp_h + 1 >= sb_bitmap.Height) {
                sb_set_bitmap_pos(0, 1);
            } else {
                sb_increment_bitmap_pos(sb_timer_increment);
            }
            sb_timer = window.CreateTimerTimeout(500);
            return;
        }
    }
    if (sb_drag_enabled && x > sb_vp_x && x < sb_vp_x+sb_vp_w && y > sb_vp_y && y < sb_vp_y+sb_vp_h) {
        if (sb_bitmap && sb_bitmap.Height > sb_vp_h) {
            sb_drag_bitmap = true;
            sb_drag_y = y;
            window.SetCursor(32645);  // IDC_SIZENS
        }
        return;
    }
    // call user's callback function
    try {on_sb_mouse_lbtn_down(x, y, mask)} catch(e) {}
    return;
}

function on_mouse_lbtn_up(x, y, mask)
{
    sb_timer && window.KillTimer(sb_timer);
    sb_drag_slider = false;
    if (sb_drag_bitmap) {
        window.SetCursor(32512);    // IDC_ARROW
        sb_drag_bitmap = false;
    }
    try {on_sb_mouse_lbtn_up(x, y, mask)} catch(e) {}
}

function on_mouse_move(x, y)
{
    sb_mouse_y = y;
    if (sb_drag_slider) {
        sb_apply_scroll(y);
        return;
    }
    if (sb_drag_bitmap) {
        sb_increment_bitmap_pos(y - sb_drag_y);
        sb_drag_y = y;
        return;
    }
    if (sb_is_hidden && sb_auto_hide_scrollbar && sb_bitmap && sb_bitmap.Height > sb_vp_h && x >= sb_sb_x && x <= sb_sb_x+15 && y >= sb_vp_y && y <= sb_vp_y+sb_vp_h) {
        window.Repaint();
        sb_mouse_is_outside = false;
    }
    try {on_sb_mouse_move(x, y)} catch(e) {}
}

function on_mouse_leave()
{
    if (! sb_is_hidden && sb_auto_hide_scrollbar) {
        window.Repaint();
    }
    sb_mouse_is_outside = true;
    try {on_sb_mouse_leave()} catch(e) {}
}

function on_mouse_wheel(offset)
{
    if (sb_mouse_wheel_enabled && sb_bitmap && sb_bitmap.Height > sb_vp_h) {
        sb_increment_bitmap_pos(offset*sb_small_inc);
    } else {
        try {on_sb_mouse_wheel(offset)} catch(e) {}
    }
}

function on_key_down(vkey)
{
    if (sb_keyboard_enabled && sb_bitmap && sb_bitmap.Height > sb_vp_h) {
        switch(vkey) {
            case 33:
                // PgUp
                sb_big_increment(1);
                break;
            case 34:
                // PgDn
                sb_big_increment(-1);
                break;
            case 35:
                // End
                sb_increment_bitmap_pos(sb_bitmap.Height*-1);
                break;
            case 36:
                // Home
                sb_increment_bitmap_pos(sb_bitmap.Height);
                break;
            case 38:
                // Up
                sb_increment_bitmap_pos(sb_small_inc);
                break;
            case 40:
                // Down
                sb_increment_bitmap_pos(sb_small_inc*-1);
                break;
        }
        return;
    }
    try {on_sb_key_down(vkey)} catch(e) {}
}

function on_timer(timerid)
{
    if (sb_timer && timerid == sb_timer.ID) {
        sb_timer && window.KillTimer(sb_timer);
        if (sb_timer_big_jumps && sb_mouse_y >= sb_slider_y && sb_mouse_y < sb_slider_y+sb_slider_h) return;
        if (sb_increment_bitmap_pos(sb_timer_increment)) {
            sb_timer = window.CreateTimerTimeout(100);
        }
        return;
    }
    try {on_sb_timer(timerid)} catch(e) {}
}


//////////////////////////// helper functions ///////////////////////////////
// These functions are not necessary for the scrollbar.  You can remove them.

// Draw multi-line text with word wrapping centered in the bitmap.
function sb_CenterStringHorizontally(gr, str, font, color, x, y, maxwidth, fontflags)
{
    if (window.Height == 0) return(-1);  // safety check: foobar enters in an infinite loop if bitmap.GetGraphics() is called when foobar is initializing.
    var i, j, xpos, ypos, arr2;
    var arr1 = str.split("\n");
    ypos = y;
    for (i=0; i<arr1.length; i++) {
        arr2 = gr.EstimateLineWrap(arr1[i], font, maxwidth).toArray();
        for (j=0; j<arr2.length; j+=2) {
            xpos = x+(maxwidth-arr2[j+1])/2;
            gr.DrawString(arr2[j], font, color, xpos, ypos, maxwidth, font.Height+50, fontflags);
            ypos = ypos + font.Height;
        }
    }
    return(ypos);
}

// Returns the height of a string to draw with the previous function.
function sb_MeasureStringHeight(str, font, maxwidth)
{
    var temp_bmp = gdi.CreateImage(1, 1);
    var temp_gr = temp_bmp.GetGraphics();

    var i, arr2;
    var arr1 = str.split("\n");
    var h = 0;

    for (i=0; i<arr1.length; i++) {
        arr2 = temp_gr.EstimateLineWrap(arr1[i], font, maxwidth).toArray();
        h = h + font.Height*arr2.length/2;
    }

    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();

    return(h);
}


Too bad using wsh.Exec() shows the console dialog when running console applications and wanting to capture the output.
So the solution is to use wsh.Run() with cmd.exe to redirect the output to a temporary text file which you can then read with utils.ReadTextFile()
I struggled with getting this to work because cmd.exe requries a lot of quoting for the > character to be parsed correctly.
So I ended up with this:
cmd.exe /C""H:\codecs and players\mediainfo_cli\MediaInfo.exe" "E:\music\Above & Beyond - Trance Around The World\Above & Beyond - Trance Around the World 353 (2010-12-31).mka" > h:\out.txt"

as you can see the entire string after /C is quoted. then you got quotes for the long filenames. When escaped for use in javascript it looks even worse:
Code: [Select]
var pp = "cmd.exe /C\"\"H:\\codecs and players\\mediainfo_cli\\MediaInfo.exe\" \""+filename+"\" > h:\\out.txt\"";
No wonder it is so easy to get tripped up here.

Someone ought to have made this simpler to do. Basically what I'm requesting is for a function in WSH panels mod that lets you run and capture output of console apps without this ugly code.


 

WSH Panel Mod script discussion/help

Reply #709
Hi!

I'm trying to create a very simple button to toggle on/off  the Stop after Album function of the... Stop after album component http://www.hydrogenaudio.org/forums/index....c=83743&hl=

I can toggle the value with
Code: [Select]
fb.RunMainMenuCommand("Control/Stop after album");

But how to access its value (which should be 0 or 1) ? I would like to change the state of the button depending of its value (if it's on, do blablabla, ... if it's off, do blablabla)


Thanks in advance for your help,

Decalicatan Decalicatan
Decalicatan Decalicatan

WSH Panel Mod script discussion/help

Reply #710
hi everyone!
I'm really bad at scripting. just wanted to ask, can i get this panel to show cover art dimensions?? (if not, any alternative solution will be really appreciated)

WSH Panel Mod script discussion/help

Reply #711
samples updated.

http://cid-649d3bfeaf541fbb.office.live.co...ide/samples.zip

contains a new script called "thumbs3". exactly the same as thumbs2 except the thumbnail strip is vertical instead of horizontal.


I have a few quick questions about your layout, I'd be glad if you answered them.
Is that tab stack on top made directly on WSH? I'm assuming since the toolbar looks like it was. Oh, and it looks awesome, by the way. And the Last.fm stuff was put on a Panel Stack, right? And is that tab stack a regular tab stack containing WSH panels?

WSH Panel Mod script discussion/help

Reply #712
But how to access its value (which should be 0 or 1) ? I would like to change the state of the button depending of its value (if it's on, do blablabla, ... if it's off, do blablabla)


i'm guessing that would require an SDK for the component to be opened up and then included in WSH panel mod. in short, not likely...

can i get this panel to show cover art dimensions?? (if not, any alternative solution will be really appreciated)


yup, what ever variable contains your image, you can get dimensions like this...

my_img.height
my_img.width

Is that tab stack on top made directly on WSH? I'm assuming since the toolbar looks like it was. Oh, and it looks awesome, by the way. And the Last.fm stuff was put on a Panel Stack, right? And is that tab stack a regular tab stack containing WSH panels?


nope, the top "tabs" are buttons in Panel Stack Splitter. and yup, the WSH panels are in a standard tab stack (inside a parent PSS with a 10px margin around the edge).

WSH Panel Mod script discussion/help

Reply #713
Is that tab stack on top made directly on WSH? I'm assuming since the toolbar looks like it was. Oh, and it looks awesome, by the way. And the Last.fm stuff was put on a Panel Stack, right? And is that tab stack a regular tab stack containing WSH panels?


nope, the top "tabs" are buttons in Panel Stack Splitter. and yup, the WSH panels are in a standard tab stack (inside a parent PSS with a 10px margin around the edge).

Thanks for the reply. Buttons... I got Panel Stack today, I'm still playing with this a little bit.
Would you mind showing me the Library tab? I'm kinda curious to see what have you done with it since I really liked your previous designs.

WSH Panel Mod script discussion/help

Reply #714
erm ok. click

WSH Panel Mod script discussion/help

Reply #715
i'm guessing that would require an SDK for the component to be opened up and then included in WSH panel mod. in short, not likely...


Thank you for your answer. I was afraid of something like that. I guess I will try to create my own "stop after album" WSH panel mod script from scratch.

Decalicatan Decalicatan
Decalicatan Decalicatan



WSH Panel Mod script discussion/help

Reply #718
Are all usermade content for WSH Panels Mod now following the new guidelines with regards to where components and associated files should be place? I.e in the foobar2000 user profile folder.
I would hate having to put junk in c:\program files\foobar2000 again.


good point. i've decided to move all my shared files in to the profile folder.

samples updated: http://cid-649d3bfeaf541fbb.office.live.co...ide/samples.zip


WSH Panel Mod script discussion/help

Reply #719
erm ok. click

Dude, what the fuck is wrong with the goddamn buttons? Every time I change something on them, foobar resets their parent Panel Stack and, well, its configuration on the grandparent Panel Stack too. Also, I can't have more than one button when its custom image isn't a square, right?

I know this isn't the thread but how can I change a Panel Stack border edge to grey, sunken and etc?

WSH Panel Mod script discussion/help

Reply #720
i'm guessing that would require an SDK for the component to be opened up and then included in WSH panel mod. in short, not likely...

Thank you for your answer. I was afraid of something like that. I guess I will try to create my own "stop after album" WSH panel mod script from scratch.

Decalicatan Decalicatan


Okey dokey this is it a basic "Stop after album" script. It is just a simple button (width 126; height 20) that can toggle on/off  the Stop After Current function for when the playback reach the last track of an album (that is when %tracknumber% = %totaltracks%)

If totaltracks is not defined it doesn't work.

As my skills in jscript are very low (I "learn" it trying to understand other people scripts) it must be written badly but it works.

If someone wants to modify it, feel free to do it but please post the modifed script here.

http://pastebin.com/K391Ksym

Code: [Select]
// ==PREPROCESSOR==
// @import "%fb2k_path%scripts\marc2003\v2\common.js"
// @name "Stop After Album v.1.0"
// @author "Decalicatan Decalicatan"
// ==/PREPROCESSOR==


// width: 126
// height: 20

var tracknumber_tf = fb.TitleFormat("%tracknumber%");
var totaltracks_tf = fb.TitleFormat("[%totaltracks%]");
var totaltracks, tracknumber;


var SAA = "Stop after album";
var SAA_state = 0;
var font = gdi.Font("Calibri", 16, 1);
var hover = 0;





function on_mouse_mbtn_down(x, y) {
    window.ShowConfigure();
}


function on_mouse_move() {
    if (fb.IsPlaying) {
        g_metadb = fb.GetNowPlaying();
        totaltracks = totaltracks_tf.EvalWithMetadb(g_metadb);
        if (totaltracks == 0) {
            hover = 0;
        } else {
            hover = 1;
            window.Repaint();
        }
    } else hover = 1;
}


function on_mouse_leave() {
    hover = 0;
    window.Repaint();
}


function StringFormat(alignH, alignV, trim, flag) {
    return ((alignH << 28) | (alignV << 24) | (trim << 20) | flag);
}

function RGB(r, g, b) {
    return (0xff000000 | (r << 16) | (g << 8) | (b));
}


function on_playlist_stop_after_current_changed(new_order_index) {
    window.Repaint();
}

function on_playback_stop(reason) {
    g_metadb = null;
    SAA_state = 0;
    if (reason != 2) window.Repaint();
}




function on_mouse_lbtn_down(x, y) {
    g_metadb = fb.GetNowPlaying();
    tracknumber = tracknumber_tf.EvalWithMetadb(g_metadb);
    if (fb.StopAfterCurrent) fb.StopAfterCurrent = 0;
    if (SAA_state !== 0) {
        SAA_state = 0;
    } else {
        SAA_state = totaltracks_tf.EvalWithMetadb(g_metadb);
        if (tracknumber == SAA_state) fb.StopAfterCurrent = 1;
    }
}



function on_playback_new_track() {
    if (SAA_state !== 0) {
        g_metadb = fb.GetNowPlaying();
        tracknumber = tracknumber_tf.EvalWithMetadb(g_metadb);
        if (tracknumber == SAA_state) fb.StopAfterCurrent = 1;
    }
}




function on_paint(gr) {
    var ww = window.Width;
    var wh = window.Height;
    totaltracks = fb.TitleFormat("[%totaltracks%]").Eval();
    tracknumber = fb.TitleFormat("[%tracknumber%]").Eval();
    if (((fb.StopAfterCurrent) && (SAA_state != tracknumber)) || ((!fb.StopAfterCurrent) && (SAA_state == tracknumber))) SAA_state = 0;
    if (hover == 0) {
        gr.FillSolidRect(0, 0, ww, wh, RGB(255, 255, 255));
        if (totaltracks == 0) {
            gr.GdiDrawText(SAA, font, RGB(205, 205, 205), 0, 0, ww, wh, DT_CENTER | DT_VCENTER | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
        } else {

            if (SAA_state) {
                gr.GdiDrawText(SAA, font, RGB(0, 128, 192), 0, 0, ww, wh, DT_CENTER | DT_VCENTER | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
            } else {
                gr.GdiDrawText(SAA, font, RGB(105, 105, 105), 0, 0, ww, wh, DT_CENTER | DT_VCENTER | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
            }
        }
    } else {
        gr.FillSolidRect(0, 0, ww, wh, RGB(0, 128, 192));
        gr.GdiDrawText(SAA, font, RGB(255, 255, 255), 0, 0, ww, wh, DT_CENTER | DT_VCENTER | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);
    }


}

Decalicatan Decalicatan

WSH Panel Mod script discussion/help

Reply #721
@ marc2003

In your last revision of samples.zip, the folder marc2003\images\2010 is missing and so is the small lastfm.png icon for the Similar Artist script

Decalicatan Decalicatan
Decalicatan Decalicatan

WSH Panel Mod script discussion/help

Reply #722
oops. i was tidying up unused files and got a bit carried away. thanks for spotting that one. it should be fixed now.


WSH Panel Mod script discussion/help

Reply #723
Anyone knows how to implement network connection timeout inside wsh panels with activexcontrol Microsoft.XMLHTTP (last.fm was literally down for two previous days and taking forever to respond)? I've been trying to search for a solution to this problem but to no avail. I know of an alternative by using wget, but I don't want to go that way unless there's no other way. Any help is appreciated.

WSH Panel Mod script discussion/help

Reply #724
Managed to implement network timeout with ServerXMLHTTP ActiveX component. Not the recommended way as this component is supposed to work on server not client. Side effect is user have to enter proxy settings manually if they are behind a proxy (well they did have to do this for wget anyway).