MC Web:Наверное зря, если панель биографии вытянута по горизонтали, то этого режима очень не хватает.
MC Web, делал это под себя, в других скриптах такого выравнивания не встречал, вот и подумал, что не пользуется популярностью. Тупанул.
duzzy , по функции(ям)
resize_image разницы не заметил, в новом скрипте внизу и в on_paint(gr) заремил функцию для теста.
Get Covers (Artwork) && radio logos
version "18022017" Добавлена возможность двигать изображение (пожелание от
AHAPXICT).
Функция работает в
Mode 1 при "выравнивании"
centre.
Для тех, кто подстраивает скрипт под себя:
добавлены переменные
- Код: Выделить всё
var lb_downn = false;
var dx = 0, dy = 0;
var delta_x = 0, delta_y = 0;
по поиску можно легко найти, в каких функциях изменения.
- Код: Выделить всё
// ==PREPROCESSOR==
// @name "Get Covers (Artwork) && radio logos"
// @author "kgena_ua"
// @version "18022017"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==
function RGBA(r, g, b, a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function RGB(r, g, b) { return (0xff000000 | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};
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 = window.GetProperty(" font name", "Arial");
var font_size = window.GetProperty(" font size", 12);
var font_style = window.GetProperty(" font style", 0);
var font = gdi.Font(font_name, font_size, font_style);
var ww = 600, wh = 600;
//var ww, wh;
DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_NOPREFIX = 0x00000800;
MF_ENABLED = 0x00000000;
MF_GRAYED = 0x00000001;
MF_SEPARATOR = 0x00000800;
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);
a_color = window.GetColorCUI(ColorTypeCUI.text);
b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
} else if (window.InstanceType == 1) {
bgcolor = window.GetColorDUI(ColorTypeDUI.background);
a_color = window.GetColorDUI(ColorTypeDUI.text);
b_color = window.GetColorDUI(ColorTypeDUI.highlight);
}
window.Repaint();
}
get_color();
function on_colors_changed(){
get_color();
}
var transparent = window.GetProperty(" bg transparent (0-255)", 200);
var fso = new ActiveXObject("Scripting.FileSystemObject");
var WshShell = new ActiveXObject("WScript.Shell");
htmlfile = new ActiveXObject('htmlfile');
var clipboardData = "";
var dir_name, album, artist;
var old_dir_name, old_album;
var logo_file_name, old_logo_file_name, logo_files = [];
var path, title, itle_stream, artist_stream, genre;
var t_type, old_t_type;
var g_img = null
var cover_name;
var cover_size;
var cover_width;
var cover_height;
var cover_dim;
var nocover_path = window.GetProperty(" nocover path",".\\maybe\\textures\\nocover\\nocover.png");
var nocover = window.GetProperty(" nocover image", false);
var nocover_transparent = window.GetProperty(" nocover transparent (0-255)", 100);
var covers_external = [];
var covers_dir = [];
var covers_root = [];
var covers_root_subs = [];
var covers_dir_subs = [];
var external = [];
var embedded = [];
var covers = [];
var images = [];
var covernumber = 0;
var attached_p_name = ["front cover", "back cover", "disc", "icon", "artist"];
var embedded_p_name = [];
var root_folders = new Array("cover", "covers", "scan", "scans", "art", "artwork", "artworks", "images", "pic");
var set_external = window.GetProperty("external", true);
var set_embedded = window.GetProperty("embedded", true);
var set_priority = window.GetProperty("set_priority", 0);
var selection_mode = window.GetProperty("selection_mode", 0);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var info = window.GetProperty("info", false);
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 25);
var align_mode_a = new Array("adjust", "adjust top", "centre", "centre - top", "stretch");
var align_mode = window.GetProperty("align mode", 0);
var p_margin = window.GetProperty(" margin", 0);
var file_operation = false;
var delay = false;
var set_cycle = false;
var cycle_timer, step = 0;
var dis_timer, dis = 0;
var mode_1 = window.GetProperty("mode 1", true);
var mode_2 = window.GetProperty("mode 2", false);
var logo_dir_name = window.GetProperty(" radio logo dir name",".\\radio Logos\\");
get_logo_files_from_dir();
var lb_downn = false;
var dx = 0, dy = 0;
var delta_x = 0, delta_y = 0;
//var panel_on = true;
function on_paint(gr) {
!window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
draw_image(gr);
switch (t_type) {
case "file":
draw_set(gr);
draw_info(gr);
break;
case "stream":
draw_info_stream(gr);
break;
}
//gr.FillSolidRect(0, 0, ww, 100, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),150));
//gr.GdiDrawText( foo, gdi.Font("Arial",12, 0), b_color, 10, 10, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
//gr.GdiDrawText( sys, gdi.Font("Arial",12, 0), b_color, 10, 30, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
}
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() {
if (metadb){
dir_name = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
album = fb.Titleformat("%album%").EvalWithMetadb(metadb);
artist = fb.Titleformat("%artist%").EvalWithMetadb(metadb);
title = fb.Titleformat("[%title%]").EvalWithMetadb(metadb);
title_stream = fb.Titleformat("[%title%]").Eval();
artist_stream = fb.Titleformat("[%artist%]").Eval();
genre = fb.Titleformat("[%genre%]").EvalWithMetadb(metadb);
t_type = track_type(metadb.RawPath);
if (old_t_type != t_type){
g_img = null;
old_t_type = t_type;
}
switch (t_type) {
case "file":
if (dir_name != old_dir_name || album != old_album){
covernumber = 0;
get_covers();
old_dir_name = dir_name;
old_album = album;
old_logo_file_name = "";
}
break;
case "stream":
covernumber = 0;
get_logo_image();
old_dir_name = "";
old_album = "";
break;
}
}
window.Repaint();
}
function get_covers() {
get_external_covers(dir_name);
get_embedded_covers();
external = set_external ? external : [];
embedded = set_embedded ? embedded : [];
covers = [];
images = [];
if (set_priority == 0) {
covers = covers.concat(external, embedded);
}
if (set_priority == 1) {
covers = covers.concat(embedded, external);
}
if (mode_2){
for (var i = 0; i < covers.length; i++) {
if (typeof covers[i] == 'object' ) {
images.push(resize_image(covers[i]));
} else {
images.push(resize_image(gdi.Image(covers[i])));
}
}
}
dx = 0, dy = 0;
window.Repaint();
next_image(0);
}
function get_embedded_covers() { //0 - front cover, 1 - back cover, 2 - disc, 3 - icon, 4 - artist
embedded = [];
embedded_p_name = [];
if ( metadb ) {
for (var i = 0; i < 5; i++) {
var temp = utils.GetAlbumArtEmbedded(metadb.RawPath, i);
if (temp) embedded.push(temp);
if (temp) embedded_p_name.push(attached_p_name[i]);
}
}
}
function get_external_covers(path) {
covers_dir = [];
covers_root = [];
covers_dir_subs = [];
covers_root_subs = [];
covers_external = [];
external = [];
try {
dir = fso.GetFolder(path);
get_covers_from_dir(covers_dir, dir);
root = dir.ParentFolder;
get_covers_from_dir(covers_root, root);
var e = new Enumerator( dir.SubFolders );
for(; !e.atEnd(); e.moveNext() ) {
get_covers_from_dir(covers_dir_subs, e.item() );
}
var e = new Enumerator( root.SubFolders );
for(; !e.atEnd(); e.moveNext() ) {
var name = e.item().Path;
var sub_root_name = name.substr(name.lastIndexOf("\\") + 1, name.length);
for (i in root_folders) {
if (sub_root_name.toLowerCase() == root_folders[i].toLowerCase()) {
get_covers_from_dir(covers_root_subs, e.item() );
}
}
}
} catch(e) {};
covers_external = covers_external.concat(covers_dir, covers_dir_subs, covers_root, covers_root_subs);
if (covers_external.length > 0) {
if (external.length == 0){
for (i in covers_external) {
var name = covers_external[i];
if ( get_fn(name).toLowerCase() == album.toLowerCase() ) {
external.push(name);
covers_external[i] = null;
}
}
}
if (external.length == 0){
for (i in covers_external) {
var name = covers_external[i];
if ( get_fn(name).toLowerCase() == artist.toLowerCase() ) {
external.push(name);
covers_external[i] = null;
}
}
}
if (external.length == 0){
for (i in covers_external) {
var name = covers_external[i];
if (artist && album){
if ( clear_n(get_fn(name)).toLowerCase() == clear_n(artist).toLowerCase() + clear_n(album).toLowerCase() ) {
external.push(name);
covers_external[i] = null;
}
}
}
}
if (external.length == 0){
for (i in covers_external) {
var name = covers_external[i];
if (get_fnext(name).match(/.*(cover|front|folder|album).*\.(jpg|jpeg|gif|png)$/i )) {
external.push(name);
covers_external[i] = null;
}
}
}
for (i in covers_external) {
if (typeof(covers_external[i]) == 'string' ) external.push(covers_external[i]);
}
}
}
function get_covers_from_dir(array, dir) {
var e = new Enumerator( dir.Files );
while (!e.atEnd()) {
var name = e.item().Name;
if (name.match(/\.(jpg|jpeg|png|gif|bmp|tiff)$/i)) {
array.push( e.item().Path );
}
e.moveNext();
}
}
function next_image(d){
fader = fade_effect ? 0 : 255;
if (d < 0) {covernumber = covernumber <= 0 ? covers.length - 1 : covernumber = covernumber - 1};
if (d > 0) {covernumber = covernumber >= covers.length - 1 ? 0 : covernumber = covernumber + 1};
if (mode_1){
if (typeof covers[covernumber] == 'object' ) {
g_img = resize_image(covers[covernumber]);
} else {
g_img = resize_image(gdi.Image(covers[covernumber]));
}
}
if (mode_2){
g_img = images[covernumber];
}
if (g_img && fade_effect) fader_timer();
}
function resize_image_(img){
if (!img) return;
if (!ww || !wh) {
ww = window.Width;
wh = window.Height;
}
var scale_w = ww / img.Width;
var scale_h = wh / img.Height;
var scale = Math.max(scale_w, scale_h);
var nww = img.Width * scale;
var nwh = img.Height * scale
var temp_bmp = gdi.CreateImage(nww, nwh);
var temp_gr = temp_bmp.GetGraphics();
temp_gr.SetSmoothingMode(2);
temp_gr.SetInterpolationMode(7);
temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
temp_bmp.ReleaseGraphics(temp_gr);
return temp_bmp;
CollectGarbage();
temp_bmp.Dispose();
temp_gr = null;
temp_bmp = null;
}
function resize_image(img){
if (!img) return;
if (!ww || !wh) {
ww = window.Width;
wh = window.Height;
}
var scale_w = ww / img.Width;
var scale_h = wh / img.Height;
var scale = Math.max(scale_w, scale_h);
var nww = Math.round(img.Width * scale);
var nwh = Math.round(img.Height * scale)
return img.Resize(nww, nwh, 2);
img && img.Dispose();
}
function draw_image(gr){
if (g_img){
var size = calc_img_size(g_img);
gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, covers.length > 0 ? fader : nocover_transparent);
}
if (!g_img && nocover){
try {
nc_img = gdi.Image(nocover_path);
var size = calc_img_size(nc_img);
gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, nocover_transparent);
} catch(e) {};
}
if (!g_img) {
gr.GdiDrawText("no image", font, a_color, 0, 0, ww, wh, DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_WORD_ELLIPSIS );
}
}
function draw_set(gr){
if(set_cycle){
gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));
var txt_cycle = cycle == 0 ? "off" : cycle + " sec";
gr.GdiDrawText("auto cycle: " + txt_cycle, font, b_color, 0, 20, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
}
}
function draw_info(gr){
var text_h = gr.CalcTextHeight("00", font);
var text_y = wh - text_h * 3 - text_h / 3 - p_margin;
if(info && g_img){
!set_cycle && gr.FillSolidRect(0, text_y - text_h / 3, ww, wh - text_y + text_h / 3, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));
if (covers[covernumber]) {
if (typeof covers[covernumber] != 'object'){
if(fso.FileExists(covers[covernumber])){
cover_name = get_fnext(covers[covernumber]);
cover_width = gdi.Image(covers[covernumber]).width;
cover_height = gdi.Image(covers[covernumber]).Height;
cover_size = formatFileSize(fso.GetFile(covers[covernumber]).size);
cover_dim = cover_width + " x " + cover_height + " " + cover_size;
}
}
if (typeof covers[covernumber] == 'object'){
cover_name = get_embedded_img_name(covernumber);
cover_width = covers[covernumber].width;
cover_height = covers[covernumber].Height;
cover_dim = "embedded " + cover_width + " x " + cover_height;
}
cover_name && gr.GdiDrawText( cover_name, font, b_color, 0, text_y, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX );
gr.GdiDrawText( cover_dim, font, a_color, 0, text_y + text_h, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
info_text = covernumber + 1 + " (" + covers.length + ") " + external.length + " external " + embedded.length + " embedded";
gr.GdiDrawText( info_text, font, a_color, 0, text_y + text_h * 2, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
}
}
}
function draw_info_stream(gr){
var text_h = gr.CalcTextHeight("00", font);
var text_y = wh - text_h * 4 - text_h / 4 - p_margin;
if (info){
gr.FillSolidRect(0, text_y - text_h / 4, ww, wh - text_y + text_h / 4, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));
gr.GdiDrawText( title_stream, font, b_color, 0, text_y, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX );
gr.GdiDrawText( artist_stream, font, b_color, 0, text_y + text_h, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX );
gr.GdiDrawText( title, font, a_color, 0, text_y + text_h * 2, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX );
gr.GdiDrawText( genre, font, a_color, 0, text_y + text_h * 3, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX );
}
}
function get_embedded_img_name(n){
if (set_priority == 0) {
idx = n - external.length;
}
if (set_priority == 1) {
idx = n ;
}
return embedded_p_name[idx];
}
function on_mouse_lbtn_down(x,y){
lb_downn = true;
delta_x = x - dx;
delta_y = y - dy;
}
function on_mouse_move(x, y) {
if (lb_downn){
dx = x - delta_x;
dy = y - delta_y;
window.Repaint();
}
window.SetCursor(32649);
}
function on_mouse_lbtn_up(x,y){
lb_downn = false;
}
function on_mouse_lbtn_dblclk (x,y){
if (typeof covers[covernumber] != 'object' ) {
if(!fso.FileExists(covers[covernumber]))return;
if (covers[covernumber]) WshShell.run( '"' + covers[covernumber] + '"' );
}
}
function on_mouse_wheel(delta) {
ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
if (!delay && !set_cycle && covers.length > 1 && t_type == "file"){
delay = true;
fdelay();
dx = 0, dy = 0;
next_image(delta);
}
if (ShiftDown) {
if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
window.SetProperty("auto cycle (sec)", cycle);
}
window.Repaint();
}
function on_mouse_leave() {
window.SetCursor(32512);
}
function fdelay(){
var delay_timer = window.SetTimeout(function() {
delay = false;
window.ClearTimeout(delay_timer);
}, 200);
}
function on_key_down(vkey) {
if (vkey == 16){
set_cycle = true;
dis_set();
window.Repaint();
}
window.Repaint();
}
function set_cycle_timer(){
cycle_timer && window.ClearInterval(cycle_timer);
cycle_timer = window.SetInterval(function() {
step = set_cycle || file_operation ? 0 : step + 1;
if (cycle > 0 && step >= cycle && t_type == "file"){
if ( covers.length > 1) next_image(1);
window.Repaint();
step = 0;
}
window.Repaint();
}, 1000 );
}
function dis_set(){
dis = 0;
dis_timer && window.ClearInterval(dis_timer);
dis_timer = window.SetInterval(function() {
if (set_cycle) {
dis++;
if(dis == 1) {
set_cycle = false;
if (cycle > 0) set_cycle_timer();
if (cycle == 0) window.ClearInterval(cycle_timer);
window.ClearInterval(dis_timer)
window.Repaint();
};
}
}, 1000 );
}
var ftimer;
function fader_timer(){
ftimer && window.ClearInterval(ftimer);
ftimer = window.SetInterval(function() {
fader = fader + fade_step;
if (fader >= 255) {
fader= 255;
window.ClearInterval(ftimer);
}
window.Repaint();
}, 50 );
}
function change_filename(){
if(!fso.FileExists(covers[covernumber]))return;
var c_file_name = get_fn(covers[covernumber]);
var nl = "\" + chr(10) + \"";
var input_box_text = nl + "Enter new file name";
var n_file_name = input_box(input_box_text, c_file_name, "Foobar 2000");
if (n_file_name) {
var dir = get_dp(covers[covernumber]);
var ext = get_fext(covers[covernumber]);
try {
fso.MoveFile( covers[covernumber], dir + "\\" + n_file_name + "." + ext );
get_covers();
for (var i = 0; i < covers.length; i++) {
if (get_fn(covers[i]) == n_file_name) {
covernumber = i;
}
}
} catch(e) {}
}
file_operation = false;
}
function delete_file(){
if(!fso.FileExists(covers[covernumber]))return;
var source = covers[covernumber];
var button_type = is_read_write(source) ? 0x3 : 0x5;
var icon_type = is_read_write(source) ? 0x20 : 0x10;
var second_button_is_default = 0x100;
var btn = WshShell.Popup("Delete file:\n\n" + source, 0, "Foobar 2000", button_type + icon_type + second_button_is_default);
switch (btn) {
case 6:
try{
fso.DeleteFile(source);
covernumber = covernumber == covers.length - 1 ? 0 : covernumber;
get_covers();
} catch(e) {}
break;
case 2:
case 7:
break;
case 4:
delete_file();
break;
}
file_operation = false;
}
function change_file_attributes(){
if(!fso.FileExists(covers[covernumber]))return;
var source = covers[covernumber];
var txt = is_read_write(source) ? "file is \nREAD-WRITE" : "file is \nREAD-ONLY";
var button_type = 0x3;
var icon_type = 0x40;
var btn = WshShell.Popup(source + "\n\n" + txt + "\nchange file attributes ?", 0, "Foobar 2000", button_type + icon_type);
switch (btn) {
case 6:
try{
var file = fso.GetFile(source);
file.Attributes = is_read_write(source) ? 33 : 32;
} catch(e) {}
break;
case 2:
case 7:
break;
}
file_operation = false;
}
function input_box(p_text, d_text, w_title){
vbe = new ActiveXObject('ScriptControl');
vbe.Language = 'VBScript';
return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}
function is_read_write(f){
if(fso.FileExists(f)) {
var file = fso.GetFile(f);
return file.Attributes == 32 ? true : false;
}
}
function on_size(){
dx = 0, dy = 0;
delta_x = 0, delta_y = 0;
ww = window.Width;
wh = window.Height;
if(g_img) next_image(covernumber);
}
function calc_img_size(img){
var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};
switch(align_mode) {
case 0: // adjust
var sw = ww / img.Width;
var sh = wh / img.Height;
var s = Math.min(sw, sh);
var x = 0;
var y = 0;
if (sw > sh) x = (ww - img.Width * s) / 2;
else if (sw < sh) y = (wh - img.height * s) / 2;
var width = img.Width * s;
var height = img.Height * s;
var cx = 0;
var cy = 0;
var cwidth = img.Width;
var cheight = img.Height;
break;
case 1: // adjust top - center
var sw = ww / img.Width;
var sh = wh / img.Height;
var s = Math.min(sw, sh);
var x = 0;
if (sw > sh) x = (ww - img.Width * s) / 2;
var y = 0;
var width = img.Width * s;
var height = img.Height * s;
var cx = 0;
var cy = 0;
var cwidth = img.Width;
var cheight = img.Height;
break;
case 2: // centre
var sr = img.Width / img.Height;
var dr = ww / wh;
if (sr < dr) {
var r = img.Width / ww;
var cheight = wh * r;
var cy = Math.round((img.Height - cheight) / 2);
if (mode_1){
cy = cy - dy;
cy = cy <= 0 ? 0 : cy;
cy = cy + wh >= img.Width ? img.Width - wh : cy;
}
var cwidth = img.Width;
var cx = 0;
} else {
var r = img.Height / wh;
var cwidth = ww * r;
var cx = Math.round((img.Width - cwidth) / 2);
if (mode_1){
cx = cx - dx;
cx = cx <= 0 ? 0 : cx;
cx = cx + ww >= img.Width ? img.Width - ww : cx;
}
var cheight = img.Height;
var cy = 0;
}
var x = 0;
var y = 0;
var width = ww;
var height = wh;
break;
case 3: // centre - top
var sr = img.Width / img.Height;
var dr = ww / wh;
if (sr < dr) {
var r = img.Width / ww;
var cheight = wh * r;
var cy = 0;
var cwidth = img.Width;
var cx = 0;
} else {
var r = img.Height / wh;
var cwidth = ww * r;
var cx = Math.round((img.Width - cwidth) / 2);
var cheight = img.Height;
var cy = 0;
}
var x = 0;
var y = 0;
var width = ww;
var height = wh;
break;
case 4: // stretch
var x = 0;
var y = 0;
var width = ww;
var height = wh;
var cx = 0;
var cy = 0;
var cwidth = img.Width;
var cheight = img.Height;
break;
}
size.x = x + p_margin;
size.y = y + p_margin;
size.width = width - p_margin * 2;
size.height = height - p_margin * 2;
size.cx = cx;
size.cy = cy;
size.cwidth = cwidth;
size.cheight = cheight;
return size;
}
function on_mouse_rbtn_up (x, y){
var _menu = window.CreatePopupMenu();
MF_STRING = t_type == "file" ? MF_ENABLED : MF_GRAYED;
_menu.AppendMenuItem(MF_STRING, 10, "External covers");
_menu.CheckMenuItem(10, set_external);
_menu.AppendMenuItem(MF_STRING, 11, "Embedded covers");
_menu.CheckMenuItem(11, set_embedded);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_STRING, 20, "Priority external");
_menu.AppendMenuItem(MF_STRING, 21, "Priority embedded");
_menu.CheckMenuRadioItem(20, 21 , set_priority + 20);
_menu.EnableMenuItem(set_priority + 20, 1);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 30, "Prefer now playing");
_menu.AppendMenuItem(MF_ENABLED, 31, "Follow selected track");
_menu.CheckMenuRadioItem(30, 31 , selection_mode + 30);
_menu.EnableMenuItem(selection_mode + 30, 1);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 40, "Info");
_menu.CheckMenuItem(40, info);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 50, "Fade effect");
_menu.CheckMenuItem(50, fade_effect);
_firstgroup = window.CreatePopupMenu();
_firstgroup.AppendTo(_menu, MF_ENABLED, "Align : " + align_mode_a[align_mode]);
_firstgroup.AppendMenuItem(MF_ENABLED, 60, align_mode_a[0]);
_firstgroup.AppendMenuItem(MF_ENABLED, 61, align_mode_a[1]);
_firstgroup.AppendMenuItem(MF_ENABLED, 62, align_mode_a[2]);
_firstgroup.AppendMenuItem(MF_ENABLED, 63, align_mode_a[3]);
_firstgroup.AppendMenuItem(MF_ENABLED, 64, align_mode_a[4]);
_firstgroup.CheckMenuRadioItem(60, 64, align_mode + 60);
_firstgroup.EnableMenuItem(align_mode + 60, 1);
MF_STRING = covers[covernumber] && typeof covers[covernumber] != 'object' && t_type == "file" ? MF_ENABLED : MF_GRAYED;
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 70, "Open folder");
_menu.AppendMenuItem(MF_STRING, 71, "Rename file");
_menu.AppendMenuItem(MF_STRING, 72, "Delete file");
_menu.AppendMenuItem(MF_STRING, 73, "Change file attributes");
if (t_type == "stream"){
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 80, "Copy filename to clipboard");
}
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
MF_STRING = mode_2 ? MF_ENABLED : MF_GRAYED;
_menu.AppendMenuItem(MF_STRING, 90, "Mode 1");
_menu.CheckMenuItem(90, mode_1);
MF_STRING = mode_1 ? MF_ENABLED : MF_GRAYED;
_menu.AppendMenuItem(MF_STRING, 91, "Mode 2");
_menu.CheckMenuItem(91, mode_2);
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 100, "Reload");
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_ENABLED, 110, "Properties");
_menu.AppendMenuItem(MF_ENABLED, 120, "Configure ...");
ret = _menu.TrackPopupMenu(x,y);
switch (ret) {
case 10:
set_external = set_external == false ? true : set_embedded == false ? true : false;
window.SetProperty("external", set_external);
covernumber = 0;
get_covers();
break;
case 11:
set_embedded = set_embedded == false ? true : set_external == false ? true : false;
window.SetProperty("embedded", set_embedded);
covernumber = 0;
get_covers();
break;
case 20:
case 21:
set_priority = ret - 20;
window.SetProperty("set_priority", set_priority);
covernumber = 0;
get_covers();
break;
case 30:
case 31:
selection_mode = ret - 30;
window.SetProperty("selection_mode", selection_mode);
on_item_focus_change();
break;
case 40:
window.SetProperty("info", !info);
info = window.GetProperty("info");
window.Repaint();
break;
case 50:
window.SetProperty("fade effect", !fade_effect);
fade_effect = window.GetProperty("fade effect");
break;
case 60:
case 61:
case 62:
case 63:
case 64:
align_mode = ret - 60;
window.SetProperty("align mode", align_mode);
dx = 0, dy = 0;
window.Repaint();
break;
case 70:
if (covers[covernumber] && typeof covers[covernumber] != 'object') WshShell.run( '"' + covers[covernumber].substring(0, covers[covernumber].lastIndexOf("\\")) + '"' );
break;
case 71:
file_operation = true;
change_filename();
break;
case 72:
file_operation = true;
delete_file();
break;
case 73:
file_operation = true;
change_file_attributes();
break;
case 80:
htmlfile.parentWindow.clipboardData.setData("text", title.replace(/[^a-zA-Z0-9а-яА-Я\s-]/g,'').replace(/\s+/g,' ').replace(/^\s+|\s+$/g,""));
break;
break;
case 90:
case 91:
window.SetProperty("Mode 1", !mode_1);
mode_1 = window.GetProperty("Mode 1");
window.SetProperty("Mode 2", !mode_1);
mode_2 = window.GetProperty("Mode 2");
covernumber = 0;
switch (t_type) {
case "file":
get_covers();
break;
case "stream":
get_logo_image();
break;
}
break;
case 100:
try {
window.Reload();
} catch(e) {};
break;
case 110:
window.ShowProperties();
break;
case 120:
window.ShowConfigure();
break;
}
_menu.Dispose();
return true;
}
function get_fnext(p) {
if (!p) return;
return p.replace(/.*\\/g,'');
}
function get_fn(p) {
if (!p) return;
return p.replace(/.*\\|\.[^.]+$/g,'')
}
function get_fext(p) {
if (!p) return;
return p.replace(/.*\./g,'');
}
function get_dp(p) {
if (!p) return;
return p.replace(/(.*)\\.*/g,'$1');
}
function clear_n(p) {
if (!p) return;
return p.replace(/[^a-zA-Zа-яА-ЯёЁ0-9]/g,'');
}
function formatFileSize(b){
if (b > 1024 * 1024){
b = Math.round(b / 1024 / 1024 * 100) / 100 + " MB"
} else if (b > 1024){
b = Math.round(b / 1024 * 100 ) / 100 + " KB"
} else {
b = b + " Bytes";
}
return b;
}
function get_logo_image() {
get_logo_files_from_dir();
logo_file_name = "";
for (var i = 0; i < logo_files.length; i++){
var file = logo_files[i].replace(/.jpg|.jpeg|.png|.gif|.bmp|.tiff/g,'').replace(/[^a-zA-Z0-9а-яА-я]/g,'');
var tfname = title.replace(/[^a-zA-Z0-9а-яА-я]/g,'');
if (tfname.toLowerCase() == file) logo_file_name = logo_files[i];
}
dx = 0, dy = 0;
window.Repaint();
if (logo_file_name != old_logo_file_name){
covers = [];
covers.push(logo_dir_name + logo_file_name);
if (mode_2){
images = []; // *************** v 2
images.push(resize_image(gdi.Image(covers[0])));
}
next_image(0);
old_logo_file_name = logo_file_name;
}
}
function get_logo_files_from_dir() {
if(!fso.FolderExists(logo_dir_name)) return;
logo_files = [];
var e = new Enumerator( fso.GetFolder(logo_dir_name).files );
while ( !e.atEnd() ) {
var name = e.item().Name;
name = name.toLowerCase();
logo_files.push(name);
e.moveNext();
}
}
function track_type(p) {
var type;
if (p.indexOf("file") >= 0){
type = "file";
} else if (p.indexOf("cdda") >= 0){
type = "cdda";
} else if (p.indexOf('://') >= 0 || p.indexOf('www') >= 0 || p.indexOf("youtube") >= 0 || p.indexOf("video") >= 0 || p.indexOf("vimeo") >= 0){
type = "stream";
} else {
type = "";
}
return type;
}
/*
UIHacks = new ActiveXObject("UIHacks");
var foo, sys;
window.SetInterval(function () {
foo = "Foo " + UIHacks.FoobarCPUUsage.toFixed(1) + " %";
sys = "Sys " + UIHacks.SystemCPUUsage.toFixed(1) + " %";
window.Repaint();
}, 1000);
*/