- Спойлер
- var DT_TOP = 0x00000000;
var DT_CENTER = 0x00000001;
var DT_VCENTER = 0x00000004;
var DT_WORDBREAK = 0x00000010;
var DT_CALCRECT = 0x00000400;
var DT_NOPREFIX = 0x00000800;
var DT_SINGLELINE = 0x00000020;
var DT_END_ELLIPSIS = 0x00008000;
var DT_WORD_ELLIPSIS = 0x00040000;
var g_text;
var g_font = gdi.Font("kroeger 05_55", 8);
var ww = 0, wh = 0;
var g_textcolor = 0x00787878;
var g_backcolor = 0xffffffff;
var g_need_calc = true;
var g_textheight = 0;
var g_offset = 0;
var g_drag = false;
var g_drag_x = 0;
var g_textwidth;
var title_tf = fb.TitleFormat("%title%");
var album_tf = fb.TitleFormat("%album%");
var artist_tf = fb.TitleFormat("%artist%");
var artist;
var title;
var album;
// START
function on_size() {
ww = window.Width;
wh = window.Height;
reset();
}
if(fb.IsPlaying) on_playback_new_track();
function on_playback_new_track(){
g_metadb = fb.GetNowPlaying();
artist = artist_tf.EvalWithMetadb(g_metadb);
title = title_tf.EvalWithMetadb(g_metadb);
album = album_tf.EvalWithMetadb(g_metadb);
}
function on_paint(gr) {
var g_text = title + " - " + artist + " - " + album;
g_textwidth = gr.CalcTextWidth(g_text, g_font);
if (g_need_calc) {
calc();
} else {
if(fb.IsPlaying) {
gr.GdiDrawText(g_text,g_font, g_textcolor, g_offset, 1, ww - g_offset, wh, DT_VCENTER | DT_END_ELLIPSIS | DT_NOPREFIX | DT_SINGLELINE);
}
}
}
function on_mouse_lbtn_down(x) {
g_drag = true;
g_drag_x = x;
}
function on_mouse_lbtn_up(x) {
g_drag = false;
g_offset=0;
window.Repaint();
}
function on_mouse_move(x) {
if (g_drag) {
applyDelta(x - g_drag_x);
g_drag_x = x;
}
}
function on_mouse_wheel() {
reset();
}
function calc() {
// Using a temp IGdiGraphics interface
var temp_bmp = gdi.CreateImage(1, 1);
var temp_gr = temp_bmp.GetGraphics();
// Calculate
arr = temp_gr.GdiDrawText(g_text, g_font, g_textcolor, 0, 0, ww, wh, DT_VCENTER | DT_SINGLELINE | DT_CALCRECT | DT_NOPREFIX).toArray();
g_offset = 0;
g_need_calc = false;
// Free the resources
temp_bmp.ReleaseGraphics(temp_gr);
temp_bmp.Dispose();
temp_gr = null;
temp_bmp = null;
window.Repaint();
}
function applyDelta(delta) {
var temp = g_offset + delta;
if ((temp <= ww / 2) && (temp >= ww / 2 - g_textwidth)) {
g_offset = temp;
window.Repaint();
}
}
function reset() {
g_need_calc = true;
g_offset = 0;
}