I'm new to jscript and after following the tutorials I built the following script. Everything displays correctly, but the loop I have keeps re-drawing the panel. Was wondering if there's a way to keep the loop from re-drawing or is there a way to just re-draw the section where time elapse and time remaining counts up and down?
Hope this makes sense Thanks in advance for any help or comments (also thanks for marc2003 for making the jscript plugin)
// ==PREPROCESSOR==
// @name "Title Header"
// @author "Chigaimaro"
// @feature "watch-metadb"
// @import "%fb2k_component_path%docs\flags.txt"
// @import "%fb2k_component_path%docs\helpers.txt"
// ==/PREPROCESSOR==
var setTitlefont = gdi.Font("Segoe UI", 16.5,0);
var artist_font = gdi.Font("Segoe UI", 13,0);
var album_font = gdi.Font("Segoe UI", 12,0);
var g_is_default_ui = window.InstanceType;
var g_font = null;
var ww = 0, wh = 0;
var g_textcolor = 0, g_textcolor_hl = 0;
var g_backcolor = 0;
var time_font = gdi.Font("Segoe UI", 18, 0);
var stat_font = gdi.Font("Segoe UI", 13, 0);
var counter = 0;
get_font();
get_colors();
function get_font() {
if (g_is_default_ui) { // DUI
g_font = window.GetFontDUI(FontTypeDUI.defaults);
} else { // CUI
g_font = window.GetFontCUI(FontTypeCUI.items);
}
}
function get_colors() {
if (g_is_default_ui) { // DUI
g_textcolor = window.GetColorDUI(ColorTypeDUI.text);
g_textcolor_hl = window.GetColorDUI(ColorTypeDUI.highlight);
g_backcolor = window.GetColorDUI(ColorTypeDUI.background);
g_selectcolor = window.GetColorDUI(ColorTypeDUI.selection);
} else { // CUI
g_textcolor = window.GetColorCUI(ColorTypeCUI.text);
g_textcolor_hl = window.GetColorCUI(ColorTypeCUI.text);
g_backcolor = window.GetColorCUI(ColorTypeCUI.background);
}
}
function on_size() {
ww = window.Width;
wh = window.Height;
}
function on_paint(gr) {
gr.FillSolidRect(0, 0, ww, wh, g_backcolor);
for(counter = 0; counter < 6; counter++){
var allMargin = ["0", "110", "220", "330", "440", "550"];
var time_tags = [fb.TitleFormat("%playback_time%").Eval(),
fb.TitleFormat("%playback_time_remaining%").Eval(),
fb.TitleFormat("%length%").Eval(),
fb.TitleFormat("$if2(%tracknumber%,'00')/$if2(%totaltracks%,'00')").Eval(),
fb.TitleFormat("$if(%discnumber%,$pad_right(%discnumber%,2),'00')$if(%totaldiscs%,'/'$pad_right(%totaldiscs%,2),)").Eval(),
fb.TitleFormat("[%replaygain_track_gain%]')").Eval()
]
var labels = ["Elapsed", "Remaining", "Length", "Track/Total", "Disc/Total", "Replaygain"];
var info_tags = [fb.TitleFormat("$info(encoding)").Eval(),
fb.TitleFormat("$info(codec)").Eval(true),
fb.TitleFormat("$if($info(bitrate),$info(bitrate)' kb/s','00 kb/s')").Eval(),
fb.TitleFormat("$channels()").Eval(true),
fb.TitleFormat("%__bitspersample%-bits").Eval(true),
fb.TitleFormat("$info(samplerate) hz").Eval()
]
tagNames = String(time_tags[counter]);
infoNames = String(info_tags[counter]);
labelNames = labels[counter];
xPosition = Number(allMargin[counter]);
gr.FillSolidRect(xPosition+5, wh - 30, 100, 20, RGBA(220,220,220,025));
gr.DrawRoundRect(xPosition+5, wh - 30, 100, 20, 4, 4, 1, g_selectcolor);
gr.FillGradRect(0,(wh / 2), ww, 2, 180, g_backcolor, (g_selectcolor + g_textcolor), focus = 0.5);
gr.GdiDrawText(labelNames, stat_font, (g_selectcolor + g_backcolor), xPosition+5, wh-75, 100, 30, DT_VCENTER| DT_CALCRECT | DT_CENTER);
if(fb.IsPlaying) {
gr.GdiDrawText(tagNames, time_font, g_textcolor_hl, xPosition+5, wh-58, 100, 30, DT_VCENTER| DT_CALCRECT | DT_CENTER);
gr.GdiDrawText(infoNames, stat_font, g_textcolor, xPosition+5, wh-35, 100, 30, DT_VCENTER| DT_CALCRECT | DT_CENTER);
gr.GdiDrawText(fb.TitleFormat("$if2(%TITLE%,'N/A')").Eval(), setTitlefont, g_textcolor, 0, 0, ww, wh, DT_WORDBREAK | DT_CALCRECT | DT_CENTER | DT_END_ELLIPSIS);
titleCount = gr.MeasureString(fb.TitleFormat("$if2(%TITLE%,'N/A')").Eval(), setTitlefont, 0, 0, ww, wh);
fb.trace(titleCount.Height);
gr.GdiDrawText(fb.TitleFormat("by: $if(%ARTIST%,%ARTIST%[' feat.'%ARTISTFEATURED%],'N/A')").Eval(), artist_font, g_textcolor_hl, 0, titleCount.Height+3, ww, wh, DT_WORDBREAK | DT_CALCRECT | DT_CENTER | DT_END_ELLIPSIS);
artistCount = gr.MeasureString(fb.TitleFormat("$if(%ARTIST%,%ARTIST%[' feat.'%ARTISTFEATURED%],'N/A')").Eval(), artist_font, 0, 0, ww, wh);
gr.GdiDrawText(fb.TitleFormat("On Album: $if(%ALBUM%,%ALBUM%$if(%RELEASE_DATE%,' ('%RELEASE_DATE%')',' ('%DATE%')'),'N/A')").Eval(), album_font, g_selectcolor, 0, (artistCount.Height + titleCount.Height + 5), ww, wh, DT_WORDBREAK | DT_CALCRECT | DT_CENTER | DT_END_ELLIPSIS);
}
}
}
function on_font_changed() {
get_font();
window.Repaint();
}
function on_colors_changed() {
get_colors();
window.Repaint();
}
function on_playback_stop(reason) {
if(reason != 2) window.Repaint();
}
function on_playback_new_track() {
window.Repaint();
}
function on_playback_time() {
window.RepaintRect(0, wh-60, 400, 25);
}