kgena_ua, большое спасибо, с цветами разобрался, ответ был рядом))
Еще вопрос по вашему скрипту
Track info, кстати спасибо - скрипт отличный и должен быть легкий, но есть непонятки:
1. При наведении и движении мышки - грузит сильно проц, почему (даже при отключенных всплывающих подсказках) - вычисление размера так влияет, не могу дотумкать?
2. При включении всплывающих подсказок, они сильно часто мерцают, есть ли такой эффект у вас? (как то было похожее когда скрипт громкости ваял - у себя решил мерцание удалением лишних w.repaint). Тут не могу понять в чем причина. Кто его часто мигать заставляет?
- Код: Выделить всё
// ==PREPROCESSOR==
// @name "properties & create file"
// @author "kgena_ua"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/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)); }
var font = gdi.Font("Areal",12,0);
var group_font = gdi.Font("Tahoma",9,0);
var g_fontR = gdi.Font("Areal",10,0);
DT_LEFT = 0x00000000;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_RIGHT = 0x00000002;
DT_WORD_ELLIPSIS = 0x00040000;
DT_SINGLELINE = 0x00000020;
var ww, wh;
var bgcolor = RGB(20,20,20);
var color1 = RGB(180,180,180);
var color2 = RGB(255,255,200);
var color3 = RGB(100,100,100);
var Tooltip = window.CreateTooltip();
Tooltip.SetMaxWidth(300);
var tstring = 0;
window.GetProperty("Tooltip", 0);
var name, value, measure, t_height;
var path = "";
var g_drag = false;
var g_drag_y = 0;
var s = 0;
var col1 = 10;
var col2 = 110;
var col3;
var pos_y;
var pos_x;
var wh_old = wh
function on_paint(gr) {
!window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
show_array2(gr);
}
function on_mouse_lbtn_down(x, y) {
g_drag = true;
g_drag_y = (y - s);
}
function on_mouse_lbtn_up(x, y) {
g_drag = false;
}
function on_mouse_move(x, y) {
window.SetCursor(32649);
pos_y = y;
pos_x = x;
tstring = Math.floor((y + Math.abs(s)) / t_height);
if (value_width[tstring * 2] > ww - col2 - col1 && pos_x > col2 && window.GetProperty("Tooltip") == 1){
Tooltip.Text = value_width[tstring * 2 + 1];
delay();
delay_flag && Tooltip.Activate();
} else {
delay_flag = false;
Tooltip.Deactivate();
}
if (g_drag) {
if (s <= 0 && (name_array.length * t_height) >= wh) {s = y - g_drag_y};
applyDelta();
}
if (s == 0 || s == wh - name_array.length * t_height) g_drag_y = (y - s);
window.Repaint();
}
function on_mouse_wheel(step) {
if (s <= 0 && name_array.length * t_height >= wh) {s = s + step * t_height};
applyDelta();
}
function applyDelta() {
s = s > 0 ? 0 : s;
s = s < (wh - name_array.length * t_height) && s < 0 ? (wh - name_array.length * t_height) : s;
window.Repaint();
}
function on_mouse_leave() {
window.SetCursor(32512);
window.Repaint();
}
function on_size() {
ww = window.Width;
wh = window.Height;
if (wh != wh_old && s < 0) {
s = wh >= wh_old ? s + 1 : s;
wh_old = wh;
}
}
var tfname = new Array(
"$meta(artist)",
"%title%",
"%album%",
"%date%",
"%genre%",
"%composer%",
"%performer%",
"%publisher%",
"$meta(album artist%)",
"%track number%",
"%totaltracks%",
"%discnumber%",
"%totaldiscs%",
"%comment%",
"%rating%",
"$meta(rating)",
"line",
"group G E N E R A L",
"$info(samplerate)",
"$info(channels)",
"$info(bitspersample)",
"$info(bitrate)",
"%codec%",
"$info(codec_profile)",
"$info(encoding)",
"%length%",
"$info(tool)",
"$info(cue_embedded)",
"line",
"group L O C A T I O N",
"%filename_ext%",
"$directory_path(%path%)",
"%subsong%",
"%filesize_natural%",
"%last_modified%",
"%folder name%",
"line",
"group P L A Y B A C K S T A T I S T I C S",
"%play_count%",
"%first_played%",
"%last_played%",
"%added%",
"line",
"group L A S T F M",
"%lastfm_bio%",
"%lastfm_similar_artist%",
"%lastfm_artist_playcount%",
"%lastfm_artist_listeners%",
"%lastfm_album_playcount%",
"%lastfm_album_listeners%",
"%lastfm_album_content%"
);
var tfname_length = tfname.length;
var delay_flag = false;
var timer;
function delay() {
timer = window.SetTimeout(function() {
delay_flag = true;
window.ClearTimeout(timer);
}, 1000);
}
var name_array = [];
var value_array = [];
var value_width = [];
var max_width;
function create_array() {
var temp_bmp = gdi.CreateImage(1, 1);
var temp_gr = temp_bmp.GetGraphics();
name_array = [];
value_array = [];
value_width = [];
for (j = 0; j < tfname_length; j++) {
group = false;
LM = false;
if (tfname[j].search('group') >= 0 || tfname[j] == "line" ) group = true;
value = Eval(tfname[j]);
if (value != 0 || group) {
name_array.push(tfname[j]);
value_array.push(value);
value_width.push(temp_gr.CalcTextWidth(value, font),value);
}
}
temp_bmp.ReleaseGraphics(temp_gr);
temp_bmp.Dispose();
temp_gr = null;
temp_bmp = null;
}
function show_array2(gr) {
t_height = gr.CalcTextHeight("text", font) + 2;
for (var i = 0; i < name_array.length; i++) {
line = false;
group = false;
if (name_array[i].search('line') >= 0) line = true;
if (name_array[i].search('group') >= 0) group = true;
row = i * t_height + s;
line_row = row + t_height / 2;
line && gr.DrawLine(col1, line_row, ww - col1, line_row, 1, color3);
name = name_array[i].replace(/[%\$\(\)]|info|meta|group |line|lastfm/g,'').replace(/_/g,' ').replace('directory pathpath','directory path');
var rating_name = name_array[i] == "$meta(rating)" ? " (tag)" : "";
gr.GdiDrawText(name + rating_name, group ? group_font : font, group ? color3 : color1, col1, row, ww - col1 * 2, t_height, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS);
if (name_array[i] == "%rating%" || name_array[i] == "$meta(rating)") {
for (var r = 0; r < value_array[i]; r++){
Draw_star(gr, col2 + star_r + star_r * 2.5 * r, row + star_r * 2, color2)
}
} else {
gr.GdiDrawText(value_array[i], font, color2, col2, row, ww - col2 - col1, t_height, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS);
}
}
}
var metadb;
on_item_focus_change();
function on_item_focus_change() {
metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
if (metadb) on_metadb_changed();
}
function on_playlist_switch() {
on_item_focus_change();
}
function on_playback_new_track() {
on_item_focus_change();
}
function on_playback_stop() {
on_item_focus_change();
}
function on_metadb_changed() {
create_array();
window.Repaint();
}
function Eval(field) {
if (metadb) {
path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval(true) : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}
}
function on_mouse_rbtn_up (x, y){
var _menu = window.CreatePopupMenu();
var i = 1;
MF_ENABLED = 0x00000000;
MF_GRAYED = 0x00000001;
_menu.AppendMenuItem(MF_ENABLED, i++, "Tooltip");
_menu.CheckMenuItem(1, window.GetProperty("Tooltip"));
_menu.AppendMenuItem(MF_ENABLED, i++, "Create txt/xls file");
ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
// if (ShiftDown) {
_menu.AppendMenuItem(0x00000800, 0, 0);
_menu.AppendMenuItem(0x00000000, 10, "Reload");
_menu.AppendMenuItem(0x00000800, 0, 0);
_menu.AppendMenuItem(0x00000000, 20, "Properties");
_menu.AppendMenuItem(0x00000000, 30, "Configure ...");
// }
ret = _menu.TrackPopupMenu(x,y);
switch (ret) {
case 1:
window.GetProperty("Tooltip") == 0 ? window.SetProperty("Tooltip",1) : window.SetProperty("Tooltip",0);
break;
case 2:
menu_create_file(x,y);
break;
case 10:
window.Reload();
break;
case 20:
window.ShowProperties();
break;
case 30:
window.ShowConfigure();
break;
}
_menu.Dispose();
return true;
}
///////////////////////////// Create txt/xls file
var fso = new ActiveXObject("Scripting.FileSystemObject");
if(!fso.FolderExists( fb.ProfilePath + "output")) {fso.CreateFolder( fb.ProfilePath + "output" )};
var output_path = fb.ProfilePath + "\\output\\";
var tag = [];
create_tag_array();
function create_tag_array() {
for (var j = 0; j < tfname.length; j++) {
if (tfname[j].indexOf('line') < 0 && tfname[j].indexOf('group') < 0){
tag.push(tfname[j])};
}
}
var outtag = [];
var separator = Array(" ; ","\t");
for (var j = 0; j < tag.length; j++) {
window.GetProperty(j + 1,0);
}
window.GetProperty("ext",0);
window.GetProperty("skip",0);
var selected;
var shift = 0;;
function create_output_array() {
outtag = [];
for (var j = 0; j < tag.length; j++) {
selected = window.GetProperty(j + 1);
if ( selected == 1 ) {outtag.push(tag[j])};
}
createTextFile();
}
function createTextFile(){
if (fb.GetSelections().Count == 0 || outtag.length ==0) return;
plist_name = plman.GetPlaylistName(plman.ActivePlaylist);
plist_name = plist_name.replace(/[\/\:\*\?\"\<\>\|]/g,'')
if (window.GetProperty("ext") == 0) {
output_file = output_path + "plist " + plist_name + ".txt";
} else {
output_file = output_path + "plist " + plist_name + ".xls";
}
try { file = fso.CreateTextFile( output_file )
} catch(e) {
if (e.number == -2146828218) return; // permission denied
}
if ( window.GetProperty("skip") == 0) {
text = [];
string = "";
for (var j = 0; j < outtag.length; j++) {
text.push(outtag[j]);
}
string = text.join(separator[window.GetProperty("ext")]);
file.WriteLine(string);
file.WriteLine("");
}
for (var i = 0; i < fb.GetSelections().Count; i++) {
item = fb.GetSelections().Item(i);
text = [];
string = "";
for (var j = 0; j < outtag.length; j++) {
select = fb.TitleFormat("[" + outtag[j] + "]").EvalWithMetadb(item);
var measure = "";
if (select != "" ) {
if (outtag[j] == "$info(bitrate)") measure = " kbps";
if (outtag[j] == "$info(samplerate)") measure = " Hz";
if (outtag[j] == "$info(bitspersample)") measure = " bps";
if (outtag[j] == "$info(channels)") measure = " ch";
}
if (select != "" || window.GetProperty("skip") == 0) {
text.push(select + measure);
}
string = text.join(separator[window.GetProperty("ext")]);
}
try { file.WriteLine(string)
} catch(e) {
if (e.number == -2146828283) file.WriteLine(":ERROR");
}
}
file.Close();
}
function menu_create_file(x,y){
var _menu = window.CreatePopupMenu();
var i = 1;
MF_ENABLED = 0x00000000;
MF_GRAYED = 0x00000001;
MF = fb.GetSelections().Count == 0 ? MF_GRAYED : MF_ENABLED;
// t = window.GetProperty("ext") == 0 ? "*.txt" : "*.xls";
_menu.AppendMenuItem(MF, i++, "create " + (window.GetProperty("ext") == 0 ? "*.txt" : "*.xls") + " file");
_menu.AppendMenuItem(0x00000800, 0, 0);
var lines = 20;
tl = 0 + shift;
bl = tag.length > lines ? lines + shift : tag.length;
for (var j = tl; j < bl; j++) {
menuItem = tag[j].replace(/[%\$\(\)]|info|meta/g,'').replace(/_/g,' ');
_menu.AppendMenuItem(MF_ENABLED, i++, menuItem);
_menu.CheckMenuItem(i-1, window.GetProperty(i - 2 + shift));
}
_menu.AppendMenuItem(0x00000800, 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(0x00000800, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 110, "skip if empty");
_menu.CheckMenuItem(110, window.GetProperty("skip"));
_menu.AppendMenuItem(0x00000800, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 120, "clear all");
if (tag.length > lines) {
_menu.AppendMenuItem(0x00000800, 0, 0);
_menu.AppendMenuItem(shift == 0 ? MF_GRAYED : MF_ENABLED, 130, "up");
_menu.AppendMenuItem(shift + lines >= tag.length ? MF_GRAYED : MF_ENABLED, 140, "down");
}
ret = _menu.TrackPopupMenu(x,y);
switch (true) {
case (ret == 1):
create_output_array();
break;
case (ret >= 2 && ret <= tag.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):
window.SetProperty("skip", window.GetProperty("skip") == 0 ? 1 : 0);
menu_create_file(x,y);
break;
case (ret == 120):
for (var j = 1; j < tag.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();
}
var star_r = 5;
function Draw_star(gr,x,y,color){
var x_points_1 = [], y_points_1 = [];
var x_points_2 = [], y_points_2 = [];
gr.SetSmoothingMode(4);
for (var j = star_r; j > 0; j--) {
for (var i = 0; i < 5; i++) {
x_points_1.push(x + (j * Math.cos(Math.PI * i / 5 * 2 - Math.PI / 2)));
y_points_1.push(y + (j * Math.sin(Math.PI * i / 5 * 2 - Math.PI / 2)));
}
for (var i = 1; i < 10; i = i + 2) {
x_points_2.push(x + (j / 2.61803 * Math.cos(Math.PI * i / 10 * 2 - Math.PI / 2)));
y_points_2.push(y + (j / 2.61803 * Math.sin(Math.PI * i / 10 * 2 - Math.PI / 2)));
}
}
for (var j = 0; j < star_r * 5 - 5; j = j + 5) {
gr.DrawLine(x_points_1[0+j], y_points_1[0+j], x_points_2[0+j], y_points_2[0+j], 1, color);
gr.DrawLine(x_points_1[0+j], y_points_1[0+j], x_points_2[4+j], y_points_2[4+j], 1, color);
gr.DrawLine(x_points_1[1+j], y_points_1[1+j], x_points_2[0+j], y_points_2[0+j], 1, color);
gr.DrawLine(x_points_1[1+j], y_points_1[1+j], x_points_2[1+j], y_points_2[1+j], 1, color);
gr.DrawLine(x_points_1[2+j], y_points_1[2+j], x_points_2[1+j], y_points_2[1+j], 1, color);
gr.DrawLine(x_points_1[2+j], y_points_1[2+j], x_points_2[2+j], y_points_2[2+j], 1, color);
gr.DrawLine(x_points_1[3+j], y_points_1[3+j], x_points_2[2+j], y_points_2[2+j], 1, color);
gr.DrawLine(x_points_1[3+j], y_points_1[3+j], x_points_2[3+j], y_points_2[3+j], 1, color);
gr.DrawLine(x_points_1[4+j], y_points_1[4+j], x_points_2[3+j], y_points_2[3+j], 1, color);
gr.DrawLine(x_points_1[4+j], y_points_1[4+j], x_points_2[4+j], y_points_2[4+j], 1, color);
}
}
И хотел поинтересоваться для чего таймер, включать по таймеру тултип?