Скрипты для foo_uie_wsh_panel_mod

Список разделов foobar2000 Секреты foobar2000

Описание: Кнопочки, конфиги, секреты, советы.

Сообщение #1781 kgena_ua » 26.03.2017, 10:41

vik-tan, по переводу наименований. Я не специально написал их на английском, я просто беру стандартные наименования:
"$meta(artist)",
"%title%",
"%album%",
"%date%", и т.д., и затем "очищаю" от ненужных символов.

Для добавления своих значений нужно вставить их в массив var tfname = [..., соблюдая синтаксис.
Для примера выкладываю этот массив с добавленным типом тега - $info(tagtype).
Код: Выделить всё
var tfname = [
"$meta(artist)",
"%title%",
"%album%",
"%date%",
"%genre%",
"%composer%",
"%performer%",
"%publisher%",
"$meta(album artist)",
"%track number%",
"%totaltracks%",
"%discnumber%",
"%totaldiscs%",
"%rating%",
"$meta(rating)",
"%comment%",
"%catalog%",
"%discid%",
"%label%",
"%publisher%",
"%subtitle%",

"group general",
"$info(samplerate)",
"$info(channels)",
"$info(bitspersample)",
"$info(bitrate)",
"%codec%",
"$info(codec_profile)",
"$info(mp3_stereo_mode)",
"$info(encoding)",
"%length%",
"$info(tool)",
"$info(cue_embedded)",
"$info(tagtype)",

"group location",
"%filename_ext%",
"$directory_path(%path%)",
"%subsong%",
"%filesize_natural%",
"%last_modified%",
"%folder name%",
"group playback statistics",
"%play_count%",
"%first_played%",
"%last_played%",
"%added%",

"group last.FM",
"%lastfm_bio%",
"%lastfm_artist_playcount%",
"%lastfm_artist_listeners%",
"%lastfm_album_playcount%",
"%lastfm_album_listeners%",
"%lastfm_album_content%",

"group ",
"%lastfm_similar_artist%"
];
kgena_ua M
Аватара
Откуда: Украина, Днепр
Репутация: 504
С нами: 10 лет 11 месяцев

Сообщение #1782 vik-tan » 26.03.2017, 18:10

kgena_ua,
C масивом понял, спасибо!!А вот как переименовать-не понял,? :insane:
vik-tan
Репутация: 0
С нами: 7 лет 8 месяцев

Сообщение #1783 Cerberus » 29.03.2017, 00:28

Приветствую! Только что заметил, что не отображается биография. В чем может быть проблема и как ее устранить?
Cerberus
Репутация: 10
С нами: 7 лет 5 месяцев

Сообщение #1784 seriousstas » 29.03.2017, 00:46

(проверил)У меня - норм...
seriousstas
Откуда: Украина , Ивано-Франковск
Репутация: 110
С нами: 9 лет 1 месяц

Сообщение #1785 Cerberus » 29.03.2017, 00:56

seriousstas, 1811201 этой версии мой скрипт) думаю что то в скрипте за это время обновлялось!??

P.S. поставил версию за 1 число этого месяца. теперь все отображается! Значит что то менялось в скрипте.
Cerberus
Репутация: 10
С нами: 7 лет 5 месяцев

Сообщение #1786 seriousstas » 30.03.2017, 23:40

Cerberus
что то в скрипте за это время обновлялось!??

s-ку добавь к ссылкам :
https ...
seriousstas
Откуда: Украина , Ивано-Франковск
Репутация: 110
С нами: 9 лет 1 месяц

Сообщение #1787 Cerberus » 31.03.2017, 01:10

seriousstas, спасибо)
Cerberus
Репутация: 10
С нами: 7 лет 5 месяцев

Сообщение #1788 vik-tan » 31.03.2017, 16:56

Ребята поправьте скрипт пожалуйста кто понимает? у меня вся библиотека отображается так(-?) лишнее,вот его убрать бы. :beer:
В АРХИВЕ -WSH Playlist Viewer.txt (автор Бретт)
Вложения
WSH Playlist Viewer.rar
(35.23 КБ) Скачиваний: 227
Снимок-1.JPG
vik-tan
Репутация: 0
С нами: 7 лет 8 месяцев

Сообщение #1789 kgena_ua » 04.04.2017, 20:28

Properties & properties file
version "28032017"


- в предыдущей версии была ошибка, которая могла приводить к зависанию плеера при импорте файла конфигурации - *.fcl;
- изменил принцип отображения подсказки, в Properties добавил выбор размера шрифта для подсказки.
- исправлена небольшая ошибка в function Eval(field).

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Properties & properties file"
// @author "kgena_ua"
// @version "28032017"
// @feature "v1.4"
// @feature "watch-metadb"
// @tooltip "custom-paint"
// ==/PREPROCESSOR==

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

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

var ww, wh, wh_old;

IDC_HAND = 32649;
IDC_ARROW = 32512;
IDC_SIZEWE = 32644;

MF_ENABLED = 0x00000000;
MF_GRAYED = 0x00000001;
MF_SEPARATOR = 0x00000800;

String.prototype.repeat = function(n) {
    return new Array(n + 1).join(this);
}

window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");

var font_name_item_name = window.GetProperty(" font name: item name", "Arial");
var font_name_item_value = window.GetProperty(" font name: item value", "Arial");
var font_name_group = window.GetProperty(" font name: group", "Arial");

var font_size_item_name = window.GetProperty(" font size: item name", 11);
var font_size_item_value = window.GetProperty(" font size: item value", 12);
var font_size_group = window.GetProperty(" font size: group", 11);

var font_style_item_name = window.GetProperty(" font style: item name", 0);
var font_style_item_value = window.GetProperty(" font style: item value", 0);
var font_style_group = window.GetProperty(" font style: group", 0);

var font_size_tooltip = window.GetProperty(" font size: tooltip", 11);

var font_item, font_group, font_tooltip;
get_font();

function get_font(){
    font_item_name = gdi.Font(font_name_item_name, font_size_item_name, font_style_item_name);
    font_item_value = gdi.Font(font_name_item_value, font_size_item_value, font_style_item_value);
    font_group = gdi.Font(font_name_group, font_size_group, font_style_group);
    font_tooltip = gdi.Font("Arial", font_size_tooltip, 0);
}

ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

ColorTypeDUI = {
   text: 0,
   background: 1,
   highlight: 2,
   selection: 3
};

function get_color(){   
    if (window.InstanceType == 0){
        bgcolor = window.GetColorCUI(ColorTypeCUI.background);
        color_item_name = window.GetColorCUI(ColorTypeCUI.text);
        color_item_value = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
        color_group_text = window.GetColorCUI(ColorTypeCUI.inactive_selection_background);
    } else if (window.InstanceType == 1) {
        bgcolor = window.GetColorDUI(ColorTypeDUI.background);
        color_item_name = window.GetColorDUI(ColorTypeDUI.text);
        color_item_value = window.GetColorDUI(ColorTypeDUI.highlight);
        color_group_text = window.GetColorDUI(ColorTypeDUI.selection);
    }
    window.Repaint();
}

get_color();

function on_colors_changed(){
    get_color();
}

var custom_colors = window.GetProperty(" colors: custom", false);

var c_bgcolor = customColor(window.GetProperty(" color: background", "0-0-0"));
var c_color_item_name = customColor(window.GetProperty(" color: item name", "180-180-180")); 
var c_color_item_value = customColor(window.GetProperty(" color: item value", "255-255-220"));
var c_color_group_text = customColor(window.GetProperty(" color: group text", "100-100-100"));

bgcolor = custom_colors ? c_bgcolor : bgcolor;
color_item_name = custom_colors ? c_color_item_name : color_item_name;
color_item_value = custom_colors ? c_color_item_value : color_item_value;
color_group_text = custom_colors ? c_color_group_text : color_group_text;

function customColor(colour){
   tempc = colour.split("-");
   return (0xff000000 | (tempc[0]<<16) | (tempc[1]<<8) | (tempc[2]));
}

var selection_mode = window.GetProperty("selection_mode", 0);

var item_name_array = [];
var item_value_array = [];
var tmp_item_name_array = [];
var tmp_item_value_array = [];
var value_width = [];
var name, value;
var similar_artist_text = "";
var similar_artist = [];

var auto_sizing = window.GetProperty("auto sizing", true);
var group_text = window.GetProperty("group text", false);
var vertical_item_padding = window.GetProperty(" vertical item padding", 1);

var t_h;
var t_x1 = window.GetProperty(" text: x", 10);
var t_x2;
window.GetProperty("text: x2 custom", 0);
var t_x3;
var lbtn_down = false;
var drag_x = 0, drag_y = 0;
var move_x = false,  move_y = false;
var s = 0;
var old_x, old_y;

var Tooltip = window.GetProperty("tooltip", false);
var tooltip = window.CreateTooltip();   
var tooltip_time = fb.CreateProfiler("Time tooltip");
var tooltip_state = false;
var tooltip_text;
var tooltip_max_w = 250;

function on_paint(gr) {
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
   
    draw_array(gr);

    gr.GdiDrawText( "", font_item_value, color_item_value, 0, 120, ww, wh, DT_RIGHT | DT_WORD_ELLIPSIS);
}

var tfname = [
"$meta(artist)",
"%title%",
"%album%",
"%date%",
"%genre%",
"%composer%",
"%performer%",
"$meta(album artist)",
"%track number%",
"%totaltracks%",
"%discnumber%",
"%totaldiscs%",
"%rating%",
"$meta(rating)",
"%comment%",
"%publisher%",
"%catalog%",
"%discid%",
"%label%",
"%releaser%",
"%subtitle%",

"group general",
"$info(samplerate)",
"$info(channels)",
"$info(bitspersample)",
"$info(bitrate)",
"%codec%",
"$info(codec_profile)",
"$info(mp3_stereo_mode)",
"$info(encoding)",
"%length%",
"$info(tool)",
"$info(cue_embedded)",
"$info(tagtype)",

//"group replaygain",
//"%replaygain_album_gain%",
//"%replaygain_album_peak%",
//"%replaygain_track_gain%",
//"%replaygain_track_peak%",

"group location",
"%filename_ext%",
"$directory_path(%path%)",
"%url%",
"%subsong%",
"%filesize_natural%",
"%last_modified%",
"%folder name%",

"group playback statistics",
"%play_count%",
"%first_played%",
"%last_played%",
"%added%",

"group last.FM",
"%lastfm_bio%",
"%lastfm_artist_playcount%",
"%lastfm_artist_listeners%",
"%lastfm_album_playcount%",
"%lastfm_album_listeners%",
"%lastfm_album_content%",

"group last.FM",
"%lastfm_similar_artist%"
];

function set_cursor(x, y) {
    if (move_y || lbtn_down) window.SetCursor(IDC_HAND);
    if (move_x && !lbtn_down) window.SetCursor(IDC_SIZEWE);
}

function on_mouse_lbtn_down(x, y) {
    lbtn_down = true;
    if (move_y) drag_y = (y - s);
    if (move_x) drag_x = x - t_x2;
    set_cursor(x, y);
}

function on_mouse_lbtn_up(x, y) {
    lbtn_down = false;
    if (move_x) {
        window.SetProperty("text: x2 custom",  t_x2);
    }
}

function on_mouse_move(x, y) {
    mouse_on_pos(x, y);
    set_cursor(x, y);
   
    if (old_y != y || old_x != x){
        if (Tooltip) tooltip_activate(x, y);
        old_y = y;
        old_x = x;
    }
   
    if (lbtn_down && move_y) {
        if (s <= 0 && (item_name_array.length * t_h) >= wh) {s = y - drag_y};
        applyDelta();
    }

    shift_down = utils.IsKeyPressed(0x10) ? true : false;
    if (!shift_down) drag_x = x - t_x2;

    if (lbtn_down && move_x) {
        auto_sizing = false;
        window.SetProperty("auto sizing", auto_sizing);
        tmp_t_x2 = x - drag_x;
        t_x2 = tmp_t_x2 <= t_x1 ? t_x1 : tmp_t_x2 >= ww - t_x1 - 50 ? ww - t_x1 - 50 : tmp_t_x2;
    }
   
    window.Repaint();
}

function on_mouse_wheel(step) {
    if (s <= 0 && item_name_array.length * t_h >= wh) {s = s + step * t_h};
    applyDelta();
}

function applyDelta() {
    s = s > 0 ? 0 : s;
    s = s < (wh - item_name_array.length * t_h) && s < 0 ? (wh - item_name_array.length * t_h) : s;
    window.Repaint();
}

function on_mouse_leave() {   
    window.SetCursor(IDC_ARROW);
    window.Repaint();
}

function mouse_on_pos(x, y){
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (ShiftDown && x >= t_x2) {
        move_x = true;
        move_y = false;
    } else {
        move_y = true;
        move_x = false;
    }
}

function on_size() {
    ww = window.Width;
    wh = window.Height;
    if (wh != wh_old  && s < 0) {
        s = wh >= wh_old ? 0 : s;
        wh_old = wh;
    }
    create_array(); // ????????/
}

function clear_item_name(n) {
    return n.replace(/.*\(|lastfm_|replaygain_|[^a-z0-9\s\_]/g,"").replace(/_/g," ");
    //return n.replace(/.*\((?!\))|lastfm_|replaygain_|[^a-z0-9\s\_]/g,"").replace(/_/g," "); 
}

function clear_group_text(n) {
    return n.replace(/group\s/g,"").replace(/(?=.)/g," ").replace(/^\s/g,"")
}


var measure = {
    'bitrate' : "  kbps",
    'samplerate' : "  Hz",
    'bitspersample' : "  bps",
    'channels' : "  ch",
    'playcount' : "  times"
}

function create_array() {
    var temp_bmp = gdi.CreateImage(1, 1);
    var temp_gr = temp_bmp.GetGraphics();
    tmp_item_name_array = [];
    tmp_item_value_array = [];
    value_width = [];
   
    t_x2 = 0;
    similar_artist_text = "";
    similar_artist = [];
   
    for (j = 0; j < tfname.length; j++) {
        group = tfname[j].search('group') >= 0 ? true : false;

        value = Eval(tfname[j]);
       
        if (value && value !=0 || group) {
            tmp_item_name_array.push(tfname[j]);
           
            if (tfname[j] != "%lastfm_similar_artist%"){
                tmp_item_value_array.push(value);
                value_width.push(temp_gr.CalcTextWidth(value, font_item_value),value);
            }
           
            if (tfname[j] == "%lastfm_similar_artist%") {
                similar_artist_text = value.replace(/(&apos;)/g, "'");
            }
        }
       
        if (!group){
            tmp_t_x2 = temp_gr.CalcTextWidth(clear_item_name(tfname[j]), font_item_name);
            t_x2 = tmp_t_x2 > t_x2 ? tmp_t_x2 : t_x2;
        }
    }
   
    t_x2 = auto_sizing ? t_x2 + t_x1 + 10 : window.GetProperty("text: x2 custom");

    if (similar_artist_text){
        similar_artist = similar_artist_text.split(';');
       
        for (var i = 0; i < similar_artist.length; i++) {
            if (i >= 1) tmp_item_name_array.push("");
            value = similar_artist[i].replace(/^\s+|\s+$/g, "") + ";";
            tmp_item_value_array.push(value);
            value_width.push(temp_gr.CalcTextWidth(value, font_item_value),value);
        }
    }

    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
   
    clear_empty_groups();
}

function clear_empty_groups() {
    item_name_array = [];
    item_value_array = [];
   
    for (j = 0; j < tmp_item_name_array.length; j++) {
        group = tmp_item_name_array[j].search('group') >= 0 ? true : false;

        item_nane = tmp_item_name_array[j];
        item_value = tmp_item_value_array[j];
       
        if (!group){
            item_name_array.push(item_nane);
            item_value_array.push(item_value);       
        }
       
        if (group){
            if (tmp_item_value_array[j + 1]){
                item_name_array.push(item_nane);
                item_value_array.push(item_value); 
            } else{
                value_width.splice(j * 2, 2);
            }
        }
    }
    if (item_name_array.length * t_h < wh && s < 0) s = 0;
}

function draw_array(gr) {
    f_h_name = gr.CalcTextHeight("Text", font_item_name);
    f_h_value = gr.CalcTextHeight("Text", font_item_value);
   
    f_h = Math.max(f_h_name, f_h_value);
   
    t_h = f_h + window.GetProperty(" vertical item padding");
   
    star_size = f_h_value - 3;
    star_offset = star_size + 2;
   
    for (var i = 0; i < item_name_array.length; i++) {
        group = item_name_array[i].search('group') >= 0 ? true : false;
       
        font = group ? font_group : font_item_name;
        color = group ? color_group_text : color_item_name;
        t_y =  i * t_h + s;
        l_y = t_y + t_h / 2;
       
        if (!group){
            name = clear_item_name(item_name_array[i]);
            rating_text = item_name_array[i] == "$meta(rating)" ? "  (tag)" : "";
            t_w = Math.min(t_x2 - 20, ww - t_x1 * 2);
            gr.GdiDrawText(name + rating_text, font, color, t_x1, t_y, t_w, t_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);         
        }
       
        if (group){
            name = group_text ? clear_group_text(item_name_array[i]) : "";
            t_w = ww - t_x1 * 2;
            gr.GdiDrawText(name, font, color, t_x1, t_y, t_w, t_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);         

            g_w = group_text && name ? gr.CalcTextWidth(name, font) + 5 : 0;
            group && gr.DrawLine(t_x1 + g_w, l_y, ww - t_x1, l_y, 1, color);
        }
       
        if (item_name_array[i] == "%rating%" || item_name_array[i] == "$meta(rating)") {
            for (var r = 0; r < item_value_array[i] * star_offset; r = r + star_offset) {
                draw_star(gr, t_x2 + star_size / 3 + r, t_y + t_h / 2, star_size, true, 0, color_item_value, false, bgcolor, 255);
            }
        } else {
            value = item_value_array[i];
            gr.GdiDrawText( value, font_item_value, color_item_value, t_x2, t_y, ww - t_x2 - t_x1, t_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);       

            t_x3 = t_x2 + gr.CalcTextWidth(value, font_item_value);
            tmp = clear_item_name(item_name_array[i]).replace(/\s/g,"");
            gr.GdiDrawText( measure[tmp], font_item_value, color_group_text, t_x3, t_y, ww - t_x3 - t_x1, t_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);       
        }
    }
}
       
var metadb;
on_item_focus_change();

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {   
    case 0:   
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
        break;
    case 1:
       metadb = fb.GetFocusItem();
        break;
    }
    if (metadb) on_metadb_changed();
}

function on_metadb_changed() {
    create_array();
    window.Repaint();
}

function Eval(field) {
    if (metadb) {
        type = metadb.RawPath;

        if (type.indexOf("file") >= 0){
            return fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
        } else{
            if (selection_mode == 0){
                if (field == "$meta(artist)" || field == "%title%"){
                    return fb.TitleFormat("[" + field + "]").Eval(true);
                }
                if (field == "%genre%"){
                    return fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
                }
            }
            return fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
        }
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
   
    _menu.AppendMenuItem(MF_ENABLED, 1, "Prefer now playing");
    _menu.AppendMenuItem(MF_ENABLED, 2, "Follow selected track");
    _menu.CheckMenuRadioItem(1, 2, selection_mode + 1);     
   _menu.EnableMenuItem(selection_mode + 1, 1);   

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 3, "Group text");
    _menu.CheckMenuItem(3, group_text);
    _menu.AppendMenuItem(MF_ENABLED, 4, "Tooltip");
    _menu.CheckMenuItem(4, Tooltip);
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 6, "Create txt/xls file");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    MF_STRING =  auto_sizing ? MF_GRAYED : MF_ENABLED;
    _menu.AppendMenuItem(MF_STRING, 7, "Auto-sizing columns");
    _menu.CheckMenuItem(7, auto_sizing);
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 10, "Reload");
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 20, "Properties");
    _menu.AppendMenuItem(MF_ENABLED, 30, "Configure ...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 1:   
        selection_mode = 0;
        window.SetProperty("selection_mode", selection_mode);
        on_item_focus_change();
        break;
    case 2:   
        selection_mode = 1;
        window.SetProperty("selection_mode", selection_mode);
        on_item_focus_change();
        break;
    case 3:
        window.SetProperty("group text", !group_text);
        group_text = window.GetProperty("group text");
        break;
    case 4: 
        window.SetProperty("tooltip", !Tooltip);
        Tooltip = window.GetProperty("tooltip");
        deactive_tooltip();   
        break;
    case 6:
        menu_create_file(x,y);
        break;
    case 7:
        if (!auto_sizing){
            auto_sizing = true;
            window.SetProperty("auto sizing", auto_sizing);
            create_array();
        }
        break;
    case 10:
        try {
            window.Reload();   
        } catch(e) {};
        break;
    case 20:
        window.ShowProperties();
        break;   
    case 30:
        window.ShowConfigure();     
        break;
   }
    _menu.Dispose();
    return true;
}

/////////////////////////////  Create file

var fso = new ActiveXObject("Scripting.FileSystemObject");
var output_path = fb.ProfilePath + "\\tmp_Properties\\";

function check_folder(n) {
    if (!n) return;
    try {
        if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
    } catch(e) {}
}

window.GetProperty("ext",1);
var separator = Array(" ; ","\t"); 
var tmp_output_item_name_array = [];
var output_array = [];
var pllist_name;
var selected;
var shift = 0;;

create_tmp_output_item_name_array();

function  create_tmp_output_item_name_array() {
    tmp_output_item_name_array = [];
    for (var j = 0; j < tfname.length; j++) {   
        if (tfname[j].search(/group|lastfm/g) < 0){
        //if (tfname[j].indexOf('group') < 0 || tfname[j].indexOf('%lastfm') < 0){
            tmp_output_item_name_array.push(tfname[j]);
        }
    }
}

for (var j = 0; j < tmp_output_item_name_array.length; j++) {   
    window.GetProperty(j + 1,0);
}

function  create_output_array() {
    output_array = [];
    for (var j = 0; j < tmp_output_item_name_array.length; j++) {   
        selected = window.GetProperty(j + 1);
        if ( selected == 1 ) {output_array.push(tmp_output_item_name_array[j])};
    }
    createTextFile();
}

function createTextFile(){
    check_folder(output_path);
    count = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Count;
    if (count == 0 || output_array.length == 0) return;

    if (window.GetProperty("ext") == 0) {
        output_file = output_path + "plist " + pllist_name + ".txt";
    } else {
        output_file = output_path + "plist " + pllist_name + ".xls"; 
    }
   
    try { file = fso.CreateTextFile( output_file )
    } catch(e) { return };
   
    var text_item_name = [];
    var string_item_name = "";
   
    for (var j = 0; j < output_array.length; j++) {
        text_item_name.push(output_array[j]);       
    }
   
    string_item_name = text_item_name.join(separator[window.GetProperty("ext")]);
    file.WriteLine(string_item_name);
    file.WriteLine("");

    for (var i = 0; i < count; i++) {
        item = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Item(i);
       
        var text_item_value = [];
        var string_item_value = "";
       
        for (var j = 0; j < output_array.length; j++) {   
            value = fb.TitleFormat("[" + output_array[j] + "]").EvalWithMetadb(item);
               
            tmp = clear_item_name(output_array[j]).replace(/\s/g,"");
            tmp = value && measure[tmp] ? measure[tmp] : "";
            text_item_value.push(value + tmp);
           
            string_item_value = text_item_value.join(separator[window.GetProperty("ext")]);
        }
       
        try { file.WriteLine(string_item_value);
        } catch(e) {}; 
    }
    file.Close();
}

function menu_create_file(x, y){
    var _menu = window.CreatePopupMenu();
    var i = 1;
 
    count = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Count;
    MF_STRING = count == 0 ? MF_GRAYED : MF_ENABLED;
   
    pllist_name = plman.GetPlaylistName(plman.ActivePlaylist);
    pllist_name = count == 0 ? "*" : pllist_name.replace(/[\/\:\*\?\"\<\>\|]/g,'');
   
    _menu.AppendMenuItem(MF_STRING, i++, "Create  " + pllist_name + (window.GetProperty("ext") == 0 ? ".txt" : ".xls"));
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
   
    var lines = 20;   
    bl = tmp_output_item_name_array.length > lines ? lines + shift : tmp_output_item_name_array.length;

    for (var j = shift; j < bl; j++) {
        menuItem = clear_item_name(tmp_output_item_name_array[j]);
        _menu.AppendMenuItem(MF_ENABLED, i++, menuItem);   
        _menu.CheckMenuItem(i-1, window.GetProperty(i - 2 + shift));
    }
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 100, "txt");
    _menu.AppendMenuItem(MF_ENABLED, 101, "xls");
    _menu.CheckMenuRadioItem(100, 101, 100 + window.GetProperty("ext"));     
   _menu.EnableMenuItem(100 + window.GetProperty("ext"), 1);
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 110, "Select all");
    _menu.AppendMenuItem(MF_ENABLED, 120, "Clear all");

    if (tmp_output_item_name_array.length > lines) {
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
        _menu.AppendMenuItem(shift == 0 ? MF_GRAYED : MF_ENABLED, 130, "Up");
        _menu.AppendMenuItem(shift + lines >= tmp_output_item_name_array.length ? MF_GRAYED : MF_ENABLED, 140, "Down");
    }

    ret = _menu.TrackPopupMenu(x, y - 250);

    switch (true) {
    case (ret == 1):
        create_output_array();
        break;
    case (ret >= 2 && ret <= tmp_output_item_name_array.length + 1):
        selected = window.GetProperty(ret - 1 + shift);
        window.SetProperty(ret - 1 + shift, selected == 0 ? 1 : 0);
        menu_create_file(x,y);
        break;
    case (ret == 100):
        window.SetProperty("ext", 0);
        menu_create_file(x,y);
        break;
    case (ret == 101):
        window.SetProperty("ext", 1);
        menu_create_file(x,y);
        break;
    case (ret == 110):
        for (var j = 1; j < tmp_output_item_name_array.length + 1; j++) {   
            window.SetProperty(j, 1);
        }
        menu_create_file(x,y);
        break;
    case (ret == 120):
        for (var j = 1; j < tmp_output_item_name_array.length + 1; j++) {   
            window.SetProperty(j, 0);
        }
        menu_create_file(x,y);
        break;
    case (ret == 130):
        shift = shift - 1;
        menu_create_file(x,y);
        break;
    case (ret == 140):
        shift = shift + 1;
        menu_create_file(x,y);
        break;
   }
   _menu.Dispose();
}

/////////////////////////////  Draw star

function draw_star(gr, x, y, img_size, fill, line_thickness, color, sh, sh_color, alpha){
    var radius = img_size / 2;
    var radius_2 = radius / 2.61803;
    line_thickness = line_thickness >= radius_2 ? radius_2 : line_thickness;
    var delta = line_thickness / 2 * Math.tan(72 / 180 * Math.PI);

    var points = [], sh_points = [];
    var x_points_1 = [], y_points_1 = [], x_points_2 = [], y_points_2 = [];

    for (var i = 0; i < 10; i++) {
        if (i % 2 == 0) {
            x_points_1.push((radius - delta) * Math.cos(Math.PI * i / 10 * 2 - Math.PI / 2));
            y_points_1.push((radius - delta) * Math.sin(Math.PI * i / 10 * 2 - Math.PI / 2));
        } else {
            x_points_2.push((radius - delta) / 2.61803 * Math.cos(Math.PI * i / 10 * 2 - Math.PI / 2));
            y_points_2.push((radius - delta) / 2.61803 * Math.sin(Math.PI * i / 10 * 2 - Math.PI / 2));
        }
    }
       
    for (var i = 0; i < 5; i++) {
        points.push(x_points_1[i] + radius, y_points_1[i] + radius, x_points_2[i] + radius, y_points_2[i] + radius);
        sh_points.push(x_points_1[i] + radius + 1, y_points_1[i] + radius + 1, x_points_2[i] + radius + 1, y_points_2[i] + radius + 1);
    }

    var img = gdi.CreateImage(img_size, img_size);
    var temp_gr = img.GetGraphics();
    temp_gr.SetSmoothingMode(2);
   
    if (line_thickness > 0) {
        sh && temp_gr.DrawPolygon(sh_color, line_thickness, sh_points);
        temp_gr.DrawPolygon(color, line_thickness, points);
    }

    if (fill && line_thickness == 0) {
        sh && temp_gr.FillPolygon(sh_color, 1, sh_points);
        temp_gr.FillPolygon(color, 1, points)
    }

    gr.DrawImage(img, x - radius, y - radius, img_size, img_size, 0, 0, img_size, img_size, 0, alpha);
   
    img.ReleaseGraphics(temp_gr);
    img.Dispose();
    temp_gr = null;
    img = null;
}

/////////////////////////////  Tooltip custom paint

function active_tooltip(){      
    if (!tooltip_state){      
        tooltip_state = true;      
        tooltip.Activate();      
        tooltip.TrackActivate = true;   
    }      
}      
      
function deactive_tooltip(){      
    if (tooltip_state){      
        tooltip_state = false;      
        tooltip.TrackActivate = false;      
        tooltip.Deactivate();      
        tooltip_time.Reset();      
    }      
}      

function on_tooltip_custom_paint(gr){
    var tooltip_t_w = gr.CalcTextWidth(tooltip_text, font_tooltip);   
    var tooltip_t_h = gr.CalcTextHeight(tooltip_text, font_tooltip);
    var tooltip_t_tmp = gr.EstimateLineWrap(tooltip_text, font_tooltip, tooltip_max_w).toArray();
    var tooltip_t = [];
    var tooltip_l = [];
    tooltip.Width = 0;      
    tooltip.Height = 0;   

    for (var i = 0; i < tooltip_t_tmp.length; i += 1) {
        if (i % 2 == 0) {
            tooltip_t.push(tooltip_t_tmp[i]);
        } else {
            tooltip_l.push(tooltip_t_tmp[i]);
        }
    }
   
    if (tooltip_t_w <= tooltip_max_w){
        tooltip.Width = tooltip_t_w + 5;
        tooltip.Height = tooltip_t_h;
    } else {
        tooltip.Width = Math.max.apply(null, tooltip_l) + 5;
        tooltip.Height = tooltip_t_h *  tooltip_t.length;
    }

    for (var i = 0; i < tooltip_t.length; i += 1) {
        gr.GdiDrawText( tooltip_t[i], font_tooltip, RGB(0,0,0), 5, tooltip_t_h * i, tooltip.Width, tooltip.Height, DT_WORDBREAK | DT_NOPREFIX );   
    }
}   

function tooltip_activate(x, y) { 
    idx = Math.floor((y + Math.abs(s)) / t_h);
    tooltip_text = value_width[idx * 2 + 1];

    tooltip_x = t_x2 - 5;
    tooltip_y = Math.floor(y / t_h) * t_h;

    if (value_width[idx * 2] > ww - t_x2 - t_x1 && x > t_x2 && x < ww && y > tooltip_y + 1 && y < tooltip_y + t_h){
        if (tooltip_time.Time > 500) active_tooltip();
        tooltip.TrackPosition(tooltip_x, tooltip_y);      
        tooltip.Text = " ";      
    } else {   
        tooltip_time.Reset();
        deactive_tooltip();   
    }
}

function print(msg) {
   fb.trace(msg);
}
kgena_ua M
Аватара
Откуда: Украина, Днепр
Репутация: 504
С нами: 10 лет 11 месяцев

Сообщение #1790 kgena_ua » 10.04.2017, 17:02

MC Web, посмотрите личку.
kgena_ua M
Аватара
Откуда: Украина, Днепр
Репутация: 504
С нами: 10 лет 11 месяцев

Сообщение #1791 MC Web » 10.04.2017, 17:22

kgena_ua, прочитал и ответил.

Добавлено спустя 1 час 1 минуту:
kgena_ua, сделал, результат в ЛС.
MC Web
Репутация: 248
С нами: 10 лет 7 месяцев

Сообщение #1792 kgena_ua » 10.04.2017, 20:34

Спасибо MC Web за перевод наименований тегов.

Properties & properties file (ml)
version "10042017"


- переключения языка - меню, пр.кл.;
- изменение ширины столбцов - Shift + лев.кл. на поле со значениями.

Спойлер
1.png


Код: Выделить всё
// ==PREPROCESSOR==
// @name "Properties & properties file (ml)"
// @author "kgena_ua"
// @version "10042017"
// @feature "v1.4"
// @feature "watch-metadb"
// @tooltip "custom-paint"
// ==/PREPROCESSOR==

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

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

var ww, wh, wh_old;

IDC_HAND = 32649;
IDC_ARROW = 32512;
IDC_SIZEWE = 32644;

MF_ENABLED = 0x00000000;
MF_GRAYED = 0x00000001;
MF_SEPARATOR = 0x00000800;

String.prototype.repeat = function(n) {
    return new Array(n + 1).join(this);
}

window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");

var font_name_item_name = window.GetProperty(" font name: item name", "Arial");
var font_name_item_value = window.GetProperty(" font name: item value", "Arial");
var font_name_group = window.GetProperty(" font name: group", "Arial");

var font_size_item_name = window.GetProperty(" font size: item name", 11);
var font_size_item_value = window.GetProperty(" font size: item value", 12);
var font_size_group = window.GetProperty(" font size: group", 11);

var font_style_item_name = window.GetProperty(" font style: item name", 0);
var font_style_item_value = window.GetProperty(" font style: item value", 0);
var font_style_group = window.GetProperty(" font style: group", 0);

var font_size_tooltip = window.GetProperty(" font size: tooltip", 12);

var font_item, font_group, font_tooltip;
get_font();

function get_font(){
    font_item_name = gdi.Font(font_name_item_name, font_size_item_name, font_style_item_name);
    font_item_value = gdi.Font(font_name_item_value, font_size_item_value, font_style_item_value);
    font_group = gdi.Font(font_name_group, font_size_group, font_style_group);
    font_tooltip = gdi.Font(font_name_item_value, font_size_tooltip, font_style_item_value);
}

ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

ColorTypeDUI = {
   text: 0,
   background: 1,
   highlight: 2,
   selection: 3
};

function get_color(){   
    if (window.InstanceType == 0){
        bgcolor = window.GetColorCUI(ColorTypeCUI.background);
        color_item_name = window.GetColorCUI(ColorTypeCUI.text);
        color_item_value = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
        color_group_text = window.GetColorCUI(ColorTypeCUI.inactive_selection_background);
    } else if (window.InstanceType == 1) {
        bgcolor = window.GetColorDUI(ColorTypeDUI.background);
        color_item_name = window.GetColorDUI(ColorTypeDUI.text);
        color_item_value = window.GetColorDUI(ColorTypeDUI.highlight);
        color_group_text = window.GetColorDUI(ColorTypeDUI.selection);
    }
    window.Repaint();
}

get_color();

function on_colors_changed(){
    get_color();
}

var custom_colors = window.GetProperty(" colors: custom", false);

var c_bgcolor = customColor(window.GetProperty(" color: background", "0-0-0"));
var c_color_item_name = customColor(window.GetProperty(" color: item name", "180-180-180")); 
var c_color_item_value = customColor(window.GetProperty(" color: item value", "255-255-220"));
var c_color_group_text = customColor(window.GetProperty(" color: group text", "100-100-100"));

bgcolor = custom_colors ? c_bgcolor : bgcolor;
color_item_name = custom_colors ? c_color_item_name : color_item_name;
color_item_value = custom_colors ? c_color_item_value : color_item_value;
color_group_text = custom_colors ? c_color_group_text : color_group_text;

function customColor(colour){
   tempc = colour.split("-");
   return (0xff000000 | (tempc[0]<<16) | (tempc[1]<<8) | (tempc[2]));
}

var selection_mode = window.GetProperty("selection_mode", 0);

var item_name_array = [];
var item_name_array_2 = [];
var item_value_array = [];
var tmp_item_name_array = [];
var tmp_item_name_array_2 = [];
var tmp_item_value_array = [];
var value_width = [];
var name, value;
var similar_artist_text = "";
var similar_artist = [];

var auto_sizing = window.GetProperty("auto sizing", true);
var group_text = window.GetProperty("group text", false);
var vertical_item_padding = window.GetProperty(" vertical item padding", 1);

var t_h;
var t_x1 = window.GetProperty(" text: x", 10);
var t_x2;
window.GetProperty("text: x2 custom", 0);
var t_x3;
var lbtn_down = false;
var drag_x = 0, drag_y = 0;
var move_x = false,  move_y = false;
var s = 0;
var old_x, old_y;

var Tooltip = window.GetProperty("tooltip", false);
var tooltip = window.CreateTooltip();   
var tooltip_time = fb.CreateProfiler("Time tooltip");
var tooltip_state = false;
var tooltip_text;
var tooltip_max_w = 250;

var lang_text = new Array("en", "ru");
var lang = window.GetProperty("lang", 1);

function on_paint(gr) {
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
   
    draw_array(gr);
    gr.GdiDrawText( "", font_item_value, color_item_value, 0, 100, ww, wh, DT_RIGHT | DT_WORD_ELLIPSIS);
}

var tfname = [
["$meta(artist)", "Исполнитель"],
["%title%", "Название"],
["%album%", "Альбом"],
["%date%", "Год"],
["%genre%", "Жанр"],
["%composer%", "Композитор"],
["%performer%", "Представитель"],         // возможно "Первый исполнитель"
["$meta(album artist)", "Исполнитель альбома"],
["%track number%", "Номер трека"],
["%totaltracks%", "Всего треков"],
["%discnumber%", "Номер диска"],
["%totaldiscs%", "Всего дисков"],
["%rating%", "Рейтинг"],
["$meta(rating)", "Рейтинг"],
["%comment%", "Комментарий"],
["%publisher%", "Издатель"],
["%catalog%", "Каталог"],
["%discid%", "ID диска"],
["%label%", "Лейбл"],            // возможно "Товарный знак"
["%releaser%", "Продавец"],            // ???
["%subtitle%", "Субтитры"],

["group_general", "общие"],           
["$info(samplerate)", "Частота дискретизации"],      // или просто "Частота"
["$info(channels)", "Каналов"],
["$info(bitspersample)", "Бит на семпл"],         // возможно "Битность"
["$info(bitrate)", "Битрейт"],
["%codec%", "Кодек"],
["$info(codec_profile)", "Профиль кодека"],
["$info(mp3_stereo_mode)", "Режим стерео MP3"],
["$info(encoding)", "Кодирование"],
["%length%", "Длина"],
["$info(tool)", "Кодировщик"],
["$info(cue_embedded)", "Встроенный CUE"],
["$info(tagtype)", "Тип тега"],

["group_replaygain", "выравнивание громкости"], 
["%replaygain_album_gain%", "Уровень громкости альбома"],
["%replaygain_album_peak%", "Пиковый уровень альбома"],
["%replaygain_track_gain%", "Уровень громкости трека"],
["%replaygain_track_peak%", "Пиковый уровень трека"],

["group_location", "расположение"],   
["%filename_ext%", "Имя файла"],
["$directory_path(%path%)", "Путь к файлу"],
["%url%", "URL-адрес"],
["%subsong%", "Подкаталог"],       
["%filesize_natural%", "Размер файла"],
["%last_modified%", "Изменен"],
["%folder_name%", "Имя папки"],

["group_playback statistics", "статистика воспроизведения"],
["%play_count%", "Количество воспроизведений"],
["%first_played%", "Первое воспроизведение"],
["%last_played%", "Последнее воспроизведение"],
["%added%", "Добавлен"],

["group_last.FM", "сайт Last.FM"],
["%lastfm_bio%", "Биография"],
["%lastfm_artist_playcount%", "Прослушиваний исполнителя"],
["%lastfm_artist_listeners%", "Слушателей исполнителя"],
["%lastfm_album_playcount%", "Прослушиваний альбома"],
["%lastfm_album_listeners%", "Слушателей альбома"],
["%lastfm_album_content%", "Содержимое альбома"],

["group_last.FM", "сайт Last.FM"],
["%lastfm_similar_artist%", "Похожие исполнители"]
];


function set_cursor(x, y) {
    if (move_y || lbtn_down) window.SetCursor(IDC_HAND);
    if (move_x && !lbtn_down) window.SetCursor(IDC_SIZEWE);
}

function on_mouse_lbtn_down(x, y) {
    lbtn_down = true;
    if (move_y) drag_y = (y - s);
    if (move_x) drag_x = x - t_x2;
    set_cursor(x, y);
}

function on_mouse_lbtn_up(x, y) {
    lbtn_down = false;
    if (move_x) {
        window.SetProperty("text: x2 custom",  t_x2);
    }
}

function on_mouse_move(x, y) {
    mouse_on_pos(x, y);
    set_cursor(x, y);
   
    if (old_y != y || old_x != x){
        if (Tooltip) tooltip_activate(x, y);
        old_y = y;
        old_x = x;
    }
   
    if (lbtn_down && move_y) {
        if (s <= 0 && (item_name_array.length * t_h) >= wh) {s = y - drag_y};
        applyDelta();
    }

    shift_down = utils.IsKeyPressed(0x10) ? true : false;
    if (!shift_down) drag_x = x - t_x2;

    if (lbtn_down && move_x) {
        auto_sizing = false;
        window.SetProperty("auto sizing", auto_sizing);
        tmp_t_x2 = x - drag_x;
        t_x2 = tmp_t_x2 <= t_x1 ? t_x1 : tmp_t_x2 >= ww - t_x1 - 50 ? ww - t_x1 - 50 : tmp_t_x2;
    }
   
    window.Repaint();
}

function on_mouse_wheel(step) {
    if (s <= 0 && item_name_array.length * t_h >= wh) {s = s + step * t_h};
    applyDelta();
}

function applyDelta() {
    s = s > 0 ? 0 : s;
    s = s < (wh - item_name_array.length * t_h) && s < 0 ? (wh - item_name_array.length * t_h) : s;
    window.Repaint();
}

function on_mouse_leave() {   
    window.SetCursor(IDC_ARROW);
    window.Repaint();
}

function mouse_on_pos(x, y){
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (ShiftDown && x >= t_x2) {
        move_x = true;
        move_y = false;
    } else {
        move_y = true;
        move_x = false;
    }
}

function on_size() {
    ww = window.Width;
    wh = window.Height;
    if (wh != wh_old  && s < 0) {
        s = wh >= wh_old ? 0 : s;
        wh_old = wh;
    }
    create_array();
}

function clear_item_name(n) {
    return n.replace(/.*\(|lastfm_|replaygain_|[^a-z0-9\s\_]/g,"").replace(/_/g," ");
    //return n.replace(/.*\((?!\))|lastfm_|replaygain_|[^a-z0-9\s\_]/g,"").replace(/_/g," "); 
}

function clear_group_text(n) {
    return n.replace(/group_/g,"").replace(/(?=.)/g," ").replace(/^\s/g,"")
}

function data_format(n) {
    if (!n) return;
    d = n.substr(8, 2);
    m = parseInt(n.substr(5, 2), 10);
    y = n.substr(0, 4);
    t = n.substr(11, 8);
    m_text = lang == 0 ? months_en[m - 1] : months_ru[m - 1];
    return d + " " + m_text + " " + y + ", " + t;
}

var measure = {
    'bitrate' : "  kbps",
    'samplerate' : "  Hz",
    'bitspersample' : "  bps",
    'channels' : "  ch",
    'playcount' : "  times"
}

var months_en = ["Jan.", "Feb.", "Mar.", "Apr.", "May", "Jun.", "Jul.", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."];
var months_ru = ["Янв.", "Фев.", "Мрт", "Апр.", "Май", "Июн.", "Июл.", "Авг.", "Сен.", "Окт.", "Нбр", "Дек."];

function create_array() {
    var temp_bmp = gdi.CreateImage(1, 1);
    var temp_gr = temp_bmp.GetGraphics();
    tmp_item_name_array = [];
    tmp_item_name_array_2 = [];
    tmp_item_value_array = [];
    value_width = [];
   
    t_x2 = 0;
    similar_artist_text = "";
    similar_artist = [];
   
    for (j = 0; j < tfname.length; j++) {
        group = tfname[j][0].search('group') >= 0 ? true : false;
       
        if (tfname[j][0].search(/last_modified|first_played|last_played|added/g) > 0){   
            value = data_format(Eval(tfname[j][0]));
        } else {
            value = Eval(tfname[j][0]);
        }
       
        if (value && value != 0 || group) {
            tmp_item_name_array.push(tfname[j][0]);
            tmp_item_name_array_2.push(tfname[j][1]);
           
           
            if (tfname[j][0] != "%lastfm_similar_artist%"){
                tmp_item_value_array.push(value);
                value_width.push(temp_gr.CalcTextWidth(value, font_item_value),value);
            }
           
            if (tfname[j][0] == "%lastfm_similar_artist%") {
                similar_artist_text = value.replace(/(&apos;)/g, "'");
            }
        }
       
        if (value && value != 0 && !group){
            tmp = lang == 0 ? clear_item_name(tfname[j][0]) : tfname[j][1];
            tmp_t_x2 = temp_gr.CalcTextWidth(tmp, font_item_name);
            t_x2 = tmp_t_x2 > t_x2 ? tmp_t_x2 : t_x2;
        }
    }
   
    t_x2 = auto_sizing ? t_x2 + t_x1 + 10 : window.GetProperty("text: x2 custom");

    if (similar_artist_text){
        similar_artist = similar_artist_text.split(';');
       
        for (var i = 0; i < similar_artist.length; i++) {
            if (i >= 1) {
                tmp_item_name_array.push("");
                tmp_item_name_array_2.push("");
            }
            value = similar_artist[i].replace(/^\s+|\s+$/g, "") + ";";
            tmp_item_value_array.push(value);
            value_width.push(temp_gr.CalcTextWidth(value, font_item_value),value);
        }
    }

    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
   
    clear_empty_groups();
}

function clear_empty_groups() {
    item_name_array = [];
    item_name_array_2 = [];
    item_value_array = [];
   
    for (j = 0; j < tmp_item_name_array.length; j++) {
        group = tmp_item_name_array[j].search('group') >= 0 ? true : false;

        item_nane = tmp_item_name_array[j];
        item_nane_2 = tmp_item_name_array_2[j];
        item_value = tmp_item_value_array[j];
       
        if (!group){
            item_name_array.push(item_nane);
            item_name_array_2.push(item_nane_2);
            item_value_array.push(item_value);       
        }
       
        if (group){
            if (tmp_item_value_array[j + 1]){
                item_name_array.push(item_nane);
                item_name_array_2.push(item_nane_2);
                item_value_array.push(item_value); 
            } else{
                value_width.splice(j * 2, 2);
            }
        }
    }
    if (item_name_array.length * t_h < wh && s < 0) s = 0;
}

function draw_array(gr) {
    f_h_name = gr.CalcTextHeight("Text", font_item_name);
    f_h_value = gr.CalcTextHeight("Text", font_item_value);
   
    f_h = Math.max(f_h_name, f_h_value);
   
    t_h = f_h + window.GetProperty(" vertical item padding");
   
    star_size = f_h_value - 3;
    star_offset = star_size + 2;
   
    for (var i = 0; i < item_name_array.length; i++) {
        group = item_name_array[i].search('group') >= 0 ? true : false;
       
        font = group ? font_group : font_item_name;
        color = group ? color_group_text : color_item_name;
        t_y =  i * t_h + s;
        l_y = t_y + t_h / 2;
       
        if (!group){
            name = clear_item_name(item_name_array[i]);
            rating_text = item_name_array[i] == "$meta(rating)" ? lang == 0 ? "  (tag)" : "  (тег)" : "";
            t_w = Math.min(ww - (ww - t_x2)- t_x1, ww - t_x1 * 2) - 10;
           
            name = lang == 0 ? name : item_name_array_2[i];
            gr.GdiDrawText(name + rating_text, font, color, t_x1, t_y, t_w, t_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);         
        }
       
        if (group){
            name = lang == 0 ? item_name_array[i] : item_name_array_2[i];
            name = group_text ? clear_group_text(name) : "";
            t_w = ww - t_x1 * 2;
            gr.GdiDrawText(name, font, color, t_x1, t_y, t_w, t_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);         

            g_w = group_text && name ? Math.min(gr.CalcTextWidth(name, font) + 5, ww - t_x1 * 2) : 0;
            group && gr.DrawLine(t_x1 + g_w, l_y, ww - t_x1, l_y, 1, color);
        }
       
        if (item_name_array[i].search(/rating/g) > 0){     
            for (var r = 0; r < Math.min(item_value_array[i] * star_offset, ww - t_x2 - t_x1); r = r + star_offset) {
                draw_star(gr, t_x2 + star_size / 3 + r, t_y + t_h / 2, star_size, true, 0, color_item_value, false, bgcolor, 255);
            }
        } else {
            value = item_value_array[i];
            t_w2 = ww - t_x2 - t_x1;
            gr.GdiDrawText( value, font_item_value, color_item_value, t_x2, t_y, t_w2, t_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);       

            t_x3 = t_x2 + gr.CalcTextWidth(value, font_item_value);
            t_w3 = ww - t_x3 - t_x1;
            tmp = clear_item_name(item_name_array[i]).replace(/\s/g,"");
            gr.GdiDrawText( measure[tmp], font_item_value, color_group_text, t_x3, t_y, t_w3, t_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);       
        }
    }
}
       
var metadb;
on_item_focus_change();

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {   
    case 0:   
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
        break;
    case 1:
       metadb = fb.GetFocusItem();
        break;
    }
    if (metadb) on_metadb_changed();
}

function on_metadb_changed() {
    create_array();
    window.Repaint();
}

function Eval(field) {
    if (metadb) {
        type = metadb.RawPath;

        if (type.indexOf("file") >= 0){
            return fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
        } else{
            if (selection_mode == 0){
                if (field == "$meta(artist)" || field == "%title%"){
                    return fb.TitleFormat("[" + field + "]").Eval(true);
                }
                if (field == "%genre%"){
                    return fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
                }
            }
            return fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
        }
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
   
    _menu.AppendMenuItem(MF_ENABLED, 1, "Prefer now playing");
    _menu.AppendMenuItem(MF_ENABLED, 2, "Follow selected track");
    _menu.CheckMenuRadioItem(1, 2, selection_mode + 1);     
   _menu.EnableMenuItem(selection_mode + 1, 1);   

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 3, "Group text");
    _menu.CheckMenuItem(3, group_text);
    _menu.AppendMenuItem(MF_ENABLED, 4, "Tooltip");
    _menu.CheckMenuItem(4, Tooltip);
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 6, "Create txt/xls file");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    MF_STRING =  auto_sizing ? MF_GRAYED : MF_ENABLED;
    _menu.AppendMenuItem(MF_STRING, 7, "Auto-sizing columns");
    _menu.CheckMenuItem(7, auto_sizing);
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 10, "item text: " + lang_text[0]);   
    _menu.AppendMenuItem(MF_ENABLED, 11, "item text: " + lang_text[1]);   
    _menu.CheckMenuRadioItem(10, 11, lang + 10);         
    _menu.EnableMenuItem(lang + 10, 1);     
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 100, "Reload");
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 200, "Properties");
    _menu.AppendMenuItem(MF_ENABLED, 300, "Configure ...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 1:   
        selection_mode = 0;
        window.SetProperty("selection_mode", selection_mode);
        on_item_focus_change();
        break;
    case 2:   
        selection_mode = 1;
        window.SetProperty("selection_mode", selection_mode);
        on_item_focus_change();
        break;
    case 3:
        window.SetProperty("group text", !group_text);
        group_text = window.GetProperty("group text");
        break;
    case 4: 
        window.SetProperty("tooltip", !Tooltip);
        Tooltip = window.GetProperty("tooltip");
        deactive_tooltip();   
        break;
    case 6:
        menu_create_file(x,y);
        break;
    case 7:
        if (!auto_sizing){
            auto_sizing = true;
            window.SetProperty("auto sizing", auto_sizing);
            create_array();
        }
        break;
    case 10:
    case 11:
        lang = ret - 10;
        window.SetProperty("lang", lang);
    case 100:
        try {
            window.Reload();   
        } catch(e) {};
        break;
    case 200:
        window.ShowProperties();
        break;   
    case 300:
        window.ShowConfigure();     
        break;
   }
    _menu.Dispose();
    return true;
}

/////////////////////////////  Create file

var fso = new ActiveXObject("Scripting.FileSystemObject");
var output_path = fb.ProfilePath + "\\tmp_Properties\\";

function check_folder(n) {
    if (!n) return;
    try {
        if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
    } catch(e) {}
}

window.GetProperty("ext",1);
var separator = Array(" ; ","\t"); 
var tmp_output_item_name_array = [];
var output_array = [];
var pllist_name;
var selected;
var shift = 0;;

create_tmp_output_item_name_array();

function  create_tmp_output_item_name_array() {
    tmp_output_item_name_array = [];
    for (var j = 0; j < tfname.length; j++) {   
        if (tfname[j][0].search(/group|lastfm/g) < 0){
        //if (tfname[j].indexOf('group') < 0 || tfname[j].indexOf('%lastfm') < 0){
            tmp_output_item_name_array.push(tfname[j][0]);
        }
    }
}

for (var j = 0; j < tmp_output_item_name_array.length; j++) {   
    window.GetProperty(j + 1,0);
}

function  create_output_array() {
    output_array = [];
    for (var j = 0; j < tmp_output_item_name_array.length; j++) {   
        selected = window.GetProperty(j + 1);
        if ( selected == 1 ) {output_array.push(tmp_output_item_name_array[j])};
    }
    createTextFile();
}

function createTextFile(){
    check_folder(output_path);
    count = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Count;
    if (count == 0 || output_array.length == 0) return;

    if (window.GetProperty("ext") == 0) {
        output_file = output_path + "plist " + pllist_name + ".txt";
    } else {
        output_file = output_path + "plist " + pllist_name + ".xls"; 
    }
   
    try { file = fso.CreateTextFile( output_file )
    } catch(e) { return };
   
    var text_item_name = [];
    var string_item_name = "";
   
    for (var j = 0; j < output_array.length; j++) {
        text_item_name.push(output_array[j]);       
    }
   
    string_item_name = text_item_name.join(separator[window.GetProperty("ext")]);
    file.WriteLine(string_item_name);
    file.WriteLine("");

    for (var i = 0; i < count; i++) {
        item = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Item(i);
       
        var text_item_value = [];
        var string_item_value = "";
       
        for (var j = 0; j < output_array.length; j++) {   
            value = fb.TitleFormat("[" + output_array[j] + "]").EvalWithMetadb(item);
               
            tmp = clear_item_name(output_array[j]).replace(/\s/g,"");
            tmp = value && measure[tmp] ? measure[tmp] : "";
            text_item_value.push(value + tmp);
           
            string_item_value = text_item_value.join(separator[window.GetProperty("ext")]);
        }
       
        try { file.WriteLine(string_item_value);
        } catch(e) {}; 
    }
    file.Close();
}

function menu_create_file(x, y){
    var _menu = window.CreatePopupMenu();
    var i = 1;
 
    count = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Count;
    MF_STRING = count == 0 ? MF_GRAYED : MF_ENABLED;
   
    pllist_name = plman.GetPlaylistName(plman.ActivePlaylist);
    pllist_name = count == 0 ? "*" : pllist_name.replace(/[\/\:\*\?\"\<\>\|]/g,'');
   
    _menu.AppendMenuItem(MF_STRING, i++, "Create  " + pllist_name + (window.GetProperty("ext") == 0 ? ".txt" : ".xls"));
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
   
    var lines = 20;   
    bl = tmp_output_item_name_array.length > lines ? lines + shift : tmp_output_item_name_array.length;

    for (var j = shift; j < bl; j++) {
        menuItem = clear_item_name(tmp_output_item_name_array[j]);
        _menu.AppendMenuItem(MF_ENABLED, i++, menuItem);   
        _menu.CheckMenuItem(i-1, window.GetProperty(i - 2 + shift));
    }
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 100, "txt");
    _menu.AppendMenuItem(MF_ENABLED, 101, "xls");
    _menu.CheckMenuRadioItem(100, 101, 100 + window.GetProperty("ext"));     
   _menu.EnableMenuItem(100 + window.GetProperty("ext"), 1);
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 110, "Select all");
    _menu.AppendMenuItem(MF_ENABLED, 120, "Clear all");

    if (tmp_output_item_name_array.length > lines) {
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
        _menu.AppendMenuItem(shift == 0 ? MF_GRAYED : MF_ENABLED, 130, "Up");
        _menu.AppendMenuItem(shift + lines >= tmp_output_item_name_array.length ? MF_GRAYED : MF_ENABLED, 140, "Down");
    }

    ret = _menu.TrackPopupMenu(x, y - 250);

    switch (true) {
    case (ret == 1):
        create_output_array();
        break;
    case (ret >= 2 && ret <= tmp_output_item_name_array.length + 1):
        selected = window.GetProperty(ret - 1 + shift);
        window.SetProperty(ret - 1 + shift, selected == 0 ? 1 : 0);
        menu_create_file(x,y);
        break;
    case (ret == 100):
        window.SetProperty("ext", 0);
        menu_create_file(x,y);
        break;
    case (ret == 101):
        window.SetProperty("ext", 1);
        menu_create_file(x,y);
        break;
    case (ret == 110):
        for (var j = 1; j < tmp_output_item_name_array.length + 1; j++) {   
            window.SetProperty(j, 1);
        }
        menu_create_file(x,y);
        break;
    case (ret == 120):
        for (var j = 1; j < tmp_output_item_name_array.length + 1; j++) {   
            window.SetProperty(j, 0);
        }
        menu_create_file(x,y);
        break;
    case (ret == 130):
        shift = shift - 1;
        menu_create_file(x,y);
        break;
    case (ret == 140):
        shift = shift + 1;
        menu_create_file(x,y);
        break;
   }
   _menu.Dispose();
}

/////////////////////////////  Draw star

function draw_star(gr, x, y, img_size, fill, line_thickness, color, sh, sh_color, alpha){
    var radius = img_size / 2;
    var radius_2 = radius / 2.61803;
    line_thickness = line_thickness >= radius_2 ? radius_2 : line_thickness;
    var delta = line_thickness / 2 * Math.tan(72 / 180 * Math.PI);

    var points = [], sh_points = [];
    var x_points_1 = [], y_points_1 = [], x_points_2 = [], y_points_2 = [];

    for (var i = 0; i < 10; i++) {
        if (i % 2 == 0) {
            x_points_1.push((radius - delta) * Math.cos(Math.PI * i / 10 * 2 - Math.PI / 2));
            y_points_1.push((radius - delta) * Math.sin(Math.PI * i / 10 * 2 - Math.PI / 2));
        } else {
            x_points_2.push((radius - delta) / 2.61803 * Math.cos(Math.PI * i / 10 * 2 - Math.PI / 2));
            y_points_2.push((radius - delta) / 2.61803 * Math.sin(Math.PI * i / 10 * 2 - Math.PI / 2));
        }
    }
       
    for (var i = 0; i < 5; i++) {
        points.push(x_points_1[i] + radius, y_points_1[i] + radius, x_points_2[i] + radius, y_points_2[i] + radius);
        sh_points.push(x_points_1[i] + radius + 1, y_points_1[i] + radius + 1, x_points_2[i] + radius + 1, y_points_2[i] + radius + 1);
    }

    var img = gdi.CreateImage(img_size, img_size);
    var temp_gr = img.GetGraphics();
    temp_gr.SetSmoothingMode(2);
   
    if (line_thickness > 0) {
        sh && temp_gr.DrawPolygon(sh_color, line_thickness, sh_points);
        temp_gr.DrawPolygon(color, line_thickness, points);
    }

    if (fill && line_thickness == 0) {
        sh && temp_gr.FillPolygon(sh_color, 1, sh_points);
        temp_gr.FillPolygon(color, 1, points)
    }

    gr.DrawImage(img, x - radius, y - radius, img_size, img_size, 0, 0, img_size, img_size, 0, alpha);
   
    img.ReleaseGraphics(temp_gr);
    img.Dispose();
    temp_gr = null;
    img = null;
}

/////////////////////////////  Tooltip custom paint

function active_tooltip(){      
    if (!tooltip_state){      
        tooltip_state = true;      
        tooltip.Activate();      
        tooltip.TrackActivate = true;   
    }      
}      
      
function deactive_tooltip(){      
    if (tooltip_state){   
        tooltip.Width = 0;      
        tooltip.Height = 0;          
        tooltip_state = false;      
        tooltip.TrackActivate = false;      
        tooltip.Deactivate();      
        tooltip_time.Reset();      
    }      
}      

function on_tooltip_custom_paint(gr){
    var tooltip_t_w = gr.CalcTextWidth( tooltip_text, font_tooltip);   
    var tooltip_t_h = gr.CalcTextHeight( "Text", font_tooltip);
    var tooltip_t_tmp = gr.EstimateLineWrap(tooltip_text, font_tooltip, tooltip_max_w).toArray();
    var tooltip_t = [];
    var tooltip_l = [];

    for (var i = 0; i < tooltip_t_tmp.length; i += 1) {
        if (i % 2 == 0) {
            tooltip_t.push(tooltip_t_tmp[i].replace(/^\s+|\s+$/g, ""));
        } else {
            tooltip_l.push(tooltip_t_tmp[i]);
        }
    }
   
    if (tooltip_t_w <= tooltip_max_w){
        tooltip.Width = tooltip_t_w + 5;
        tooltip.Height = tooltip_t_h;
    } else {
        tooltip.Width = Math.max.apply(null, tooltip_l) + 5;
        tooltip.Height = tooltip_t_h * tooltip_t.length;
    }

    for (var i = 0; i < tooltip_t.length; i += 1) {
        gr.GdiDrawText( tooltip_t[i], font_tooltip, RGB(0,0,0), 5, tooltip_t_h * i + 1, tooltip.Width, tooltip.Height, DT_LEFT | DT_WORDBREAK | DT_NOPREFIX );   
    }
}   

function tooltip_activate(x, y) { 
    idx = Math.floor((y + Math.abs(s)) / t_h);

    tooltip_x = t_x2 - 5;
    tooltip_y = Math.floor(y / t_h) * t_h;

    if (value_width[idx * 2] > ww - t_x2 - t_x1 && x > t_x2 && x < ww && y > tooltip_y + 1 && y < tooltip_y + t_h){
        if (tooltip_time.Time > 300 && !tooltip_state) {
            tooltip_text = value_width[idx * 2 + 1];
            active_tooltip();
            tooltip.TrackPosition(tooltip_x, tooltip_y);      
            tooltip.Text = " ";   
        }       
    } else {   
        tooltip_time.Reset();
        deactive_tooltip();   
    }
}

function print(msg) {
   fb.trace(msg);
}




kgena_ua M
Аватара
Откуда: Украина, Днепр
Репутация: 504
С нами: 10 лет 11 месяцев

Сообщение #1793 vik-tan » 10.04.2017, 21:40

kgena_ua,Спасибо Вам и MC Web. Еще бы и это заодно перевести.И можно тоже белым шрифтом, а то совсем плохо видно.
Вложения
44.JPG
44.JPG (36.22 КБ) Просмотров: 2248
vik-tan
Репутация: 0
С нами: 7 лет 8 месяцев

Сообщение #1794 LUR » 11.04.2017, 00:36

kgena_ua, вопрос тебе по скрипту для биографии. Можно ли убрать вызов get_pic() из on_size, ничего не сломав?) А то он тормозит.
LUR M
Модератор
Аватара
Откуда: Минск
Репутация: 367
С нами: 11 лет 4 месяца

Сообщение #1795 kgena_ua » 15.04.2017, 21:54

LUR, да без проблем, можно удалить.

vik-tan, выкладываю весь скрипт, т.к. пришлось переделать в нескольких местах.
Properties & properties file (ml)
version "15042017"


Изменить или добавить единицы измерения можно в массиве
Код: Выделить всё
var measure_arr = [
["$info(bitrate)", "kbps", "кбит/с"],
["$info(samplerate)", "Hz", "Гц"],
["$info(bitspersample)", "bps", ""],
["$info(channels)", "ch", ""],
["%play_count%", "times", ""]
]

Сам скрипт
Код: Выделить всё
// ==PREPROCESSOR==
// @name "Properties & properties file (ml)"
// @author "kgena_ua"
// @version "15042017"
// @feature "v1.4"
// @feature "watch-metadb"
// @tooltip "custom-paint"
// ==/PREPROCESSOR==

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

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

var ww, wh, wh_old;

IDC_HAND = 32649;
IDC_ARROW = 32512;
IDC_SIZEWE = 32644;

MF_ENABLED = 0x00000000;
MF_GRAYED = 0x00000001;
MF_SEPARATOR = 0x00000800;

String.prototype.repeat = function(n) {
    return new Array(n + 1).join(this);
}

window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");

var font_name_item_name = window.GetProperty(" font name: item name", "Arial");
var font_name_item_value = window.GetProperty(" font name: item value", "Arial");
var font_name_group = window.GetProperty(" font name: group", "Arial");

var font_size_item_name = window.GetProperty(" font size: item name", 11);
var font_size_item_value = window.GetProperty(" font size: item value", 12);
var font_size_group = window.GetProperty(" font size: group", 11);

var font_style_item_name = window.GetProperty(" font style: item name", 0);
var font_style_item_value = window.GetProperty(" font style: item value", 0);
var font_style_group = window.GetProperty(" font style: group", 0);

var font_size_tooltip = window.GetProperty(" font size: tooltip", 12);

var font_item, font_group, font_tooltip;
get_font();

function get_font(){
    font_item_name = gdi.Font(font_name_item_name, font_size_item_name, font_style_item_name);
    font_item_value = gdi.Font(font_name_item_value, font_size_item_value, font_style_item_value);
    font_group = gdi.Font(font_name_group, font_size_group, font_style_group);
    font_tooltip = gdi.Font(font_name_item_value, font_size_tooltip, font_style_item_value);
}

ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

ColorTypeDUI = {
   text: 0,
   background: 1,
   highlight: 2,
   selection: 3
};

function get_color(){   
    if (window.InstanceType == 0){
        bgcolor = window.GetColorCUI(ColorTypeCUI.background);
        color_item_name = window.GetColorCUI(ColorTypeCUI.text);
        color_item_value = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
        color_group_text = window.GetColorCUI(ColorTypeCUI.inactive_selection_background);
    } else if (window.InstanceType == 1) {
        bgcolor = window.GetColorDUI(ColorTypeDUI.background);
        color_item_name = window.GetColorDUI(ColorTypeDUI.text);
        color_item_value = window.GetColorDUI(ColorTypeDUI.highlight);
        color_group_text = window.GetColorDUI(ColorTypeDUI.selection);
    }
    window.Repaint();
}

get_color();

function on_colors_changed(){
    get_color();
}

var custom_colors = window.GetProperty(" colors: custom", false);

var c_bgcolor = customColor(window.GetProperty(" color: background", "0-0-0"));
var c_color_item_name = customColor(window.GetProperty(" color: item name", "180-180-180")); 
var c_color_item_value = customColor(window.GetProperty(" color: item value", "255-255-220"));
var c_color_group_text = customColor(window.GetProperty(" color: group text", "100-100-100"));

bgcolor = custom_colors ? c_bgcolor : bgcolor;
color_item_name = custom_colors ? c_color_item_name : color_item_name;
color_item_value = custom_colors ? c_color_item_value : color_item_value;
color_group_text = custom_colors ? c_color_group_text : color_group_text;

function customColor(colour){
   tempc = colour.split("-");
   return (0xff000000 | (tempc[0]<<16) | (tempc[1]<<8) | (tempc[2]));
}

var selection_mode = window.GetProperty("selection_mode", 0);

var item_name_array = [];
var item_name_array_2 = [];
var item_value_array = [];
var tmp_item_name_array = [];
var tmp_item_name_array_2 = [];
var tmp_item_value_array = [];
var value_width = [];
var name, value;
var similar_artist_text = "";
var similar_artist = [];

var auto_sizing = window.GetProperty("auto sizing", true);
var group_text = window.GetProperty("group text", false);
var vertical_item_padding = window.GetProperty(" vertical item padding", 1);

var t_h;
var t_x1 = window.GetProperty(" text: x", 10);
var t_x2;
window.GetProperty("text: x2 custom", 0);
var t_x3;
var lbtn_down = false;
var drag_x = 0, drag_y = 0;
var move_x = false,  move_y = false;
var s = 0;
var old_x, old_y;

var Tooltip = window.GetProperty("tooltip", false);
var tooltip = window.CreateTooltip();   
var tooltip_time = fb.CreateProfiler("Time tooltip");
var tooltip_state = false;
var tooltip_text;
var tooltip_max_w = 250;

var lang_text = new Array("en", "ru");
var lang = window.GetProperty("lang", 1);

function on_paint(gr) {
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
   
    draw_array(gr);
    gr.GdiDrawText( "", font_item_value, color_item_value, 0, 100, ww, wh, DT_RIGHT | DT_WORD_ELLIPSIS);
}

var tfname = [
["$meta(artist)", "Исполнитель"],
["%title%", "Название"],
["%album%", "Альбом"],
["%date%", "Год"],
["%genre%", "Жанр"],
["%composer%", "Композитор"],
["%performer%", "Представитель"],         // возможно "Первый исполнитель"
["$meta(album artist)", "Исполнитель альбома"],
["%track number%", "Номер трека"],
["%totaltracks%", "Всего треков"],
["%discnumber%", "Номер диска"],
["%totaldiscs%", "Всего дисков"],
["%rating%", "Рейтинг"],
["$meta(rating)", "Рейтинг"],
["%comment%", "Комментарий"],
["%publisher%", "Издатель"],
["%catalog%", "Каталог"],
["%discid%", "ID диска"],
["%label%", "Лейбл"],            // возможно "Товарный знак"
["%releaser%", "Продавец"],            // ???
["%subtitle%", "Субтитры"],

["group_general", "общие"],           
["$info(samplerate)", "Частота дискретизации"],
["$info(channels)", "Каналов"],
["$info(bitspersample)", "Бит на семпл"],
["$info(bitrate)", "Битрейт"],
["%codec%", "Кодек"],
["$info(codec_profile)", "Профиль кодека"],
["$info(mp3_stereo_mode)", "Режим стерео MP3"],
["$info(encoding)", "Кодирование"],
["%length%", "Длина"],
["$info(tool)", "Кодировщик"],
["$info(cue_embedded)", "Встроенный CUE"],
["$info(tagtype)", "Тип тега"],

["group_replaygain", "усиление громкости"], 
["%replaygain_album_gain%", "Усиление громкости альбома"],
["%replaygain_album_peak%", "Пиковый уровень альбома"],
["%replaygain_track_gain%", "усиление громкости трека"],
["%replaygain_track_peak%", "Пиковый уровень трека"],

["group_location", "расположение"],   
["%filename_ext%", "Имя файла"],
["$directory_path(%path%)", "Путь к файлу"],
["%url%", "URL-адрес"],
["%subsong%", "Номер подкомпозиции"],       
["%filesize_natural%", "Размер файла"],
["%last_modified%", "Изменен"],
["%folder_name%", "Имя папки"],

["group_playback statistics", "статистика воспроизведения"],
["%play_count%", "Количество воспроизведений"],
["%first_played%", "Первое воспроизведение"],
["%last_played%", "Последнее воспроизведение"],
["%added%", "Добавлен"],

["group_last.FM", "сайт Last.FM"],
["%lastfm_bio%", "Биография"],
["%lastfm_artist_playcount%", "Прослушиваний исполнителя"],
["%lastfm_artist_listeners%", "Слушателей исполнителя"],
["%lastfm_album_playcount%", "Прослушиваний альбома"],
["%lastfm_album_listeners%", "Слушателей альбома"],
["%lastfm_album_content%", "Содержимое альбома"],

["group_last.FM", "сайт Last.FM"],
["%lastfm_similar_artist%", "Похожие исполнители"]
];


function set_cursor(x, y) {
    if (move_y || lbtn_down) window.SetCursor(IDC_HAND);
    if (move_x && !lbtn_down) window.SetCursor(IDC_SIZEWE);
}

function on_mouse_lbtn_down(x, y) {
    lbtn_down = true;
    if (move_y) drag_y = (y - s);
    if (move_x) drag_x = x - t_x2;
    set_cursor(x, y);
}

function on_mouse_lbtn_up(x, y) {
    lbtn_down = false;
    if (move_x) {
        window.SetProperty("text: x2 custom",  t_x2);
    }
}

function on_mouse_move(x, y) {
    mouse_on_pos(x, y);
    set_cursor(x, y);
   
    if (old_y != y || old_x != x){
        if (Tooltip) tooltip_activate(x, y);
        old_y = y;
        old_x = x;
    }
   
    if (lbtn_down && move_y) {
        if (s <= 0 && (item_name_array.length * t_h) >= wh) {s = y - drag_y};
        applyDelta();
    }

    shift_down = utils.IsKeyPressed(0x10) ? true : false;
    if (!shift_down) drag_x = x - t_x2;

    if (lbtn_down && move_x) {
        auto_sizing = false;
        window.SetProperty("auto sizing", auto_sizing);
        tmp_t_x2 = x - drag_x;
        t_x2 = tmp_t_x2 <= t_x1 ? t_x1 : tmp_t_x2 >= ww - t_x1 - 50 ? ww - t_x1 - 50 : tmp_t_x2;
    }
   
    window.Repaint();
}

function on_mouse_wheel(step) {
    if (s <= 0 && item_name_array.length * t_h >= wh) {s = s + step * t_h};
    applyDelta();
}

function applyDelta() {
    s = s > 0 ? 0 : s;
    s = s < (wh - item_name_array.length * t_h) && s < 0 ? (wh - item_name_array.length * t_h) : s;
    window.Repaint();
}

function on_mouse_leave() {   
    window.SetCursor(IDC_ARROW);
    window.Repaint();
}

function mouse_on_pos(x, y){
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (ShiftDown && x >= t_x2) {
        move_x = true;
        move_y = false;
    } else {
        move_y = true;
        move_x = false;
    }
}

function on_size() {
    ww = window.Width;
    wh = window.Height;
    if (wh != wh_old  && s < 0) {
        s = wh >= wh_old ? 0 : s;
        wh_old = wh;
    }
    create_array();
}

function clear_item_name(n) {
    return n.replace(/.*\(|lastfm_|replaygain_|[^a-z0-9\s\_]/g,"").replace(/_/g," ");
    //return n.replace(/.*\((?!\))|lastfm_|replaygain_|[^a-z0-9\s\_]/g,"").replace(/_/g," "); 
}

function clear_group_text(n) {
    return n.replace(/group_/g,"").replace(/(?=.)/g," ").replace(/^\s/g,"")
}

function data_format(n) {
    if (!n) return;
    d = n.substr(8, 2);
    m = parseInt(n.substr(5, 2), 10);
    y = n.substr(0, 4);
    t = n.substr(11, 8);
    m_text = lang == 0 ? months_en[m - 1] : months_ru[m - 1];
    return d + " " + m_text + " " + y + ", " + t;
}

var measure_arr = [
["$info(bitrate)", "kbps", "кбит/с"],
["$info(samplerate)", "Hz", "Гц"],
["$info(bitspersample)", "bps", ""],
["$info(channels)", "ch", ""],
["%play_count%", "times", ""]
]

function get_measure(n) {
    tmp = "";
    var j = 0;
    do {
        if (measure_arr[j][0] == n) {
            tmp = lang == 0 ? measure_arr[j][1] : measure_arr[j][2];
        }     
        j++;
    } while (j < measure_arr.length);
    return tmp;
}

var months_en = ["Jan.", "Feb.", "Mar.", "Apr.", "May", "Jun.", "Jul.", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."];
var months_ru = ["Янв.", "Фев.", "Мрт", "Апр.", "Май", "Июн.", "Июл.", "Авг.", "Сен.", "Окт.", "Нбр", "Дек."];

function create_array() {
    var temp_bmp = gdi.CreateImage(1, 1);
    var temp_gr = temp_bmp.GetGraphics();
    tmp_item_name_array = [];
    tmp_item_name_array_2 = [];
    tmp_item_value_array = [];
    value_width = [];
   
    t_x2 = 0;
    similar_artist_text = "";
    similar_artist = [];
   
    for (j = 0; j < tfname.length; j++) {
        group = tfname[j][0].search('group') >= 0 ? true : false;
       
        if (tfname[j][0].search(/last_modified|first_played|last_played|added/g) > 0){   
            value = data_format(Eval(tfname[j][0]));
        } else {
            value = Eval(tfname[j][0]);
        }
       
        if (value && value != 0 || group) {
            tmp_item_name_array.push(tfname[j][0]);
            tmp_item_name_array_2.push(tfname[j][1]);
           
           
            if (tfname[j][0] != "%lastfm_similar_artist%"){
                tmp_item_value_array.push(value);
                value_width.push(temp_gr.CalcTextWidth(value, font_item_value),value);
            }
           
            if (tfname[j][0] == "%lastfm_similar_artist%") {
                similar_artist_text = value.replace(/(&apos;)/g, "'");
            }
        }
       
        if (value && value != 0 && !group){
            tmp = lang == 0 ? clear_item_name(tfname[j][0]) : tfname[j][1];
            tmp_t_x2 = temp_gr.CalcTextWidth(tmp, font_item_name);
            t_x2 = tmp_t_x2 > t_x2 ? tmp_t_x2 : t_x2;
        }
    }
   
    t_x2 = auto_sizing ? t_x2 + t_x1 + 10 : window.GetProperty("text: x2 custom");

    if (similar_artist_text){
        similar_artist = similar_artist_text.split(';');
       
        for (var i = 0; i < similar_artist.length; i++) {
            if (i >= 1) {
                tmp_item_name_array.push("");
                tmp_item_name_array_2.push("");
            }
            value = similar_artist[i].replace(/^\s+|\s+$/g, "") + ";";
            tmp_item_value_array.push(value);
            value_width.push(temp_gr.CalcTextWidth(value, font_item_value),value);
        }
    }

    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
   
    clear_empty_groups();
}

function clear_empty_groups() {
    item_name_array = [];
    item_name_array_2 = [];
    item_value_array = [];
   
    for (j = 0; j < tmp_item_name_array.length; j++) {
        group = tmp_item_name_array[j].search('group') >= 0 ? true : false;

        item_nane = tmp_item_name_array[j];
        item_nane_2 = tmp_item_name_array_2[j];
        item_value = tmp_item_value_array[j];
       
        if (!group){
            item_name_array.push(item_nane);
            item_name_array_2.push(item_nane_2);
            item_value_array.push(item_value);       
        }
       
        if (group){
            if (tmp_item_value_array[j + 1]){
                item_name_array.push(item_nane);
                item_name_array_2.push(item_nane_2);
                item_value_array.push(item_value); 
            } else{
                value_width.splice(j * 2, 2);
            }
        }
    }
    if (item_name_array.length * t_h < wh && s < 0) s = 0;
}

function draw_array(gr) {
    f_h_name = gr.CalcTextHeight("Text", font_item_name);
    f_h_value = gr.CalcTextHeight("Text", font_item_value);
   
    f_h = Math.max(f_h_name, f_h_value);
   
    t_h = f_h + window.GetProperty(" vertical item padding");
   
    star_size = f_h_value - 3;
    star_offset = star_size + 2;
   
    for (var i = 0; i < item_name_array.length; i++) {
        group = item_name_array[i].search('group') >= 0 ? true : false;
       
        font = group ? font_group : font_item_name;
        color = group ? color_group_text : color_item_name;
        t_y =  i * t_h + s;
        l_y = t_y + t_h / 2;
       
        if (!group){
            name = clear_item_name(item_name_array[i]);
            rating_text = item_name_array[i] == "$meta(rating)" ? lang == 0 ? "  (tag)" : "  (тег)" : "";
            t_w = Math.min(ww - (ww - t_x2)- t_x1, ww - t_x1 * 2) - 10;
           
            name = lang == 0 ? name : item_name_array_2[i];
            gr.GdiDrawText(name + rating_text, font, color, t_x1, t_y, t_w, t_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);         
        }
       
        if (group){
            name = lang == 0 ? item_name_array[i] : item_name_array_2[i];
            name = group_text ? clear_group_text(name) : "";
            t_w = ww - t_x1 * 2;
            gr.GdiDrawText(name, font, color, t_x1, t_y, t_w, t_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);         

            g_w = group_text && name ? Math.min(gr.CalcTextWidth(name, font) + 5, ww - t_x1 * 2) : 0;
            group && gr.DrawLine(t_x1 + g_w, l_y, ww - t_x1, l_y, 1, color);
        }
       
        if (item_name_array[i].search(/rating/g) > 0){     
            for (var r = 0; r < Math.min(item_value_array[i] * star_offset, ww - t_x2 - t_x1); r = r + star_offset) {
                draw_star(gr, t_x2 + star_size / 3 + r, t_y + t_h / 2, star_size, true, 0, color_item_value, false, bgcolor, 255);
            }
        } else {
            value = item_value_array[i];
            t_w2 = ww - t_x2 - t_x1;
            gr.GdiDrawText( value, font_item_value, color_item_value, t_x2, t_y, t_w2, t_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);       

            t_x3 = t_x2 + gr.CalcTextWidth(value, font_item_value);
            t_w3 = ww - t_x3 - t_x1;
           
            text = "  " + get_measure(item_name_array[i]);
            gr.GdiDrawText( text, font_item_value, color_item_value, t_x3, t_y, t_w3, t_h, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);       
        }
    }
}
       
var metadb;
on_item_focus_change();

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {   
    case 0:   
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
        break;
    case 1:
       metadb = fb.GetFocusItem();
        break;
    }
    if (metadb) on_metadb_changed();
}

function on_metadb_changed() {
    create_array();
    window.Repaint();
}

function Eval(field) {
    if (metadb) {
        type = metadb.RawPath;

        if (type.indexOf("file") >= 0){
            return fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
        } else{
            if (selection_mode == 0){
                if (field == "$meta(artist)" || field == "%title%"){
                    return fb.TitleFormat("[" + field + "]").Eval(true);
                }
                if (field == "%genre%"){
                    return fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
                }
            }
            return fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
        }
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
   
    _menu.AppendMenuItem(MF_ENABLED, 1, "Prefer now playing");
    _menu.AppendMenuItem(MF_ENABLED, 2, "Follow selected track");
    _menu.CheckMenuRadioItem(1, 2, selection_mode + 1);     
   _menu.EnableMenuItem(selection_mode + 1, 1);   

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 3, "Group text");
    _menu.CheckMenuItem(3, group_text);
    _menu.AppendMenuItem(MF_ENABLED, 4, "Tooltip");
    _menu.CheckMenuItem(4, Tooltip);
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 6, "Create txt/xls file");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    MF_STRING =  auto_sizing ? MF_GRAYED : MF_ENABLED;
    _menu.AppendMenuItem(MF_STRING, 7, "Auto-sizing columns");
    _menu.CheckMenuItem(7, auto_sizing);
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 10, "item text: " + lang_text[0]);   
    _menu.AppendMenuItem(MF_ENABLED, 11, "item text: " + lang_text[1]);   
    _menu.CheckMenuRadioItem(10, 11, lang + 10);         
    _menu.EnableMenuItem(lang + 10, 1);     
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 100, "Reload");
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 200, "Properties");
    _menu.AppendMenuItem(MF_ENABLED, 300, "Configure ...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 1:   
        selection_mode = 0;
        window.SetProperty("selection_mode", selection_mode);
        on_item_focus_change();
        break;
    case 2:   
        selection_mode = 1;
        window.SetProperty("selection_mode", selection_mode);
        on_item_focus_change();
        break;
    case 3:
        window.SetProperty("group text", !group_text);
        group_text = window.GetProperty("group text");
        break;
    case 4: 
        window.SetProperty("tooltip", !Tooltip);
        Tooltip = window.GetProperty("tooltip");
        deactive_tooltip();   
        break;
    case 6:
        menu_create_file(x,y);
        break;
    case 7:
        if (!auto_sizing){
            auto_sizing = true;
            window.SetProperty("auto sizing", auto_sizing);
            create_array();
        }
        break;
    case 10:
    case 11:
        lang = ret - 10;
        window.SetProperty("lang", lang);
    case 100:
        try {
            window.Reload();   
        } catch(e) {};
        break;
    case 200:
        window.ShowProperties();
        break;   
    case 300:
        window.ShowConfigure();     
        break;
   }
    _menu.Dispose();
    return true;
}

/////////////////////////////  Create file

var fso = new ActiveXObject("Scripting.FileSystemObject");
var output_path = fb.ProfilePath + "\\tmp_Properties\\";

function check_folder(n) {
    if (!n) return;
    try {
        if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
    } catch(e) {}
}

window.GetProperty("ext",1);
var separator = Array(" ; ","\t"); 
var tmp_output_item_name_array = [];
var output_array = [];
var pllist_name;
var selected;
var shift = 0;;

create_tmp_output_item_name_array();

function  create_tmp_output_item_name_array() {
    tmp_output_item_name_array = [];
    for (var j = 0; j < tfname.length; j++) {   
        if (tfname[j][0].search(/group|lastfm/g) < 0){
        //if (tfname[j].indexOf('group') < 0 || tfname[j].indexOf('%lastfm') < 0){
            tmp_output_item_name_array.push(tfname[j][0]);
        }
    }
}

for (var j = 0; j < tmp_output_item_name_array.length; j++) {   
    window.GetProperty(j + 1,0);
}

function  create_output_array() {
    output_array = [];
    for (var j = 0; j < tmp_output_item_name_array.length; j++) {   
        selected = window.GetProperty(j + 1);
        if ( selected == 1 ) {output_array.push(tmp_output_item_name_array[j])};
    }
    createTextFile();
}

function createTextFile(){
    check_folder(output_path);
    count = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Count;
    if (count == 0 || output_array.length == 0) return;

    if (window.GetProperty("ext") == 0) {
        output_file = output_path + "plist " + pllist_name + ".txt";
    } else {
        output_file = output_path + "plist " + pllist_name + ".xls"; 
    }
   
    try { file = fso.CreateTextFile( output_file )
    } catch(e) { return };
   
    var text_item_name = [];
    var string_item_name = "";
   
    for (var j = 0; j < output_array.length; j++) {
        text_item_name.push(output_array[j]);       
    }
   
    string_item_name = text_item_name.join(separator[window.GetProperty("ext")]);
    file.WriteLine(string_item_name);
    file.WriteLine("");

    for (var i = 0; i < count; i++) {
        item = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Item(i);
       
        var text_item_value = [];
        var string_item_value = "";
       
        for (var j = 0; j < output_array.length; j++) {   
            value = fb.TitleFormat("[" + output_array[j] + "]").EvalWithMetadb(item);
               
            text = get_measure(output_array[j]);
            text = value && text ?  "  " + text : "";
           
            text_item_value.push(value + text);
           
            string_item_value = text_item_value.join(separator[window.GetProperty("ext")]);
        }
       
        try { file.WriteLine(string_item_value);
        } catch(e) {}; 
    }
    file.Close();
}

function menu_create_file(x, y){
    var _menu = window.CreatePopupMenu();
    var i = 1;
 
    count = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Count;
    MF_STRING = count == 0 ? MF_GRAYED : MF_ENABLED;
   
    pllist_name = plman.GetPlaylistName(plman.ActivePlaylist);
    pllist_name = count == 0 ? "*" : pllist_name.replace(/[\/\:\*\?\"\<\>\|]/g,'');
   
    _menu.AppendMenuItem(MF_STRING, i++, "Create  " + pllist_name + (window.GetProperty("ext") == 0 ? ".txt" : ".xls"));
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
   
    var lines = 20;   
    bl = tmp_output_item_name_array.length > lines ? lines + shift : tmp_output_item_name_array.length;

    for (var j = shift; j < bl; j++) {
        menuItem = clear_item_name(tmp_output_item_name_array[j]);
        _menu.AppendMenuItem(MF_ENABLED, i++, menuItem);   
        _menu.CheckMenuItem(i-1, window.GetProperty(i - 2 + shift));
    }
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 100, "txt");
    _menu.AppendMenuItem(MF_ENABLED, 101, "xls");
    _menu.CheckMenuRadioItem(100, 101, 100 + window.GetProperty("ext"));     
    _menu.EnableMenuItem(100 + window.GetProperty("ext"), 1);
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 110, "Select all");
    _menu.AppendMenuItem(MF_ENABLED, 120, "Clear all");

    if (tmp_output_item_name_array.length > lines) {
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
        _menu.AppendMenuItem(shift == 0 ? MF_GRAYED : MF_ENABLED, 130, "Up");
        _menu.AppendMenuItem(shift + lines >= tmp_output_item_name_array.length ? MF_GRAYED : MF_ENABLED, 140, "Down");
    }

    ret = _menu.TrackPopupMenu(x, y - 250);

    switch (true) {
    case (ret == 1):
        create_output_array();
        break;
    case (ret >= 2 && ret <= tmp_output_item_name_array.length + 1):
        selected = window.GetProperty(ret - 1 + shift);
        window.SetProperty(ret - 1 + shift, selected == 0 ? 1 : 0);
        menu_create_file(x,y);
        break;
    case (ret == 100):
        window.SetProperty("ext", 0);
        menu_create_file(x,y);
        break;
    case (ret == 101):
        window.SetProperty("ext", 1);
        menu_create_file(x,y);
        break;
    case (ret == 110):
        for (var j = 1; j < tmp_output_item_name_array.length + 1; j++) {   
            window.SetProperty(j, 1);
        }
        menu_create_file(x,y);
        break;
    case (ret == 120):
        for (var j = 1; j < tmp_output_item_name_array.length + 1; j++) {   
            window.SetProperty(j, 0);
        }
        menu_create_file(x,y);
        break;
    case (ret == 130):
        shift = shift - 1;
        menu_create_file(x,y);
        break;
    case (ret == 140):
        shift = shift + 1;
        menu_create_file(x,y);
        break;
   }
   _menu.Dispose();
}

/////////////////////////////  Draw star

function draw_star(gr, x, y, img_size, fill, line_thickness, color, sh, sh_color, alpha){
    var radius = img_size / 2;
    var radius_2 = radius / 2.61803;
    line_thickness = line_thickness >= radius_2 ? radius_2 : line_thickness;
    var delta = line_thickness / 2 * Math.tan(72 / 180 * Math.PI);

    var points = [], sh_points = [];
    var x_points_1 = [], y_points_1 = [], x_points_2 = [], y_points_2 = [];

    for (var i = 0; i < 10; i++) {
        if (i % 2 == 0) {
            x_points_1.push((radius - delta) * Math.cos(Math.PI * i / 10 * 2 - Math.PI / 2));
            y_points_1.push((radius - delta) * Math.sin(Math.PI * i / 10 * 2 - Math.PI / 2));
        } else {
            x_points_2.push((radius - delta) / 2.61803 * Math.cos(Math.PI * i / 10 * 2 - Math.PI / 2));
            y_points_2.push((radius - delta) / 2.61803 * Math.sin(Math.PI * i / 10 * 2 - Math.PI / 2));
        }
    }
       
    for (var i = 0; i < 5; i++) {
        points.push(x_points_1[i] + radius, y_points_1[i] + radius, x_points_2[i] + radius, y_points_2[i] + radius);
        sh_points.push(x_points_1[i] + radius + 1, y_points_1[i] + radius + 1, x_points_2[i] + radius + 1, y_points_2[i] + radius + 1);
    }

    var img = gdi.CreateImage(img_size, img_size);
    var temp_gr = img.GetGraphics();
    temp_gr.SetSmoothingMode(2);
   
    if (line_thickness > 0) {
        sh && temp_gr.DrawPolygon(sh_color, line_thickness, sh_points);
        temp_gr.DrawPolygon(color, line_thickness, points);
    }

    if (fill && line_thickness == 0) {
        sh && temp_gr.FillPolygon(sh_color, 1, sh_points);
        temp_gr.FillPolygon(color, 1, points)
    }

    gr.DrawImage(img, x - radius, y - radius, img_size, img_size, 0, 0, img_size, img_size, 0, alpha);
   
    img.ReleaseGraphics(temp_gr);
    img.Dispose();
    temp_gr = null;
    img = null;
}

/////////////////////////////  Tooltip custom paint

function active_tooltip(){      
    if (!tooltip_state){      
        tooltip_state = true;      
        tooltip.Activate();      
        tooltip.TrackActivate = true;   
    }      
}      
      
function deactive_tooltip(){      
    if (tooltip_state){   
        tooltip.Width = 0;      
        tooltip.Height = 0;          
        tooltip_state = false;      
        tooltip.TrackActivate = false;      
        tooltip.Deactivate();      
        tooltip_time.Reset();      
    }      
}      

function on_tooltip_custom_paint(gr){
    var tooltip_t_w = gr.CalcTextWidth( tooltip_text, font_tooltip);   
    var tooltip_t_h = gr.CalcTextHeight( "Text", font_tooltip);
    var tooltip_t_tmp = gr.EstimateLineWrap(tooltip_text, font_tooltip, tooltip_max_w).toArray();
    var tooltip_t = [];
    var tooltip_l = [];

    for (var i = 0; i < tooltip_t_tmp.length; i += 1) {
        if (i % 2 == 0) {
            tooltip_t.push(tooltip_t_tmp[i].replace(/^\s+|\s+$/g, ""));
        } else {
            tooltip_l.push(tooltip_t_tmp[i]);
        }
    }
   
    if (tooltip_t_w <= tooltip_max_w){
        tooltip.Width = tooltip_t_w + 5;
        tooltip.Height = tooltip_t_h;
    } else {
        tooltip.Width = Math.max.apply(null, tooltip_l) + 5;
        tooltip.Height = tooltip_t_h * tooltip_t.length;
    }

    for (var i = 0; i < tooltip_t.length; i += 1) {
        gr.GdiDrawText( tooltip_t[i], font_tooltip, RGB(0,0,0), 5, tooltip_t_h * i + 1, tooltip.Width, tooltip.Height, DT_LEFT | DT_WORDBREAK | DT_NOPREFIX );   
    }
}   

function tooltip_activate(x, y) { 
    idx = Math.floor((y + Math.abs(s)) / t_h);

    tooltip_x = t_x2 - 5;
    tooltip_y = Math.floor(y / t_h) * t_h;

    if (value_width[idx * 2] > ww - t_x2 - t_x1 && x > t_x2 && x < ww && y > tooltip_y + 1 && y < tooltip_y + t_h){
        if (tooltip_time.Time > 300 && !tooltip_state) {
            tooltip_text = value_width[idx * 2 + 1];
            active_tooltip();
            tooltip.TrackPosition(tooltip_x, tooltip_y);      
            tooltip.Text = " ";   
        }       
    } else {   
        tooltip_time.Reset();
        deactive_tooltip();   
    }
}

function print(msg) {
   fb.trace(msg);
}


kgena_ua M
Аватара
Откуда: Украина, Днепр
Репутация: 504
С нами: 10 лет 11 месяцев

Сообщение #1796 pois22ple » 16.04.2017, 12:20

kgena_ua,
Попробовал Properties & properties file (ml) version "15042017".
Взвожу галку на строке "Tooltip", перемещаюсь на строку которая не помещается в окошке (заканчивается ...).
Вижу белый квадратик, далее любое движение мышью или ее колесом и скрипт валится:
JScript Panel (Properties & properties file (ml) v15042017 by kgena_ua)
JavaScript runtime error:
Object doesn't support this property or method
File: <main>
Line: 898, Col: 9
<source text only available at compile time>
Вложения
Буфер обмена01.jpg
pois22ple
Репутация: 10
С нами: 17 лет 7 месяцев

Сообщение #1797 MC Web » 16.04.2017, 12:54

pois22ple, этот скрипт для Панели WSH.

kgena_ua, приветствую.

Я обычно у себя перед названием скрипта ставлю WSH или JS, чтобы не было такой путаницы.
MC Web
Репутация: 248
С нами: 10 лет 7 месяцев

Сообщение #1798 pois22ple » 16.04.2017, 14:26

MC Web,
Ну, что же, подключил компонент foo_uie_wsh_panel_mod (версия 1.6.3)
Результат тот же.
Вложения
Буфер обмена01.jpg
pois22ple
Репутация: 10
С нами: 17 лет 7 месяцев

Сообщение #1799 MC Web » 16.04.2017, 14:48

pois22ple:Ну, что же, подключил компонент foo_uie_wsh_panel_mod (версия 1.6.3)
Ставьте foo_uie_wsh_panel_mod (версия 1.5.6) и не мучайтесь.
Дальнейшие версии - это эксперименты сторонних разработчиков, а не автора компонента.

Результат работы (версия 1.5.6):

Изображение
MC Web
Репутация: 248
С нами: 10 лет 7 месяцев

Сообщение #1800 seriousstas » 22.04.2017, 01:02

MC Web
Скрипт Properties без проблем работает под JScript Panel
по JS Panel - уже писал :
/viewtopic.php?p=64091#p64091
Любой скрипт можно переделать в пару кликов под современную панель .
Смысл ?
1.Не будет необходимости ставить два компонента панелей одновременно .
2.Удобно для тестирования новых скриптов (последние библиотеки только на новой панели)
По активации - деактивации подсказок (для kgena_ua) :
Код: Выделить всё
      window.CreateTooltip([font_name][, font_size_px][, font_style]); (IFbTooltip)
      /*(
      font_name: default "Segoe UI"
      font_size_px: default 12
      font_style: default 0 see flags.txt > FontStyle
      */

         interface IFbTooltip {
            // this will be used in the examples below.
            // var tooltip = window.CreateTooltip();

            Properties:
               Text; (string) (read, write)
               // example: tooltip.Text = "Whoop";

               TrackActivate; (boolean) (write)

            Methods:
               Activate(); (void)
               /*
               only do this when text has changed otherwise it will flicker
               example:
               var text = "...";
               if (tooltip.Text != text) {
                  tooltip.Text = text;
                  tooltip.Activate();
               }
               */

               Deactivate(); (void)

               Dispose(); (void)

               GetDelayTime(type); (int)
               SetDelayTime(type, time); (void)
               // type: see flags.txt > Used in IFbTooltip.GetDelayTime() and IFbTooltip.SetDelayTime()

               SetMaxWidth(width); (void)
               /*
               use if you want multi-line tooltips
               example:
               tooltip.SetMaxWidth(800);
               tooltip.Text = "Line1\nLine2";
               use \n as a new line separator
               */
seriousstas
Откуда: Украина , Ивано-Франковск
Репутация: 110
С нами: 9 лет 1 месяц

Пред.След.

Вернуться в Секреты foobar2000